Skip to content

Commit 13323a9

Browse files
committed
Move proxy circularity check out of swiftly run
1 parent 29ae892 commit 13323a9

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

Sources/Swiftly/Proxy.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,13 @@ public enum Proxy {
5656
throw Error(message: "No swift toolchain could be selected from either from a .swift-version file, or the default. You can try using `swiftly install <toolchain version>` to install one.")
5757
}
5858

59-
try await Swiftly.currentPlatform.proxy(toolchain, binName, Array(CommandLine.arguments[1...]))
59+
// Prevent circularities with a memento environment variable
60+
guard ProcessInfo.processInfo.environment["SWIFTLY_PROXY_IN_PROGRESS"] == nil else {
61+
throw Error(message: "Circular swiftly proxy invocation")
62+
}
63+
let env = ["SWIFTLY_PROXY_IN_PROGRESS": "1"]
64+
65+
try await Swiftly.currentPlatform.proxy(toolchain, binName, Array(CommandLine.arguments[1...]), env)
6066
} catch let terminated as RunProgramError {
6167
exit(terminated.exitCode)
6268
} catch let error as Error {

Sources/SwiftlyCore/Platform.swift

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -143,12 +143,6 @@ extension Platform {
143143
let tcPath = self.findToolchainLocation(toolchain).appendingPathComponent("usr/bin")
144144
var newEnv = ProcessInfo.processInfo.environment
145145

146-
// Prevent circularities with a memento environment variable
147-
guard newEnv["SWIFTLY_PROXY_IN_PROGRESS"] == nil else {
148-
throw Error(message: "Circular swiftly proxy invocation")
149-
}
150-
newEnv["SWIFTLY_PROXY_IN_PROGRESS"] = "1"
151-
152146
// The toolchain goes to the beginning of the PATH
153147
var newPath = newEnv["PATH"] ?? ""
154148
if !newPath.hasPrefix(tcPath.path + ":") {
@@ -164,8 +158,12 @@ extension Platform {
164158
/// In the case where the command exit with a non-zero exit code a RunProgramError is thrown with
165159
/// the exit code and program information.
166160
///
167-
public func proxy(_ toolchain: ToolchainVersion, _ command: String, _ arguments: [String]) async throws {
168-
try self.runProgram([command] + arguments, env: self.proxyEnv(toolchain))
161+
public func proxy(_ toolchain: ToolchainVersion, _ command: String, _ arguments: [String], _ env: [String: String] = [:]) async throws {
162+
var newEnv = try self.proxyEnv(toolchain)
163+
for (key, value) in env {
164+
newEnv[key] = value
165+
}
166+
try self.runProgram([command] + arguments, env: newEnv)
169167
}
170168

171169
/// Proxy the invocation of the provided command to the chosen toolchain and capture the output.

0 commit comments

Comments
 (0)