Skip to content

Commit 97fe246

Browse files
committed
Toolchains: disable xcrun commands on non-Darwin platforms
Shortcut the `xcrun` based finding of tools to immediately fail on non-macOS platforms, returning `nil`. This should help non-macOS platforms by avoiding the unnecessary search paths and failing to execute the command which is not found.
1 parent bd50b23 commit 97fe246

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

Sources/SwiftDriver/Toolchains/Toolchain.swift

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -224,12 +224,16 @@ extension Toolchain {
224224
return path
225225
} else if let path = lookupExecutablePath(filename: executableName(executable), currentWorkingDirectory: fileSystem.currentWorkingDirectory, searchPaths: [try executableDir]) {
226226
return path
227-
} else if let path = try? xcrunFind(executable: executableName(executable)) {
227+
}
228+
#if canImport(Darwin)
229+
if let path = try? xcrunFind(executable: executableName(executable)) {
228230
return path
229-
} else if !["swift-frontend", "swift"].contains(executable),
230-
let parentDirectory = try? getToolPath(.swiftCompiler).parentDirectory,
231-
try parentDirectory != executableDir,
232-
let path = lookupExecutablePath(filename: executableName(executable), searchPaths: [parentDirectory]) {
231+
}
232+
#endif
233+
if !["swift-frontend", "swift"].contains(executable),
234+
let parentDirectory = try? getToolPath(.swiftCompiler).parentDirectory,
235+
try parentDirectory != executableDir,
236+
let path = lookupExecutablePath(filename: executableName(executable), searchPaths: [parentDirectory]) {
233237
// If the driver library's client and the frontend are in different directories,
234238
// try looking for tools next to the frontend.
235239
return path
@@ -246,9 +250,9 @@ extension Toolchain {
246250
} else {
247251
return try AbsolutePath(validating: "/usr/bin/" + executable)
248252
}
249-
} else {
250-
throw ToolchainError.unableToFind(tool: executable)
251253
}
254+
255+
throw ToolchainError.unableToFind(tool: executable)
252256
}
253257

254258
/// Looks for the executable in the `SWIFT_DRIVER_SWIFTSCAN_LIB` environment variable, if found nothing,

0 commit comments

Comments
 (0)