Skip to content

Commit 5aa8f5b

Browse files
committed
[Commands] Add support for SWIFTPM_MIRROR_CONFIG override
<rdar://problem/45418410> SWIFTPM_MIRROR_CONFIG environment variable does not seem to be working as expected
1 parent 0df5552 commit 5aa8f5b

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

Sources/Commands/SwiftTool.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,12 @@ public class SwiftTool<Options: ToolOptions> {
423423
}
424424

425425
func configFilePath() throws -> AbsolutePath {
426+
// Look for the override in the environment.
427+
if let envPath = Process.env["SWIFTPM_MIRROR_CONFIG"] {
428+
return try AbsolutePath(validating: envPath)
429+
}
430+
431+
// Otherwise, use the default path.
426432
return try getPackageRoot().appending(components: ".swiftpm", "config")
427433
}
428434

Tests/CommandsTests/PackageToolTests.swift

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ import Workspace
2323

2424
final class PackageToolTests: XCTestCase {
2525
@discardableResult
26-
private func execute(_ args: [String], packagePath: AbsolutePath? = nil) throws -> String {
27-
return try SwiftPMProduct.SwiftPackage.execute(args, packagePath: packagePath).spm_chomp()
26+
private func execute(_ args: [String], packagePath: AbsolutePath? = nil, env: [String: String]? = nil) throws -> String {
27+
return try SwiftPMProduct.SwiftPackage.execute(args, packagePath: packagePath, env: env).spm_chomp()
2828
}
2929

3030
func testUsage() throws {
@@ -535,6 +535,7 @@ final class PackageToolTests: XCTestCase {
535535
mktmpdir { prefix in
536536
let fs = localFileSystem
537537
let packageRoot = prefix.appending(component: "Foo")
538+
let configOverride = prefix.appending(component: "configoverride")
538539
let configFile = packageRoot.appending(components: ".swiftpm", "config")
539540

540541
fs.createEmptyFiles(at: packageRoot, files:
@@ -549,6 +550,11 @@ final class PackageToolTests: XCTestCase {
549550
try execute(["config", "set-mirror", "--package-url", "[email protected]:apple/swift-package-manager.git", "--mirror-url", "[email protected]:foo/swift-package-manager.git"], packagePath: packageRoot)
550551
XCTAssertTrue(fs.isFile(configFile))
551552

553+
// Test env override.
554+
try execute(["config", "set-mirror", "--package-url", "https://github.com/foo/bar", "--mirror-url", "https://myi.8713187.xyz/foo/bar"], packagePath: packageRoot, env: ["SWIFTPM_MIRROR_CONFIG": configOverride.asString])
555+
XCTAssertTrue(fs.isFile(configOverride))
556+
XCTAssertTrue(try fs.readFileContents(configOverride).asString!.contains("mygithub"))
557+
552558
// Test reading.
553559
XCTAssertEqual(try execute(["config", "get-mirror", "--package-url", "https://github.com/foo/bar"], packagePath: packageRoot),
554560
"https://myi.8713187.xyz/foo/bar")

0 commit comments

Comments
 (0)