Skip to content

Commit a2bc957

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`. Deprecate the the current method to avoid API break.
1 parent 3cb4c9a commit a2bc957

File tree

1 file changed

+27
-8
lines changed

1 file changed

+27
-8
lines changed

Sources/PackageDescription/BuildSettings.swift

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,21 +58,40 @@ 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+
// deprecated 2/2022
62+
@available(*, deprecated, message: "use a variant without optional parameters instead")
6863
public static func when(
6964
platforms: [Platform]? = nil,
7065
configuration: BuildConfiguration? = nil
7166
) -> BuildSettingCondition {
72-
// FIXME: This should be an error, not a precondition.
7367
precondition(!(platforms == nil && configuration == nil))
7468
return BuildSettingCondition(platforms: platforms, config: configuration)
7569
}
70+
71+
/// Creates a build setting condition.
72+
///
73+
/// - Parameters:
74+
/// - platforms: The applicable platforms for this build setting condition.
75+
/// - configuration: The applicable build configuration for this build setting condition.
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+
public static func when(platforms: [Platform]) -> BuildSettingCondition {
85+
BuildSettingCondition(platforms: platforms, config: .none)
86+
}
87+
88+
/// Creates a build setting condition.
89+
///
90+
/// - Parameters:
91+
/// - configuration: The applicable build configuration for this build setting condition.
92+
public static func when(configuration: BuildConfiguration) -> BuildSettingCondition {
93+
BuildSettingCondition(platforms: .none, config: configuration)
94+
}
7695
}
7796

7897
/// The underlying build setting data.

0 commit comments

Comments
 (0)