Skip to content

Commit 645fe16

Browse files
authored
Make it impossible to create an invalid BuildSettingCondition. (#4131)
Instead of a single method that takes two optional values, use multiple methods so that it is impossible for both to be `nil`.
1 parent 93188c6 commit 645fe16

File tree

1 file changed

+29
-8
lines changed

1 file changed

+29
-8
lines changed

Sources/PackageDescription/BuildSettings.swift

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,21 +58,42 @@ public struct BuildSettingCondition: Encodable {
5858
self.config = config
5959
}
6060

61-
/// Creates a build setting condition.
62-
///
63-
/// At least one parameter is mandatory.
64-
///
65-
/// - Parameters:
66-
/// - platforms: The applicable platforms for this build setting condition.
67-
/// - configuration: The applicable build configuration for this build setting condition.
61+
@available(_PackageDescription, deprecated: 999.0)
6862
public static func when(
6963
platforms: [Platform]? = nil,
7064
configuration: BuildConfiguration? = nil
7165
) -> BuildSettingCondition {
72-
// FIXME: This should be an error, not a precondition.
7366
precondition(!(platforms == nil && configuration == nil))
7467
return BuildSettingCondition(platforms: platforms, config: configuration)
7568
}
69+
70+
/// Creates a build setting condition.
71+
///
72+
/// - Parameters:
73+
/// - platforms: The applicable platforms for this build setting condition.
74+
/// - configuration: The applicable build configuration for this build setting condition.
75+
@available(_PackageDescription, introduced: 999.0)
76+
public static func when(platforms: [Platform], configuration: BuildConfiguration) -> BuildSettingCondition {
77+
BuildSettingCondition(platforms: platforms, config: configuration)
78+
}
79+
80+
/// Creates a build setting condition.
81+
///
82+
/// - Parameters:
83+
/// - platforms: The applicable platforms for this build setting condition.
84+
@available(_PackageDescription, introduced: 999.0)
85+
public static func when(platforms: [Platform]) -> BuildSettingCondition {
86+
BuildSettingCondition(platforms: platforms, config: .none)
87+
}
88+
89+
/// Creates a build setting condition.
90+
///
91+
/// - Parameters:
92+
/// - configuration: The applicable build configuration for this build setting condition.
93+
@available(_PackageDescription, introduced: 999.0)
94+
public static func when(configuration: BuildConfiguration) -> BuildSettingCondition {
95+
BuildSettingCondition(platforms: .none, config: configuration)
96+
}
7697
}
7798

7899
/// The underlying build setting data.

0 commit comments

Comments
 (0)