Skip to content

Allow "macos" when parsing triples #300

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

Merged
merged 1 commit into from
Mar 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions Sources/TSCUtility/Triple.swift
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,10 @@ public struct Triple: Encodable, Equatable {
}

fileprivate static func parseOS(_ string: String) -> OS? {
for candidate in OS.allCases where string.hasPrefix(candidate.rawValue) {
return candidate
}

return nil
var candidates = OS.allCases.map{ (name: $0.rawValue, value: $0) }
// LLVM target triples support this alternate spelling as well.
candidates.append((name: "macos", value: .macOS))
return candidates.first(where: { string.hasPrefix($0.name) })?.value
}

fileprivate static func parseVersion(_ string: String) -> String? {
Expand Down
4 changes: 4 additions & 0 deletions Tests/TSCUtilityTests/TripleTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ class TripleTests : XCTestCase {
let newVersion = "10.12"
let tripleString = macos!.tripleString(forPlatformVersion: newVersion)
XCTAssertEqual(tripleString, "x86_64-apple-macosx10.12")
let macosNoX = try? Triple("x86_64-apple-macos12.2")
XCTAssertNotNil(macosNoX!)
XCTAssertEqual(macosNoX!.os, .macOS)
XCTAssertEqual(macosNoX!.osVersion, "12.2")

let android = try? Triple("aarch64-unknown-linux-android24")
XCTAssertNotNil(android)
Expand Down