Skip to content

Commit

Permalink
Make it impossible to create an invalid BuildSettingCondition.
Browse files Browse the repository at this point in the history
Instead of a single method that takes two optional values, use multiple methods so that it is impossible for both to be `nil`.
  • Loading branch information
Šimon Javora authored and sjavora committed Feb 12, 2022
1 parent 85a84d9 commit fbe0d7a
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions Sources/PackageDescription/BuildSettings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,27 @@ public struct BuildSettingCondition: Encodable {

/// Creates a build setting condition.
///
/// At least one parameter is mandatory.
/// - Parameters:
/// - platforms: The applicable platforms for this build setting condition.
/// - configuration: The applicable build configuration for this build setting condition.
public static func when(platforms: [Platform], configuration: BuildConfiguration) -> BuildSettingCondition {
BuildSettingCondition(platforms: platforms, config: configuration)
}

/// Creates a build setting condition.
///
/// - Parameters:
/// - platforms: The applicable platforms for this build setting condition.
public static func when(platforms: [Platform]) -> BuildSettingCondition {
BuildSettingCondition(platforms: platforms, config: .none)
}

/// Creates a build setting condition.
///
/// - Parameters:
/// - configuration: The applicable build configuration for this build setting condition.
public static func when(
platforms: [Platform]? = nil,
configuration: BuildConfiguration? = nil
) -> BuildSettingCondition {
// FIXME: This should be an error, not a precondition.
precondition(!(platforms == nil && configuration == nil))
return BuildSettingCondition(platforms: platforms, config: configuration)
public static func when(configuration: BuildConfiguration) -> BuildSettingCondition {
BuildSettingCondition(platforms: .none, config: configuration)
}
}

Expand Down

0 comments on commit fbe0d7a

Please sign in to comment.