@@ -224,8 +224,10 @@ public struct Driver {
224224 /// Should use file lists for inputs (number of inputs exceeds `fileListThreshold`).
225225 let shouldUseInputFileList : Bool
226226
227- /// VirtualPath for shared all sources file list. `nil` if unused.
228- @_spi ( Testing) public let allSourcesFileList : VirtualPath ?
227+ /// VirtualPath for shared all sources file list. `nil` if unused. This is used as a cache for
228+ /// the file list computed during CompileJob creation and only holds valid to be query by tests
229+ /// after planning to build.
230+ @_spi ( Testing) public var allSourcesFileList : VirtualPath ? = nil
229231
230232 /// The mode in which the compiler will execute.
231233 @_spi ( Testing) public let compilerMode : CompilerMode
@@ -272,6 +274,35 @@ public struct Driver {
272274 let enableCaching : Bool
273275 let useClangIncludeTree : Bool
274276
277+ /// Scanner prefix mapping.
278+ let scannerPrefixMap : [ AbsolutePath : AbsolutePath ]
279+ let scannerPrefixMapSDK : AbsolutePath ?
280+ let scannerPrefixMapToolchain : AbsolutePath ?
281+ lazy var prefixMapping : [ ( AbsolutePath , AbsolutePath ) ] = {
282+ var mapping : [ ( AbsolutePath , AbsolutePath ) ] = scannerPrefixMap. map {
283+ return ( $0. key, $0. value)
284+ }
285+ do {
286+ guard isFrontendArgSupported ( . scannerPrefixMap) else {
287+ return [ ]
288+ }
289+ if let sdkMapping = scannerPrefixMapSDK,
290+ let sdkPath = absoluteSDKPath {
291+ mapping. append ( ( sdkPath, sdkMapping) )
292+ }
293+ if let toolchainMapping = scannerPrefixMapToolchain {
294+ let toolchainPath = try toolchain. executableDir. parentDirectory // usr
295+ . parentDirectory // toolchain
296+ mapping. append ( ( toolchainPath, toolchainMapping) )
297+ }
298+ // The mapping needs to be sorted so the mapping is determinisitic.
299+ // The sorting order is reversed so /tmp/tmp is preferred over /tmp in remapping.
300+ return mapping. sorted { $0. 0 > $1. 0 }
301+ } catch {
302+ return mapping. sorted { $0. 0 > $1. 0 }
303+ }
304+ } ( )
305+
275306 /// Code & data for incremental compilation. Nil if not running in incremental mode.
276307 /// Set during planning because needs the jobs to look at outputs.
277308 @_spi ( Testing) public private( set) var incrementalCompilationState : IncrementalCompilationState ? = nil
@@ -598,6 +629,17 @@ public struct Driver {
598629 let cachingEnableOverride = parsedOptions. hasArgument ( . driverExplicitModuleBuild) && env. keys. contains ( " SWIFT_ENABLE_CACHING " )
599630 self . enableCaching = parsedOptions. hasArgument ( . cacheCompileJob) || cachingEnableOverride
600631 self . useClangIncludeTree = enableCaching && env. keys. contains ( " SWIFT_CACHING_USE_INCLUDE_TREE " )
632+ self . scannerPrefixMap = try Self . computeScanningPrefixMapper ( & parsedOptions)
633+ if let sdkMapping = parsedOptions. getLastArgument ( . scannerPrefixMapSdk) ? . asSingle {
634+ self . scannerPrefixMapSDK = try AbsolutePath ( validating: sdkMapping)
635+ } else {
636+ self . scannerPrefixMapSDK = nil
637+ }
638+ if let toolchainMapping = parsedOptions. getLastArgument ( . scannerPrefixMapToolchain) ? . asSingle {
639+ self . scannerPrefixMapToolchain = try AbsolutePath ( validating: toolchainMapping)
640+ } else {
641+ self . scannerPrefixMapToolchain = nil
642+ }
601643
602644 // Compute the working directory.
603645 workingDirectory = try parsedOptions. getLastArgument ( . workingDirectory) . map { workingDirectoryArg in
@@ -678,13 +720,6 @@ public struct Driver {
678720
679721 self . fileListThreshold = try Self . computeFileListThreshold ( & self . parsedOptions, diagnosticsEngine: diagnosticsEngine)
680722 self . shouldUseInputFileList = inputFiles. count > fileListThreshold
681- if shouldUseInputFileList {
682- let swiftInputs = inputFiles. filter ( \. type. isPartOfSwiftCompilation)
683- self . allSourcesFileList = try VirtualPath . createUniqueFilelist ( RelativePath ( validating: " sources " ) ,
684- . list( swiftInputs. map ( \. file) ) )
685- } else {
686- self . allSourcesFileList = nil
687- }
688723
689724 self . lto = Self . ltoKind ( & parsedOptions, diagnosticsEngine: diagnosticsEngine)
690725 // Figure out the primary outputs from the driver.
@@ -3524,4 +3559,18 @@ extension Driver {
35243559 }
35253560 return options
35263561 }
3562+
3563+ static func computeScanningPrefixMapper( _ parsedOptions: inout ParsedOptions ) throws -> [ AbsolutePath : AbsolutePath ] {
3564+ var mapping : [ AbsolutePath : AbsolutePath ] = [ : ]
3565+ for opt in parsedOptions. arguments ( for: . scannerPrefixMap) {
3566+ let pluginArg = opt. argument. asSingle. split ( separator: " = " , maxSplits: 1 )
3567+ if pluginArg. count != 2 {
3568+ throw Error . invalidArgumentValue ( Option . scannerPrefixMap. spelling, opt. argument. asSingle)
3569+ }
3570+ let key = try AbsolutePath ( validating: String ( pluginArg [ 0 ] ) )
3571+ let value = try AbsolutePath ( validating: String ( pluginArg [ 1 ] ) )
3572+ mapping [ key] = value
3573+ }
3574+ return mapping
3575+ }
35273576}
0 commit comments