@@ -142,8 +142,7 @@ public typealias ExternalTargetModuleDetailsMap = [ModuleDependencyId: ExternalT
142
142
// Resolve all dependency module inputs for this Swift module
143
143
try resolveExplicitModuleDependencies ( moduleId: moduleId,
144
144
inputs: & inputs,
145
- commandLine: & commandLine,
146
- isMainModule: false )
145
+ commandLine: & commandLine)
147
146
148
147
// Build the .swiftinterfaces file using a list of command line options specified in the
149
148
// `details` field.
@@ -199,8 +198,7 @@ public typealias ExternalTargetModuleDetailsMap = [ModuleDependencyId: ExternalT
199
198
200
199
// Resolve all dependency module inputs for this Clang module
201
200
try resolveExplicitModuleDependencies ( moduleId: moduleId, inputs: & inputs,
202
- commandLine: & commandLine,
203
- isMainModule: false )
201
+ commandLine: & commandLine)
204
202
205
203
let moduleMapPath = moduleDetails. moduleMapPath. path
206
204
let modulePCMPath = moduleInfo. modulePath
@@ -229,8 +227,7 @@ public typealias ExternalTargetModuleDetailsMap = [ModuleDependencyId: ExternalT
229
227
/// to use explicitly-built module dependencies.
230
228
private mutating func resolveExplicitModuleDependencies( moduleId: ModuleDependencyId ,
231
229
inputs: inout [ TypedVirtualPath ] ,
232
- commandLine: inout [ Job . ArgTemplate ] ,
233
- isMainModule: Bool ) throws {
230
+ commandLine: inout [ Job . ArgTemplate ] ) throws {
234
231
// Prohibit the frontend from implicitly building textual modules into binary modules.
235
232
var swiftDependencyArtifacts : [ SwiftModuleArtifactInfo ] = [ ]
236
233
var clangDependencyArtifacts : [ ClangModuleArtifactInfo ] = [ ]
@@ -265,24 +262,25 @@ public typealias ExternalTargetModuleDetailsMap = [ModuleDependencyId: ExternalT
265
262
266
263
// Swift Main Module dependencies are passed encoded in a JSON file as described by
267
264
// SwiftModuleArtifactInfo
268
- if isMainModule {
269
- if enableCAS {
270
- let dependencyFile =
271
- try serializeModuleDependenciesToCAS ( for: moduleId,
272
- swiftDependencyArtifacts: swiftDependencyArtifacts,
273
- clangDependencyArtifacts: clangDependencyArtifacts)
274
- commandLine. appendFlag ( " -explicit-swift-module-map-file " )
275
- commandLine. appendFlag ( dependencyFile)
276
- } else {
277
- let dependencyFile =
278
- try serializeModuleDependencies ( for: moduleId,
279
- swiftDependencyArtifacts: swiftDependencyArtifacts,
280
- clangDependencyArtifacts: clangDependencyArtifacts)
281
- commandLine. appendFlag ( " -explicit-swift-module-map-file " )
282
- commandLine. appendPath ( dependencyFile)
283
- inputs. append ( TypedVirtualPath ( file: dependencyFile. intern ( ) ,
284
- type: . jsonSwiftArtifacts) )
285
- }
265
+ guard moduleId == . swift( dependencyGraph. mainModuleName) else { return }
266
+ let dependencyFileContent =
267
+ try serializeModuleDependencies ( for: moduleId,
268
+ swiftDependencyArtifacts: swiftDependencyArtifacts,
269
+ clangDependencyArtifacts: clangDependencyArtifacts)
270
+ if enableCAS {
271
+ // When using a CAS, write JSON into CAS and pass the ID on command-line.
272
+ let casID = try swiftScanOracle. store ( data: dependencyFileContent)
273
+ commandLine. appendFlag ( " -explicit-swift-module-map-file " )
274
+ commandLine. appendFlag ( casID)
275
+ } else {
276
+ // Write JSON to a file and add the JSON artifacts to command-line and inputs.
277
+ let dependencyFile =
278
+ VirtualPath . createUniqueTemporaryFileWithKnownContents ( . init( " \( moduleId. moduleName) -dependencies.json " ) ,
279
+ dependencyFileContent)
280
+ commandLine. appendFlag ( " -explicit-swift-module-map-file " )
281
+ commandLine. appendPath ( dependencyFile)
282
+ inputs. append ( TypedVirtualPath ( file: dependencyFile. intern ( ) ,
283
+ type: . jsonSwiftArtifacts) )
286
284
}
287
285
}
288
286
@@ -386,8 +384,7 @@ public typealias ExternalTargetModuleDetailsMap = [ModuleDependencyId: ExternalT
386
384
" -Xcc " , " -fno-implicit-module-maps " )
387
385
try resolveExplicitModuleDependencies ( moduleId: mainModuleId,
388
386
inputs: & inputs,
389
- commandLine: & commandLine,
390
- isMainModule: true )
387
+ commandLine: & commandLine)
391
388
}
392
389
393
390
/// Resolve all module dependencies of the main module and add them to the lists of
@@ -433,53 +430,36 @@ public typealias ExternalTargetModuleDetailsMap = [ModuleDependencyId: ExternalT
433
430
}
434
431
435
432
// Return if depscanner provided build commands.
436
- if enableCAS , let scannerPCHArgs = mainModuleDetails. bridgingPchCommandLine {
433
+ if let scannerPCHArgs = mainModuleDetails. bridgingPchCommandLine {
437
434
scannerPCHArgs. forEach { commandLine. appendFlag ( $0) }
438
435
return
439
436
}
440
437
438
+ assert ( !enableCAS, " Caching build should always return command-line from scanner " )
441
439
// Prohibit the frontend from implicitly building textual modules into binary modules.
442
440
commandLine. appendFlags ( " -disable-implicit-swift-modules " ,
443
441
" -Xcc " , " -fno-implicit-modules " ,
444
442
" -Xcc " , " -fno-implicit-module-maps " )
445
443
446
- if enableCAS {
447
- let dependencyFile =
448
- try serializeModuleDependenciesToCAS ( for: mainModuleId,
449
- swiftDependencyArtifacts: swiftDependencyArtifacts,
450
- clangDependencyArtifacts: clangDependencyArtifacts)
451
- commandLine. appendFlag ( " -explicit-swift-module-map-file " )
452
- commandLine. appendFlag ( dependencyFile)
453
- } else {
454
- let dependencyFile =
444
+ let dependencyFileContent =
455
445
try serializeModuleDependencies ( for: mainModuleId,
456
446
swiftDependencyArtifacts: swiftDependencyArtifacts,
457
447
clangDependencyArtifacts: clangDependencyArtifacts)
458
- commandLine. appendFlag ( " -explicit-swift-module-map-file " )
459
- commandLine. appendPath ( dependencyFile)
460
- inputs. append ( TypedVirtualPath ( file: dependencyFile. intern ( ) ,
461
- type: . jsonSwiftArtifacts) )
462
- }
463
- }
464
448
465
- /// Store the output file artifacts for a given module in a JSON file, return the file's path.
466
- private func serializeModuleDependencies( for moduleId: ModuleDependencyId ,
467
- swiftDependencyArtifacts: [ SwiftModuleArtifactInfo ] ,
468
- clangDependencyArtifacts: [ ClangModuleArtifactInfo ]
469
- ) throws -> VirtualPath {
470
- let allDependencyArtifacts : [ ModuleDependencyArtifactInfo ] =
471
- swiftDependencyArtifacts. map { ModuleDependencyArtifactInfo . swift ( $0) } +
472
- clangDependencyArtifacts. map { ModuleDependencyArtifactInfo . clang ( $0) }
473
- let encoder = JSONEncoder ( )
474
- encoder. outputFormatting = [ . prettyPrinted]
475
- let contents = try encoder. encode ( allDependencyArtifacts)
476
- return VirtualPath . createUniqueTemporaryFileWithKnownContents ( . init( " \( moduleId. moduleName) -dependencies.json " ) , contents)
449
+ let dependencyFile =
450
+ VirtualPath . createUniqueTemporaryFileWithKnownContents ( . init( " \( mainModuleId. moduleName) -dependencies.json " ) ,
451
+ dependencyFileContent)
452
+ commandLine. appendFlag ( " -explicit-swift-module-map-file " )
453
+ commandLine. appendPath ( dependencyFile)
454
+ inputs. append ( TypedVirtualPath ( file: dependencyFile. intern ( ) ,
455
+ type: . jsonSwiftArtifacts) )
477
456
}
478
457
479
- private func serializeModuleDependenciesToCAS( for moduleId: ModuleDependencyId ,
458
+ /// Serialize the output file artifacts for a given module in JSON format.
459
+ private func serializeModuleDependencies( for moduleId: ModuleDependencyId ,
480
460
swiftDependencyArtifacts: [ SwiftModuleArtifactInfo ] ,
481
461
clangDependencyArtifacts: [ ClangModuleArtifactInfo ]
482
- ) throws -> String {
462
+ ) throws -> Data {
483
463
// The module dependency map in CAS needs to be stable.
484
464
// Sort the dependencies by name.
485
465
let allDependencyArtifacts : [ ModuleDependencyArtifactInfo ] =
@@ -488,8 +468,7 @@ public typealias ExternalTargetModuleDetailsMap = [ModuleDependencyId: ExternalT
488
468
let encoder = JSONEncoder ( )
489
469
// Use sorted key to ensure the order of the keys is stable.
490
470
encoder. outputFormatting = [ . prettyPrinted, . sortedKeys]
491
- let contents = try encoder. encode ( allDependencyArtifacts)
492
- return try swiftScanOracle. store ( data: contents)
471
+ return try encoder. encode ( allDependencyArtifacts)
493
472
}
494
473
495
474
private func getPCMHashParts( pcmArgs: [ String ] , contextHash: String ) -> [ String ] {
0 commit comments