@@ -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 ,
@@ -396,18 +403,31 @@ public typealias ExternalTargetModuleDetailsMap = [ModuleDependencyId: ExternalT
396
403
/// inputs and command line flags.
397
404
public mutating func resolveMainModuleDependencies( inputs: inout [ TypedVirtualPath ] ,
398
405
commandLine: inout [ Job . ArgTemplate ] ) throws {
399
- let mainModuleId : ModuleDependencyId = . swift( dependencyGraph. mainModuleName)
400
-
401
- let mainModuleDetails = try dependencyGraph. swiftModuleDetails ( of: mainModuleId)
402
- if let additionalArgs = mainModuleDetails. commandLine {
403
- additionalArgs. forEach { commandLine. appendFlag ( $0) }
406
+ // If not previously computed, gather all dependency input files and command-line arguments
407
+ if resolvedMainModuleDependenciesArgs == nil {
408
+ var inputAdditions : [ TypedVirtualPath ] = [ ]
409
+ var commandLineAdditions : [ Job . ArgTemplate ] = [ ]
410
+ let mainModuleId : ModuleDependencyId = . swift( dependencyGraph. mainModuleName)
411
+ let mainModuleDetails = try dependencyGraph. swiftModuleDetails ( of: mainModuleId)
412
+ if let additionalArgs = mainModuleDetails. commandLine {
413
+ additionalArgs. forEach { commandLine. appendFlag ( $0) }
414
+ }
415
+ commandLineAdditions. appendFlags ( " -disable-implicit-swift-modules " ,
416
+ " -Xcc " , " -fno-implicit-modules " ,
417
+ " -Xcc " , " -fno-implicit-module-maps " )
418
+ try resolveExplicitModuleDependencies ( moduleId: mainModuleId,
419
+ inputs: & inputAdditions,
420
+ commandLine: & commandLineAdditions)
421
+ resolvedMainModuleDependenciesArgs = ResolvedModuleDependenciesCommandLineComponents (
422
+ inputs: inputAdditions,
423
+ commandLine: commandLineAdditions
424
+ )
404
425
}
405
- commandLine. appendFlags ( " -disable-implicit-swift-modules " ,
406
- " -Xcc " , " -fno-implicit-modules " ,
407
- " -Xcc " , " -fno-implicit-module-maps " )
408
- try resolveExplicitModuleDependencies ( moduleId: mainModuleId,
409
- inputs: & inputs,
410
- commandLine: & commandLine)
426
+ guard let mainModuleDependenciesArgs = resolvedMainModuleDependenciesArgs else {
427
+ fatalError ( " Failed to compute resolved explicit dependency arguments. " )
428
+ }
429
+ inputs. append ( contentsOf: mainModuleDependenciesArgs. inputs)
430
+ commandLine. append ( contentsOf: mainModuleDependenciesArgs. commandLine)
411
431
}
412
432
413
433
/// Resolve all module dependencies of the main module and add them to the lists of
0 commit comments