Skip to content

Commit

Permalink
Toolchains: disable xcrun commands on non-Darwin platforms
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
compnerd committed Jan 20, 2025
1 parent bd50b23 commit 97fe246
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions Sources/SwiftDriver/Toolchains/Toolchain.swift
Original file line number Diff line number Diff line change
Expand Up @@ -224,12 +224,16 @@ extension Toolchain {
return path
} else if let path = lookupExecutablePath(filename: executableName(executable), currentWorkingDirectory: fileSystem.currentWorkingDirectory, searchPaths: [try executableDir]) {
return path
} else if let path = try? xcrunFind(executable: executableName(executable)) {
}
#if canImport(Darwin)
if let path = try? xcrunFind(executable: executableName(executable)) {
return path
} else if !["swift-frontend", "swift"].contains(executable),
let parentDirectory = try? getToolPath(.swiftCompiler).parentDirectory,
try parentDirectory != executableDir,
let path = lookupExecutablePath(filename: executableName(executable), searchPaths: [parentDirectory]) {
}
#endif
if !["swift-frontend", "swift"].contains(executable),
let parentDirectory = try? getToolPath(.swiftCompiler).parentDirectory,
try parentDirectory != executableDir,
let path = lookupExecutablePath(filename: executableName(executable), searchPaths: [parentDirectory]) {
// If the driver library's client and the frontend are in different directories,
// try looking for tools next to the frontend.
return path
Expand All @@ -246,9 +250,9 @@ extension Toolchain {
} else {
return try AbsolutePath(validating: "/usr/bin/" + executable)
}
} else {
throw ToolchainError.unableToFind(tool: executable)
}

throw ToolchainError.unableToFind(tool: executable)
}

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

0 comments on commit 97fe246

Please sign in to comment.