File tree Expand file tree Collapse file tree 2 files changed +10
-1
lines changed Expand file tree Collapse file tree 2 files changed +10
-1
lines changed Original file line number Diff line number Diff line change @@ -36,7 +36,7 @@ public struct Triple: Encodable, Equatable {
3636 case unknownOS( os: String )
3737 }
3838
39- public enum Arch : String , Encodable {
39+ public enum Arch : String , Encodable , CaseIterable {
4040 case x86_64
4141 case x86_64h
4242 case i686
@@ -135,6 +135,11 @@ public struct Triple: Encodable, Equatable {
135135 self . abiVersion = abiVersion
136136 }
137137
138+ fileprivate static func parseArch( _ string: String ) -> Arch ? {
139+ var candidates = Arch . allCases. map { ( name: $0. rawValue, value: $0) }
140+ return candidates. first ( where: { string. hasPrefix ( $0. name) } ) ? . value
141+ }
142+
138143 fileprivate static func parseOS( _ string: String ) -> OS ? {
139144 var candidates = OS . allCases. map { ( name: $0. rawValue, value: $0) }
140145 // LLVM target triples support this alternate spelling as well.
@@ -201,6 +206,7 @@ public struct Triple: Encodable, Equatable {
201206 fatalError ( " Failed to get target info ( \( error) ) " )
202207 #endif
203208 }
209+
204210 // Parse the compiler's JSON output.
205211 let parsedTargetInfo : JSON
206212 do {
Original file line number Diff line number Diff line change @@ -40,6 +40,9 @@ class TripleTests : XCTestCase {
4040 let linuxWithABIVersion = try ? Triple ( " x86_64-unknown-linux-gnu42 " )
4141 XCTAssertEqual ( linuxWithABIVersion!. abi, . other( name: " gnu " ) )
4242 XCTAssertEqual ( linuxWithABIVersion!. abiVersion, " 42 " )
43+
44+ let androidArm = try ? Triple ( " armv7a-unknown-linux-androideabi " )
45+ XCTAssertEqual ( androidArm!. arch, . armv7)
4346 }
4447
4548 func testEquality( ) throws {
You can’t perform that action at this time.
0 commit comments