Skip to content

Commit

Permalink
Make it impossible to create an invalid BuildSettingCondition. (#4131)
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
sjavora authored Feb 15, 2022
1 parent 93188c6 commit 645fe16
Showing 1 changed file with 29 additions and 8 deletions.
37 changes: 29 additions & 8 deletions Sources/PackageDescription/BuildSettings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,21 +58,42 @@ 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.
@available(_PackageDescription, deprecated: 999.0)
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.
@available(_PackageDescription, introduced: 999.0)
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.
@available(_PackageDescription, introduced: 999.0)
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.
@available(_PackageDescription, introduced: 999.0)
public static func when(configuration: BuildConfiguration) -> BuildSettingCondition {
BuildSettingCondition(platforms: .none, config: configuration)
}
}

/// The underlying build setting data.
Expand Down

0 comments on commit 645fe16

Please sign in to comment.