@@ -336,7 +336,14 @@ public struct Driver {
336336 let importedObjCHeader : VirtualPath . Handle ?
337337
338338 /// 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+ } ( )
340347
341348 /// Path to the dependencies file.
342349 let dependenciesFilePath : VirtualPath . Handle ?
@@ -801,10 +808,6 @@ public struct Driver {
801808 recordedInputModificationDates: recordedInputModificationDates)
802809
803810 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)
808811
809812 self . supportedFrontendFlags =
810813 try Self . computeSupportedCompilerArgs ( of: self . toolchain,
@@ -829,7 +832,7 @@ public struct Driver {
829832 diagnosticsEngine. emit ( . warning( " -cache-compile-job cannot be used without explicit module build, turn off caching " ) ,
830833 location: nil )
831834 self . enableCaching = false
832- } else if importedObjCHeader != nil && bridgingPrecompiledHeader == nil {
835+ } else if importedObjCHeader != nil , !parsedOptions . hasFlag ( positive : . enableBridgingPch , negative : . disableBridgingPch , default : true ) {
833836 diagnosticsEngine. emit ( . warning( " -cache-compile-job cannot be used with -disable-bridging-pch, turn off caching " ) ,
834837 location: nil )
835838 self . enableCaching = false
@@ -1779,7 +1782,7 @@ extension Driver {
17791782 /// The swift-driver doesn't have actions, so the logic here takes the jobs and tries
17801783 /// to mimic the actions that would be created by the C++ driver and
17811784 /// prints them in *hopefully* the same order.
1782- private func printActions( _ jobs: [ Job ] ) {
1785+ private mutating func printActions( _ jobs: [ Job ] ) {
17831786 defer {
17841787 stdoutStream. flush ( )
17851788 }
@@ -2872,23 +2875,29 @@ extension Driver {
28722875 static func computeBridgingPrecompiledHeader( _ parsedOptions: inout ParsedOptions ,
28732876 compilerMode: CompilerMode ,
28742877 importedObjCHeader: VirtualPath . Handle ? ,
2875- outputFileMap: OutputFileMap ? ) throws -> VirtualPath . Handle ? {
2878+ outputFileMap: OutputFileMap ? ,
2879+ contextHash: String ? ) -> VirtualPath . Handle ? {
28762880 guard compilerMode. supportsBridgingPCH,
28772881 let input = importedObjCHeader,
28782882 parsedOptions. hasFlag ( positive: . enableBridgingPch, negative: . disableBridgingPch, default: true ) else {
28792883 return nil
28802884 }
28812885
2882- if let outputPath = try outputFileMap? . existingOutput ( inputFile: input, outputType: . pch) {
2886+ if let outputPath = try ? outputFileMap? . existingOutput ( inputFile: input, outputType: . pch) {
28832887 return outputPath
28842888 }
28852889
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+ }
28882897 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 ( )
28902899 } else {
2891- return try VirtualPath . createUniqueTemporaryFile ( RelativePath ( validating: pchFileName ) ) . intern ( )
2900+ return try ? VirtualPath . temporary ( RelativePath ( validating: pchFile ) ) . intern ( )
28922901 }
28932902 }
28942903}
0 commit comments