@@ -28,6 +28,22 @@ using namespace swift;
28
28
using namespace clang ::tooling;
29
29
using namespace clang ::tooling::dependencies;
30
30
31
+ static std::string lookupModuleOutput (const ModuleID &MID,
32
+ ModuleOutputKind MOK) {
33
+ // Deciding the output paths is done in swift-driver.
34
+ switch (MOK) {
35
+ case ModuleOutputKind::ModuleFile:
36
+ return " <replace-me>" ;
37
+ case ModuleOutputKind::DependencyFile:
38
+ return " <replace-me>" ;
39
+ case ModuleOutputKind::DependencyTargets:
40
+ return MID.ModuleName + " -" + MID.ContextHash ;
41
+ case ModuleOutputKind::DiagnosticSerializationFile:
42
+ return " <replace-me>" ;
43
+ }
44
+ llvm_unreachable (" Fully covered switch above!" );
45
+ }
46
+
31
47
// Add search paths.
32
48
// Note: This is handled differently for the Clang importer itself, which
33
49
// adds search paths to Clang's data structures rather than to its
@@ -119,13 +135,6 @@ void ClangImporter::recordModuleDependencies(
119
135
for (const auto &fileDep : clangModuleDep.FileDeps ) {
120
136
fileDeps.push_back (fileDep.getKey ().str ());
121
137
}
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
138
130
139
std::vector<std::string> swiftArgs;
131
140
// We are using Swift frontend mode.
@@ -142,22 +151,13 @@ void ClangImporter::recordModuleDependencies(
142
151
addClangArg (arg);
143
152
};
144
153
145
- // Add all args inherited from creating the importer.
146
- auto It = allArgs.begin ();
154
+ // Add args reported by the scanner.
155
+ auto It = clangModuleDep.BuildArguments .begin ();
156
+ auto ItEnd = clangModuleDep.BuildArguments .end ();
157
+ // Skip -cc1.
158
+ ++It;
147
159
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
- }
159
-
160
- while (It != allArgs.end ()) {
160
+ while (It != ItEnd) {
161
161
StringRef arg = *It;
162
162
// Remove the -target arguments because we should use the target triple
163
163
// specified with `-clang-target` on the scanner invocation, or
@@ -169,22 +169,11 @@ void ClangImporter::recordModuleDependencies(
169
169
// specified in the interface file.
170
170
It += 1 ;
171
171
} else {
172
- addClangArg (*It);
172
+ addClangFrontendArg (*It);
173
173
++ It;
174
174
}
175
175
}
176
176
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
177
// If the scanner is invoked with '-clang-target', ensure this is the target
189
178
// used to build this PCM.
190
179
if (Impl.SwiftContext .LangOpts .ClangTarget .hasValue ()) {
@@ -267,7 +256,7 @@ Optional<ModuleDependencies> ClangImporter::getModuleDependencies(
267
256
268
257
auto clangDependencies = cache.getClangScannerTool ().getFullDependencies (
269
258
commandLineArgs, workingDir, cache.getAlreadySeenClangModules (),
270
- moduleName);
259
+ lookupModuleOutput, moduleName);
271
260
if (!clangDependencies) {
272
261
auto errorStr = toString (clangDependencies.takeError ());
273
262
// We ignore the "module 'foo' not found" error, the Swift dependency
@@ -322,7 +311,8 @@ bool ClangImporter::addBridgingHeaderDependencies(
322
311
ctx.SourceMgr .getFileSystem ()->getCurrentWorkingDirectory ().get ();
323
312
324
313
auto clangDependencies = cache.getClangScannerTool ().getFullDependencies (
325
- commandLineArgs, workingDir, cache.getAlreadySeenClangModules ());
314
+ commandLineArgs, workingDir, cache.getAlreadySeenClangModules (),
315
+ lookupModuleOutput);
326
316
if (!clangDependencies) {
327
317
// FIXME: Route this to a normal diagnostic.
328
318
llvm::logAllUnhandledErrors (clangDependencies.takeError (), llvm::errs ());
0 commit comments