Skip to content

Commit 23756a4

Browse files
Šimon Javorasjavora
authored andcommitted
Make it impossible to create an invalid BuildSettingCondition.
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 85a84d9 commit 23756a4

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

Sources/PackageDescription/BuildSettings.swift

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,18 +60,27 @@ public struct BuildSettingCondition: Encodable {
6060

6161
/// Creates a build setting condition.
6262
///
63-
/// At least one parameter is mandatory.
63+
/// - Parameters:
64+
/// - platforms: The applicable platforms for this build setting condition.
65+
/// - configuration: The applicable build configuration for this build setting condition.
66+
public static func when(platforms: [Platform], configuration: BuildConfiguration) -> BuildSettingCondition {
67+
BuildSettingCondition(platforms: platforms, config: configuration)
68+
}
69+
70+
/// Creates a build setting condition.
6471
///
6572
/// - Parameters:
6673
/// - platforms: The applicable platforms for this build setting condition.
74+
public static func when(platforms: [Platform]) -> BuildSettingCondition {
75+
BuildSettingCondition(platforms: platforms, config: nil)
76+
}
77+
78+
/// Creates a build setting condition.
79+
///
80+
/// - Parameters:
6781
/// - configuration: The applicable build configuration for this build setting condition.
68-
public static func when(
69-
platforms: [Platform]? = nil,
70-
configuration: BuildConfiguration? = nil
71-
) -> BuildSettingCondition {
72-
// FIXME: This should be an error, not a precondition.
73-
precondition(!(platforms == nil && configuration == nil))
74-
return BuildSettingCondition(platforms: platforms, config: configuration)
82+
public static func when(configuration: BuildConfiguration) -> BuildSettingCondition {
83+
BuildSettingCondition(platforms: nil, config: configuration)
7584
}
7685
}
7786

0 commit comments

Comments
 (0)