@@ -224,8 +224,10 @@ public struct Driver {
224
224
/// Should use file lists for inputs (number of inputs exceeds `fileListThreshold`).
225
225
let shouldUseInputFileList : Bool
226
226
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
229
231
230
232
/// The mode in which the compiler will execute.
231
233
@_spi ( Testing) public let compilerMode : CompilerMode
@@ -272,6 +274,35 @@ public struct Driver {
272
274
let enableCaching : Bool
273
275
let useClangIncludeTree : Bool
274
276
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
+
275
306
/// Code & data for incremental compilation. Nil if not running in incremental mode.
276
307
/// Set during planning because needs the jobs to look at outputs.
277
308
@_spi ( Testing) public private( set) var incrementalCompilationState : IncrementalCompilationState ? = nil
@@ -598,6 +629,17 @@ public struct Driver {
598
629
let cachingEnableOverride = parsedOptions. hasArgument ( . driverExplicitModuleBuild) && env. keys. contains ( " SWIFT_ENABLE_CACHING " )
599
630
self . enableCaching = parsedOptions. hasArgument ( . cacheCompileJob) || cachingEnableOverride
600
631
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
+ }
601
643
602
644
// Compute the working directory.
603
645
workingDirectory = try parsedOptions. getLastArgument ( . workingDirectory) . map { workingDirectoryArg in
@@ -678,13 +720,6 @@ public struct Driver {
678
720
679
721
self . fileListThreshold = try Self . computeFileListThreshold ( & self . parsedOptions, diagnosticsEngine: diagnosticsEngine)
680
722
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
- }
688
723
689
724
self . lto = Self . ltoKind ( & parsedOptions, diagnosticsEngine: diagnosticsEngine)
690
725
// Figure out the primary outputs from the driver.
@@ -3502,4 +3537,18 @@ extension Driver {
3502
3537
}
3503
3538
return options
3504
3539
}
3540
+
3541
+ static func computeScanningPrefixMapper( _ parsedOptions: inout ParsedOptions ) throws -> [ AbsolutePath : AbsolutePath ] {
3542
+ var mapping : [ AbsolutePath : AbsolutePath ] = [ : ]
3543
+ for opt in parsedOptions. arguments ( for: . scannerPrefixMap) {
3544
+ let pluginArg = opt. argument. asSingle. split ( separator: " = " , maxSplits: 1 )
3545
+ if pluginArg. count != 2 {
3546
+ throw Error . invalidArgumentValue ( Option . scannerPrefixMap. spelling, opt. argument. asSingle)
3547
+ }
3548
+ let key = try AbsolutePath ( validating: String ( pluginArg [ 0 ] ) )
3549
+ let value = try AbsolutePath ( validating: String ( pluginArg [ 1 ] ) )
3550
+ mapping [ key] = value
3551
+ }
3552
+ return mapping
3553
+ }
3505
3554
}
0 commit comments