Skip to content

Commit b7b4c85

Browse files
authored
Allow "macos" when parsing triples (#300)
LLVM target triples support either "macosx" or "macos", so our parsing code should also support both spellings.
1 parent 503e25f commit b7b4c85

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

Sources/TSCUtility/Triple.swift

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,11 +104,10 @@ public struct Triple: Encodable, Equatable {
104104
}
105105

106106
fileprivate static func parseOS(_ string: String) -> OS? {
107-
for candidate in OS.allCases where string.hasPrefix(candidate.rawValue) {
108-
return candidate
109-
}
110-
111-
return nil
107+
var candidates = OS.allCases.map{ (name: $0.rawValue, value: $0) }
108+
// LLVM target triples support this alternate spelling as well.
109+
candidates.append((name: "macos", value: .macOS))
110+
return candidates.first(where: { string.hasPrefix($0.name) })?.value
112111
}
113112

114113
fileprivate static func parseVersion(_ string: String) -> String? {

Tests/TSCUtilityTests/TripleTests.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ class TripleTests : XCTestCase {
2424
let newVersion = "10.12"
2525
let tripleString = macos!.tripleString(forPlatformVersion: newVersion)
2626
XCTAssertEqual(tripleString, "x86_64-apple-macosx10.12")
27+
let macosNoX = try? Triple("x86_64-apple-macos12.2")
28+
XCTAssertNotNil(macosNoX!)
29+
XCTAssertEqual(macosNoX!.os, .macOS)
30+
XCTAssertEqual(macosNoX!.osVersion, "12.2")
2731

2832
let android = try? Triple("aarch64-unknown-linux-android24")
2933
XCTAssertNotNil(android)

0 commit comments

Comments
 (0)