Skip to content

Commit c9bf5b3

Browse files
authored
Infer properties of derived test target. (#7041)
Right now, when we construct the derived test target used on Linux/Windows with corelibs-xctest, we don't preserve the `platforms` property. The toolchain then infers a value for it based on the current OS. Since Swift doesn't currently support versioning on those platforms, the end result is the same. However, if we want to start using a derived test target with swift-testing on Apple platforms, we need to propagate this information correctly. This PR does that.
1 parent 173355b commit c9bf5b3

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

Sources/Build/BuildPlan/BuildPlan+Test.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ extension BuildPlan {
8686
let discoveryResolvedTarget = ResolvedTarget(
8787
target: discoveryTarget,
8888
dependencies: testProduct.targets.map { .target($0, conditions: []) },
89-
defaultLocalization: .none, // safe since this is a derived target
90-
platforms: .init(declared: [], derivedXCTestPlatformProvider: .none) // safe since this is a derived target
89+
defaultLocalization: testProduct.defaultLocalization,
90+
platforms: testProduct.platforms
9191
)
9292
let discoveryTargetBuildDescription = try SwiftTargetBuildDescription(
9393
package: package,
@@ -119,8 +119,8 @@ extension BuildPlan {
119119
let entryPointResolvedTarget = ResolvedTarget(
120120
target: entryPointTarget,
121121
dependencies: testProduct.targets.map { .target($0, conditions: []) } + [.target(discoveryResolvedTarget, conditions: [])],
122-
defaultLocalization: .none, // safe since this is a derived target
123-
platforms: .init(declared: [], derivedXCTestPlatformProvider: .none) // safe since this is a derived target
122+
defaultLocalization: testProduct.defaultLocalization,
123+
platforms: testProduct.platforms
124124
)
125125
return try SwiftTargetBuildDescription(
126126
package: package,
@@ -148,8 +148,8 @@ extension BuildPlan {
148148
let entryPointResolvedTarget = ResolvedTarget(
149149
target: entryPointTarget,
150150
dependencies: entryPointResolvedTarget.dependencies + [.target(discoveryTargets.resolved, conditions: [])],
151-
defaultLocalization: .none, // safe since this is a derived target
152-
platforms: .init(declared: [], derivedXCTestPlatformProvider: .none) // safe since this is a derived target
151+
defaultLocalization: testProduct.defaultLocalization,
152+
platforms: testProduct.platforms
153153
)
154154
let entryPointTargetBuildDescription = try SwiftTargetBuildDescription(
155155
package: package,

Sources/PackageGraph/ResolvedProduct.swift

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,14 @@ public final class ResolvedProduct {
5959
self.underlyingProduct = product
6060
self.targets = targets
6161

62+
// defaultLocalization is currently shared across the entire package
63+
// this may need to be enhanced if / when we support localization per target or product
64+
let defaultLocalization = self.targets.first?.defaultLocalization
65+
self.defaultLocalization = defaultLocalization
66+
67+
let platforms = Self.computePlatforms(targets: targets)
68+
self.platforms = platforms
69+
6270
self.testEntryPointTarget = underlyingProduct.testEntryPointPath.map { testEntryPointPath in
6371
// Create an executable resolved target with the entry point file, adding product's targets as dependencies.
6472
let dependencies: [Target.Dependency] = product.targets.map { .target($0, conditions: []) }
@@ -69,16 +77,10 @@ public final class ResolvedProduct {
6977
return ResolvedTarget(
7078
target: swiftTarget,
7179
dependencies: targets.map { .target($0, conditions: []) },
72-
defaultLocalization: .none, // safe since this is a derived product
73-
platforms: .init(declared: [], derivedXCTestPlatformProvider: .none) // safe since this is a derived product
80+
defaultLocalization: defaultLocalization ?? .none, // safe since this is a derived product
81+
platforms: platforms
7482
)
7583
}
76-
77-
// defaultLocalization is currently shared across the entire package
78-
// this may need to be enhanced if / when we support localization per target or product
79-
self.defaultLocalization = self.targets.first?.defaultLocalization
80-
81-
self.platforms = Self.computePlatforms(targets: targets)
8284
}
8385

8486
/// True if this product contains Swift targets.

0 commit comments

Comments
 (0)