Skip to content

Commit

Permalink
Move OS component version comparison to isRuntimeCompatible
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxDesiatov committed Sep 19, 2023
1 parent 3c3422a commit 2fa29e7
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 10 deletions.
13 changes: 13 additions & 0 deletions Sources/Basics/Triple+Basics.swift
Expand Up @@ -183,6 +183,19 @@ extension Triple {
return ".resources"
}
}

public func isRuntimeCompatible(with triple: Triple) -> Bool {
if
self.arch == triple.arch &&
self.vendor == triple.vendor &&
self.os == triple.os &&
self.environment == triple.environment
{
return self.osVersion >= triple.osVersion
} else {
return false
}
}
}

extension Triple: CustomStringConvertible {
Expand Down
11 changes: 1 addition & 10 deletions Sources/PackageModel/SwiftSDKBundle.swift
Expand Up @@ -429,16 +429,7 @@ extension [SwiftSDKBundle] {
for (artifactID, variants) in bundle.artifacts {
for variant in variants {
guard variant.metadata.supportedTriples.contains(where: { variantTriple in
if
hostTriple.arch == variantTriple.arch &&
hostTriple.vendor == variantTriple.vendor &&
hostTriple.os == variantTriple.os &&
hostTriple.environment == variantTriple.environment
{
return hostTriple.osVersion >= variantTriple.osVersion
} else {
return false
}
hostTriple.isRuntimeCompatible(with: variantTriple)
}) else {
continue
}
Expand Down
7 changes: 7 additions & 0 deletions Tests/BasicsTests/TripleTests.swift
Expand Up @@ -165,4 +165,11 @@ final class TripleTests: XCTestCase {
XCTAssertTriple("x86_64-unknown-windows-msvc", matches: (.x86_64, nil, nil, .win32, .msvc, .coff))
XCTAssertTriple("wasm32-unknown-wasi", matches: (.wasm32, nil, nil, .wasi, nil, .wasm))
}

func testIsRuntimeCompatibleWith() throws {
try XCTAssertTrue(Triple("x86_64-apple-macosx").isRuntimeCompatible(with: Triple("x86_64-apple-macosx")))
try XCTAssertTrue(Triple("x86_64-unknown-linux").isRuntimeCompatible(with: Triple("x86_64-unknown-linux")))
try XCTAssertFalse(Triple("x86_64-apple-macosx").isRuntimeCompatible(with: Triple("x86_64-apple-linux")))
try XCTAssertTrue(Triple("x86_64-apple-macosx14.0").isRuntimeCompatible(with: Triple("x86_64-apple-macosx13.0")))
}
}

0 comments on commit 2fa29e7

Please sign in to comment.