@@ -88,15 +88,6 @@ class ExplicitModuleDependencyResolver {
8888 tracker(std::move(tracker)) {
8989 // Copy commandline.
9090 commandline = resolvingDepInfo.getCommandline ();
91-
92- if (resolvingDepInfo.isSwiftInterfaceModule ()) {
93- auto swiftTextualDeps = resolvingDepInfo.getAsSwiftInterfaceModule ();
94- auto &interfacePath = swiftTextualDeps->swiftInterfaceFile ;
95- auto SDKPath = instance.getASTContext ().SearchPathOpts .getSDKPath ();
96- outputPathResolver = std::make_unique<InterfaceModuleOutputPathResolver>(
97- moduleID.ModuleName , interfacePath, SDKPath,
98- instance.getInvocation ());
99- }
10091 }
10192
10293 llvm::Error
@@ -178,12 +169,10 @@ class ExplicitModuleDependencyResolver {
178169 }
179170 }
180171
181- // It is necessary to update the command line to take
182- // the pruned unused VFS overlay into account before remapping the
183- // command line.
172+ SwiftInterfaceModuleOutputPathResolution::ResultTy swiftInterfaceOutputPath;
184173 if (resolvingDepInfo.isSwiftInterfaceModule ()) {
185- pruneUnusedVFSOverlay ();
186- updateSwiftInterfaceModuleOutputPath ();
174+ pruneUnusedVFSOverlay (swiftInterfaceOutputPath );
175+ updateSwiftInterfaceModuleOutputPath (swiftInterfaceOutputPath );
187176 }
188177
189178 // Update the dependency in the cache with the modified command-line.
@@ -197,7 +186,7 @@ class ExplicitModuleDependencyResolver {
197186 }
198187
199188 auto dependencyInfoCopy = resolvingDepInfo;
200- if (auto err = finalize (dependencyInfoCopy))
189+ if (auto err = finalize (dependencyInfoCopy, swiftInterfaceOutputPath ))
201190 return err;
202191
203192 dependencyInfoCopy.setIsFinalized (true );
@@ -207,15 +196,16 @@ class ExplicitModuleDependencyResolver {
207196
208197private:
209198 // Finalize the resolving dependency info.
210- llvm::Error finalize (ModuleDependencyInfo &depInfo) {
199+ llvm::Error finalize (ModuleDependencyInfo &depInfo,
200+ const SwiftInterfaceModuleOutputPathResolution::ResultTy
201+ &swiftInterfaceModuleOutputPath) {
211202 if (resolvingDepInfo.isSwiftPlaceholderModule ())
212203 return llvm::Error::success ();
213204
214- if (outputPathResolver) {
215- auto resolvedPath = outputPathResolver->getOutputPath ();
216- depInfo.setOutputPathAndHash (resolvedPath.outputPath .str ().str (),
217- resolvedPath.hash .str ());
218- }
205+ if (resolvingDepInfo.isSwiftInterfaceModule ())
206+ depInfo.setOutputPathAndHash (
207+ swiftInterfaceModuleOutputPath.outputPath .str ().str (),
208+ swiftInterfaceModuleOutputPath.hash .str ());
219209
220210 // Add macros.
221211 for (auto ¯o : macros)
@@ -396,16 +386,18 @@ class ExplicitModuleDependencyResolver {
396386 }
397387 }
398388
399- void pruneUnusedVFSOverlay () {
389+ void pruneUnusedVFSOverlay (
390+ SwiftInterfaceModuleOutputPathResolution::ResultTy &outputPath) {
400391 // Pruning of unused VFS overlay options for Clang dependencies is performed
401392 // by the Clang dependency scanner.
402393 if (moduleID.Kind == ModuleDependencyKind::Clang)
403394 return ;
404395
396+ // Prune the command line.
405397 std::vector<std::string> resolvedCommandLine;
406398 size_t skip = 0 ;
407- for (auto it = commandline.begin (), end = commandline.end ();
408- it != end; it ++) {
399+ for (auto it = commandline.begin (), end = commandline.end (); it != end;
400+ it++) {
409401 if (skip) {
410402 skip--;
411403 continue ;
@@ -423,50 +415,50 @@ class ExplicitModuleDependencyResolver {
423415 resolvedCommandLine.push_back (*it);
424416 }
425417
426- // Filter the extra args that we use to calculate the hash of the module.
427- // The key assumption is that these args are clang importer args, so we
428- // do not need to check for -Xcc.
429- auto extraArgsFilter =
430- [&](InterfaceModuleOutputPathResolver::ArgListTy &args) {
431- bool skip = false ;
432- InterfaceModuleOutputPathResolver::ArgListTy newArgs;
433- for (auto it = args.begin (), end = args.end (); it != end; it++) {
434- if (skip) {
435- skip = false ;
436- continue ;
437- }
438-
439- if ((it + 1 ) != end && isVFSOverlayFlag (*it)) {
440- if (!usedVFSOverlayPaths.contains (*(it + 1 ))) {
441- skip = true ;
442- continue ;
443- }
444- }
445-
446- newArgs.push_back (*it);
447- }
448- args = std::move (newArgs);
449- return ;
450- };
418+ commandline = std::move (resolvedCommandLine);
451419
452- if (outputPathResolver)
453- outputPathResolver->pruneExtraArgs (extraArgsFilter);
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 ();
454423
455- commandline = std::move (resolvedCommandLine);
456- }
424+ SwiftInterfaceModuleOutputPathResolution::ArgListTy extraArgsList;
425+ const SwiftInterfaceModuleOutputPathResolution::ArgListTy
426+ &clangImpporterOptions =
427+ CI.getClangImporterOptions ()
428+ .getReducedExtraArgsForSwiftModuleDependency ();
457429
458- void updateSwiftInterfaceModuleOutputPath () {
459- // The command line needs update once we prune the unused VFS overlays.
460- // The update consists of two steps.
461- // 1. Obtain the output path, which includes the module hash that takes the
462- // VFS pruning into account.
463- // 2. Update `-o `'s value on the command line with the new output path.
430+ skip = 0 ;
431+ for (auto it = clangImpporterOptions.begin (),
432+ end = clangImpporterOptions.end ();
433+ it != end; it++) {
434+ if (skip) {
435+ skip = 0 ;
436+ continue ;
437+ }
438+
439+ if ((it + 1 ) != end && isVFSOverlayFlag (*it)) {
440+ if (!usedVFSOverlayPaths.contains (*(it + 1 ))) {
441+ skip = 1 ;
442+ continue ;
443+ }
444+ }
464445
465- assert (outputPathResolver &&
466- " Can only update if we have an outputPathResolver." );
467- const auto &expandedName = outputPathResolver->getOutputPath ();
446+ extraArgsList.push_back (*it);
447+ }
448+
449+ auto swiftTextualDeps = resolvingDepInfo.getAsSwiftInterfaceModule ();
450+ auto &interfacePath = swiftTextualDeps->swiftInterfaceFile ;
451+ auto sdkPath = instance.getASTContext ().SearchPathOpts .getSDKPath ();
452+ SwiftInterfaceModuleOutputPathResolution::getOutputPath (
453+ outputPath, moduleID.ModuleName , interfacePath, sdkPath, CI,
454+ extraArgsList);
455+
456+ return ;
457+ }
468458
469- StringRef outputName = expandedName.outputPath .str ();
459+ void updateSwiftInterfaceModuleOutputPath (
460+ const SwiftInterfaceModuleOutputPathResolution::ResultTy &outputPath) {
461+ StringRef outputName = outputPath.outputPath .str ();
470462
471463 bool isOutputPath = false ;
472464 for (auto &A : commandline) {
@@ -604,7 +596,6 @@ class ExplicitModuleDependencyResolver {
604596 ModuleDependenciesCache &cache;
605597 CompilerInstance &instance;
606598 const ModuleDependencyInfo &resolvingDepInfo;
607- std::unique_ptr<InterfaceModuleOutputPathResolver> outputPathResolver;
608599
609600 std::optional<SwiftDependencyTracker> tracker;
610601 std::vector<std::string> rootIDs;
0 commit comments