Skip to content

Commit

Permalink
Merge pull request #17 from banjun/fix-llvm-cache-dir-error
Browse files Browse the repository at this point in the history
Fix LLVM ERROR: cannot get default cache directory
  • Loading branch information
banjun authored Feb 5, 2024
2 parents a33514b + 3549dc7 commit f56cc5b
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions Sources/Core/NSTaskCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,20 @@ 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] ?? [:]
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")

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

0 comments on commit f56cc5b

Please sign in to comment.