Skip to content

Commit 2378d6d

Browse files
grynspanMaxDesiatov
andcommitted
Fix test targets that depend on macros and swift-testing (#7508)
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]>
1 parent 4f19176 commit 2378d6d

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

Sources/Commands/SwiftBuildCommand.swift

+17-6
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,7 @@ package struct SwiftBuildCommand: AsyncSwiftCommand {
149149
throw ExitCode.failure
150150
}
151151
if case .allIncludingTests = subset {
152-
var buildParameters = try swiftCommandState.productsBuildParameters
153-
for library in try options.testLibraryOptions.enabledTestingLibraries(swiftCommandState: swiftCommandState) {
152+
func updateTestingParameters(of buildParameters: inout BuildParameters, library: BuildParameters.Testing.Library) {
154153
buildParameters.testingParameters = .init(
155154
configuration: buildParameters.configuration,
156155
targetTriple: buildParameters.triple,
@@ -161,18 +160,30 @@ package struct SwiftBuildCommand: AsyncSwiftCommand {
161160
testEntryPointPath: globalOptions.build.testEntryPointPath,
162161
library: library
163162
)
164-
try build(swiftCommandState, subset: subset, buildParameters: buildParameters)
163+
}
164+
var productsBuildParameters = try swiftCommandState.productsBuildParameters
165+
var toolsBuildParameters = try swiftCommandState.toolsBuildParameters
166+
for library in try options.testLibraryOptions.enabledTestingLibraries(swiftCommandState: swiftCommandState) {
167+
updateTestingParameters(of: &productsBuildParameters, library: library)
168+
updateTestingParameters(of: &toolsBuildParameters, library: library)
169+
try build(swiftCommandState, subset: subset, productsBuildParameters: productsBuildParameters, toolsBuildParameters: toolsBuildParameters)
165170
}
166171
} else {
167-
try build(swiftCommandState, subset: subset)
172+
try build(swiftCommandState, subset: subset, productsBuildParameters: nil, toolsBuildParameters: nil)
168173
}
169174
}
170175

171-
private func build(_ swiftCommandState: SwiftCommandState, subset: BuildSubset, buildParameters: BuildParameters? = nil) throws {
176+
private func build(
177+
_ swiftCommandState: SwiftCommandState,
178+
subset: BuildSubset,
179+
productsBuildParameters: BuildParameters?,
180+
toolsBuildParameters: BuildParameters?
181+
) throws {
172182
let buildSystem = try swiftCommandState.createBuildSystem(
173183
explicitProduct: options.product,
174184
shouldLinkStaticSwiftStdlib: options.shouldLinkStaticSwiftStdlib,
175-
productsBuildParameters: buildParameters,
185+
productsBuildParameters: productsBuildParameters,
186+
toolsBuildParameters: toolsBuildParameters,
176187
// command result output goes on stdout
177188
// ie "swift build" should output to stdout
178189
outputStream: TSCBasic.stdoutStream

0 commit comments

Comments
 (0)