@@ -296,9 +296,9 @@ public typealias ExternalTargetModuleDetailsMap = [ModuleDependencyId: ExternalT
296
296
// SwiftModuleArtifactInfo
297
297
guard moduleId == . swift( dependencyGraph. mainModuleName) else { return }
298
298
let dependencyFileContent =
299
- try serializeModuleDependencies ( for : moduleId ,
300
- swiftDependencyArtifacts : swiftDependencyArtifacts ,
301
- clangDependencyArtifacts : clangDependencyArtifacts )
299
+ try serializeModuleDependencies ( swiftDependencyArtifacts : swiftDependencyArtifacts ,
300
+ clangDependencyArtifacts : clangDependencyArtifacts ,
301
+ cachingEnabled : cas != nil )
302
302
if let cas = self . cas {
303
303
// When using a CAS, write JSON into CAS and pass the ID on command-line.
304
304
let casID = try cas. store ( data: dependencyFileContent)
@@ -534,9 +534,9 @@ public typealias ExternalTargetModuleDetailsMap = [ModuleDependencyId: ExternalT
534
534
" -Xcc " , " -fno-implicit-module-maps " )
535
535
536
536
let dependencyFileContent =
537
- try serializeModuleDependencies ( for : mainModuleId ,
538
- swiftDependencyArtifacts : swiftDependencyArtifacts ,
539
- clangDependencyArtifacts : clangDependencyArtifacts )
537
+ try serializeModuleDependencies ( swiftDependencyArtifacts : swiftDependencyArtifacts ,
538
+ clangDependencyArtifacts : clangDependencyArtifacts ,
539
+ cachingEnabled : false )
540
540
541
541
let dependencyFile =
542
542
try VirtualPath . createUniqueTemporaryFileWithKnownContents ( . init( validating: " \( mainModuleId. moduleName) -dependencies.json " ) ,
@@ -548,15 +548,43 @@ public typealias ExternalTargetModuleDetailsMap = [ModuleDependencyId: ExternalT
548
548
}
549
549
550
550
/// Serialize the output file artifacts for a given module in JSON format.
551
- private func serializeModuleDependencies( for moduleId : ModuleDependencyId ,
552
- swiftDependencyArtifacts : Set < SwiftModuleArtifactInfo > ,
553
- clangDependencyArtifacts : Set < ClangModuleArtifactInfo >
551
+ private func serializeModuleDependencies( swiftDependencyArtifacts : Set < SwiftModuleArtifactInfo > ,
552
+ clangDependencyArtifacts : Set < ClangModuleArtifactInfo > ,
553
+ cachingEnabled : Bool
554
554
) throws -> Data {
555
+ // Helper function to abstract the path.
556
+ func abstractPath( _ module: String , suffix: String ) throws -> TextualVirtualPath {
557
+ let path = try VirtualPath ( path: module + suffix)
558
+ return TextualVirtualPath ( path: path. intern ( ) )
559
+ }
555
560
// The module dependency map in CAS needs to be stable.
556
- // Sort the dependencies by name.
561
+ // For caching build, updated the dependency info to exclude paths that are compiler outputs from the mapping.
562
+ // Use abstract names and paths because caching build loads modules directly from CAS.
557
563
let allDependencyArtifacts : [ ModuleDependencyArtifactInfo ] =
558
- swiftDependencyArtifacts. sorted ( ) . map { ModuleDependencyArtifactInfo . swift ( $0) } +
559
- clangDependencyArtifacts. sorted ( ) . map { ModuleDependencyArtifactInfo . clang ( $0) }
564
+ try swiftDependencyArtifacts. sorted ( ) . map { info in
565
+ if !cachingEnabled {
566
+ return ModuleDependencyArtifactInfo . swift ( info)
567
+ }
568
+ let updatedInfo = try SwiftModuleArtifactInfo ( name: info. moduleName,
569
+ modulePath: abstractPath ( info. moduleName, suffix: " .swiftmodule " ) ,
570
+ docPath: nil ,
571
+ sourceInfoPath: nil ,
572
+ headerDependencies: info. prebuiltHeaderDependencyPaths,
573
+ isFramework: info. isFramework,
574
+ moduleCacheKey: info. moduleCacheKey)
575
+ return ModuleDependencyArtifactInfo . swift ( updatedInfo)
576
+ } +
577
+ clangDependencyArtifacts. sorted ( ) . map { info in
578
+ if !cachingEnabled {
579
+ return ModuleDependencyArtifactInfo . clang ( info)
580
+ }
581
+ let updatedInfo = try ClangModuleArtifactInfo ( name: info. moduleName,
582
+ modulePath: abstractPath ( info. moduleName, suffix: " .pcm " ) ,
583
+ moduleMapPath: info. clangModuleMapPath,
584
+ moduleCacheKey: info. clangModuleCacheKey,
585
+ isBridgingHeaderDependency: info. isBridgingHeaderDependency)
586
+ return ModuleDependencyArtifactInfo . clang ( updatedInfo)
587
+ }
560
588
let encoder = JSONEncoder ( )
561
589
// Use sorted key to ensure the order of the keys is stable.
562
590
encoder. outputFormatting = [ . prettyPrinted, . sortedKeys]
0 commit comments