@@ -16,8 +16,9 @@ import Foundation
1616extension Driver {
1717 /// For the current moduleDependencyGraph, plan the order and generate jobs
1818 /// for explicitly building all dependency modules.
19- mutating func planExplicitModuleDependenciesCompile( dependencyGraph: InterModuleDependencyGraph )
20- throws -> [ Job ] {
19+ mutating func planExplicitModuleDependenciesCompile(
20+ dependencyGraph: InterModuleDependencyGraph
21+ ) throws -> [ Job ] {
2122 var jobs : [ Job ] = [ ]
2223 for (id, moduleInfo) in dependencyGraph. modules {
2324 // The generation of the main module file will be handled elsewhere in the driver.
@@ -26,23 +27,27 @@ extension Driver {
2627 }
2728 switch id {
2829 case . swift( let moduleName) :
29- let swiftModuleBuildJob = try genSwiftModuleDependencyBuildJob ( moduleInfo: moduleInfo,
30- moduleName: moduleName)
30+ let swiftModuleBuildJob =
31+ try genSwiftModuleDependencyBuildJob ( moduleInfo: moduleInfo,
32+ moduleName: moduleName,
33+ dependencyGraph: dependencyGraph)
3134 jobs. append ( swiftModuleBuildJob)
3235 case . clang( let moduleName) :
33- let clangModuleBuildJob = try genClangModuleDependencyBuildJob ( moduleInfo: moduleInfo,
34- moduleName: moduleName)
36+ let clangModuleBuildJob =
37+ try genClangModuleDependencyBuildJob ( moduleInfo: moduleInfo,
38+ moduleName: moduleName,
39+ dependencyGraph: dependencyGraph)
3540 jobs. append ( clangModuleBuildJob)
36-
3741 }
3842 }
3943 return jobs
4044 }
4145
4246 /// For a given swift module dependency, generate a build job
4347 mutating private func genSwiftModuleDependencyBuildJob( moduleInfo: ModuleInfo ,
44- moduleName: String ) throws -> Job {
45- // FIXIT: Needs more error handling
48+ moduleName: String ,
49+ dependencyGraph: InterModuleDependencyGraph
50+ ) throws -> Job {
4651 guard case . swift( let swiftModuleDetails) = moduleInfo. details else {
4752 throw Error . malformedModuleDependency ( moduleName, " no `details` object " )
4853 }
@@ -52,7 +57,18 @@ extension Driver {
5257 TypedVirtualPath ( file: try VirtualPath ( path: moduleInfo. modulePath) , type: . swiftModule)
5358 ]
5459 var commandLine : [ Job . ArgTemplate ] = swiftCompilerPrefixArgs. map { Job . ArgTemplate. flag ( $0) }
55- commandLine. appendFlag ( " -frontend " )
60+ // First, take the command line options provided in the dependency information
61+ swiftModuleDetails. commandLine? . forEach { commandLine. appendFlags ( $0) }
62+
63+ if ( swiftModuleDetails. commandLine == nil ||
64+ !swiftModuleDetails. commandLine!. contains ( " -frontend " ) ) {
65+ commandLine. appendFlag ( " -frontend " )
66+ }
67+
68+ try addModuleDependencies ( moduleInfo: moduleInfo,
69+ dependencyGraph: dependencyGraph,
70+ inputs: & inputs,
71+ commandLine: & commandLine)
5672
5773 // Build the .swiftinterfaces file using a list of command line options specified in the
5874 // `details` field.
@@ -62,7 +78,6 @@ extension Driver {
6278 inputs. append ( TypedVirtualPath ( file: try VirtualPath ( path: moduleInterfacePath) ,
6379 type: . swiftInterface) )
6480 try addCommonModuleOptions ( commandLine: & commandLine, outputs: & outputs)
65- swiftModuleDetails. commandLine? . forEach { commandLine. appendFlag ( $0) }
6681
6782 return Job (
6883 moduleName: moduleName,
@@ -76,7 +91,9 @@ extension Driver {
7691
7792 /// For a given clang module dependency, generate a build job
7893 mutating private func genClangModuleDependencyBuildJob( moduleInfo: ModuleInfo ,
79- moduleName: String ) throws -> Job {
94+ moduleName: String ,
95+ dependencyGraph: InterModuleDependencyGraph
96+ ) throws -> Job {
8097 // For clang modules, the Fast Dependency Scanner emits a list of source
8198 // files (with a .modulemap among them), and a list of compile command
8299 // options.
@@ -89,15 +106,27 @@ extension Driver {
89106 TypedVirtualPath ( file: try VirtualPath ( path: moduleInfo. modulePath) , type: . pcm)
90107 ]
91108 var commandLine : [ Job . ArgTemplate ] = swiftCompilerPrefixArgs. map { Job . ArgTemplate. flag ( $0) }
92- commandLine. appendFlag ( " -frontend " )
109+
110+ // First, take the command line options provided in the dependency information
111+ clangModuleDetails. commandLine? . forEach { commandLine. appendFlags ( $0) }
112+
113+ if ( clangModuleDetails. commandLine == nil ||
114+ !clangModuleDetails. commandLine!. contains ( " -frontend " ) ) {
115+ commandLine. appendFlag ( " -frontend " )
116+ }
93117 commandLine. appendFlags ( " -emit-pcm " , " -module-name " , moduleName)
94118
119+ try addModuleDependencies ( moduleInfo: moduleInfo,
120+ dependencyGraph: dependencyGraph,
121+ inputs: & inputs,
122+ commandLine: & commandLine)
123+
95124 // The only required input is the .modulemap for this module.
96- commandLine. append ( Job . ArgTemplate. path ( try VirtualPath ( path: clangModuleDetails. moduleMapPath) ) )
125+ commandLine. append ( Job . ArgTemplate. path (
126+ try VirtualPath ( path: clangModuleDetails. moduleMapPath) ) )
97127 inputs. append ( TypedVirtualPath ( file: try VirtualPath ( path: clangModuleDetails. moduleMapPath) ,
98128 type: . clangModuleMap) )
99129 try addCommonModuleOptions ( commandLine: & commandLine, outputs: & outputs)
100- clangModuleDetails. commandLine? . forEach { commandLine. appendFlags ( " -Xcc " , $0) }
101130
102131 return Job (
103132 moduleName: moduleName,
@@ -108,4 +137,24 @@ extension Driver {
108137 outputs: outputs
109138 )
110139 }
140+
141+
142+ /// For the specified module, update its command line flags and inputs
143+ /// to use explicitly-built module dependencies.
144+ private func addModuleDependencies( moduleInfo: ModuleInfo ,
145+ dependencyGraph: InterModuleDependencyGraph ,
146+ inputs: inout [ TypedVirtualPath ] ,
147+ commandLine: inout [ Job . ArgTemplate ] ) throws {
148+ // Prohibit the frontend from implicitly building textual modules into binary modules.
149+ commandLine. appendFlags ( " -disable-implicit-swift-modules " , " -Xcc " , " -Xclang " , " -Xcc " ,
150+ " -fno-implicit-modules " )
151+ for moduleId in moduleInfo. directDependencies {
152+ guard let dependencyInfo = dependencyGraph. modules [ moduleId] else {
153+ throw Error . missingModuleDependency ( moduleId. moduleName)
154+ }
155+ try addModuleAsExplicitDependency ( moduleInfo: dependencyInfo,
156+ dependencyGraph: dependencyGraph,
157+ commandLine: & commandLine, inputs: & inputs)
158+ }
159+ }
111160}
0 commit comments