@@ -336,7 +336,14 @@ public struct Driver {
336
336
let importedObjCHeader : VirtualPath . Handle ?
337
337
338
338
/// The path to the pch for the imported Objective-C header.
339
- let bridgingPrecompiledHeader : VirtualPath . Handle ?
339
+ lazy var bridgingPrecompiledHeader : VirtualPath . Handle ? = {
340
+ let contextHash = try ? explicitDependencyBuildPlanner? . getMainModuleContextHash ( )
341
+ return Self . computeBridgingPrecompiledHeader ( & parsedOptions,
342
+ compilerMode: compilerMode,
343
+ importedObjCHeader: importedObjCHeader,
344
+ outputFileMap: outputFileMap,
345
+ contextHash: contextHash)
346
+ } ( )
340
347
341
348
/// Path to the dependencies file.
342
349
let dependenciesFilePath : VirtualPath . Handle ?
@@ -801,10 +808,6 @@ public struct Driver {
801
808
recordedInputModificationDates: recordedInputModificationDates)
802
809
803
810
self . importedObjCHeader = try Self . computeImportedObjCHeader ( & parsedOptions, compilerMode: compilerMode, diagnosticEngine: diagnosticEngine)
804
- self . bridgingPrecompiledHeader = try Self . computeBridgingPrecompiledHeader ( & parsedOptions,
805
- compilerMode: compilerMode,
806
- importedObjCHeader: importedObjCHeader,
807
- outputFileMap: outputFileMap)
808
811
809
812
self . supportedFrontendFlags =
810
813
try Self . computeSupportedCompilerArgs ( of: self . toolchain,
@@ -829,7 +832,7 @@ public struct Driver {
829
832
diagnosticsEngine. emit ( . warning( " -cache-compile-job cannot be used without explicit module build, turn off caching " ) ,
830
833
location: nil )
831
834
self . enableCaching = false
832
- } else if importedObjCHeader != nil && bridgingPrecompiledHeader == nil {
835
+ } else if importedObjCHeader != nil , !parsedOptions . hasFlag ( positive : . enableBridgingPch , negative : . disableBridgingPch , default : true ) {
833
836
diagnosticsEngine. emit ( . warning( " -cache-compile-job cannot be used with -disable-bridging-pch, turn off caching " ) ,
834
837
location: nil )
835
838
self . enableCaching = false
@@ -1779,7 +1782,7 @@ extension Driver {
1779
1782
/// The swift-driver doesn't have actions, so the logic here takes the jobs and tries
1780
1783
/// to mimic the actions that would be created by the C++ driver and
1781
1784
/// prints them in *hopefully* the same order.
1782
- private func printActions( _ jobs: [ Job ] ) {
1785
+ private mutating func printActions( _ jobs: [ Job ] ) {
1783
1786
defer {
1784
1787
stdoutStream. flush ( )
1785
1788
}
@@ -2872,23 +2875,29 @@ extension Driver {
2872
2875
static func computeBridgingPrecompiledHeader( _ parsedOptions: inout ParsedOptions ,
2873
2876
compilerMode: CompilerMode ,
2874
2877
importedObjCHeader: VirtualPath . Handle ? ,
2875
- outputFileMap: OutputFileMap ? ) throws -> VirtualPath . Handle ? {
2878
+ outputFileMap: OutputFileMap ? ,
2879
+ contextHash: String ? ) -> VirtualPath . Handle ? {
2876
2880
guard compilerMode. supportsBridgingPCH,
2877
2881
let input = importedObjCHeader,
2878
2882
parsedOptions. hasFlag ( positive: . enableBridgingPch, negative: . disableBridgingPch, default: true ) else {
2879
2883
return nil
2880
2884
}
2881
2885
2882
- if let outputPath = try outputFileMap? . existingOutput ( inputFile: input, outputType: . pch) {
2886
+ if let outputPath = try ? outputFileMap? . existingOutput ( inputFile: input, outputType: . pch) {
2883
2887
return outputPath
2884
2888
}
2885
2889
2886
- let inputFile = VirtualPath . lookup ( input)
2887
- let pchFileName = inputFile. basenameWithoutExt. appendingFileTypeExtension ( . pch)
2890
+ let pchFile : String
2891
+ let baseName = VirtualPath . lookup ( input) . basenameWithoutExt
2892
+ if let hash = contextHash {
2893
+ pchFile = baseName + " - " + hash + " .pch "
2894
+ } else {
2895
+ pchFile = baseName. appendingFileTypeExtension ( . pch)
2896
+ }
2888
2897
if let outputDirectory = parsedOptions. getLastArgument ( . pchOutputDir) ? . asSingle {
2889
- return try VirtualPath ( path: outputDirectory) . appending ( component: pchFileName ) . intern ( )
2898
+ return try ? VirtualPath ( path: outputDirectory) . appending ( component: pchFile ) . intern ( )
2890
2899
} else {
2891
- return try VirtualPath . createUniqueTemporaryFile ( RelativePath ( validating: pchFileName ) ) . intern ( )
2900
+ return try ? VirtualPath . temporary ( RelativePath ( validating: pchFile ) ) . intern ( )
2892
2901
}
2893
2902
}
2894
2903
}
0 commit comments