@@ -28,6 +28,22 @@ using namespace swift;
2828using namespace clang ::tooling;
2929using namespace clang ::tooling::dependencies;
3030
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+
3147// Add search paths.
3248// Note: This is handled differently for the Clang importer itself, which
3349// adds search paths to Clang's data structures rather than to its
@@ -119,13 +135,6 @@ void ClangImporter::recordModuleDependencies(
119135 for (const auto &fileDep : clangModuleDep.FileDeps ) {
120136 fileDeps.push_back (fileDep.getKey ().str ());
121137 }
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));
129138
130139 std::vector<std::string> swiftArgs;
131140 // We are using Swift frontend mode.
@@ -142,22 +151,13 @@ void ClangImporter::recordModuleDependencies(
142151 addClangArg (arg);
143152 };
144153
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;
147159
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) {
161161 StringRef arg = *It;
162162 // Remove the -target arguments because we should use the target triple
163163 // specified with `-clang-target` on the scanner invocation, or
@@ -169,22 +169,11 @@ void ClangImporter::recordModuleDependencies(
169169 // specified in the interface file.
170170 It += 1 ;
171171 } else {
172- addClangArg (*It);
172+ addClangFrontendArg (*It);
173173 ++ It;
174174 }
175175 }
176176
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-
188177 // If the scanner is invoked with '-clang-target', ensure this is the target
189178 // used to build this PCM.
190179 if (Impl.SwiftContext .LangOpts .ClangTarget .hasValue ()) {
@@ -267,7 +256,7 @@ Optional<ModuleDependencies> ClangImporter::getModuleDependencies(
267256
268257 auto clangDependencies = cache.getClangScannerTool ().getFullDependencies (
269258 commandLineArgs, workingDir, cache.getAlreadySeenClangModules (),
270- moduleName);
259+ lookupModuleOutput, moduleName);
271260 if (!clangDependencies) {
272261 auto errorStr = toString (clangDependencies.takeError ());
273262 // We ignore the "module 'foo' not found" error, the Swift dependency
@@ -322,7 +311,8 @@ bool ClangImporter::addBridgingHeaderDependencies(
322311 ctx.SourceMgr .getFileSystem ()->getCurrentWorkingDirectory ().get ();
323312
324313 auto clangDependencies = cache.getClangScannerTool ().getFullDependencies (
325- commandLineArgs, workingDir, cache.getAlreadySeenClangModules ());
314+ commandLineArgs, workingDir, cache.getAlreadySeenClangModules (),
315+ lookupModuleOutput);
326316 if (!clangDependencies) {
327317 // FIXME: Route this to a normal diagnostic.
328318 llvm::logAllUnhandledErrors (clangDependencies.takeError (), llvm::errs ());
0 commit comments