Skip to content

Conversation

grynspan
Copy link
Contributor

Explanation: Add --enable-code-coverage to swift build. This flag allows enabling code coverage when splitting a test run between swift build and swift test --skip-build.
Scope: New option for the swift build command.
Original PR: #7508 (partial), #7518
Risk: Low. Behaviour is identical for swift build without the new flag, and the new flag must be explicitly specified.
Testing: Ran swift build unit tests at desk and in CI.
Reviewer: @bnbarham, @MaxDesiatov, @stmontgomery

grynspan and others added 2 commits May 15, 2024 10:51
After #7353 landed, I noticed that the build products for test targets
were not being emitted correctly. swift-testing and XCTest produce
separate build products (with distinct names) but this wasn't happening
as intended. It turns out that the changes to split `buildParameters`
into `productsBuildParameters` and `toolsBuildParameters` weren't fully
propagated to our testing infrastructure.

I also noticed `SWIFT_PM_SUPPORTS_SWIFT_TESTING` wasn't being set
correctly anymore (same root cause) although we've decided to ignore
that flag over in swift-testing anyway (see
swiftlang/swift-testing#376.)

This regression caused build failures in swift-testing (e.g.
[here](https://ci.swift.org/job/pr-swift-testing-macos/663/console))
with the telltale failure signature:

>
/Users/ec2-user/jenkins/workspace/pr-swift-testing-macos/branch-main/swift-testing/.build/x86_64-apple-macosx/debug/swift-testingPackageTests.xctest/Contents/MacOS/swift-testingPackageTests:
/Users/ec2-user/jenkins/workspace/pr-swift-testing-macos/branch-main/swift-testing/.build/x86_64-apple-macosx/debug/swift-testingPackageTests.xctest/Contents/MacOS/swift-testingPackageTests:
cannot execute binary file

Which indicates that it thinks the filename for the swift-testing build
product is the XCTest bundle's executable.

This PR plumbs through the two build parameters arguments to everywhere
in `swift test` and `swift build` that needs them and resolves the
issue.

---------

Co-authored-by: Max Desiatov <[email protected]>
This PR adds the `--enable-code-coverage` flag (from `swift test`) to
`swift build` so that code coverage can be used in a two-stage build
process (build, then execute later.)

Resolves rdar://127309781.
@grynspan grynspan added swift build Changes impacting `swift build` command-line interface swift 6.0 Related to Swift 6.0 release branch labels May 15, 2024
@grynspan grynspan requested a review from stmontgomery May 15, 2024 15:09
@grynspan grynspan self-assigned this May 15, 2024
@grynspan
Copy link
Contributor Author

@swift-ci please test

@grynspan grynspan merged commit 165f35c into release/6.0 May 15, 2024
@grynspan grynspan deleted the jgrynspan/swift-build-enable-code-coverage-6.0 branch May 15, 2024 17:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

command-line interface enhancement swift build Changes impacting `swift build` swift 6.0 Related to Swift 6.0 release branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants