Skip to content

Commit 0897e28

Browse files
committed
Allow a custom env for more xcrun invocations
Basically a continuation of #1766
1 parent 5f63b90 commit 0897e28

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

Sources/Build/llbuild.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public struct LLBuildManifestGenerator {
8787
}
8888

8989
/// Generate manifest at the given path.
90-
public func generateManifest(at path: AbsolutePath) throws {
90+
public func generateManifest(at path: AbsolutePath, environment: [String:String] = Process.env) throws {
9191
var targets = Targets()
9292

9393
// Create commands for all target description in the plan.
@@ -99,7 +99,7 @@ public struct LLBuildManifestGenerator {
9999
buildByDefault: plan.graph.reachableTargets.contains(target),
100100
isTest: description.isTestTarget)
101101
case .clang(let description):
102-
targets.append(try createClangCompileTarget(description),
102+
targets.append(try createClangCompileTarget(description, environment: environment),
103103
buildByDefault: plan.graph.reachableTargets.contains(target),
104104
isTest: description.isTestTarget)
105105
}
@@ -215,7 +215,7 @@ public struct LLBuildManifestGenerator {
215215
}
216216

217217
/// Create a llbuild target for a Clang target description.
218-
private func createClangCompileTarget(_ target: ClangTargetBuildDescription) throws -> Target {
218+
private func createClangCompileTarget(_ target: ClangTargetBuildDescription, environment: [String:String] = Process.env) throws -> Target {
219219

220220
let standards = [
221221
(target.clangTarget.cxxLanguageStandard, SupportedLanguageExtension.cppExtensions),

Sources/Workspace/UserToolchain.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,9 @@ public final class UserToolchain: Toolchain {
129129
return lookupExecutablePath(filename: getenv(variable), searchPaths: searchPaths)
130130
}
131131

132+
/// Environment to use when looking up tools.
133+
private let processEnvironment: [String: String]
134+
132135
public func getClangCompiler() throws -> AbsolutePath {
133136

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

160-
public init(destination: Destination, environment: [String:String] = Process.env) throws {
163+
public init(destination: Destination, environment: [String: String] = Process.env) throws {
161164
self.destination = destination
165+
self.processEnvironment = environment
162166

163167
// Get the search paths from PATH.
164168
let searchPaths = getEnvSearchPaths(

0 commit comments

Comments
 (0)