@@ -100,15 +100,24 @@ public final class UserToolchain: Toolchain {
100
100
#endif
101
101
}
102
102
103
+ public typealias SwiftCompilers = ( compile: AbsolutePath , manifest: AbsolutePath )
104
+
103
105
/// Determines the Swift compiler paths for compilation and manifest parsing.
104
- private static func determineSwiftCompilers( binDir: AbsolutePath , lookup : ( String ) -> AbsolutePath ? , envSearchPaths : [ AbsolutePath ] ) throws -> ( compile : AbsolutePath , manifest : AbsolutePath ) {
106
+ public static func determineSwiftCompilers( binDir: AbsolutePath ) throws -> SwiftCompilers {
105
107
func validateCompiler( at path: AbsolutePath ? ) throws {
106
108
guard let path = path else { return }
107
109
guard localFileSystem. isExecutableFile ( path) else {
108
110
throw InvalidToolchainDiagnostic ( " could not find the `swiftc \( hostExecutableSuffix) ` at expected path \( path) " )
109
111
}
110
112
}
111
113
114
+ // Get the search paths from PATH.
115
+ let envSearchPaths = getEnvSearchPaths (
116
+ pathString: ProcessEnv . path,
117
+ currentWorkingDirectory: localFileSystem. currentWorkingDirectory
118
+ )
119
+
120
+ let lookup = { UserToolchain . lookup ( variable: $0, searchPaths: envSearchPaths) }
112
121
// Get overrides.
113
122
let SWIFT_EXEC_MANIFEST = lookup ( " SWIFT_EXEC_MANIFEST " )
114
123
let SWIFT_EXEC = lookup ( " SWIFT_EXEC " )
@@ -139,9 +148,6 @@ public final class UserToolchain: Toolchain {
139
148
return lookupExecutablePath ( filename: ProcessEnv . vars [ variable] , searchPaths: searchPaths)
140
149
}
141
150
142
- /// Environment to use when looking up tools.
143
- private let processEnvironment : [ String : String ]
144
-
145
151
/// Returns the path to clang compiler tool.
146
152
public func getClangCompiler( ) throws -> AbsolutePath {
147
153
// Check if we already computed.
@@ -272,21 +278,20 @@ public final class UserToolchain: Toolchain {
272
278
273
279
public init ( destination: Destination , environment: [ String : String ] = ProcessEnv . vars) throws {
274
280
self . destination = destination
275
- self . processEnvironment = environment
276
281
277
282
// Get the search paths from PATH.
278
- let searchPaths = getEnvSearchPaths (
279
- pathString: ProcessEnv . path, currentWorkingDirectory : localFileSystem . currentWorkingDirectory )
280
-
281
- self . envSearchPaths = searchPaths
283
+ self . envSearchPaths = getEnvSearchPaths (
284
+ pathString: ProcessEnv . path,
285
+ currentWorkingDirectory : localFileSystem . currentWorkingDirectory
286
+ )
282
287
283
288
// Get the binDir from destination.
284
289
let binDir = destination. binDir
285
290
286
- let swiftCompilers = try UserToolchain . determineSwiftCompilers ( binDir: binDir, lookup : { UserToolchain . lookup ( variable : $0 , searchPaths : searchPaths ) } , envSearchPaths : searchPaths )
291
+ let swiftCompilers = try UserToolchain . determineSwiftCompilers ( binDir: binDir)
287
292
self . swiftCompiler = swiftCompilers. compile
288
293
self . archs = destination. archs
289
-
294
+
290
295
// Use the triple from destination or compute the host triple using swiftc.
291
296
var triple = destination. target ?? Triple . getHostTriple ( usingSwiftCompiler: swiftCompilers. compile)
292
297
@@ -303,7 +308,9 @@ public final class UserToolchain: Toolchain {
303
308
if triple. isDarwin ( ) {
304
309
// FIXME: We should have some general utility to find tools.
305
310
let xctestFindArgs = [ " /usr/bin/xcrun " , " --sdk " , " macosx " , " --find " , " xctest " ]
306
- self . xctest = try AbsolutePath ( validating: Process . checkNonZeroExit ( arguments: xctestFindArgs, environment: environment) . spm_chomp ( ) )
311
+ self . xctest = try AbsolutePath (
312
+ validating: Process . checkNonZeroExit ( arguments: xctestFindArgs, environment: environment
313
+ ) . spm_chomp ( ) )
307
314
} else {
308
315
self . xctest = nil
309
316
}
0 commit comments