@@ -88,15 +88,6 @@ class ExplicitModuleDependencyResolver {
88
88
tracker(std::move(tracker)) {
89
89
// Copy commandline.
90
90
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
- }
100
91
}
101
92
102
93
llvm::Error
@@ -178,12 +169,10 @@ class ExplicitModuleDependencyResolver {
178
169
}
179
170
}
180
171
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;
184
173
if (resolvingDepInfo.isSwiftInterfaceModule ()) {
185
- pruneUnusedVFSOverlay ();
186
- updateSwiftInterfaceModuleOutputPath ();
174
+ pruneUnusedVFSOverlay (swiftInterfaceOutputPath );
175
+ updateSwiftInterfaceModuleOutputPath (swiftInterfaceOutputPath );
187
176
}
188
177
189
178
// Update the dependency in the cache with the modified command-line.
@@ -197,7 +186,7 @@ class ExplicitModuleDependencyResolver {
197
186
}
198
187
199
188
auto dependencyInfoCopy = resolvingDepInfo;
200
- if (auto err = finalize (dependencyInfoCopy))
189
+ if (auto err = finalize (dependencyInfoCopy, swiftInterfaceOutputPath ))
201
190
return err;
202
191
203
192
dependencyInfoCopy.setIsFinalized (true );
@@ -207,15 +196,16 @@ class ExplicitModuleDependencyResolver {
207
196
208
197
private:
209
198
// Finalize the resolving dependency info.
210
- llvm::Error finalize (ModuleDependencyInfo &depInfo) {
199
+ llvm::Error finalize (ModuleDependencyInfo &depInfo,
200
+ const SwiftInterfaceModuleOutputPathResolution::ResultTy
201
+ &swiftInterfaceModuleOutputPath) {
211
202
if (resolvingDepInfo.isSwiftPlaceholderModule ())
212
203
return llvm::Error::success ();
213
204
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 ());
219
209
220
210
// Add macros.
221
211
for (auto ¯o : macros)
@@ -396,16 +386,18 @@ class ExplicitModuleDependencyResolver {
396
386
}
397
387
}
398
388
399
- void pruneUnusedVFSOverlay () {
389
+ void pruneUnusedVFSOverlay (
390
+ SwiftInterfaceModuleOutputPathResolution::ResultTy &outputPath) {
400
391
// Pruning of unused VFS overlay options for Clang dependencies is performed
401
392
// by the Clang dependency scanner.
402
393
if (moduleID.Kind == ModuleDependencyKind::Clang)
403
394
return ;
404
395
396
+ // Prune the command line.
405
397
std::vector<std::string> resolvedCommandLine;
406
398
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++) {
409
401
if (skip) {
410
402
skip--;
411
403
continue ;
@@ -423,50 +415,50 @@ class ExplicitModuleDependencyResolver {
423
415
resolvedCommandLine.push_back (*it);
424
416
}
425
417
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);
451
419
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 ();
454
423
455
- commandline = std::move (resolvedCommandLine);
456
- }
424
+ SwiftInterfaceModuleOutputPathResolution::ArgListTy extraArgsList;
425
+ const SwiftInterfaceModuleOutputPathResolution::ArgListTy
426
+ &clangImpporterOptions =
427
+ CI.getClangImporterOptions ()
428
+ .getReducedExtraArgsForSwiftModuleDependency ();
457
429
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
+ }
464
445
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
+ }
468
458
469
- StringRef outputName = expandedName.outputPath .str ();
459
+ void updateSwiftInterfaceModuleOutputPath (
460
+ const SwiftInterfaceModuleOutputPathResolution::ResultTy &outputPath) {
461
+ StringRef outputName = outputPath.outputPath .str ();
470
462
471
463
bool isOutputPath = false ;
472
464
for (auto &A : commandline) {
@@ -604,7 +596,6 @@ class ExplicitModuleDependencyResolver {
604
596
ModuleDependenciesCache &cache;
605
597
CompilerInstance &instance;
606
598
const ModuleDependencyInfo &resolvingDepInfo;
607
- std::unique_ptr<InterfaceModuleOutputPathResolver> outputPathResolver;
608
599
609
600
std::optional<SwiftDependencyTracker> tracker;
610
601
std::vector<std::string> rootIDs;
0 commit comments