Skip to content

Commit 48485dd

Browse files
authored
Merge pull request #2638 from aciidb0mb3r/plumb-options
[PackageLoading] Plumb platform options to SupportedPlatforms
2 parents 1444b46 + a83716f commit 48485dd

File tree

3 files changed

+23
-4
lines changed

3 files changed

+23
-4
lines changed

Sources/PackageLoading/PackageBuilder.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -848,7 +848,8 @@ public final class PackageBuilder {
848848

849849
let supportedPlatform = SupportedPlatform(
850850
platform: platformRegistry.platformByName[platform.platformName]!,
851-
version: PlatformVersion(platform.version)
851+
version: PlatformVersion(platform.version),
852+
options: platform.options
852853
)
853854

854855
supportedPlatforms.append(supportedPlatform)
@@ -863,7 +864,8 @@ public final class PackageBuilder {
863864

864865
let supportedPlatform = SupportedPlatform(
865866
platform: platform,
866-
version: platform.oldestSupportedVersion
867+
version: platform.oldestSupportedVersion,
868+
options: []
867869
)
868870

869871
supportedPlatforms.append(supportedPlatform)

Sources/PackageModel/Platform.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,12 @@ public struct SupportedPlatform {
116116
/// The minimum required version for this platform.
117117
public let version: PlatformVersion
118118

119-
public init(platform: Platform, version: PlatformVersion) {
119+
/// The options declared by the platform.
120+
public let options: [String]
121+
122+
public init(platform: Platform, version: PlatformVersion, options: [String]) {
120123
self.platform = platform
121124
self.version = version
125+
self.options = options
122126
}
123127
}

Tests/PackageLoadingTests/PackageBuilderTests.swift

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1507,7 +1507,7 @@ class PackageBuilderTests: XCTestCase {
15071507
var manifest = Manifest.createManifest(
15081508
name: "pkg",
15091509
platforms: [
1510-
PlatformDescription(name: "macos", version: "10.12"),
1510+
PlatformDescription(name: "macos", version: "10.12", options: ["option1"]),
15111511
],
15121512
v: .v5,
15131513
targets: [
@@ -1529,12 +1529,20 @@ class PackageBuilderTests: XCTestCase {
15291529
PackageBuilderTester(manifest, in: fs) { package, _ in
15301530
package.checkModule("foo") { t in
15311531
t.checkPlatforms(expectedPlatforms)
1532+
t.checkPlatformOptions(.macOS, options: ["option1"])
1533+
t.checkPlatformOptions(.iOS, options: [])
1534+
15321535
}
15331536
package.checkModule("bar") { t in
15341537
t.checkPlatforms(expectedPlatforms)
1538+
t.checkPlatformOptions(.macOS, options: ["option1"])
1539+
t.checkPlatformOptions(.iOS, options: [])
1540+
15351541
}
15361542
package.checkModule("cbar") { t in
15371543
t.checkPlatforms(expectedPlatforms)
1544+
t.checkPlatformOptions(.macOS, options: ["option1"])
1545+
t.checkPlatformOptions(.iOS, options: [])
15381546
}
15391547
}
15401548

@@ -2133,6 +2141,11 @@ final class PackageBuilderTester {
21332141
let targetPlatforms = Dictionary(uniqueKeysWithValues: target.platforms.map({ ($0.platform.name, $0.version.versionString) }))
21342142
XCTAssertEqual(platforms, targetPlatforms, file: file, line: line)
21352143
}
2144+
2145+
func checkPlatformOptions(_ platform: PackageModel.Platform, options: [String], file: StaticString = #file, line: UInt = #line) {
2146+
let platform = target.getSupportedPlatform(for: platform)
2147+
XCTAssertEqual(platform?.options, options, file: file, line: line)
2148+
}
21362149
}
21372150

21382151
final class ModuleDependencyResult {

0 commit comments

Comments
 (0)