Skip to content

Commit 7d79801

Browse files
committed
Get search paths only in determineSwiftCompilers
1 parent de56a8f commit 7d79801

File tree

3 files changed

+18
-27
lines changed

3 files changed

+18
-27
lines changed

Sources/Commands/SwiftTool.swift

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -639,10 +639,6 @@ public class SwiftTool {
639639
} catch {
640640
return .failure(error)
641641
}
642-
// Get the search paths from PATH.
643-
let searchPaths = getEnvSearchPaths(
644-
pathString: ProcessEnv.vars["PATH"], currentWorkingDirectory: localFileSystem.currentWorkingDirectory)
645-
646642
// Apply any manual overrides.
647643
if let triple = self.options.customCompileTriple {
648644
destination.target = triple
@@ -656,7 +652,7 @@ public class SwiftTool {
656652
// Set default SDK path when target is WASI whose SDK is embeded
657653
// in Swift toolchain
658654
do {
659-
let compilers = try UserToolchain.determineSwiftCompilers(binDir: destination.binDir, envSearchPaths: searchPaths)
655+
let compilers = try UserToolchain.determineSwiftCompilers(binDir: destination.binDir)
660656
destination.sdk = compilers.compile
661657
.parentDirectory // bin
662658
.parentDirectory // usr
@@ -672,17 +668,14 @@ public class SwiftTool {
672668
return self._hostToolchain
673669
}
674670

675-
return Result(catching: { try UserToolchain(destination: destination, searchPaths: searchPaths) })
671+
return Result(catching: { try UserToolchain(destination: destination) })
676672
}()
677673

678674
/// Lazily compute the host toolchain used to compile the package description.
679675
private lazy var _hostToolchain: Result<UserToolchain, Swift.Error> = {
680-
// Get the search paths from PATH.
681-
let searchPaths = getEnvSearchPaths(
682-
pathString: ProcessEnv.vars["PATH"], currentWorkingDirectory: localFileSystem.currentWorkingDirectory)
683676
return Result(catching: {
684677
try UserToolchain(destination: Destination.hostDestination(
685-
originalWorkingDirectory: self.originalWorkingDirectory), searchPaths: searchPaths)
678+
originalWorkingDirectory: self.originalWorkingDirectory))
686679
})
687680
}()
688681

Sources/SPMTestSupport/Resources.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,7 @@ public class Resources: ManifestResourceProvider {
5959
#else
6060
binDir = AbsolutePath(CommandLine.arguments[0], relativeTo: localFileSystem.currentWorkingDirectory!).parentDirectory
6161
#endif
62-
let searchPaths = getEnvSearchPaths(
63-
pathString: ProcessEnv.vars["PATH"], currentWorkingDirectory: localFileSystem.currentWorkingDirectory)
64-
toolchain = try! UserToolchain(destination: Destination.hostDestination(binDir), searchPaths: searchPaths)
62+
toolchain = try! UserToolchain(destination: Destination.hostDestination(binDir))
6563
}
6664

6765
/// True if SwiftPM has PackageDescription 4 runtime available.

Sources/Workspace/UserToolchain.swift

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -105,14 +105,20 @@ public final class UserToolchain: Toolchain {
105105
public typealias SwiftCompilers = (compile: AbsolutePath, manifest: AbsolutePath)
106106

107107
/// Determines the Swift compiler paths for compilation and manifest parsing.
108-
public static func determineSwiftCompilers(binDir: AbsolutePath, envSearchPaths: [AbsolutePath]) throws -> SwiftCompilers {
108+
public static func determineSwiftCompilers(binDir: AbsolutePath) throws -> SwiftCompilers {
109109
func validateCompiler(at path: AbsolutePath?) throws {
110110
guard let path = path else { return }
111111
guard localFileSystem.isExecutableFile(path) else {
112112
throw InvalidToolchainDiagnostic("could not find the `swiftc\(hostExecutableSuffix)` at expected path \(path)")
113113
}
114114
}
115115

116+
// Get the search paths from PATH.
117+
let envSearchPaths = getEnvSearchPaths(
118+
pathString: ProcessEnv.path,
119+
currentWorkingDirectory: localFileSystem.currentWorkingDirectory
120+
)
121+
116122
let lookup = { UserToolchain.lookup(variable: $0, searchPaths: envSearchPaths) }
117123
// Get overrides.
118124
let SWIFT_EXEC_MANIFEST = lookup("SWIFT_EXEC_MANIFEST")
@@ -144,9 +150,6 @@ public final class UserToolchain: Toolchain {
144150
return lookupExecutablePath(filename: ProcessEnv.vars[variable], searchPaths: searchPaths)
145151
}
146152

147-
/// Environment to use when looking up tools.
148-
private let processEnvironment: [String: String]
149-
150153
/// Returns the path to clang compiler tool.
151154
public func getClangCompiler() throws -> AbsolutePath {
152155
// Check if we already computed.
@@ -267,25 +270,22 @@ public final class UserToolchain: Toolchain {
267270
+ destination.extraSwiftCFlags
268271
}
269272

270-
public init(destination: Destination, searchPaths: [AbsolutePath], environment: [String: String] = ProcessEnv.vars) throws {
273+
public init(destination: Destination) throws {
271274
self.destination = destination
272-
self.processEnvironment = environment
273275

274276
// Get the search paths from PATH.
275-
let searchPaths = getEnvSearchPaths(
276-
pathString: ProcessEnv.path,
277+
self.envSearchPaths = getEnvSearchPaths(
278+
pathString: ProcessEnv.path,
277279
currentWorkingDirectory: localFileSystem.currentWorkingDirectory
278-
) + searchPaths
279-
280-
self.envSearchPaths = searchPaths
280+
)
281281

282282
// Get the binDir from destination.
283283
let binDir = destination.binDir
284284

285-
let swiftCompilers = try UserToolchain.determineSwiftCompilers(binDir: binDir, envSearchPaths: searchPaths)
285+
let swiftCompilers = try UserToolchain.determineSwiftCompilers(binDir: binDir)
286286
self.swiftCompiler = swiftCompilers.compile
287287
self.archs = destination.archs
288-
288+
289289
// Use the triple from destination or compute the host triple using swiftc.
290290
var triple = destination.target ?? Triple.getHostTriple(usingSwiftCompiler: swiftCompilers.compile)
291291

@@ -302,7 +302,7 @@ public final class UserToolchain: Toolchain {
302302
if triple.isDarwin() {
303303
// FIXME: We should have some general utility to find tools.
304304
let xctestFindArgs = ["/usr/bin/xcrun", "--sdk", "macosx", "--find", "xctest"]
305-
self.xctest = try AbsolutePath(validating: Process.checkNonZeroExit(arguments: xctestFindArgs, environment: environment).spm_chomp())
305+
self.xctest = try AbsolutePath(validating: Process.checkNonZeroExit(arguments: xctestFindArgs, environment: ProcessEnv.vars).spm_chomp())
306306
} else {
307307
self.xctest = nil
308308
}

0 commit comments

Comments
 (0)