23
23
#include " llvm/Support/FileSystem.h"
24
24
#include " llvm/Support/Signals.h"
25
25
26
+ // TODO: Move back into Clang header.
27
+ #include " llvm/CAS/CachingOnDiskFileSystem.h"
28
+
26
29
using namespace swift ;
27
30
28
31
using namespace clang ::tooling;
29
32
using namespace clang ::tooling::dependencies;
30
33
34
+ static std::string lookupModuleOutput (const ModuleID &MID,
35
+ ModuleOutputKind MOK) {
36
+ // Deciding the output paths is done in swift-driver.
37
+ switch (MOK) {
38
+ case ModuleOutputKind::ModuleFile:
39
+ return " <replace-me>" ;
40
+ case ModuleOutputKind::DependencyFile:
41
+ return " <replace-me>" ;
42
+ case ModuleOutputKind::DependencyTargets:
43
+ return MID.ModuleName + " -" + MID.ContextHash ;
44
+ case ModuleOutputKind::DiagnosticSerializationFile:
45
+ return " <replace-me>" ;
46
+ }
47
+ llvm_unreachable (" Fully covered switch above!" );
48
+ }
49
+
31
50
// Add search paths.
32
51
// Note: This is handled differently for the Clang importer itself, which
33
52
// adds search paths to Clang's data structures rather than to its
@@ -119,13 +138,6 @@ void ClangImporter::recordModuleDependencies(
119
138
for (const auto &fileDep : clangModuleDep.FileDeps ) {
120
139
fileDeps.push_back (fileDep.getKey ().str ());
121
140
}
122
- // Inherit all Clang driver args when creating the clang importer.
123
- ArrayRef<std::string> allArgs = Impl.ClangArgs ;
124
- ClangImporterOptions Opts;
125
-
126
- // Ensure the arguments we collected is sufficient to create a Clang
127
- // invocation.
128
- assert (createClangInvocation (this , Opts, nullptr , allArgs));
129
141
130
142
std::vector<std::string> swiftArgs;
131
143
// We are using Swift frontend mode.
@@ -142,22 +154,13 @@ void ClangImporter::recordModuleDependencies(
142
154
addClangArg (arg);
143
155
};
144
156
145
- // Add all args inherited from creating the importer.
146
- auto It = allArgs.begin ();
147
-
148
- {
149
- StringRef arg = *It;
150
- if (arg == " clang" ||
151
- arg.endswith (llvm::sys::path::get_separator ().str () + " clang" )) {
152
- // Remove the initial path to clang executable argument, to avoid
153
- // treating it as an executable input to compilation. It is not needed
154
- // because the consumer of this command-line will invoke the emit-PCM
155
- // action via swift-frontend.
156
- It += 1 ;
157
- }
158
- }
157
+ // Add args reported by the scanner.
158
+ auto It = clangModuleDep.BuildArguments .begin ();
159
+ auto ItEnd = clangModuleDep.BuildArguments .end ();
160
+ // Skip -cc1.
161
+ ++It;
159
162
160
- while (It != allArgs. end () ) {
163
+ while (It != ItEnd ) {
161
164
StringRef arg = *It;
162
165
// Remove the -target arguments because we should use the target triple
163
166
// specified with `-clang-target` on the scanner invocation, or
@@ -169,22 +172,11 @@ void ClangImporter::recordModuleDependencies(
169
172
// specified in the interface file.
170
173
It += 1 ;
171
174
} else {
172
- addClangArg (*It);
175
+ addClangFrontendArg (*It);
173
176
++ It;
174
177
}
175
178
}
176
179
177
- // Add the equivalent of the old `getAdditionalArgsWithoutModulePaths`.
178
- // TODO: Should we be passing all cc1 args (ie.
179
- // `getCanonicalCommandLineWithoutModulePaths`)?
180
- addClangFrontendArg (" -fno-implicit-modules" );
181
- addClangFrontendArg (" -emit-module" );
182
- addClangFrontendArg (Twine (" -fmodule-name=" ) + clangModuleDep.ID .ModuleName );
183
- if (clangModuleDep.IsSystem )
184
- addClangFrontendArg (" -fsystem-module" );
185
- if (clangModuleDep.BuildInvocation .getLangOpts ()->NeededByPCHOrCompilationUsesPCH )
186
- addClangFrontendArg (" -fmodule-related-to-pch" );
187
-
188
180
// If the scanner is invoked with '-clang-target', ensure this is the target
189
181
// used to build this PCM.
190
182
if (Impl.SwiftContext .LangOpts .ClangTarget .hasValue ()) {
@@ -267,7 +259,7 @@ Optional<ModuleDependencies> ClangImporter::getModuleDependencies(
267
259
268
260
auto clangDependencies = cache.getClangScannerTool ().getFullDependencies (
269
261
commandLineArgs, workingDir, cache.getAlreadySeenClangModules (),
270
- moduleName);
262
+ lookupModuleOutput, moduleName);
271
263
if (!clangDependencies) {
272
264
auto errorStr = toString (clangDependencies.takeError ());
273
265
// We ignore the "module 'foo' not found" error, the Swift dependency
@@ -322,7 +314,8 @@ bool ClangImporter::addBridgingHeaderDependencies(
322
314
ctx.SourceMgr .getFileSystem ()->getCurrentWorkingDirectory ().get ();
323
315
324
316
auto clangDependencies = cache.getClangScannerTool ().getFullDependencies (
325
- commandLineArgs, workingDir, cache.getAlreadySeenClangModules ());
317
+ commandLineArgs, workingDir, cache.getAlreadySeenClangModules (),
318
+ lookupModuleOutput);
326
319
if (!clangDependencies) {
327
320
// FIXME: Route this to a normal diagnostic.
328
321
llvm::logAllUnhandledErrors (clangDependencies.takeError (), llvm::errs ());
0 commit comments