@@ -81,7 +81,7 @@ namespace {
8181class ExplicitModuleDependencyResolver {
8282public:
8383 ExplicitModuleDependencyResolver (
84- ModuleDependencyID moduleID, ModuleDependenciesCache &cache,
84+ const ModuleDependencyID & moduleID, ModuleDependenciesCache &cache,
8585 CompilerInstance &instance, std::optional<SwiftDependencyTracker> tracker)
8686 : moduleID(moduleID), cache(cache), instance(instance),
8787 resolvingDepInfo (cache.findKnownDependency(moduleID)),
@@ -169,7 +169,11 @@ class ExplicitModuleDependencyResolver {
169169 }
170170 }
171171
172- pruneUnusedVFSOverlay ();
172+ SwiftInterfaceModuleOutputPathResolution::ResultTy swiftInterfaceOutputPath;
173+ if (resolvingDepInfo.isSwiftInterfaceModule ()) {
174+ pruneUnusedVFSOverlay (swiftInterfaceOutputPath);
175+ updateSwiftInterfaceModuleOutputPath (swiftInterfaceOutputPath);
176+ }
173177
174178 // Update the dependency in the cache with the modified command-line.
175179 if (resolvingDepInfo.isSwiftInterfaceModule () ||
@@ -182,7 +186,7 @@ class ExplicitModuleDependencyResolver {
182186 }
183187
184188 auto dependencyInfoCopy = resolvingDepInfo;
185- if (auto err = finalize (dependencyInfoCopy))
189+ if (auto err = finalize (dependencyInfoCopy, swiftInterfaceOutputPath ))
186190 return err;
187191
188192 dependencyInfoCopy.setIsFinalized (true );
@@ -192,14 +196,21 @@ class ExplicitModuleDependencyResolver {
192196
193197private:
194198 // Finalize the resolving dependency info.
195- llvm::Error finalize (ModuleDependencyInfo &depInfo) {
199+ llvm::Error finalize (ModuleDependencyInfo &depInfo,
200+ const SwiftInterfaceModuleOutputPathResolution::ResultTy
201+ &swiftInterfaceModuleOutputPath) {
196202 if (resolvingDepInfo.isSwiftPlaceholderModule ())
197203 return llvm::Error::success ();
198204
205+ if (resolvingDepInfo.isSwiftInterfaceModule ())
206+ depInfo.setOutputPathAndHash (
207+ swiftInterfaceModuleOutputPath.outputPath .str ().str (),
208+ swiftInterfaceModuleOutputPath.hash .str ());
209+
199210 // Add macros.
200211 for (auto ¯o : macros)
201- depInfo.addMacroDependency (
202- macro. first (), macro. second . LibraryPath , macro.second .ExecutablePath );
212+ depInfo.addMacroDependency (macro. first (), macro. second . LibraryPath ,
213+ macro.second .ExecutablePath );
203214
204215 for (auto ¯o : depInfo.getMacroDependencies ()) {
205216 std::string arg = macro.second .LibraryPath + " #" +
@@ -213,8 +224,7 @@ class ExplicitModuleDependencyResolver {
213224 return err;
214225
215226 if (!bridgingHeaderBuildCmd.empty ())
216- depInfo.updateBridgingHeaderCommandLine (
217- bridgingHeaderBuildCmd);
227+ depInfo.updateBridgingHeaderCommandLine (bridgingHeaderBuildCmd);
218228 if (!resolvingDepInfo.isSwiftBinaryModule ()) {
219229 depInfo.updateCommandLine (commandline);
220230 if (auto err = updateModuleCacheKey (depInfo))
@@ -376,16 +386,18 @@ class ExplicitModuleDependencyResolver {
376386 }
377387 }
378388
379- void pruneUnusedVFSOverlay () {
389+ void pruneUnusedVFSOverlay (
390+ SwiftInterfaceModuleOutputPathResolution::ResultTy &outputPath) {
380391 // Pruning of unused VFS overlay options for Clang dependencies is performed
381392 // by the Clang dependency scanner.
382393 if (moduleID.Kind == ModuleDependencyKind::Clang)
383394 return ;
384395
396+ // Prune the command line.
385397 std::vector<std::string> resolvedCommandLine;
386398 size_t skip = 0 ;
387- for (auto it = commandline.begin (), end = commandline.end ();
388- it != end; it ++) {
399+ for (auto it = commandline.begin (), end = commandline.end (); it != end;
400+ it++) {
389401 if (skip) {
390402 skip--;
391403 continue ;
@@ -402,7 +414,62 @@ class ExplicitModuleDependencyResolver {
402414 }
403415 resolvedCommandLine.push_back (*it);
404416 }
417+
405418 commandline = std::move (resolvedCommandLine);
419+
420+ // Prune the clang impoter options. We do not need to deal with -Xcc because
421+ // these are clang options.
422+ const auto &CI = instance.getInvocation ();
423+
424+ SwiftInterfaceModuleOutputPathResolution::ArgListTy extraArgsList;
425+ const auto &clangImporterOptions =
426+ CI.getClangImporterOptions ()
427+ .getReducedExtraArgsForSwiftModuleDependency ();
428+
429+ skip = 0 ;
430+ for (auto it = clangImporterOptions.begin (),
431+ end = clangImporterOptions.end ();
432+ it != end; it++) {
433+ if (skip) {
434+ skip = 0 ;
435+ continue ;
436+ }
437+
438+ if ((it + 1 ) != end && isVFSOverlayFlag (*it)) {
439+ if (!usedVFSOverlayPaths.contains (*(it + 1 ))) {
440+ skip = 1 ;
441+ continue ;
442+ }
443+ }
444+
445+ extraArgsList.push_back (*it);
446+ }
447+
448+ auto swiftTextualDeps = resolvingDepInfo.getAsSwiftInterfaceModule ();
449+ auto &interfacePath = swiftTextualDeps->swiftInterfaceFile ;
450+ auto sdkPath = instance.getASTContext ().SearchPathOpts .getSDKPath ();
451+ SwiftInterfaceModuleOutputPathResolution::setOutputPath (
452+ outputPath, moduleID.ModuleName , interfacePath, sdkPath, CI,
453+ extraArgsList);
454+
455+ return ;
456+ }
457+
458+ void updateSwiftInterfaceModuleOutputPath (
459+ const SwiftInterfaceModuleOutputPathResolution::ResultTy &outputPath) {
460+ StringRef outputName = outputPath.outputPath .str ();
461+
462+ bool isOutputPath = false ;
463+ for (auto &A : commandline) {
464+ if (isOutputPath) {
465+ A = outputName.str ();
466+ break ;
467+ } else if (A == " -o" ) {
468+ isOutputPath = true ;
469+ }
470+ }
471+
472+ return ;
406473 }
407474
408475 llvm::Error collectCASDependencies (ModuleDependencyInfo &dependencyInfoCopy) {
@@ -524,7 +591,7 @@ class ExplicitModuleDependencyResolver {
524591 }
525592
526593private:
527- ModuleDependencyID moduleID;
594+ const ModuleDependencyID & moduleID;
528595 ModuleDependenciesCache &cache;
529596 CompilerInstance &instance;
530597 const ModuleDependencyInfo &resolvingDepInfo;
@@ -540,7 +607,7 @@ class ExplicitModuleDependencyResolver {
540607};
541608
542609static llvm::Error resolveExplicitModuleInputs (
543- ModuleDependencyID moduleID,
610+ const ModuleDependencyID & moduleID,
544611 const std::set<ModuleDependencyID> &dependencies,
545612 ModuleDependenciesCache &cache, CompilerInstance &instance,
546613 std::optional<std::set<ModuleDependencyID>> bridgingHeaderDeps,
0 commit comments