Skip to content

Commit 35df0c6

Browse files
authored
Merge pull request swiftlang#2918 from neonichu/xcbuild-enable-testability
Enable testability if test discovery is enabled
2 parents d1c1c3a + 2dfd47c commit 35df0c6

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
}
@@ -315,6 +320,11 @@ final class PackagePIFProjectBuilder: PIFProjectBuilder {
315320
releaseSettings[.DEBUG_INFORMATION_FORMAT] = "dwarf-with-dsym"
316321
releaseSettings[.GCC_OPTIMIZATION_LEVEL] = "s"
317322
releaseSettings[.SWIFT_OPTIMIZATION_LEVEL] = "-Owholemodule"
323+
324+
if parameters.enableTestDiscovery {
325+
releaseSettings[.ENABLE_TESTABILITY] = "YES"
326+
}
327+
318328
addBuildConfiguration(name: "Release", settings: releaseSettings)
319329

320330
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
@@ -2162,6 +2162,7 @@ extension PIFBuilderParameters {
21622162
shouldCreateDylibForDynamicProducts: Bool = false
21632163
) -> Self {
21642164
PIFBuilderParameters(
2165+
enableTestDiscovery: false,
21652166
shouldCreateDylibForDynamicProducts: shouldCreateDylibForDynamicProducts
21662167
)
21672168
}

0 commit comments

Comments
 (0)