Skip to content

Commit 485e35e

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

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
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: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,8 @@ public final class UserToolchain: Toolchain {
129129
return lookupExecutablePath(filename: getenv(variable), searchPaths: searchPaths)
130130
}
131131

132+
private let environment: [String:String]
133+
132134
public func getClangCompiler() throws -> AbsolutePath {
133135

134136
if let clangCompiler = _clangCompiler {
@@ -142,7 +144,7 @@ public final class UserToolchain: Toolchain {
142144
clangCompiler = value
143145
} else {
144146
// No value in env, so search for `clang`.
145-
let foundPath = try Process.checkNonZeroExit(arguments: whichClangArgs).chomp()
147+
let foundPath = try Process.checkNonZeroExit(arguments: whichClangArgs, environment: environment).chomp()
146148
guard !foundPath.isEmpty else {
147149
throw InvalidToolchainDiagnostic("could not find `clang`")
148150
}
@@ -159,6 +161,7 @@ public final class UserToolchain: Toolchain {
159161

160162
public init(destination: Destination, environment: [String:String] = Process.env) throws {
161163
self.destination = destination
164+
self.environment = environment
162165

163166
// Get the search paths from PATH.
164167
let searchPaths = getEnvSearchPaths(

0 commit comments

Comments
 (0)