@@ -336,7 +336,13 @@ 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+ Self . computeBridgingPrecompiledHeader ( & parsedOptions,
341+ compilerMode: compilerMode,
342+ importedObjCHeader: importedObjCHeader,
343+ outputFileMap: outputFileMap,
344+ planner: explicitDependencyBuildPlanner)
345+ } ( )
340346
341347 /// Path to the dependencies file.
342348 let dependenciesFilePath : VirtualPath . Handle ?
@@ -801,10 +807,6 @@ public struct Driver {
801807 recordedInputModificationDates: recordedInputModificationDates)
802808
803809 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)
808810
809811 self . supportedFrontendFlags =
810812 try Self . computeSupportedCompilerArgs ( of: self . toolchain,
@@ -829,7 +831,7 @@ public struct Driver {
829831 diagnosticsEngine. emit ( . warning( " -cache-compile-job cannot be used without explicit module build, turn off caching " ) ,
830832 location: nil )
831833 self . enableCaching = false
832- } else if importedObjCHeader != nil && bridgingPrecompiledHeader == nil {
834+ } else if importedObjCHeader != nil , !parsedOptions . hasFlag ( positive : . enableBridgingPch , negative : . disableBridgingPch , default : true ) {
833835 diagnosticsEngine. emit ( . warning( " -cache-compile-job cannot be used with -disable-bridging-pch, turn off caching " ) ,
834836 location: nil )
835837 self . enableCaching = false
@@ -1779,7 +1781,7 @@ extension Driver {
17791781 /// The swift-driver doesn't have actions, so the logic here takes the jobs and tries
17801782 /// to mimic the actions that would be created by the C++ driver and
17811783 /// prints them in *hopefully* the same order.
1782- private func printActions( _ jobs: [ Job ] ) {
1784+ private mutating func printActions( _ jobs: [ Job ] ) {
17831785 defer {
17841786 stdoutStream. flush ( )
17851787 }
@@ -2872,23 +2874,29 @@ extension Driver {
28722874 static func computeBridgingPrecompiledHeader( _ parsedOptions: inout ParsedOptions ,
28732875 compilerMode: CompilerMode ,
28742876 importedObjCHeader: VirtualPath . Handle ? ,
2875- outputFileMap: OutputFileMap ? ) throws -> VirtualPath . Handle ? {
2877+ outputFileMap: OutputFileMap ? ,
2878+ planner: ExplicitDependencyBuildPlanner ? ) -> VirtualPath . Handle ? {
28762879 guard compilerMode. supportsBridgingPCH,
28772880 let input = importedObjCHeader,
28782881 parsedOptions. hasFlag ( positive: . enableBridgingPch, negative: . disableBridgingPch, default: true ) else {
28792882 return nil
28802883 }
28812884
2882- if let outputPath = try outputFileMap? . existingOutput ( inputFile: input, outputType: . pch) {
2885+ if let outputPath = try ? outputFileMap? . existingOutput ( inputFile: input, outputType: . pch) {
28832886 return outputPath
28842887 }
28852888
2886- let inputFile = VirtualPath . lookup ( input)
2887- let pchFileName = inputFile. basenameWithoutExt. appendingFileTypeExtension ( . pch)
2889+ let pchFile : String
2890+ var baseName = VirtualPath . lookup ( input) . basenameWithoutExt
2891+ if let contextHash = try ? planner? . getMainModuleContextHash ( ) {
2892+ pchFile = baseName + " - " + contextHash + " .pch "
2893+ } else {
2894+ pchFile = baseName. appendingFileTypeExtension ( . pch)
2895+ }
28882896 if let outputDirectory = parsedOptions. getLastArgument ( . pchOutputDir) ? . asSingle {
2889- return try VirtualPath ( path: outputDirectory) . appending ( component: pchFileName ) . intern ( )
2897+ return try ? VirtualPath ( path: outputDirectory) . appending ( component: pchFile ) . intern ( )
28902898 } else {
2891- return try VirtualPath . createUniqueTemporaryFile ( RelativePath ( validating: pchFileName ) ) . intern ( )
2899+ return try ? VirtualPath . temporary ( RelativePath ( validating: pchFile ) ) . intern ( )
28922900 }
28932901 }
28942902}
0 commit comments