Skip to content

Commit 18e4a0a

Browse files
committed
fenced netrc feature for macOS 10.13+
1 parent fadbf2e commit 18e4a0a

File tree

3 files changed

+28
-9
lines changed

3 files changed

+28
-9
lines changed

Sources/Commands/Options.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,10 @@ public class ToolOptions {
112112
archs.count > 1 ? .xcode : _buildSystem
113113
}
114114

115+
#if os(macOS)
115116
/// The location of the netrc file which should be use for authentication when downloading binary target artifacts
116117
public var netrcFilePath: AbsolutePath?
118+
#endif
117119

118120
public var _buildSystem: BuildSystemKind = .native
119121

Sources/Commands/SwiftTool.swift

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -474,11 +474,16 @@ public class SwiftTool<Options: ToolOptions> {
474474
option: parser.add(option: "--build-system", kind: BuildSystemKind.self, usage: nil),
475475
to: { $0._buildSystem = $1 })
476476

477-
binder.bind(
478-
option: parser.add(
479-
option: "--netrc-file", kind: PathArgument.self,
480-
usage: "Absolute path to netrc file for downloading binary target artifacts"),
481-
to: { $0.netrcFilePath = $1.path })
477+
#if os(macOS)
478+
if #available(macOS 10.13, *) {
479+
// implementation of the netrc reader depends upon macOS 10.13
480+
binder.bind(
481+
option: parser.add(
482+
option: "--netrc-file", kind: PathArgument.self,
483+
usage: "Absolute path to netrc file for downloading binary target artifacts"),
484+
to: { $0.netrcFilePath = $1.path })
485+
}
486+
#endif
482487

483488
// Let subclasses bind arguments.
484489
type(of: self).defineArguments(parser: parser, binder: binder)
@@ -610,7 +615,13 @@ public class SwiftTool<Options: ToolOptions> {
610615
}()
611616

612617
func resolvedNetrcFilePath() -> AbsolutePath? {
613-
return options.netrcFilePath ?? AbsolutePath("\(NSHomeDirectory())/.netrc")
618+
// Netrc feature depends upon macOS 10.13
619+
#if os(macOS)
620+
if #available(macOS 10.13, *) {
621+
return options.netrcFilePath
622+
}
623+
#endif
624+
return nil
614625
}
615626

616627
/// Holds the currently active workspace.

Sources/Workspace/Workspace.swift

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1403,9 +1403,15 @@ extension Workspace {
14031403
private func download(_ artifacts: [ManagedArtifact], diagnostics: DiagnosticsEngine) {
14041404
let group = DispatchGroup()
14051405
let tempDiagnostics = DiagnosticsEngine()
1406-
1407-
let netrc = try? Netrc.load(fromFileAtPath: netrcFilePath).get()
14081406

1407+
var authProvider: AuthorizationProviding? = nil
1408+
#if os(macOS)
1409+
// Netrc feature currently only supported on macOS 10.13+ due to dependency
1410+
// on NSTextCheckingResult.range(with:)
1411+
if #available(macOS 10.13, *) {
1412+
authProvider = try? Netrc.load(fromFileAtPath: netrcFilePath).get()
1413+
}
1414+
#endif
14091415
for artifact in artifacts {
14101416
group.enter()
14111417

@@ -1429,7 +1435,7 @@ extension Workspace {
14291435
downloader.downloadFile(
14301436
at: parsedURL,
14311437
to: archivePath,
1432-
withAuthorizationProvider: netrc,
1438+
withAuthorizationProvider: authProvider,
14331439
progress: { bytesDownloaded, totalBytesToDownload in
14341440
self.delegate?.downloadingBinaryArtifact(
14351441
from: url,

0 commit comments

Comments
 (0)