Skip to content

Commit c406a8f

Browse files
committed
Added support to TSC for using Netrc credentials for binary artifact access https://forums.swift.org/t/spm-support-basic-auth-for-non-git-binary-dependency-hosts/37878
1 parent 04f92b9 commit c406a8f

File tree

4 files changed

+30
-5
lines changed

4 files changed

+30
-5
lines changed

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ let macOSPlatform: SupportedPlatform
2020
if let deploymentTarget = ProcessInfo.processInfo.environment["SWIFTPM_MACOS_DEPLOYMENT_TARGET"] {
2121
macOSPlatform = .macOS(deploymentTarget)
2222
} else {
23-
macOSPlatform = .macOS(.v10_13)
23+
macOSPlatform = .macOS(.v10_10)
2424
}
2525

2626
let package = Package(

Sources/Workspace/Workspace.swift

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

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

@@ -1430,7 +1436,7 @@ extension Workspace {
14301436
downloader.downloadFile(
14311437
at: parsedURL,
14321438
to: archivePath,
1433-
withAuthorizationProvider: netrc,
1439+
withAuthorizationProvider: authProvider,
14341440
progress: { bytesDownloaded, totalBytesToDownload in
14351441
self.delegate?.downloadingBinaryArtifact(
14361442
from: url,

Tests/CommandsTests/PackageToolTests.swift

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,25 @@ final class PackageToolTests: XCTestCase {
4343
}
4444

4545
func testNetrcFile() throws {
46-
XCTAssert(try execute(["--netrc-file", "/Users/me/.hidden/.netrc"]).stdout.contains("Absolute path to netrc file"))
46+
func verifyUnsupportedOSThrows() {
47+
do {
48+
// should throw and be caught
49+
try execute(["--netrc-file", "/Users/me/.hidden/.netrc"])
50+
XCTFail()
51+
} catch {
52+
XCTAssert(true)
53+
}
54+
}
55+
#if os(macOS)
56+
if #available(macOS 10.13, *) {
57+
// should succeed
58+
XCTAssert(try execute(["--netrc-file", "/Users/me/.hidden/.netrc"]).stdout.contains("Absolute path to netrc file"))
59+
} else {
60+
verifyUnsupportedOSThrows()
61+
}
62+
#else
63+
verifyUnsupportedOSThrows()
64+
#endif
4765
}
4866

4967
func testResolve() throws {

swift-tools-support-core/Package.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import PackageDescription
1515

1616
let package = Package(
1717
name: "swift-tools-support-core",
18+
platforms: [.macOS(.v10_13)],
1819
products: [
1920
.library(
2021
name: "SwiftToolsSupport",

0 commit comments

Comments
 (0)