Skip to content

Commit

Permalink
Fix finding of xz in the PATH
Browse files Browse the repository at this point in the history
 - Seems like the environment needed to be passed to the which() method.
  • Loading branch information
xtremekforever committed Feb 20, 2025
1 parent c63f6be commit 3b853b3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ extension SwiftSDKGenerator {
let xzPath = try await which("xz")
if xzPath == nil {
logger.warning("""
The 'xz' utility was not found in path. \
The `xz` utility was not found in `PATH`. \
Consider installing it for more efficient downloading of package lists.
""")
}
Expand Down
6 changes: 5 additions & 1 deletion Sources/SwiftSDKGenerator/SystemUtils/which.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
//===----------------------------------------------------------------------===//

import AsyncProcess
import Foundation

/// Look for an executable using the `which` utility.
///
Expand All @@ -19,9 +20,12 @@ import AsyncProcess
/// - Returns: The path to the executable if found, otherwise nil.
func which(_ executableName: String) async throws -> String? {
let result = try await ProcessExecutor.runCollectingOutput(
executable: "/usr/bin/which", [executableName], collectStandardOutput: true, collectStandardError: false
executable: "/usr/bin/which", [executableName], collectStandardOutput: true, collectStandardError: false,
environment: ProcessInfo.processInfo.environment
)

try result.exitReason.throwIfNonZero()

if let output = result.standardOutput {
let path = String(buffer: output).trimmingCharacters(in: .whitespacesAndNewlines)
return path.isEmpty ? nil : path
Expand Down

0 comments on commit 3b853b3

Please sign in to comment.