Skip to content

Commit c5b3735

Browse files
committed
fixup
1 parent 3b2bf99 commit c5b3735

File tree

2 files changed

+87
-6
lines changed

2 files changed

+87
-6
lines changed

Sources/Workspace/Workspace.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1616,7 +1616,7 @@ extension Workspace {
16161616
let metadata = try jsonDecoder.decode(ArchiveIndexFile.self, from: body)
16171617
// FIXME: this filter needs to become more sophisticated
16181618
guard let supportedArchive = metadata.archives.first(where: { $0.fileName.lowercased().hasSuffix(".zip") && $0.supportedTriples.contains(hostToolchain.triple) }) else {
1619-
throw StringError("No supported archive was found for '\(hostToolchain.triple)'")
1619+
throw StringError("No supported archive was found for '\(hostToolchain.triple.tripleString)'")
16201620
}
16211621
// add relevant archive
16221622
zipArtifacts.append(

Tests/WorkspaceTests/WorkspaceTests.swift

Lines changed: 86 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4847,6 +4847,7 @@ final class WorkspaceTests: XCTestCase {
48474847
let sandbox = AbsolutePath("/tmp/ws/")
48484848
let fs = InMemoryFileSystem()
48494849
var downloads: [MockDownloader.Download] = []
4850+
let hostToolchain = try UserToolchain(destination: .hostDestination())
48504851

48514852
let ariFiles = [
48524853
"""
@@ -4856,7 +4857,7 @@ final class WorkspaceTests: XCTestCase {
48564857
{
48574858
"fileName": "a1.zip",
48584859
"checksum": "a1",
4859-
"supportedTriples": ["x86_64-apple-macosx"]
4860+
"supportedTriples": ["\(hostToolchain.triple.tripleString)"]
48604861
}
48614862
]
48624863
}
@@ -4868,7 +4869,7 @@ final class WorkspaceTests: XCTestCase {
48684869
{
48694870
"fileName": "a2/a2.zip",
48704871
"checksum": "a2",
4871-
"supportedTriples": ["x86_64-apple-macosx"]
4872+
"supportedTriples": ["\(hostToolchain.triple.tripleString)"]
48724873
}
48734874
]
48744875
}
@@ -5120,6 +5121,7 @@ final class WorkspaceTests: XCTestCase {
51205121
func testDownloadArchiveIndexFileBadChecksum() throws {
51215122
let sandbox = AbsolutePath("/tmp/ws/")
51225123
let fs = InMemoryFileSystem()
5124+
let hostToolchain = try UserToolchain(destination: .hostDestination())
51235125

51245126
let ari = """
51255127
{
@@ -5128,7 +5130,7 @@ final class WorkspaceTests: XCTestCase {
51285130
{
51295131
"fileName": "a1.zip",
51305132
"checksum": "a1",
5131-
"supportedTriples": ["x86_64-apple-macosx"]
5133+
"supportedTriples": ["\(hostToolchain.triple.tripleString)"]
51325134
}
51335135
]
51345136
}
@@ -5258,6 +5260,7 @@ final class WorkspaceTests: XCTestCase {
52585260
func testDownloadArchiveIndexFileBadArchivesChecksum() throws {
52595261
let sandbox = AbsolutePath("/tmp/ws/")
52605262
let fs = InMemoryFileSystem()
5263+
let hostToolchain = try UserToolchain(destination: .hostDestination())
52615264

52625265
let ari = """
52635266
{
@@ -5266,7 +5269,7 @@ final class WorkspaceTests: XCTestCase {
52665269
{
52675270
"fileName": "a.zip",
52685271
"checksum": "a",
5269-
"supportedTriples": ["x86_64-apple-macosx"]
5272+
"supportedTriples": ["\(hostToolchain.triple.tripleString)"]
52705273
}
52715274
]
52725275
}
@@ -5375,6 +5378,7 @@ final class WorkspaceTests: XCTestCase {
53755378
func testDownloadArchiveIndexFileArchiveNotFound() throws {
53765379
let sandbox = AbsolutePath("/tmp/ws/")
53775380
let fs = InMemoryFileSystem()
5381+
let hostToolchain = try UserToolchain(destination: .hostDestination())
53785382

53795383
let ari = """
53805384
{
@@ -5383,7 +5387,7 @@ final class WorkspaceTests: XCTestCase {
53835387
{
53845388
"fileName": "not-found.zip",
53855389
"checksum": "a",
5386-
"supportedTriples": ["x86_64-apple-macosx"]
5390+
"supportedTriples": ["\(hostToolchain.triple.tripleString)"]
53875391
}
53885392
]
53895393
}
@@ -5451,6 +5455,83 @@ final class WorkspaceTests: XCTestCase {
54515455
}
54525456
}
54535457

5458+
func testDownloadArchiveIndexTripleNotFound() throws {
5459+
let sandbox = AbsolutePath("/tmp/ws/")
5460+
let fs = InMemoryFileSystem()
5461+
5462+
let hostToolchain = try UserToolchain(destination: .hostDestination())
5463+
let andriodTriple = try Triple("x86_64-unknown-linux-android")
5464+
let notHostTriple = hostToolchain.triple == andriodTriple ? .macOS : andriodTriple
5465+
5466+
let ari = """
5467+
{
5468+
"schemaVersion": "1.0",
5469+
"archives": [
5470+
{
5471+
"fileName": "a1.zip",
5472+
"checksum": "a1",
5473+
"supportedTriples": ["\(notHostTriple.tripleString)"]
5474+
}
5475+
]
5476+
}
5477+
"""
5478+
let checksumAlgorithm = MockHashAlgorithm() // used in tests
5479+
let ariChecksum = checksumAlgorithm.hash(ari).hexadecimalRepresentation
5480+
5481+
// returns a dummy ari files for the requested artifact
5482+
let httpClient = HTTPClient(handler: { request, _, completion in
5483+
do {
5484+
let contents: String
5485+
switch request.url.lastPathComponent {
5486+
case "a.ari":
5487+
contents = ari
5488+
default:
5489+
throw StringError("unexpected url \(request.url)")
5490+
}
5491+
completion(.success(.init(statusCode: 200, body: Data(contents.utf8))))
5492+
} catch {
5493+
completion(.failure( DownloaderError.clientError(error)))
5494+
}
5495+
})
5496+
5497+
let workspace = try MockWorkspace(
5498+
sandbox: sandbox,
5499+
fs: fs,
5500+
httpClient: httpClient,
5501+
roots: [
5502+
MockPackage(
5503+
name: "Foo",
5504+
targets: [
5505+
MockTarget(name: "Foo", dependencies: ["A"]),
5506+
],
5507+
products: [],
5508+
dependencies: [
5509+
.git(name: "A", requirement: .exact("1.0.0")),
5510+
]
5511+
),
5512+
],
5513+
packages: [
5514+
MockPackage(
5515+
name: "A",
5516+
targets: [
5517+
MockTarget(name: "A", type: .binary, url: "https://a.com/a.ari", checksum: ariChecksum),
5518+
],
5519+
products: [
5520+
MockProduct(name: "A", targets: ["A"]),
5521+
],
5522+
versions: ["0.9.0", "1.0.0"]
5523+
),
5524+
]
5525+
)
5526+
5527+
workspace.checkPackageGraphFailure(roots: ["Foo"]) { diagnostics in
5528+
XCTAssertEqual(workspace.downloader.downloads, [])
5529+
DiagnosticsEngineTester(diagnostics) { result in
5530+
result.check(diagnostic: .contains("failed retrieving 'https://a.com/a.ari': No supported archive was found for '\(hostToolchain.triple.tripleString)'"), behavior: .error)
5531+
}
5532+
}
5533+
}
5534+
54545535
func testAndroidCompilerFlags() throws {
54555536
let target = try Triple("x86_64-unknown-linux-android")
54565537
let sdk = AbsolutePath("/some/path/to/an/SDK.sdk")

0 commit comments

Comments
 (0)