-
-
Notifications
You must be signed in to change notification settings - Fork 332
refactor!: strongly typed values in BuildSettings
and BuildFileSettings
#903
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 37 commits
e52015a
dc0187c
80c6dee
4c49b9c
0d54629
dd33958
091d6c4
2dfe8f2
9e2a6cb
f0b621c
34d0674
098cdb5
519c511
8e32b39
f118244
024210c
b72b60e
e6c2170
d3d0bf3
364b8ae
bc6a9df
fd8f898
fef1fb1
5ff523d
d56c55a
7785310
f2098b7
6dac103
2fea426
16e9412
0f3a60e
7f7aaca
09b3fac
5cf9160
2461290
648909e
c4eb844
b8aeb90
5d26cf5
d04f4ff
3945b8c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,6 +31,8 @@ jobs: | |
- uses: actions/checkout@v3 | ||
- uses: jdx/mise-action@v2 | ||
- uses: swift-actions/setup-swift@v2 | ||
with: | ||
swift-version: "6.0.2" | ||
- name: Build | ||
run: swift build --configuration release | ||
test: | ||
|
@@ -49,6 +51,8 @@ jobs: | |
- uses: actions/checkout@v3 | ||
- uses: jdx/mise-action@v2 | ||
- uses: swift-actions/setup-swift@v2 | ||
with: | ||
swift-version: "6.0.2" | ||
- run: | | ||
git config --global user.email '[email protected]' | ||
git config --global user.name 'xcodeproj' | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
// swift-tools-version:5.10.0 | ||
// swift-tools-version:6.0.0 | ||
|
||
import PackageDescription | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
public enum BuildFileSetting: Sendable, Equatable { | ||
case string(String) | ||
case array([String]) | ||
|
||
public var stringValue: String? { | ||
if case let .string(value) = self { | ||
value | ||
} else { | ||
nil | ||
} | ||
} | ||
|
||
public var arrayValue: [String]? { | ||
if case let .array(value) = self { | ||
value | ||
} else { | ||
nil | ||
} | ||
} | ||
} | ||
|
||
extension BuildFileSetting: Codable { | ||
public init(from decoder: Decoder) throws { | ||
let container = try decoder.singleValueContainer() | ||
do { | ||
let string = try container.decode(String.self) | ||
self = .string(string) | ||
} catch { | ||
let array = try container.decode([String].self) | ||
self = .array(array) | ||
} | ||
} | ||
|
||
public func encode(to encoder: Encoder) throws { | ||
var container = encoder.singleValueContainer() | ||
switch self { | ||
case let .string(string): | ||
try container.encode(string) | ||
case let .array(array): | ||
try container.encode(array) | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,82 @@ | ||
import Foundation | ||
|
||
/// Build settings. | ||
public typealias BuildSettings = [String: Any] | ||
public typealias BuildSettings = [String: BuildSetting] | ||
|
||
private let yes = "YES" | ||
private let no = "NO" | ||
|
||
public enum BuildSetting: Sendable, Equatable { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would also add some basic documentation. |
||
case string(String) | ||
case array([String]) | ||
|
||
public var stringValue: String? { | ||
if case let .string(value) = self { | ||
value | ||
} else { | ||
nil | ||
} | ||
} | ||
|
||
public var boolValue: Bool? { | ||
if case let .string(value) = self { | ||
switch value { | ||
case yes: true | ||
case no: false | ||
default: nil | ||
Comment on lines
+25
to
+26
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Xcode's behavior is actually defaulting to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the purposes of this utility it strictly checking for boolean build settings as opposed to attempting to resolve a boolean value for the build setting. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Makes sense! |
||
} | ||
} else { | ||
nil | ||
} | ||
} | ||
|
||
public var arrayValue: [String]? { | ||
if case let .array(value) = self { | ||
value | ||
} else { | ||
nil | ||
} | ||
} | ||
} | ||
|
||
extension BuildSetting: CustomStringConvertible { | ||
public var description: String { | ||
switch self { | ||
case let .string(string): | ||
string | ||
case let .array(array): | ||
array.joined(separator: " ") | ||
} | ||
} | ||
} | ||
|
||
extension BuildSetting: Decodable { | ||
public init(from decoder: Decoder) throws { | ||
let container = try decoder.singleValueContainer() | ||
do { | ||
let string = try container.decode(String.self) | ||
self = .string(string) | ||
} catch { | ||
let array = try container.decode([String].self) | ||
self = .array(array) | ||
} | ||
} | ||
} | ||
|
||
extension BuildSetting: ExpressibleByArrayLiteral { | ||
public init(arrayLiteral elements: String...) { | ||
self = .array(elements) | ||
} | ||
} | ||
|
||
extension BuildSetting: ExpressibleByStringInterpolation { | ||
public init(stringLiteral value: StringLiteralType) { | ||
self = .string(value) | ||
} | ||
} | ||
|
||
extension BuildSetting: ExpressibleByBooleanLiteral { | ||
public init(booleanLiteral value: Bool) { | ||
self = .string(value ? yes : no) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's pretty self-explanatory but given this is public now, I'd add some basic documentation.