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`.

Deprecate the the current method to avoid API break.
  • Loading branch information
Šimon Javora authored and sjavora committed Feb 13, 2022
1 parent 3cb4c9a commit a2bc957
Showing 1 changed file with 27 additions and 8 deletions.
35 changes: 27 additions & 8 deletions Sources/PackageDescription/BuildSettings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,21 +58,40 @@ public struct BuildSettingCondition: Encodable {
self.config = config
}

/// 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.
// deprecated 2/2022
@available(*, deprecated, message: "use a variant without optional parameters instead")
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)
}

/// Creates a build setting condition.
///
/// - 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(configuration: BuildConfiguration) -> BuildSettingCondition {
BuildSettingCondition(platforms: .none, config: configuration)
}
}

/// The underlying build setting data.
Expand Down

0 comments on commit a2bc957

Please sign in to comment.