Skip to content

Commit 221d289

Browse files
committed
fixup
1 parent bbac0fd commit 221d289

File tree

1 file changed

+49
-52
lines changed

1 file changed

+49
-52
lines changed

Sources/Workspace/Workspace.swift

Lines changed: 49 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1575,76 +1575,73 @@ extension Workspace {
15751575
let result = ThreadSafeArrayStore<ManagedArtifact>()
15761576

15771577
var authProvider: AuthorizationProviding? = nil
1578-
var didDownloadAnyArtifact = false
1578+
// Netrc feature currently only supported on macOS
15791579
#if os(macOS)
1580-
// Netrc feature currently only supported on macOS 10.13+ due to dependency
1581-
// on NSTextCheckingResult.range(with:)
1582-
if #available(macOS 10.13, *) {
1583-
authProvider = try? Netrc.load(fromFileAtPath: netrcFilePath).get()
1584-
}
1580+
authProvider = try? Netrc.load(fromFileAtPath: netrcFilePath).get()
15851581
#endif
15861582

15871583
// zip files to download
15881584
// stored in a thread-safe way as we may fetch more from "ari" files
15891585
let zipArtifacts = ThreadSafeArrayStore<RemoteArtifact>(artifacts.filter { $0.url.pathExtension.lowercased() == "zip" })
15901586

15911587
// fetch and parse "ari" files, if any
1592-
let hostToolchain = try UserToolchain(destination: .hostDestination())
1593-
let jsonDecoder = JSONDecoder.makeWithDefaults()
15941588
let indexFiles = artifacts.filter { $0.url.pathExtension.lowercased() == "ari" }
1595-
for indexFile in indexFiles {
1596-
group.enter()
1597-
var request = HTTPClient.Request(method: .get, url: indexFile.url)
1598-
request.options.validResponseCodes = [200]
1599-
request.options.authorizationProvider = authProvider?.authorization(for:)
1600-
self.httpClient.execute(request) { result in
1601-
defer { group.leave() }
1589+
if !indexFiles.isEmpty {
1590+
let hostToolchain = try UserToolchain(destination: .hostDestination())
1591+
let jsonDecoder = JSONDecoder.makeWithDefaults()
1592+
for indexFile in indexFiles {
1593+
group.enter()
1594+
var request = HTTPClient.Request(method: .get, url: indexFile.url)
1595+
request.options.validResponseCodes = [200]
1596+
request.options.authorizationProvider = authProvider?.authorization(for:)
1597+
self.httpClient.execute(request) { result in
1598+
defer { group.leave() }
16021599

1603-
do {
1604-
switch result {
1605-
case .failure(let error):
1606-
throw error
1607-
case .success(let response):
1608-
guard let body = response.body else {
1609-
throw StringError("Body is empty")
1610-
}
1611-
// FIXME: would be nice if checksumAlgorithm.hash took Data directly
1612-
let bodyChecksum = self.checksumAlgorithm.hash(ByteString(body)).hexadecimalRepresentation
1613-
guard bodyChecksum == indexFile.checksum else {
1614-
throw StringError("checksum of downloaded artifact of binary target '\(indexFile.targetName)' (\(bodyChecksum)) does not match checksum specified by the manifest (\(indexFile.checksum ))")
1615-
}
1616-
let metadata = try jsonDecoder.decode(ArchiveIndexFile.self, from: body)
1617-
// FIXME: this filter needs to become more sophisticated
1618-
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.tripleString)'")
1600+
do {
1601+
switch result {
1602+
case .failure(let error):
1603+
throw error
1604+
case .success(let response):
1605+
guard let body = response.body else {
1606+
throw StringError("Body is empty")
1607+
}
1608+
// FIXME: would be nice if checksumAlgorithm.hash took Data directly
1609+
let bodyChecksum = self.checksumAlgorithm.hash(ByteString(body)).hexadecimalRepresentation
1610+
guard bodyChecksum == indexFile.checksum else {
1611+
throw StringError("checksum of downloaded artifact of binary target '\(indexFile.targetName)' (\(bodyChecksum)) does not match checksum specified by the manifest (\(indexFile.checksum ))")
1612+
}
1613+
let metadata = try jsonDecoder.decode(ArchiveIndexFile.self, from: body)
1614+
// FIXME: this filter needs to become more sophisticated
1615+
guard let supportedArchive = metadata.archives.first(where: { $0.fileName.lowercased().hasSuffix(".zip") && $0.supportedTriples.contains(hostToolchain.triple) }) else {
1616+
throw StringError("No supported archive was found for '\(hostToolchain.triple.tripleString)'")
1617+
}
1618+
// add relevant archive
1619+
zipArtifacts.append(
1620+
RemoteArtifact(
1621+
packageRef: indexFile.packageRef,
1622+
targetName: indexFile.targetName,
1623+
url: indexFile.url.deletingLastPathComponent().appendingPathComponent(supportedArchive.fileName),
1624+
checksum: supportedArchive.checksum)
1625+
)
16201626
}
1621-
// add relevant archive
1622-
zipArtifacts.append(
1623-
RemoteArtifact(
1624-
packageRef: indexFile.packageRef,
1625-
targetName: indexFile.targetName,
1626-
url: indexFile.url.deletingLastPathComponent().appendingPathComponent(supportedArchive.fileName),
1627-
checksum: supportedArchive.checksum)
1628-
)
1627+
} catch {
1628+
tempDiagnostics.emit(.error("failed retrieving '\(indexFile.url)': \(error)"))
16291629
}
1630-
} catch {
1631-
tempDiagnostics.emit(.error("failed retrieving '\(indexFile.url)': \(error)"))
16321630
}
16331631
}
1634-
}
16351632

1636-
// wait for all "ari" files to be processed
1637-
group.wait()
1633+
// wait for all "ari" files to be processed
1634+
group.wait()
16381635

1639-
// no reason to continue if we already ran into issues
1640-
if tempDiagnostics.hasErrors {
1641-
// collect all diagnostics
1642-
diagnostics.append(contentsOf: tempDiagnostics)
1643-
throw Diagnostics.fatalError
1636+
// no reason to continue if we already ran into issues
1637+
if tempDiagnostics.hasErrors {
1638+
// collect all diagnostics
1639+
diagnostics.append(contentsOf: tempDiagnostics)
1640+
throw Diagnostics.fatalError
1641+
}
16441642
}
16451643

16461644
// finally download zip files, if any
1647-
didDownloadAnyArtifact = zipArtifacts.count > 0
16481645
for artifact in (zipArtifacts.map{ $0 }) {
16491646
group.enter()
16501647
defer { group.leave() }
@@ -1724,7 +1721,7 @@ extension Workspace {
17241721

17251722
group.wait()
17261723

1727-
if didDownloadAnyArtifact {
1724+
if zipArtifacts.count > 0 {
17281725
delegate?.didDownloadBinaryArtifacts()
17291726
}
17301727

0 commit comments

Comments
 (0)