Skip to content

Commit 57f9d0d

Browse files
committed
Enable testability if test discovery is enabled
This just makes XCBuild support match what we do in SwiftPM's own build system here: https://github.com/apple/swift-package-manager/blob/master/Sources/XCBuildSupport/PIFBuilder.swift#L308 We should probably revisit this behaviour, because this seems like a very confusing side effect on macOS where test discovery isn't even a thing, but right now we just want to match what the builtin build system does.
1 parent 4948122 commit 57f9d0d

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

Sources/XCBuildSupport/PIFBuilder.swift

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,18 @@ import PackageGraph
2020
/// The parameters required by `PIFBuilder`.
2121
public struct PIFBuilderParameters {
2222

23+
/// Whether or not test discovery is enabled.
24+
public let enableTestDiscovery: Bool
25+
2326
/// Whether to create dylibs for dynamic library products.
2427
public let shouldCreateDylibForDynamicProducts: Bool
2528

2629
/// Creates a `PIFBuilderParameters` instance.
2730
/// - Parameters:
31+
/// - enableTestDiscovery: Whether or not test discovery is enabled.
2832
/// - shouldCreateDylibForDynamicProducts: Whether to create dylibs for dynamic library products.
29-
public init(shouldCreateDylibForDynamicProducts: Bool) {
33+
public init(enableTestDiscovery: Bool, shouldCreateDylibForDynamicProducts: Bool) {
34+
self.enableTestDiscovery = enableTestDiscovery
3035
self.shouldCreateDylibForDynamicProducts = shouldCreateDylibForDynamicProducts
3136
}
3237
}
@@ -299,6 +304,11 @@ final class PackagePIFProjectBuilder: PIFProjectBuilder {
299304
releaseSettings[.DEBUG_INFORMATION_FORMAT] = "dwarf-with-dsym"
300305
releaseSettings[.GCC_OPTIMIZATION_LEVEL] = "s"
301306
releaseSettings[.SWIFT_OPTIMIZATION_LEVEL] = "-Owholemodule"
307+
308+
if parameters.enableTestDiscovery {
309+
releaseSettings[.ENABLE_TESTABILITY] = "YES"
310+
}
311+
302312
addBuildConfiguration(name: "Release", settings: releaseSettings)
303313

304314
for product in package.products.sorted(by: { $0.name < $1.name }) {

Sources/XCBuildSupport/XcodeBuildSystem.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ extension BuildConfiguration {
218218
extension PIFBuilderParameters {
219219
public init(_ buildParameters: BuildParameters) {
220220
self.init(
221+
enableTestDiscovery: buildParameters.enableTestDiscovery,
221222
shouldCreateDylibForDynamicProducts: buildParameters.shouldCreateDylibForDynamicProducts
222223
)
223224
}

Tests/XCBuildSupportTests/PIFBuilderTests.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2159,6 +2159,7 @@ extension PIFBuilderParameters {
21592159
shouldCreateDylibForDynamicProducts: Bool = false
21602160
) -> Self {
21612161
PIFBuilderParameters(
2162+
enableTestDiscovery: false,
21622163
shouldCreateDylibForDynamicProducts: shouldCreateDylibForDynamicProducts
21632164
)
21642165
}

0 commit comments

Comments
 (0)