Skip to content

Commit 25b51ce

Browse files
committed
ADD - SWIFT_DRIVER_TOOLNAME_EXEC support for all Toolchains.
1 parent e53c79b commit 25b51ce

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

Sources/SwiftDriver/Toolchains/DarwinToolchain.swift

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@
1111
//===----------------------------------------------------------------------===//
1212
import TSCBasic
1313

14-
fileprivate func envVarName(forExecutable toolName: String) -> String {
15-
return "SWIFT_DRIVER_\(toolName.uppercased())_EXEC"
16-
}
17-
1814
/// Toolchain for Darwin-based platforms, such as macOS and iOS.
1915
///
2016
/// FIXME: This class is not thread-safe.
@@ -124,7 +120,7 @@ public final class DarwinToolchain: Toolchain {
124120
/// looks in the executable path; finally, fallback to xcrunFind.
125121
/// - Parameter exec: executable to look for [i.e. `swift`].
126122
func lookup(exec: String) throws -> AbsolutePath {
127-
if let overrideString = env[envVarName(forExecutable: exec)] {
123+
if let overrideString = envVar(forExecutable: exec) {
128124
return try AbsolutePath(validating: overrideString)
129125
} else if let path = lookupExecutablePath(filename: exec, searchPaths: [executableDir]) {
130126
return path

Sources/SwiftDriver/Toolchains/Toolchain.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,4 +83,15 @@ extension Toolchain {
8383
}
8484
return AbsolutePath(path).parentDirectory
8585
}
86+
87+
/// Looks for `SWIFT_DRIVER_TOOLNAME_EXEC` in the `env` property.
88+
/// - Returns: Environment variable value, if any.
89+
func envVar(forExecutable toolName: String) -> String? {
90+
return env[envVarName(for: toolName)]
91+
}
92+
93+
/// - Returns: String in the form of: `SWIFT_DRIVER_TOOLNAME_EXEC`
94+
private func envVarName(for toolName: String) -> String {
95+
return "SWIFT_DRIVER_\(toolName.uppercased())_EXEC"
96+
}
8697
}

0 commit comments

Comments
 (0)