@@ -527,7 +527,7 @@ extension Driver {
527
527
try resolveVersionedClangDependencies ( dependencyGraph: & dependencyGraph)
528
528
529
529
// Set dependency modules' paths to be saved in the module cache.
530
- try updateDependencyModulesWithModuleCachePath ( dependencyGraph: & dependencyGraph)
530
+ try resolveDependencyModulePaths ( dependencyGraph: & dependencyGraph)
531
531
532
532
// Update the dependency oracle, adding this new dependency graph to its store
533
533
try interModuleDependencyOracle. mergeModules ( from: dependencyGraph)
@@ -536,29 +536,61 @@ extension Driver {
536
536
}
537
537
538
538
/// Update the given inter-module dependency graph to set module paths to be within the module cache,
539
- /// if one is present.
540
- private mutating func updateDependencyModulesWithModuleCachePath( dependencyGraph:
541
- inout InterModuleDependencyGraph )
539
+ /// if one is present, and for Swift modules to use the context hash in the file name.
540
+ private mutating func resolveDependencyModulePaths( dependencyGraph: inout InterModuleDependencyGraph )
542
541
throws {
543
- let moduleCachePath = parsedOptions. getLastArgument ( . moduleCachePath) ? . asSingle
544
- if moduleCachePath != nil {
545
- for (moduleId, moduleInfo) in dependencyGraph. modules {
546
- // Output path on the main module is determined by the invocation arguments.
547
- guard moduleId. moduleName != dependencyGraph. mainModuleName else {
548
- continue
549
- }
550
- let modulePath = VirtualPath . lookup ( moduleInfo. modulePath. path)
551
- // Only update paths on modules which do not already specify a path beyond their module name
552
- // and a file extension.
553
- if modulePath. description == moduleId. moduleName + " .swiftmodule " ||
554
- modulePath. description == moduleId. moduleName + " .pcm " {
555
- // Use VirtualPath to get the OS-specific path separators right.
556
- let modulePathInCache =
557
- try VirtualPath ( path: moduleCachePath!)
558
- . appending ( component: modulePath. description)
559
- dependencyGraph. modules [ moduleId] !. modulePath =
560
- TextualVirtualPath ( path: modulePathInCache. intern ( ) )
561
- }
542
+ // For Swift module dependencies, set the output path to include
543
+ // the module's context hash
544
+ try resolveSwiftDependencyModuleFileNames ( dependencyGraph: & dependencyGraph)
545
+
546
+ // If a module cache path is specified, update all module dependencies
547
+ // to be output into it.
548
+ if let moduleCachePath = parsedOptions. getLastArgument ( . moduleCachePath) ? . asSingle {
549
+ try resolveDependencyModulePathsRelativeToModuleCache ( dependencyGraph: & dependencyGraph,
550
+ moduleCachePath: moduleCachePath)
551
+ }
552
+ }
553
+
554
+ /// For Swift module dependencies, set the output path to include the module's context hash
555
+ private mutating func resolveSwiftDependencyModuleFileNames( dependencyGraph: inout InterModuleDependencyGraph )
556
+ throws {
557
+ for (moduleId, moduleInfo) in dependencyGraph. modules {
558
+ // Output path on the main module is determined by the invocation arguments.
559
+ guard moduleId. moduleName != dependencyGraph. mainModuleName else {
560
+ continue
561
+ }
562
+ guard case . swift( let swiftDetails) = moduleInfo. details else {
563
+ continue
564
+ }
565
+ guard let contextHash = swiftDetails. contextHash else {
566
+ throw Driver . Error. missingContextHashOnSwiftDependency ( moduleId. moduleName)
567
+ }
568
+ let plainPath = VirtualPath . lookup ( dependencyGraph. modules [ moduleId] !. modulePath. path)
569
+ let updatedPath = plainPath. parentDirectory. appending ( component: " \( plainPath. basenameWithoutExt) - \( contextHash) . \( plainPath. extension!) " )
570
+ dependencyGraph. modules [ moduleId] !. modulePath = TextualVirtualPath ( path: updatedPath. intern ( ) )
571
+ }
572
+ }
573
+
574
+ /// Resolve all paths to dependency binary module files to be relative to the module cache path.
575
+ private mutating func resolveDependencyModulePathsRelativeToModuleCache( dependencyGraph: inout InterModuleDependencyGraph ,
576
+ moduleCachePath: String )
577
+ throws {
578
+ for (moduleId, moduleInfo) in dependencyGraph. modules {
579
+ // Output path on the main module is determined by the invocation arguments.
580
+ guard moduleId. moduleName != dependencyGraph. mainModuleName else {
581
+ continue
582
+ }
583
+ let modulePath = VirtualPath . lookup ( moduleInfo. modulePath. path)
584
+ // Only update paths on modules which do not already specify a path beyond their module name
585
+ // and a file extension.
586
+ if modulePath. description == moduleId. moduleName + " .swiftmodule " ||
587
+ modulePath. description == moduleId. moduleName + " .pcm " {
588
+ // Use VirtualPath to get the OS-specific path separators right.
589
+ let modulePathInCache =
590
+ try VirtualPath ( path: moduleCachePath)
591
+ . appending ( component: modulePath. description)
592
+ dependencyGraph. modules [ moduleId] !. modulePath =
593
+ TextualVirtualPath ( path: modulePathInCache. intern ( ) )
562
594
}
563
595
}
564
596
}
0 commit comments