Skip to content

Allow a custom env for more xcrun invocations #1770

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 7, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions Sources/Workspace/UserToolchain.swift
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,9 @@ public final class UserToolchain: Toolchain {
return lookupExecutablePath(filename: getenv(variable), searchPaths: searchPaths)
}

/// Environment to use when looking up tools.
private let processEnvironment: [String: String]

public func getClangCompiler() throws -> AbsolutePath {

if let clangCompiler = _clangCompiler {
Expand All @@ -142,7 +145,7 @@ public final class UserToolchain: Toolchain {
clangCompiler = value
} else {
// No value in env, so search for `clang`.
let foundPath = try Process.checkNonZeroExit(arguments: whichClangArgs).chomp()
let foundPath = try Process.checkNonZeroExit(arguments: whichClangArgs, environment: processEnvironment).chomp()
guard !foundPath.isEmpty else {
throw InvalidToolchainDiagnostic("could not find `clang`")
}
Expand All @@ -157,8 +160,9 @@ public final class UserToolchain: Toolchain {
return clangCompiler
}

public init(destination: Destination, environment: [String:String] = Process.env) throws {
public init(destination: Destination, environment: [String: String] = Process.env) throws {
self.destination = destination
self.processEnvironment = environment

// Get the search paths from PATH.
let searchPaths = getEnvSearchPaths(
Expand Down