Skip to content

[5.7] Add support for -file-prefix-map #1105

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Sources/SwiftDriver/Driver/Driver.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2027,6 +2027,14 @@ extension Driver {
}
}

for filePrefixMap in parsedOptions.arguments(for: .filePrefixMap) {
let value = filePrefixMap.argument.asSingle
let parts = value.split(separator: "=", maxSplits: 1, omittingEmptySubsequences: false)
if parts.count != 2 {
diagnosticsEngine.emit(.error_opt_invalid_mapping(option: filePrefixMap.option, value: value))
}
}

// Determine the debug level.
let level: DebugInfo.Level?
if let levelOption = parsedOptions.getLast(in: .g), levelOption.option != .gnone {
Expand Down
3 changes: 1 addition & 2 deletions Sources/SwiftDriver/Jobs/FrontendJobHelpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,8 @@ extension Driver {
try commandLine.appendLast(.accessNotesPath, from: &parsedOptions)
try commandLine.appendLast(.enableActorDataRaceChecks, .disableActorDataRaceChecks, from: &parsedOptions)
try commandLine.appendAll(.D, from: &parsedOptions)
try commandLine.appendAll(.debugPrefixMap, from: &parsedOptions)
try commandLine.appendAll(.debugPrefixMap, .coveragePrefixMap, .filePrefixMap, from: &parsedOptions)
try commandLine.appendAllArguments(.Xfrontend, from: &parsedOptions)
try commandLine.appendAll(.coveragePrefixMap, from: &parsedOptions)
try commandLine.appendLast(.warnConcurrency, from: &parsedOptions)
try commandLine.appendAll(.moduleAlias, from: &parsedOptions)
if isFrontendArgSupported(.enableBareSlashRegex) {
Expand Down
2 changes: 2 additions & 0 deletions Sources/SwiftOptions/Options.swift
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,7 @@ extension Option {
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>")
public static let FEQ: Option = Option("-F=", .joined, alias: Option.F, attributes: [.frontend, .argumentIsPath])
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.")
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")
public static let filelist: Option = Option("-filelist", .separate, attributes: [.frontend, .noDriver], helpText: "Specify source inputs in a file rather than on the command line")
public static let findUsr: Option = Option("-find-usr", .flag, attributes: [.noDriver], helpText: "Find USR for decls by given condition")
public static let findUsr_: Option = Option("--find-usr", .flag, alias: Option.findUsr, attributes: [.noDriver], helpText: "Find USR for decls by given condition")
Expand Down Expand Up @@ -1030,6 +1031,7 @@ extension Option {
Option.externalPassPipelineFilename,
Option.FEQ,
Option.fileCompilationDir,
Option.filePrefixMap,
Option.filelist,
Option.findUsr,
Option.findUsr_,
Expand Down
20 changes: 20 additions & 0 deletions Tests/SwiftDriverTests/SwiftDriverTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,26 @@ final class SwiftDriverTests: XCTestCase {
}
}

func testFilePrefixMapInvalidDiagnostic() throws {
try assertDriverDiagnostics(args: "swiftc", "-c", "foo.swift", "-o", "foo.o", "-file-prefix-map", "invalid") {
$1.expect(.error("values for '-file-prefix-map' must be in the format 'original=remapped', but 'invalid' was provided"))
}
}

func testFilePrefixMapMultiplePassToFrontend() throws {
try assertNoDriverDiagnostics(args: "swiftc", "foo.swift", "-file-prefix-map", "foo=bar", "-file-prefix-map", "dog=doggo") { driver in
let jobs = try driver.planBuild()
let commandLine = jobs[0].commandLine
let index = commandLine.firstIndex(of: .flag("-file-prefix-map"))
let lastIndex = commandLine.lastIndex(of: .flag("-file-prefix-map"))
XCTAssertNotNil(index)
XCTAssertNotNil(lastIndex)
XCTAssertNotEqual(index, lastIndex)
XCTAssertEqual(commandLine[index!.advanced(by: 1)], .flag("foo=bar"))
XCTAssertEqual(commandLine[lastIndex!.advanced(by: 1)], .flag("dog=doggo"))
}
}

func testMultiThreadingOutputs() throws {
try assertDriverDiagnostics(args: "swiftc", "-c", "foo.swift", "bar.swift", "-o", "bar.ll", "-o", "foo.ll", "-num-threads", "2", "-whole-module-optimization") {
$1.expect(.error("cannot specify -o when generating multiple output files"))
Expand Down