Skip to content

Commit ad7bf44

Browse files
committed
fixup
1 parent 456a370 commit ad7bf44

File tree

5 files changed

+18
-8
lines changed

5 files changed

+18
-8
lines changed

Sources/Build/BuildPlan.swift

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -589,7 +589,7 @@ public final class SwiftTargetBuildDescription {
589589
public let isTestTarget: Bool
590590

591591
/// True if this is the test discovery target.
592-
public let testDiscoveryTarget: Bool
592+
public let isTestDiscoveryTarget: Bool
593593

594594
/// True if this module needs to be parsed as a library based on the target type and the configuration
595595
/// of the source code (for example because it has a single source file whose name isn't "main.swift").
@@ -632,7 +632,7 @@ public final class SwiftTargetBuildDescription {
632632
buildToolPluginInvocationResults: [BuildToolPluginInvocationResult] = [],
633633
prebuildCommandResults: [PrebuildCommandResult] = [],
634634
isTestTarget: Bool? = nil,
635-
testDiscoveryTarget: Bool = false,
635+
isTestDiscoveryTarget: Bool = false,
636636
fileSystem: FileSystem
637637
) throws {
638638
assert(target.underlyingTarget is SwiftTarget, "underlying target type mismatch \(target)")
@@ -641,7 +641,7 @@ public final class SwiftTargetBuildDescription {
641641
self.buildParameters = buildParameters
642642
// Unless mentioned explicitly, use the target type to determine if this is a test target.
643643
self.isTestTarget = isTestTarget ?? (target.type == .test)
644-
self.testDiscoveryTarget = testDiscoveryTarget
644+
self.isTestDiscoveryTarget = isTestDiscoveryTarget
645645
self.fileSystem = fileSystem
646646
self.tempsPath = buildParameters.buildPath.appending(component: target.c99name + ".build")
647647
self.derivedSources = Sources(paths: [], root: tempsPath.appending(component: "DerivedSources"))
@@ -1095,7 +1095,11 @@ public final class SwiftTargetBuildDescription {
10951095

10961096
/// Testing arguments according to the build configuration.
10971097
private var testingArguments: [String] {
1098-
if buildParameters.enableTestability {
1098+
if self.isTestTarget {
1099+
// test targets must be built with -enable-testing
1100+
// since its required for test discovery (the non objective-c reflection kind)
1101+
return ["-enable-testing"]
1102+
} else if buildParameters.enableTestability {
10991103
return ["-enable-testing"]
11001104
} else {
11011105
return []
@@ -1564,7 +1568,7 @@ public class BuildPlan {
15641568
toolsVersion: toolsVersion,
15651569
buildParameters: buildParameters,
15661570
isTestTarget: true,
1567-
testDiscoveryTarget: true,
1571+
isTestDiscoveryTarget: true,
15681572
fileSystem: fileSystem
15691573
)
15701574

Sources/Build/LLBuildManifestBuilder.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -823,7 +823,7 @@ extension LLBuildManifestBuilder {
823823
for target in plan.targets {
824824
guard case .swift(let target) = target,
825825
target.isTestTarget,
826-
target.testDiscoveryTarget else { continue }
826+
target.isTestDiscoveryTarget else { continue }
827827

828828
let testDiscoveryTarget = target
829829

Sources/Commands/TestingSupport.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ extension SwiftTool {
139139
) throws -> BuildParameters {
140140
var parameters = try self.buildParameters()
141141
// for test commands, we normally enable building with testability
142+
// but we let users override this with a flag
142143
parameters.enableTestability = enableTestability ?? true
143144
return parameters
144145
}

Sources/SPMBuildCore/BuildParameters.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,12 @@ public struct BuildParameters: Encodable {
228228
self.isXcodeBuildSystemEnabled = isXcodeBuildSystemEnabled
229229
self.printManifestGraphviz = printManifestGraphviz
230230
// decide on testability based on debug/release config
231+
// the goals of this being based on the build configuration is
232+
// that `swift build` followed by a `swift test` will need to do minimal rebuilding
233+
// given that the default configuration for `swift build` is debug
234+
// and that `swift test` normally requires building with testable enabled.
235+
// when building and testing in release mode, one can use the '--disable-testable-imports' flag
236+
// to disable testability in `swift test`, but that requires that the tests do not use the testable imports feature
231237
self.enableTestability = enableTestability ?? (.debug == configuration)
232238
// decide if to enable the use of test manifests based on platform. this is likely to change in the future
233239
self.testDiscoveryStrategy = triple.isDarwin() ? .objectiveC : .manifest(generate: forceTestDiscovery)

Tests/CommandsTests/TestToolTests.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,8 @@ final class TestToolTests: CommandsTestCase {
6969

7070
// disabled
7171
do {
72-
let result = try execute(["--disable-testable-imports", "--vv"], packagePath: path)
72+
_ = try execute(["--disable-testable-imports", "--vv"], packagePath: path)
7373
} catch SwiftPMProductError.executionFailure(_, let stdout, _) {
74-
XCTAssertNoMatch(stdout, .contains("-enable-testing"))
7574
XCTAssertMatch(stdout, .contains("was not compiled for testing"))
7675
}
7776

0 commit comments

Comments
 (0)