@@ -1575,76 +1575,73 @@ extension Workspace {
1575
1575
let result = ThreadSafeArrayStore < ManagedArtifact > ( )
1576
1576
1577
1577
var authProvider : AuthorizationProviding ? = nil
1578
- var didDownloadAnyArtifact = false
1578
+ // Netrc feature currently only supported on macOS
1579
1579
#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 ( )
1585
1581
#endif
1586
1582
1587
1583
// zip files to download
1588
1584
// stored in a thread-safe way as we may fetch more from "ari" files
1589
1585
let zipArtifacts = ThreadSafeArrayStore < RemoteArtifact > ( artifacts. filter { $0. url. pathExtension. lowercased ( ) == " zip " } )
1590
1586
1591
1587
// fetch and parse "ari" files, if any
1592
- let hostToolchain = try UserToolchain ( destination: . hostDestination( ) )
1593
- let jsonDecoder = JSONDecoder . makeWithDefaults ( )
1594
1588
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 ( ) }
1602
1599
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
+ )
1620
1626
}
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) " ) )
1629
1629
}
1630
- } catch {
1631
- tempDiagnostics. emit ( . error( " failed retrieving ' \( indexFile. url) ': \( error) " ) )
1632
1630
}
1633
1631
}
1634
- }
1635
1632
1636
- // wait for all "ari" files to be processed
1637
- group. wait ( )
1633
+ // wait for all "ari" files to be processed
1634
+ group. wait ( )
1638
1635
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
+ }
1644
1642
}
1645
1643
1646
1644
// finally download zip files, if any
1647
- didDownloadAnyArtifact = zipArtifacts. count > 0
1648
1645
for artifact in ( zipArtifacts. map { $0 } ) {
1649
1646
group. enter ( )
1650
1647
defer { group. leave ( ) }
@@ -1724,7 +1721,7 @@ extension Workspace {
1724
1721
1725
1722
group. wait ( )
1726
1723
1727
- if didDownloadAnyArtifact {
1724
+ if zipArtifacts . count > 0 {
1728
1725
delegate? . didDownloadBinaryArtifacts ( )
1729
1726
}
1730
1727
0 commit comments