Skip to content

Commit a11b7e9

Browse files
committed
Use fully qualified command paths only if the binary can be found in the selected toolchain
1 parent edb9439 commit a11b7e9

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

Sources/Swiftly/Run.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,9 @@ struct Run: SwiftlyCommand {
105105

106106
try await Swiftly.currentPlatform.proxy(ctx, toolchain, command[0], [String](command[1...]))
107107
} catch let terminated as RunProgramError {
108+
if ctx.mockedHomeDir != nil {
109+
throw terminated
110+
}
108111
Foundation.exit(terminated.exitCode)
109112
} catch {
110113
throw error

Sources/SwiftlyCore/Platform.swift

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,11 +167,19 @@ extension Platform {
167167
public func proxy(_ ctx: SwiftlyCoreContext, _ toolchain: ToolchainVersion, _ command: String, _ arguments: [String], _ env: [String: String] = [:]) async throws {
168168
let tcPath = self.findToolchainLocation(ctx, toolchain).appendingPathComponent("usr/bin")
169169

170+
let commandTcPath = tcPath.appendingPathComponent(command)
171+
let commandToRun = if FileManager.default.fileExists(atPath: commandTcPath.path) {
172+
commandTcPath.path
173+
} else {
174+
command
175+
}
176+
170177
var newEnv = try self.proxyEnv(ctx, env: ProcessInfo.processInfo.environment, toolchain: toolchain)
171178
for (key, value) in env {
172179
newEnv[key] = value
173180
}
174-
try self.runProgram([tcPath.appendingPathComponent(command).path] + arguments, env: newEnv)
181+
182+
try self.runProgram([commandToRun] + arguments, env: newEnv)
175183
}
176184

177185
/// Proxy the invocation of the provided command to the chosen toolchain and capture the output.
@@ -181,7 +189,15 @@ extension Platform {
181189
///
182190
public func proxyOutput(_ ctx: SwiftlyCoreContext, _ toolchain: ToolchainVersion, _ command: String, _ arguments: [String]) async throws -> String? {
183191
let tcPath = self.findToolchainLocation(ctx, toolchain).appendingPathComponent("usr/bin")
184-
return try await self.runProgramOutput(tcPath.appendingPathComponent(command).path, arguments, env: self.proxyEnv(ctx, env: ProcessInfo.processInfo.environment, toolchain: toolchain))
192+
193+
let commandTcPath = tcPath.appendingPathComponent(command)
194+
let commandToRun = if FileManager.default.fileExists(atPath: commandTcPath.path) {
195+
commandTcPath.path
196+
} else {
197+
command
198+
}
199+
200+
return try await self.runProgramOutput(commandToRun, arguments, env: self.proxyEnv(ctx, env: ProcessInfo.processInfo.environment, toolchain: toolchain))
185201
}
186202

187203
/// Run a program.

0 commit comments

Comments
 (0)