@@ -55,6 +55,13 @@ public typealias ExternalTargetModuleDetailsMap = [ModuleDependencyId: ExternalT
55
55
/// Does this compile support `.explicitInterfaceModuleBuild`
56
56
private var supportsExplicitInterfaceBuild : Bool
57
57
58
+ /// Cached command-line additions for all main module compile jobs
59
+ private struct ResolvedModuleDependenciesCommandLineComponents {
60
+ let inputs : [ TypedVirtualPath ]
61
+ let commandLine : [ Job . ArgTemplate ]
62
+ }
63
+ private var resolvedMainModuleDependenciesArgs : ResolvedModuleDependenciesCommandLineComponents ? = nil
64
+
58
65
public init ( dependencyGraph: InterModuleDependencyGraph ,
59
66
toolchain: Toolchain ,
60
67
dependencyOracle: InterModuleDependencyOracle ,
@@ -391,18 +398,31 @@ public typealias ExternalTargetModuleDetailsMap = [ModuleDependencyId: ExternalT
391
398
/// inputs and command line flags.
392
399
public mutating func resolveMainModuleDependencies( inputs: inout [ TypedVirtualPath ] ,
393
400
commandLine: inout [ Job . ArgTemplate ] ) throws {
394
- let mainModuleId : ModuleDependencyId = . swift( dependencyGraph. mainModuleName)
395
-
396
- let mainModuleDetails = try dependencyGraph. swiftModuleDetails ( of: mainModuleId)
397
- if let additionalArgs = mainModuleDetails. commandLine {
398
- additionalArgs. forEach { commandLine. appendFlag ( $0) }
401
+ // If not previously computed, gather all dependency input files and command-line arguments
402
+ if resolvedMainModuleDependenciesArgs == nil {
403
+ var inputAdditions : [ TypedVirtualPath ] = [ ]
404
+ var commandLineAdditions : [ Job . ArgTemplate ] = [ ]
405
+ let mainModuleId : ModuleDependencyId = . swift( dependencyGraph. mainModuleName)
406
+ let mainModuleDetails = try dependencyGraph. swiftModuleDetails ( of: mainModuleId)
407
+ if let additionalArgs = mainModuleDetails. commandLine {
408
+ additionalArgs. forEach { commandLine. appendFlag ( $0) }
409
+ }
410
+ commandLineAdditions. appendFlags ( " -disable-implicit-swift-modules " ,
411
+ " -Xcc " , " -fno-implicit-modules " ,
412
+ " -Xcc " , " -fno-implicit-module-maps " )
413
+ try resolveExplicitModuleDependencies ( moduleId: mainModuleId,
414
+ inputs: & inputAdditions,
415
+ commandLine: & commandLineAdditions)
416
+ resolvedMainModuleDependenciesArgs = ResolvedModuleDependenciesCommandLineComponents (
417
+ inputs: inputAdditions,
418
+ commandLine: commandLineAdditions
419
+ )
399
420
}
400
- commandLine. appendFlags ( " -disable-implicit-swift-modules " ,
401
- " -Xcc " , " -fno-implicit-modules " ,
402
- " -Xcc " , " -fno-implicit-module-maps " )
403
- try resolveExplicitModuleDependencies ( moduleId: mainModuleId,
404
- inputs: & inputs,
405
- commandLine: & commandLine)
421
+ guard let mainModuleDependenciesArgs = resolvedMainModuleDependenciesArgs else {
422
+ fatalError ( " Failed to compute resolved explicit dependency arguments. " )
423
+ }
424
+ inputs. append ( contentsOf: mainModuleDependenciesArgs. inputs)
425
+ commandLine. append ( contentsOf: mainModuleDependenciesArgs. commandLine)
406
426
}
407
427
408
428
/// Resolve all module dependencies of the main module and add them to the lists of
0 commit comments