Skip to content

Commit 7063c45

Browse files
authored
Fix MacCatalyst minimum deployment fallback (#5620)
If a package does not specify a custom deployment target for MacCatalyst, we are supposed to fallback to the iOS one, if declared. This currently does not work for test targets, because we prefer the minimum XCTest deployment target, even if it may be lower than the customized iOS one.
1 parent 2a5650d commit 7063c45

File tree

2 files changed

+70
-12
lines changed

2 files changed

+70
-12
lines changed

Sources/PackageGraph/PackageGraph+Loading.swift

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -617,14 +617,19 @@ private func computePlatforms(
617617
for platformName in remainingPlatforms.sorted() {
618618
let platform = platformRegistry.platformByName[platformName]!
619619

620-
let oldestSupportedVersion: PlatformVersion
620+
let minimumSupportedVersion: PlatformVersion
621621
if usingXCTest, let xcTestMinimumDeploymentTarget = xcTestMinimumDeploymentTargets[platform] {
622-
oldestSupportedVersion = xcTestMinimumDeploymentTarget
623-
} else if platform == .macCatalyst, let iOS = derivedPlatforms.first(where: { $0.platform == .iOS }) {
622+
minimumSupportedVersion = xcTestMinimumDeploymentTarget
623+
} else {
624+
minimumSupportedVersion = platform.oldestSupportedVersion
625+
}
626+
627+
let oldestSupportedVersion: PlatformVersion
628+
if platform == .macCatalyst, let iOS = derivedPlatforms.first(where: { $0.platform == .iOS }) {
624629
// If there was no deployment target specified for Mac Catalyst, fall back to the iOS deployment target.
625-
oldestSupportedVersion = max(platform.oldestSupportedVersion, iOS.version)
630+
oldestSupportedVersion = max(minimumSupportedVersion, iOS.version)
626631
} else {
627-
oldestSupportedVersion = platform.oldestSupportedVersion
632+
oldestSupportedVersion = minimumSupportedVersion
628633
}
629634

630635
let supportedPlatform = SupportedPlatform(

Tests/PackageGraphTests/PackageGraphTests.swift

Lines changed: 60 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1926,6 +1926,13 @@ class PackageGraphTests: XCTestCase {
19261926
"openbsd": "0.0"
19271927
]
19281928

1929+
let customXCTestMinimumDeploymentTargets = [
1930+
PackageModel.Platform.macOS: PlatformVersion("10.15"),
1931+
PackageModel.Platform.iOS: PlatformVersion("11.0"),
1932+
PackageModel.Platform.tvOS: PlatformVersion("11.0"),
1933+
PackageModel.Platform.watchOS: PlatformVersion("4.0"),
1934+
]
1935+
19291936
do {
19301937
// One platform with an override.
19311938
let manifest = Manifest.createRootManifest(
@@ -1947,13 +1954,6 @@ class PackageGraphTests: XCTestCase {
19471954
]
19481955
)
19491956

1950-
let customXCTestMinimumDeploymentTargets = [
1951-
PackageModel.Platform.macOS: PlatformVersion("10.15"),
1952-
PackageModel.Platform.iOS: PlatformVersion("11.0"),
1953-
PackageModel.Platform.tvOS: PlatformVersion("11.0"),
1954-
PackageModel.Platform.watchOS: PlatformVersion("4.0"),
1955-
]
1956-
19571957
let observability = ObservabilitySystem.makeForTesting()
19581958
let graph = try loadPackageGraph(
19591959
fileSystem: fs,
@@ -2093,6 +2093,59 @@ class PackageGraphTests: XCTestCase {
20932093
}
20942094
}
20952095
}
2096+
2097+
do {
2098+
// Test MacCatalyst overriding behavior.
2099+
let manifest = Manifest.createRootManifest(
2100+
name: "pkg",
2101+
platforms: [
2102+
PlatformDescription(name: "ios", version: "15.0"),
2103+
],
2104+
products: [
2105+
try ProductDescription(name: "cbar", type: .library(.automatic), targets: ["cbar"]),
2106+
],
2107+
targets: [
2108+
try TargetDescription(name: "cbar"),
2109+
try TargetDescription(name: "test", type: .test)
2110+
]
2111+
)
2112+
2113+
let observability = ObservabilitySystem.makeForTesting()
2114+
let graph = try loadPackageGraph(
2115+
fileSystem: fs,
2116+
manifests: [manifest],
2117+
customXCTestMinimumDeploymentTargets: customXCTestMinimumDeploymentTargets,
2118+
observabilityScope: observability.topScope
2119+
)
2120+
XCTAssertNoDiagnostics(observability.diagnostics)
2121+
2122+
PackageGraphTester(graph) { result in
2123+
let expectedDeclaredPlatforms = [
2124+
"ios": "15.0",
2125+
]
2126+
2127+
var expectedDerivedPlatforms = defaultDerivedPlatforms.merging(expectedDeclaredPlatforms, uniquingKeysWith: { lhs, rhs in rhs })
2128+
var expectedDerivedPlatformsForTests = defaultDerivedPlatforms.merging(customXCTestMinimumDeploymentTargets.map { ($0.name, $1.versionString) }, uniquingKeysWith: { lhs, rhs in rhs })
2129+
expectedDerivedPlatformsForTests["ios"] = expectedDeclaredPlatforms["ios"]
2130+
2131+
// Gets derived to be the same as the declared iOS deployment target.
2132+
expectedDerivedPlatforms["maccatalyst"] = expectedDeclaredPlatforms["ios"]
2133+
expectedDerivedPlatformsForTests["maccatalyst"] = expectedDeclaredPlatforms["ios"]
2134+
2135+
result.checkTarget("test") { target in
2136+
target.checkDeclaredPlatforms(expectedDeclaredPlatforms)
2137+
target.checkDerivedPlatforms(expectedDerivedPlatformsForTests)
2138+
}
2139+
result.checkTarget("cbar") { target in
2140+
target.checkDeclaredPlatforms(expectedDeclaredPlatforms)
2141+
target.checkDerivedPlatforms(expectedDerivedPlatforms)
2142+
}
2143+
result.checkProduct("cbar") { product in
2144+
product.checkDeclaredPlatforms(expectedDeclaredPlatforms)
2145+
product.checkDerivedPlatforms(expectedDerivedPlatforms)
2146+
}
2147+
}
2148+
}
20962149
}
20972150

20982151
func testCustomPlatforms() throws {

0 commit comments

Comments
 (0)