Skip to content

Commit

Permalink
add env HOME to avoid LLVM ERROR: cannot get default cache directory
Browse files Browse the repository at this point in the history
  • Loading branch information
banjun committed Feb 5, 2024
1 parent a33514b commit acc36d4
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions Sources/Core/NSTaskCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,22 @@ struct NSTaskCommand {
}

@discardableResult
func run(clearEnvironments: Bool = true) throws -> (stdout: String?, stderr: String?) {
func run(clearEnvironments: Bool = true, setEnvHome: String? = NSHomeDirectory()) throws -> (stdout: String?, stderr: String?) {
let NSTask: AnyClass? = NSClassFromString("NSTask")
let task = NSTask?.value(forKey: "new") as? NSObject
guard let task else { throw Error.nsTaskUnavailable }

var environment = task.value(forKey: "environment") as? [AnyHashable: Any] ?? [:]
print("⚡ environment before = \(environment)")
if clearEnvironments {
task.setValue([:], forKey: "environment")
environment.removeAll()
}
if let setEnvHome {
// preserve or add HOME to avoid error: `LLVM ERROR: cannot get default cache directory`
environment["HOME"] = setEnvHome
}
task.setValue(environment, forKey: "environment")
print("⚡ environment after = \(environment)")

task.setValue(launchPath, forKey: "launchPath")
task.setValue(args, forKey: "arguments")
Expand Down

0 comments on commit acc36d4

Please sign in to comment.