Skip to content

Commit e3fabb3

Browse files
authored
Merge pull request #1076 from DavidGoldman/hermeticindexstore
Add support for `-file-prefix-map`
2 parents 45ae4a6 + a44fe02 commit e3fabb3

File tree

4 files changed

+31
-2
lines changed

4 files changed

+31
-2
lines changed

Sources/SwiftDriver/Driver/Driver.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2020,6 +2020,14 @@ extension Driver {
20202020
}
20212021
}
20222022

2023+
for filePrefixMap in parsedOptions.arguments(for: .filePrefixMap) {
2024+
let value = filePrefixMap.argument.asSingle
2025+
let parts = value.split(separator: "=", maxSplits: 1, omittingEmptySubsequences: false)
2026+
if parts.count != 2 {
2027+
diagnosticsEngine.emit(.error_opt_invalid_mapping(option: filePrefixMap.option, value: value))
2028+
}
2029+
}
2030+
20232031
// Determine the debug level.
20242032
let level: DebugInfo.Level?
20252033
if let levelOption = parsedOptions.getLast(in: .g), levelOption.option != .gnone {

Sources/SwiftDriver/Jobs/FrontendJobHelpers.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,9 +201,8 @@ extension Driver {
201201
try commandLine.appendLast(.accessNotesPath, from: &parsedOptions)
202202
try commandLine.appendLast(.enableActorDataRaceChecks, .disableActorDataRaceChecks, from: &parsedOptions)
203203
try commandLine.appendAll(.D, from: &parsedOptions)
204-
try commandLine.appendAll(.debugPrefixMap, from: &parsedOptions)
204+
try commandLine.appendAll(.debugPrefixMap, .coveragePrefixMap, .filePrefixMap, from: &parsedOptions)
205205
try commandLine.appendAllArguments(.Xfrontend, from: &parsedOptions)
206-
try commandLine.appendAll(.coveragePrefixMap, from: &parsedOptions)
207206
try commandLine.appendLast(.warnConcurrency, from: &parsedOptions)
208207
try commandLine.appendAll(.moduleAlias, from: &parsedOptions)
209208
if isFrontendArgSupported(.enableBareSlashRegex) {

Sources/SwiftOptions/Options.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,7 @@ extension Option {
361361
public static let externalPassPipelineFilename: Option = Option("-external-pass-pipeline-filename", .separate, attributes: [.helpHidden, .frontend, .noDriver], metaVar: "<pass_pipeline_file>", helpText: "Use the pass pipeline defined by <pass_pipeline_file>")
362362
public static let FEQ: Option = Option("-F=", .joined, alias: Option.F, attributes: [.frontend, .argumentIsPath])
363363
public static let fileCompilationDir: Option = Option("-file-compilation-dir", .separate, attributes: [.frontend], metaVar: "<path>", helpText: "The compilation directory to embed in the debug info. Coverage mapping is not supported yet.")
364+
public static let filePrefixMap: Option = Option("-file-prefix-map", .separate, attributes: [.frontend], metaVar: "<prefix=replacement>", helpText: "Remap source paths in debug, coverage, and index info")
364365
public static let filelist: Option = Option("-filelist", .separate, attributes: [.frontend, .noDriver], helpText: "Specify source inputs in a file rather than on the command line")
365366
public static let findUsr: Option = Option("-find-usr", .flag, attributes: [.noDriver], helpText: "Find USR for decls by given condition")
366367
public static let findUsr_: Option = Option("--find-usr", .flag, alias: Option.findUsr, attributes: [.noDriver], helpText: "Find USR for decls by given condition")
@@ -1030,6 +1031,7 @@ extension Option {
10301031
Option.externalPassPipelineFilename,
10311032
Option.FEQ,
10321033
Option.fileCompilationDir,
1034+
Option.filePrefixMap,
10331035
Option.filelist,
10341036
Option.findUsr,
10351037
Option.findUsr_,

Tests/SwiftDriverTests/SwiftDriverTests.swift

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,26 @@ final class SwiftDriverTests: XCTestCase {
396396
}
397397
}
398398

399+
func testFilePrefixMapInvalidDiagnostic() throws {
400+
try assertDriverDiagnostics(args: "swiftc", "-c", "foo.swift", "-o", "foo.o", "-file-prefix-map", "invalid") {
401+
$1.expect(.error("values for '-file-prefix-map' must be in the format 'original=remapped', but 'invalid' was provided"))
402+
}
403+
}
404+
405+
func testFilePrefixMapMultiplePassToFrontend() throws {
406+
try assertNoDriverDiagnostics(args: "swiftc", "foo.swift", "-file-prefix-map", "foo=bar", "-file-prefix-map", "dog=doggo") { driver in
407+
let jobs = try driver.planBuild()
408+
let commandLine = jobs[0].commandLine
409+
let index = commandLine.firstIndex(of: .flag("-file-prefix-map"))
410+
let lastIndex = commandLine.lastIndex(of: .flag("-file-prefix-map"))
411+
XCTAssertNotNil(index)
412+
XCTAssertNotNil(lastIndex)
413+
XCTAssertNotEqual(index, lastIndex)
414+
XCTAssertEqual(commandLine[index!.advanced(by: 1)], .flag("foo=bar"))
415+
XCTAssertEqual(commandLine[lastIndex!.advanced(by: 1)], .flag("dog=doggo"))
416+
}
417+
}
418+
399419
func testMultiThreadingOutputs() throws {
400420
try assertDriverDiagnostics(args: "swiftc", "-c", "foo.swift", "bar.swift", "-o", "bar.ll", "-o", "foo.ll", "-num-threads", "2", "-whole-module-optimization") {
401421
$1.expect(.error("cannot specify -o when generating multiple output files"))

0 commit comments

Comments
 (0)