Skip to content

Commit

Permalink
Fix test targets that depend on macros and swift-testing (apple#7508)
Browse files Browse the repository at this point in the history
After apple#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
apple/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 <m_desiatov@apple.com>
  • Loading branch information
2 people authored and furby-tm committed May 15, 2024
1 parent e900f41 commit c41425f
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 55 deletions.
23 changes: 17 additions & 6 deletions Sources/Commands/SwiftBuildCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,7 @@ package struct SwiftBuildCommand: AsyncSwiftCommand {
throw ExitCode.failure
}
if case .allIncludingTests = subset {
var buildParameters = try swiftCommandState.productsBuildParameters
for library in try options.testLibraryOptions.enabledTestingLibraries(swiftCommandState: swiftCommandState) {
func updateTestingParameters(of buildParameters: inout BuildParameters, library: BuildParameters.Testing.Library) {
buildParameters.testingParameters = .init(
configuration: buildParameters.configuration,
targetTriple: buildParameters.triple,
Expand All @@ -161,18 +160,30 @@ package struct SwiftBuildCommand: AsyncSwiftCommand {
testEntryPointPath: globalOptions.build.testEntryPointPath,
library: library
)
try build(swiftCommandState, subset: subset, buildParameters: buildParameters)
}
var productsBuildParameters = try swiftCommandState.productsBuildParameters
var toolsBuildParameters = try swiftCommandState.toolsBuildParameters
for library in try options.testLibraryOptions.enabledTestingLibraries(swiftCommandState: swiftCommandState) {
updateTestingParameters(of: &productsBuildParameters, library: library)
updateTestingParameters(of: &toolsBuildParameters, library: library)
try build(swiftCommandState, subset: subset, productsBuildParameters: productsBuildParameters, toolsBuildParameters: toolsBuildParameters)
}
} else {
try build(swiftCommandState, subset: subset)
try build(swiftCommandState, subset: subset, productsBuildParameters: nil, toolsBuildParameters: nil)
}
}

private func build(_ swiftCommandState: SwiftCommandState, subset: BuildSubset, buildParameters: BuildParameters? = nil) throws {
private func build(
_ swiftCommandState: SwiftCommandState,
subset: BuildSubset,
productsBuildParameters: BuildParameters?,
toolsBuildParameters: BuildParameters?
) throws {
let buildSystem = try swiftCommandState.createBuildSystem(
explicitProduct: options.product,
shouldLinkStaticSwiftStdlib: options.shouldLinkStaticSwiftStdlib,
productsBuildParameters: buildParameters,
productsBuildParameters: productsBuildParameters,
toolsBuildParameters: toolsBuildParameters,
// command result output goes on stdout
// ie "swift build" should output to stdout
outputStream: TSCBasic.stdoutStream
Expand Down

0 comments on commit c41425f

Please sign in to comment.