Skip to content

Commit 7a75eb8

Browse files
authored
Use Triple equality for finding matching binaries (#4270)
In swiftlang/swift-tools-support-core#300, I made `Triple` more lenient w.r.t. different spellings of macOS. Since we are using string matching for finding matching binary artifacts, that would break with differently spelled triples. This PR in conjunction with swiftlang/swift-tools-support-core#307 ensures that we are finding artifacts based on the parsed representation of triples, not their string representations.
1 parent 8b41eae commit 7a75eb8

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

Sources/SPMBuildCore/BinaryTarget+Extensions.swift

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ extension BinaryTarget {
5959
}
6060

6161
public func parseArtifactArchives(for triple: Triple, fileSystem: FileSystem) throws -> [ExecutableInfo] {
62+
// The host triple might contain a version which we don't want to take into account here.
63+
let versionLessTriple = try triple.withoutVersion()
6264
// We return at most a single variant of each artifact.
6365
let metadata = try ArtifactsArchiveMetadata.parse(fileSystem: fileSystem, rootPath: self.artifactPath)
6466
// Currently we filter out everything except executables.
@@ -68,19 +70,25 @@ extension BinaryTarget {
6870
return executables.flatMap { entry in
6971
// FIXME: this filter needs to become more sophisticated
7072
entry.value.variants.filter {
71-
let tripleStrings = $0.supportedTriples.map { $0.tripleString }
72-
if triple.isDarwin() {
73-
return tripleStrings.contains(triple.tripleString(forPlatformVersion: ""))
74-
} else {
75-
return tripleStrings.contains(triple.tripleString)
76-
}
73+
return $0.supportedTriples.contains(versionLessTriple)
7774
}.map{
7875
ExecutableInfo(name: entry.key, executablePath: AbsolutePath($0.path, relativeTo: self.artifactPath))
7976
}
8077
}
8178
}
8279
}
8380

81+
fileprivate extension Triple {
82+
func withoutVersion() throws -> Triple {
83+
if isDarwin() {
84+
let stringWithoutVersion = tripleString(forPlatformVersion: "")
85+
return try Triple(stringWithoutVersion)
86+
} else {
87+
return self
88+
}
89+
}
90+
}
91+
8492
fileprivate extension Triple.OS {
8593
/// Returns a representation of the receiver that can be compared with platform strings declared in an XCFramework.
8694
var asXCFrameworkPlatformString: String? {

0 commit comments

Comments
 (0)