Skip to content

Allow a custom env for various xcrun invocations #1766

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
Aug 28, 2018
Merged
Show file tree
Hide file tree
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
11 changes: 6 additions & 5 deletions Sources/Workspace/Destination.swift
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ public struct Destination {
/// The destination describing the host OS.
public static func hostDestination(
_ binDir: AbsolutePath? = nil,
originalWorkingDirectory: AbsolutePath? = localFileSystem.currentWorkingDirectory
originalWorkingDirectory: AbsolutePath? = localFileSystem.currentWorkingDirectory,
environment: [String:String] = Process.env
) throws -> Destination {
// Select the correct binDir.
let binDir = binDir ?? Destination.hostBinDir(
Expand All @@ -98,7 +99,7 @@ public struct Destination {
} else {
// No value in env, so search for it.
let sdkPathStr = try Process.checkNonZeroExit(
args: "xcrun", "--sdk", "macosx", "--show-sdk-path").chomp()
arguments: ["xcrun", "--sdk", "macosx", "--show-sdk-path"], environment: environment).chomp()
guard !sdkPathStr.isEmpty else {
throw DestinationError.invalidInstallation("default SDK not found")
}
Expand All @@ -107,7 +108,7 @@ public struct Destination {

// Compute common arguments for clang and swift.
// This is currently just frameworks path.
let commonArgs = Destination.sdkPlatformFrameworkPath().map({ ["-F", $0.asString] }) ?? []
let commonArgs = Destination.sdkPlatformFrameworkPath(environment: environment).map({ ["-F", $0.asString] }) ?? []

return Destination(
target: hostTargetTriple,
Expand All @@ -132,12 +133,12 @@ public struct Destination {
}

/// Returns macosx sdk platform framework path.
public static func sdkPlatformFrameworkPath() -> AbsolutePath? {
public static func sdkPlatformFrameworkPath(environment: [String:String] = Process.env) -> AbsolutePath? {
if let path = _sdkPlatformFrameworkPath {
return path
}
let platformPath = try? Process.checkNonZeroExit(
args: "xcrun", "--sdk", "macosx", "--show-sdk-platform-path").chomp()
arguments: ["xcrun", "--sdk", "macosx", "--show-sdk-platform-path"], environment: environment).chomp()

if let platformPath = platformPath, !platformPath.isEmpty {
_sdkPlatformFrameworkPath = AbsolutePath(platformPath).appending(
Expand Down
4 changes: 2 additions & 2 deletions Sources/Workspace/UserToolchain.swift
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public final class UserToolchain: Toolchain {
return clangCompiler
}

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

// Get the search paths from PATH.
Expand All @@ -183,7 +183,7 @@ public final class UserToolchain: Toolchain {
#if os(macOS)
// FIXME: We should have some general utility to find tools.
let xctestFindArgs = ["xcrun", "--sdk", "macosx", "--find", "xctest"]
self.xctest = try AbsolutePath(validating: Process.checkNonZeroExit(arguments: xctestFindArgs).chomp())
self.xctest = try AbsolutePath(validating: Process.checkNonZeroExit(arguments: xctestFindArgs, environment: environment).chomp())
#else
self.xctest = nil
#endif
Expand Down