@@ -32,10 +32,14 @@ public struct ExplicitModuleBuildHandler {
32
32
private let toolchain : Toolchain
33
33
34
34
/// The file system which we should interact with.
35
+ /// FIXME: Our end goal is to not have any direct filesystem manipulation in here, but that's dependent on getting the
36
+ /// dependency scanner/dependency job generation moved into a Job.
35
37
private let fileSystem : FileSystem
36
38
37
39
/// Path to the directory that will contain the temporary files.
38
40
/// e.g. Explicit Swift module artifact files
41
+ /// FIXME: Our end goal is to not have any direct filesystem manipulation in here, but that's dependent on getting the
42
+ /// dependency scanner/dependency job generation moved into a Job.
39
43
private let temporaryDirectory : AbsolutePath
40
44
41
45
public init ( dependencyGraph: InterModuleDependencyGraph , toolchain: Toolchain ,
@@ -236,43 +240,61 @@ public struct ExplicitModuleBuildHandler {
236
240
commandLine. appendFlags ( " -disable-implicit-swift-modules " , " -Xcc " , " -Xclang " , " -Xcc " ,
237
241
" -fno-implicit-modules " )
238
242
var swiftDependencyArtifacts : [ SwiftModuleArtifactInfo ] = [ ]
239
- try addModuleDependencies ( moduleId: moduleId, pcmArgs: pcmArgs, inputs: & inputs,
240
- commandLine: & commandLine,
243
+ var clangDependencyArtifacts : [ ClangModuleArtifactInfo ] = [ ]
244
+ try addModuleDependencies ( moduleId: moduleId, pcmArgs: pcmArgs,
245
+ clangDependencyArtifacts: & clangDependencyArtifacts,
241
246
swiftDependencyArtifacts: & swiftDependencyArtifacts)
242
247
248
+ // Swift Module dependencies are passed encoded in a JSON file as described by
249
+ // SwiftModuleArtifactInfo
243
250
if !swiftDependencyArtifacts. isEmpty {
244
- let dependencyFile = try serializeModuleDependencies ( for : moduleId ,
245
- dependencyArtifacts: swiftDependencyArtifacts)
251
+ let dependencyFile =
252
+ try serializeModuleDependencies ( for : moduleId , dependencyArtifacts: swiftDependencyArtifacts)
246
253
commandLine. appendFlag ( " -explicit-swift-module-map-file " )
247
254
commandLine. appendPath ( dependencyFile)
248
255
inputs. append ( TypedVirtualPath ( file: try VirtualPath ( path: dependencyFile. pathString) ,
249
256
type: . jsonSwiftArtifacts) )
250
- // Each individual moduel binary is still an "input" to ensure the build system gets the
257
+ // Each individual module binary is still an "input" to ensure the build system gets the
251
258
// order correctly.
252
259
for dependencyModule in swiftDependencyArtifacts {
253
260
inputs. append ( TypedVirtualPath ( file: try VirtualPath ( path: dependencyModule. modulePath) ,
254
261
type: . swiftModule) )
255
262
}
256
263
}
264
+ // Clang module depenencies are specified on the command line eplicitly
265
+ for moduleArtifactInfo in clangDependencyArtifacts {
266
+ let clangModulePath =
267
+ TypedVirtualPath ( file: try VirtualPath ( path: moduleArtifactInfo. modulePath) ,
268
+ type: . pcm)
269
+ let clangModuleMapPath =
270
+ TypedVirtualPath ( file: try VirtualPath ( path: moduleArtifactInfo. moduleMapPath) ,
271
+ type: . clangModuleMap)
272
+ commandLine. appendFlags ( " -Xcc " , " -Xclang " , " -Xcc " ,
273
+ " -fmodule-file= \( clangModulePath. file. description) " )
274
+ commandLine. appendFlags ( " -Xcc " , " -Xclang " , " -Xcc " ,
275
+ " -fmodule-map-file= \( clangModuleMapPath. file. description) " )
276
+ inputs. append ( clangModulePath)
277
+ inputs. append ( clangModuleMapPath)
278
+ }
257
279
}
258
280
259
281
/// Add a specific module dependency as an input and a corresponding command
260
282
/// line flag. Dispatches to clang and swift-specific variants.
261
- mutating private func addModuleDependencies( moduleId: ModuleDependencyId ,
262
- pcmArgs: [ String ] ,
263
- inputs: inout [ TypedVirtualPath ] ,
264
- commandLine: inout [ Job . ArgTemplate ] ,
283
+ mutating private func addModuleDependencies( moduleId: ModuleDependencyId , pcmArgs: [ String ] ,
284
+ clangDependencyArtifacts: inout [ ClangModuleArtifactInfo ] ,
265
285
swiftDependencyArtifacts: inout [ SwiftModuleArtifactInfo ]
266
286
) throws {
267
287
for dependencyId in try dependencyGraph. moduleInfo ( of: moduleId) . directDependencies {
268
288
switch dependencyId {
269
289
case . swift:
270
290
try addSwiftModuleDependency ( moduleId: moduleId, dependencyId: dependencyId,
271
- pcmArgs: pcmArgs, inputs: & inputs, commandLine: & commandLine,
291
+ pcmArgs: pcmArgs,
292
+ clangDependencyArtifacts: & clangDependencyArtifacts,
272
293
swiftDependencyArtifacts: & swiftDependencyArtifacts)
273
294
case . clang:
274
295
try addClangModuleDependency ( moduleId: moduleId, dependencyId: dependencyId,
275
- pcmArgs: pcmArgs, inputs: & inputs, commandLine: & commandLine,
296
+ pcmArgs: pcmArgs,
297
+ clangDependencyArtifacts: & clangDependencyArtifacts,
276
298
swiftDependencyArtifacts: & swiftDependencyArtifacts)
277
299
}
278
300
}
@@ -285,8 +307,7 @@ public struct ExplicitModuleBuildHandler {
285
307
mutating private func addSwiftModuleDependency( moduleId: ModuleDependencyId ,
286
308
dependencyId: ModuleDependencyId ,
287
309
pcmArgs: [ String ] ,
288
- inputs: inout [ TypedVirtualPath ] ,
289
- commandLine: inout [ Job . ArgTemplate ] ,
310
+ clangDependencyArtifacts: inout [ ClangModuleArtifactInfo ] ,
290
311
swiftDependencyArtifacts: inout [ SwiftModuleArtifactInfo ]
291
312
) throws {
292
313
// Generate a build job for the dependency module, if not already generated
@@ -300,15 +321,15 @@ public struct ExplicitModuleBuildHandler {
300
321
let swiftModulePath = TypedVirtualPath ( file: try VirtualPath ( path: dependencyInfo. modulePath) ,
301
322
type: . swiftModule)
302
323
303
- // Collect the requried information about this module
324
+ // Collect the required information about this module
304
325
// TODO: add .swiftdoc and .swiftsourceinfo for this module.
305
326
swiftDependencyArtifacts. append (
306
327
SwiftModuleArtifactInfo ( name: dependencyId. moduleName,
307
328
modulePath: swiftModulePath. file. description) )
308
329
309
330
// Process all transitive dependencies as direct
310
331
try addModuleDependencies ( moduleId: dependencyId, pcmArgs: pcmArgs,
311
- inputs : & inputs , commandLine : & commandLine ,
332
+ clangDependencyArtifacts : & clangDependencyArtifacts ,
312
333
swiftDependencyArtifacts: & swiftDependencyArtifacts)
313
334
}
314
335
@@ -319,8 +340,7 @@ public struct ExplicitModuleBuildHandler {
319
340
mutating private func addClangModuleDependency( moduleId: ModuleDependencyId ,
320
341
dependencyId: ModuleDependencyId ,
321
342
pcmArgs: [ String ] ,
322
- inputs: inout [ TypedVirtualPath ] ,
323
- commandLine: inout [ Job . ArgTemplate ] ,
343
+ clangDependencyArtifacts: inout [ ClangModuleArtifactInfo ] ,
324
344
swiftDependencyArtifacts: inout [ SwiftModuleArtifactInfo ]
325
345
) throws {
326
346
// Generate a build job for the dependency module at the given target, if not already generated
@@ -333,21 +353,17 @@ public struct ExplicitModuleBuildHandler {
333
353
let dependencyInfo = try dependencyGraph. moduleInfo ( of: dependencyId)
334
354
let dependencyClangModuleDetails = try dependencyGraph. clangModuleDetails ( of: dependencyId)
335
355
let clangModulePath =
336
- TypedVirtualPath ( file: try ExplicitModuleBuildHandler . targetEncodedClangModuleFilePath (
337
- for: dependencyInfo, pcmArgs: pcmArgs) , type: . pcm)
338
- let clangModuleMapPath =
339
- TypedVirtualPath ( file: try VirtualPath ( path: dependencyClangModuleDetails. moduleMapPath) ,
340
- type: . clangModuleMap)
341
- commandLine. appendFlags ( " -Xcc " , " -Xclang " , " -Xcc " ,
342
- " -fmodule-map-file= \( clangModuleMapPath. file. description) " )
343
- commandLine. appendFlags ( " -Xcc " , " -Xclang " , " -Xcc " ,
344
- " -fmodule-file= \( clangModulePath. file. description) " )
345
- inputs. append ( clangModulePath)
346
- inputs. append ( clangModuleMapPath)
356
+ try ExplicitModuleBuildHandler . targetEncodedClangModuleFilePath ( for: dependencyInfo,
357
+ pcmArgs: pcmArgs)
358
+
359
+ // Collect the requried information about this module
360
+ clangDependencyArtifacts. append (
361
+ ClangModuleArtifactInfo ( name: dependencyId. moduleName, modulePath: clangModulePath. description,
362
+ moduleMapPath: dependencyClangModuleDetails. moduleMapPath) )
347
363
348
364
// Process all transitive dependencies as direct
349
365
try addModuleDependencies ( moduleId: dependencyId, pcmArgs: pcmArgs,
350
- inputs : & inputs , commandLine : & commandLine ,
366
+ clangDependencyArtifacts : & clangDependencyArtifacts ,
351
367
swiftDependencyArtifacts: & swiftDependencyArtifacts)
352
368
}
353
369
}
0 commit comments