Skip to content

Commit 58efe70

Browse files
committed
Add -coverage-prefix-map arg
This is analogous to this change in Driver.cpp swiftlang/swift#32175
1 parent 9b53f54 commit 58efe70

File tree

4 files changed

+29
-0
lines changed

4 files changed

+29
-0
lines changed

Sources/SwiftDriver/Driver/Driver.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,7 @@ public struct Driver {
296296
self.numParallelJobs = Self.determineNumParallelJobs(&parsedOptions, diagnosticsEngine: diagnosticEngine, env: env)
297297

298298
try Self.validateWarningControlArgs(&parsedOptions)
299+
Self.validateCoverageArgs(&parsedOptions, diagnosticsEngine: diagnosticEngine)
299300

300301
// Compute debug information output.
301302
self.debugInfo = Self.computeDebugInfo(&parsedOptions, diagnosticsEngine: diagnosticEngine)
@@ -1512,6 +1513,16 @@ extension Driver {
15121513
throw Error.conflictingOptions(.warningsAsErrors, .suppressWarnings)
15131514
}
15141515
}
1516+
1517+
private static func validateCoverageArgs(_ parsedOptions: inout ParsedOptions, diagnosticsEngine: DiagnosticsEngine) {
1518+
for coveragePrefixMap in parsedOptions.arguments(for: .coveragePrefixMap) {
1519+
let value = coveragePrefixMap.argument.asSingle
1520+
let parts = value.split(separator: "=", maxSplits: 1, omittingEmptySubsequences: false)
1521+
if parts.count != 2 {
1522+
diagnosticsEngine.emit(.error_opt_invalid_mapping(option: coveragePrefixMap.option, value: value))
1523+
}
1524+
}
1525+
}
15151526
}
15161527

15171528
extension Triple {

Sources/SwiftDriver/Jobs/FrontendJobHelpers.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ extension Driver {
170170
try commandLine.appendAll(.sanitizeEQ, from: &parsedOptions)
171171
try commandLine.appendAll(.debugPrefixMap, from: &parsedOptions)
172172
try commandLine.appendAllArguments(.Xfrontend, from: &parsedOptions)
173+
try commandLine.appendAll(.coveragePrefixMap, from: &parsedOptions)
173174

174175
if let workingDirectory = workingDirectory {
175176
// Add -Xcc -working-directory before any other -Xcc options to ensure it is

Sources/SwiftOptions/Options.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ extension Option {
3131
public static let colorDiagnostics: Option = Option("-color-diagnostics", .flag, attributes: [.frontend, .doesNotAffectIncrementalBuild], helpText: "Print diagnostics in color")
3232
public static let compileModuleFromInterface: Option = Option("-compile-module-from-interface", .flag, attributes: [.helpHidden, .frontend, .noDriver], helpText: "Treat the (single) input as a swiftinterface and produce a module", group: .modes)
3333
public static let continueBuildingAfterErrors: Option = Option("-continue-building-after-errors", .flag, attributes: [.frontend, .doesNotAffectIncrementalBuild], helpText: "Continue building, even after errors are encountered")
34+
public static let coveragePrefixMap: Option = Option("-coverage-prefix-map", .separate, attributes: [.frontend], helpText: "Remap source paths in coverage info")
3435
public static let CrossModuleOptimization: Option = Option("-cross-module-optimization", .flag, attributes: [.helpHidden, .frontend], helpText: "Perform cross-module optimization")
3536
public static let crosscheckUnqualifiedLookup: Option = Option("-crosscheck-unqualified-lookup", .flag, attributes: [.frontend, .noDriver], helpText: "Compare legacy DeclContext- to ASTScope-based unqualified name lookup (for debugging)")
3637
public static let c: Option = Option("-c", .flag, alias: Option.emitObject, attributes: [.frontend, .noInteractive], group: .modes)
@@ -503,6 +504,7 @@ extension Option {
503504
Option.colorDiagnostics,
504505
Option.compileModuleFromInterface,
505506
Option.continueBuildingAfterErrors,
507+
Option.coveragePrefixMap,
506508
Option.CrossModuleOptimization,
507509
Option.crosscheckUnqualifiedLookup,
508510
Option.c,

Tests/SwiftDriverTests/SwiftDriverTests.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,21 @@ final class SwiftDriverTests: XCTestCase {
358358
}
359359
}
360360

361+
func testCoverageSettings() throws {
362+
try assertNoDriverDiagnostics(args: "swiftc", "foo.swift", "-coverage-prefix-map", "foo=bar=baz", "-coverage-prefix-map", "qux=") { driver in
363+
let jobs = try driver.planBuild()
364+
XCTAssertTrue(jobs[0].commandLine.contains(.flag("-coverage-prefix-map")))
365+
XCTAssertTrue(jobs[0].commandLine.contains(.flag("foo=bar=baz")))
366+
XCTAssertTrue(jobs[0].commandLine.contains(.flag("-coverage-prefix-map")))
367+
XCTAssertTrue(jobs[0].commandLine.contains(.flag("qux=")))
368+
}
369+
370+
try assertDriverDiagnostics(args: "swiftc", "foo.swift", "-coverage-prefix-map", "foo", "-coverage-prefix-map", "bar") {
371+
$1.expect(.error("values for '-coverage-prefix-map' must be in the format original=remapped not 'foo'"))
372+
$1.expect(.error("values for '-coverage-prefix-map' must be in the format original=remapped not 'bar'"))
373+
}
374+
}
375+
361376
func testModuleSettings() throws {
362377
try assertNoDriverDiagnostics(args: "swiftc", "foo.swift") { driver in
363378
XCTAssertNil(driver.moduleOutputInfo.output)

0 commit comments

Comments
 (0)