Skip to content

Commit 60fcb94

Browse files
committed
working with custom netrc file location
1 parent a9dcb7e commit 60fcb94

File tree

6 files changed

+30
-1
lines changed

6 files changed

+30
-1
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_10)
23+
macOSPlatform = .macOS(.v10_13)
2424
}
2525

2626
let package = Package(

Sources/Commands/Options.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,9 @@ public class ToolOptions {
111111
// Force the Xcode build system if we want to build more than one arch.
112112
archs.count > 1 ? .xcode : _buildSystem
113113
}
114+
115+
/// The location of the netrc file which should be use for authentication when downloading binary target artifacts
116+
public var netrcFilePath: AbsolutePath?
114117

115118
public var _buildSystem: BuildSystemKind = .native
116119

Sources/Commands/SwiftTool.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
import func Foundation.NSUserName
1212
import class Foundation.ProcessInfo
13+
import func Foundation.NSHomeDirectory
1314
import Dispatch
1415

1516
import TSCLibc
@@ -472,6 +473,12 @@ public class SwiftTool<Options: ToolOptions> {
472473
binder.bind(
473474
option: parser.add(option: "--build-system", kind: BuildSystemKind.self, usage: nil),
474475
to: { $0._buildSystem = $1 })
476+
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 })
475482

476483
// Let subclasses bind arguments.
477484
type(of: self).defineArguments(parser: parser, binder: binder)
@@ -601,6 +608,10 @@ public class SwiftTool<Options: ToolOptions> {
601608
private lazy var _swiftpmConfig: Result<SwiftPMConfig, Swift.Error> = {
602609
return Result(catching: { SwiftPMConfig(path: try configFilePath()) })
603610
}()
611+
612+
func resolvedNetrcFilePath() -> AbsolutePath? {
613+
return options.netrcFilePath ?? AbsolutePath("\(NSHomeDirectory())/.netrc")
614+
}
604615

605616
/// Holds the currently active workspace.
606617
///
@@ -626,6 +637,7 @@ public class SwiftTool<Options: ToolOptions> {
626637
delegate: delegate,
627638
config: try getSwiftPMConfig(),
628639
repositoryProvider: provider,
640+
netrcFilePath: resolvedNetrcFilePath(),
629641
isResolverPrefetchingEnabled: options.shouldEnableResolverPrefetching,
630642
skipUpdate: options.skipDependencyUpdate,
631643
enableResolverTrace: options.enableResolverTrace

Sources/SPMTestSupport/MockDownloader.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ public class MockDownloader: Downloader {
4949
public func downloadFile(
5050
at url: Foundation.URL,
5151
to destinationPath: AbsolutePath,
52+
withAuthorizationProvider authorizationProvider: AuthorizationProviding?,
5253
progress: @escaping Downloader.Progress,
5354
completion: @escaping Downloader.Completion
5455
) {

Sources/Workspace/Workspace.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,8 @@ public class Workspace {
346346

347347
/// The downloader used for downloading binary artifacts.
348348
fileprivate let downloader: Downloader
349+
350+
fileprivate let netrcFilePath: AbsolutePath?
349351

350352
/// The downloader used for unarchiving binary artifacts.
351353
fileprivate let archiver: Archiver
@@ -396,6 +398,7 @@ public class Workspace {
396398
fileSystem: FileSystem = localFileSystem,
397399
repositoryProvider: RepositoryProvider = GitRepositoryProvider(),
398400
downloader: Downloader = FoundationDownloader(),
401+
netrcFilePath: AbsolutePath? = nil,
399402
archiver: Archiver = ZipArchiver(),
400403
checksumAlgorithm: HashAlgorithm = SHA256(),
401404
additionalFileRules: [FileRuleDescription] = [],
@@ -412,6 +415,7 @@ public class Workspace {
412415
self.currentToolsVersion = currentToolsVersion
413416
self.toolsVersionLoader = toolsVersionLoader
414417
self.downloader = downloader
418+
self.netrcFilePath = netrcFilePath
415419
self.archiver = archiver
416420
self.checksumAlgorithm = checksumAlgorithm
417421
self.isResolverPrefetchingEnabled = isResolverPrefetchingEnabled
@@ -1400,6 +1404,8 @@ extension Workspace {
14001404
let group = DispatchGroup()
14011405
let tempDiagnostics = DiagnosticsEngine()
14021406

1407+
let netrc = try? Netrc.load(fromFileAtPath: netrcFilePath).get()
1408+
14031409
for artifact in artifacts {
14041410
group.enter()
14051411

@@ -1418,9 +1424,12 @@ extension Workspace {
14181424

14191425
let parsedURL = URL(string: url)!
14201426
let archivePath = parentDirectory.appending(component: parsedURL.lastPathComponent)
1427+
1428+
14211429
downloader.downloadFile(
14221430
at: parsedURL,
14231431
to: archivePath,
1432+
withAuthorizationProvider: netrc,
14241433
progress: { bytesDownloaded, totalBytesToDownload in
14251434
self.delegate?.downloadingBinaryArtifact(
14261435
from: url,

Tests/CommandsTests/PackageToolTests.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ final class PackageToolTests: XCTestCase {
4141
func testVersion() throws {
4242
XCTAssert(try execute(["--version"]).stdout.contains("Swift Package Manager"))
4343
}
44+
45+
func testNetrcFile() throws {
46+
XCTAssert(try execute(["--netrc-file", "/Users/me/.hidden/.netrc"]).stdout.contains("Absolute path to netrc file"))
47+
}
4448

4549
func testResolve() throws {
4650
fixture(name: "DependencyResolution/External/Simple") { prefix in

0 commit comments

Comments
 (0)