Skip to content

Add -coverage-prefix-map arg #128

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 1 commit into from
Jun 16, 2020
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
11 changes: 11 additions & 0 deletions Sources/SwiftDriver/Driver/Driver.swift
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ public struct Driver {
self.numParallelJobs = Self.determineNumParallelJobs(&parsedOptions, diagnosticsEngine: diagnosticEngine, env: env)

try Self.validateWarningControlArgs(&parsedOptions)
Self.validateCoverageArgs(&parsedOptions, diagnosticsEngine: diagnosticEngine)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't love creating a new function for this but there wasn't another obvious place to put it

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your comment made me think about an alternative approach. validateCoverageArgs could be parseCoverageArgs that parses the args, diagnoses failures, and then returns an array of (original, remapped) pairs. Then, we render that array to arguments in addCommonFrontendOptions. What you do you think about that approach?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(I'm open to make any changes like that) Gut feeling is it might not be worth adding that much processing to these options considering we don't even handle them, it feels like it could increase the surface area for bugs around this

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. I'm fine with treating this as a "validate" call like you have it, but wanted to float the idea in case you preferred this alternative design. I don't feel strongly about it.


// Compute debug information output.
self.debugInfo = Self.computeDebugInfo(&parsedOptions, diagnosticsEngine: diagnosticEngine)
Expand Down Expand Up @@ -1512,6 +1513,16 @@ extension Driver {
throw Error.conflictingOptions(.warningsAsErrors, .suppressWarnings)
}
}

private static func validateCoverageArgs(_ parsedOptions: inout ParsedOptions, diagnosticsEngine: DiagnosticsEngine) {
for coveragePrefixMap in parsedOptions.arguments(for: .coveragePrefixMap) {
let value = coveragePrefixMap.argument.asSingle
let parts = value.split(separator: "=", maxSplits: 1, omittingEmptySubsequences: false)
if parts.count != 2 {
diagnosticsEngine.emit(.error_opt_invalid_mapping(option: coveragePrefixMap.option, value: value))
}
}
}
}

extension Triple {
Expand Down
1 change: 1 addition & 0 deletions Sources/SwiftDriver/Jobs/FrontendJobHelpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ extension Driver {
try commandLine.appendAll(.sanitizeEQ, from: &parsedOptions)
try commandLine.appendAll(.debugPrefixMap, from: &parsedOptions)
try commandLine.appendAllArguments(.Xfrontend, from: &parsedOptions)
try commandLine.appendAll(.coveragePrefixMap, from: &parsedOptions)

if let workingDirectory = workingDirectory {
// Add -Xcc -working-directory before any other -Xcc options to ensure it is
Expand Down
2 changes: 2 additions & 0 deletions Sources/SwiftOptions/Options.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ extension Option {
public static let colorDiagnostics: Option = Option("-color-diagnostics", .flag, attributes: [.frontend, .doesNotAffectIncrementalBuild], helpText: "Print diagnostics in color")
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)
public static let continueBuildingAfterErrors: Option = Option("-continue-building-after-errors", .flag, attributes: [.frontend, .doesNotAffectIncrementalBuild], helpText: "Continue building, even after errors are encountered")
public static let coveragePrefixMap: Option = Option("-coverage-prefix-map", .separate, attributes: [.frontend], helpText: "Remap source paths in coverage info")
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did this manually because I couldn't get the option generation working, but I think I got the right stuff here

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks fine. We can do a separate regeneration pass.

public static let CrossModuleOptimization: Option = Option("-cross-module-optimization", .flag, attributes: [.helpHidden, .frontend], helpText: "Perform cross-module optimization")
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)")
public static let c: Option = Option("-c", .flag, alias: Option.emitObject, attributes: [.frontend, .noInteractive], group: .modes)
Expand Down Expand Up @@ -503,6 +504,7 @@ extension Option {
Option.colorDiagnostics,
Option.compileModuleFromInterface,
Option.continueBuildingAfterErrors,
Option.coveragePrefixMap,
Option.CrossModuleOptimization,
Option.crosscheckUnqualifiedLookup,
Option.c,
Expand Down
15 changes: 15 additions & 0 deletions Tests/SwiftDriverTests/SwiftDriverTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,21 @@ final class SwiftDriverTests: XCTestCase {
}
}

func testCoverageSettings() throws {
try assertNoDriverDiagnostics(args: "swiftc", "foo.swift", "-coverage-prefix-map", "foo=bar=baz", "-coverage-prefix-map", "qux=") { driver in
let jobs = try driver.planBuild()
XCTAssertTrue(jobs[0].commandLine.contains(.flag("-coverage-prefix-map")))
XCTAssertTrue(jobs[0].commandLine.contains(.flag("foo=bar=baz")))
XCTAssertTrue(jobs[0].commandLine.contains(.flag("-coverage-prefix-map")))
XCTAssertTrue(jobs[0].commandLine.contains(.flag("qux=")))
}

try assertDriverDiagnostics(args: "swiftc", "foo.swift", "-coverage-prefix-map", "foo", "-coverage-prefix-map", "bar") {
$1.expect(.error("values for '-coverage-prefix-map' must be in the format original=remapped not 'foo'"))
$1.expect(.error("values for '-coverage-prefix-map' must be in the format original=remapped not 'bar'"))
}
}

func testModuleSettings() throws {
try assertNoDriverDiagnostics(args: "swiftc", "foo.swift") { driver in
XCTAssertNil(driver.moduleOutputInfo.output)
Expand Down