@@ -107,34 +107,35 @@ extension Toolchain {
107
107
return " SWIFT_DRIVER_ \( toolName. uppercased ( ) ) _EXEC "
108
108
}
109
109
110
- /// Looks for the executable in the `SWIFT_DRIVER_TOOLNAME_EXEC` enviroment variable, if found nothing,
110
+ /// Looks for the executable in the `SWIFT_DRIVER_TOOLNAME_EXEC` environment variable, if found nothing,
111
111
/// looks in the `executableDir`, `xcrunFind` or in the `searchPaths`.
112
- /// - Parameter exec : executable to look for [i.e. `swift`].
113
- func lookup( exec : String ) throws -> AbsolutePath {
114
- if let overrideString = envVar ( forExecutable: exec ) {
112
+ /// - Parameter executable : executable to look for [i.e. `swift`].
113
+ func lookup( executable : String ) throws -> AbsolutePath {
114
+ if let overrideString = envVar ( forExecutable: executable ) {
115
115
return try AbsolutePath ( validating: overrideString)
116
- } else if let path = lookupExecutablePath ( filename: exec , searchPaths: [ executableDir] ) {
116
+ } else if let path = lookupExecutablePath ( filename: executable , searchPaths: [ executableDir] ) {
117
117
return path
118
- } else if let path = try ? xcrunFind ( exec : exec ) {
118
+ } else if let path = try ? xcrunFind ( executable : executable ) {
119
119
return path
120
- } else if let path = lookupExecutablePath ( filename: exec , searchPaths: searchPaths) {
120
+ } else if let path = lookupExecutablePath ( filename: executable , searchPaths: searchPaths) {
121
121
return path
122
122
} else {
123
- // This is a hack so our tests work on linux. We need a better way for looking up tools in general.
124
- return AbsolutePath ( " /usr/bin/ " + exec )
123
+ // This is a hack so our tests work on linux.
124
+ return AbsolutePath ( " /usr/bin/ " + executable )
125
125
}
126
126
}
127
127
128
- private func xcrunFind( exec: String ) throws -> AbsolutePath {
129
- #if os(macOS)
128
+ private func xcrunFind( executable: String ) throws -> AbsolutePath {
129
+ let xcrun = " xcrun "
130
+ guard lookupExecutablePath ( filename: xcrun, searchPaths: searchPaths) != nil else {
131
+ throw ToolchainError . unableToFind ( tool: xcrun)
132
+ }
133
+
130
134
let path = try Process . checkNonZeroExit (
131
- arguments: [ " xcrun " , " -sdk " , " macosx " , " --find " , exec ] ,
135
+ arguments: [ xcrun, " -sdk " , " macosx " , " --find " , executable ] ,
132
136
environment: env
133
137
) . spm_chomp ( )
134
138
return AbsolutePath ( path)
135
- #else
136
- throw ToolchainError . unableToFind ( tool: exec)
137
- #endif
138
139
}
139
140
}
140
141
0 commit comments