@@ -81,7 +81,7 @@ namespace {
81
81
class ExplicitModuleDependencyResolver {
82
82
public:
83
83
ExplicitModuleDependencyResolver (
84
- ModuleDependencyID moduleID, ModuleDependenciesCache &cache,
84
+ const ModuleDependencyID & moduleID, ModuleDependenciesCache &cache,
85
85
CompilerInstance &instance, std::optional<SwiftDependencyTracker> tracker)
86
86
: moduleID(moduleID), cache(cache), instance(instance),
87
87
resolvingDepInfo (cache.findKnownDependency(moduleID)),
@@ -169,7 +169,11 @@ class ExplicitModuleDependencyResolver {
169
169
}
170
170
}
171
171
172
- pruneUnusedVFSOverlay ();
172
+ SwiftInterfaceModuleOutputPathResolution::ResultTy swiftInterfaceOutputPath;
173
+ if (resolvingDepInfo.isSwiftInterfaceModule ()) {
174
+ pruneUnusedVFSOverlay (swiftInterfaceOutputPath);
175
+ updateSwiftInterfaceModuleOutputPath (swiftInterfaceOutputPath);
176
+ }
173
177
174
178
// Update the dependency in the cache with the modified command-line.
175
179
if (resolvingDepInfo.isSwiftInterfaceModule () ||
@@ -182,7 +186,7 @@ class ExplicitModuleDependencyResolver {
182
186
}
183
187
184
188
auto dependencyInfoCopy = resolvingDepInfo;
185
- if (auto err = finalize (dependencyInfoCopy))
189
+ if (auto err = finalize (dependencyInfoCopy, swiftInterfaceOutputPath ))
186
190
return err;
187
191
188
192
dependencyInfoCopy.setIsFinalized (true );
@@ -192,14 +196,21 @@ class ExplicitModuleDependencyResolver {
192
196
193
197
private:
194
198
// Finalize the resolving dependency info.
195
- llvm::Error finalize (ModuleDependencyInfo &depInfo) {
199
+ llvm::Error finalize (ModuleDependencyInfo &depInfo,
200
+ const SwiftInterfaceModuleOutputPathResolution::ResultTy
201
+ &swiftInterfaceModuleOutputPath) {
196
202
if (resolvingDepInfo.isSwiftPlaceholderModule ())
197
203
return llvm::Error::success ();
198
204
205
+ if (resolvingDepInfo.isSwiftInterfaceModule ())
206
+ depInfo.setOutputPathAndHash (
207
+ swiftInterfaceModuleOutputPath.outputPath .str ().str (),
208
+ swiftInterfaceModuleOutputPath.hash .str ());
209
+
199
210
// Add macros.
200
211
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 );
203
214
204
215
for (auto ¯o : depInfo.getMacroDependencies ()) {
205
216
std::string arg = macro.second .LibraryPath + " #" +
@@ -213,8 +224,7 @@ class ExplicitModuleDependencyResolver {
213
224
return err;
214
225
215
226
if (!bridgingHeaderBuildCmd.empty ())
216
- depInfo.updateBridgingHeaderCommandLine (
217
- bridgingHeaderBuildCmd);
227
+ depInfo.updateBridgingHeaderCommandLine (bridgingHeaderBuildCmd);
218
228
if (!resolvingDepInfo.isSwiftBinaryModule ()) {
219
229
depInfo.updateCommandLine (commandline);
220
230
if (auto err = updateModuleCacheKey (depInfo))
@@ -376,16 +386,18 @@ class ExplicitModuleDependencyResolver {
376
386
}
377
387
}
378
388
379
- void pruneUnusedVFSOverlay () {
389
+ void pruneUnusedVFSOverlay (
390
+ SwiftInterfaceModuleOutputPathResolution::ResultTy &outputPath) {
380
391
// Pruning of unused VFS overlay options for Clang dependencies is performed
381
392
// by the Clang dependency scanner.
382
393
if (moduleID.Kind == ModuleDependencyKind::Clang)
383
394
return ;
384
395
396
+ // Prune the command line.
385
397
std::vector<std::string> resolvedCommandLine;
386
398
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++) {
389
401
if (skip) {
390
402
skip--;
391
403
continue ;
@@ -402,7 +414,62 @@ class ExplicitModuleDependencyResolver {
402
414
}
403
415
resolvedCommandLine.push_back (*it);
404
416
}
417
+
405
418
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 ;
406
473
}
407
474
408
475
llvm::Error collectCASDependencies (ModuleDependencyInfo &dependencyInfoCopy) {
@@ -524,7 +591,7 @@ class ExplicitModuleDependencyResolver {
524
591
}
525
592
526
593
private:
527
- ModuleDependencyID moduleID;
594
+ const ModuleDependencyID & moduleID;
528
595
ModuleDependenciesCache &cache;
529
596
CompilerInstance &instance;
530
597
const ModuleDependencyInfo &resolvingDepInfo;
@@ -540,7 +607,7 @@ class ExplicitModuleDependencyResolver {
540
607
};
541
608
542
609
static llvm::Error resolveExplicitModuleInputs (
543
- ModuleDependencyID moduleID,
610
+ const ModuleDependencyID & moduleID,
544
611
const std::set<ModuleDependencyID> &dependencies,
545
612
ModuleDependenciesCache &cache, CompilerInstance &instance,
546
613
std::optional<std::set<ModuleDependencyID>> bridgingHeaderDeps,
0 commit comments