Skip to content

Commit a706e77

Browse files
committed
[Workspace] Allow SWIFTPM_PD_LIBS to accept a list of search paths
<rdar://problem/45473237> SWIFTPM_PD_LIBS should accept a list of paths
1 parent d1968f6 commit a706e77

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

Documentation/Development.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,4 +183,7 @@ $ SWIFT_EXEC=/path/to/my/built/swiftc swift build
183183

184184
SwiftPM computes the path of runtime libraries relative to where it is
185185
installed. This path can be overridden by setting the environment variable
186-
`SWIFTPM_PD_LIBS` to a directory containing the libraries.
186+
`SWIFTPM_PD_LIBS` to a directory containing the libraries. This can be a list of
187+
absolute search paths separated by colon (":"). SwiftPM will choose the first
188+
path which exists on disk. If none of the path are present on disk, it will fall
189+
back to built-in computation.

Sources/Workspace/UserToolchain.swift

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -240,11 +240,18 @@ public final class UserToolchain: Toolchain {
240240
] + destination.extraCCFlags
241241

242242
// Compute the path of directory containing the PackageDescription libraries.
243-
let pdLibDir: AbsolutePath
244-
if let pdLibDirEnvStr = getenv("SWIFTPM_PD_LIBS"), let pdLibDirEnv = try? AbsolutePath(validating: pdLibDirEnvStr) {
245-
pdLibDir = pdLibDirEnv
246-
} else {
247-
pdLibDir = binDir.parentDirectory.appending(components: "lib", "swift", "pm")
243+
var pdLibDir = binDir.parentDirectory.appending(components: "lib", "swift", "pm")
244+
245+
// Look for an override in the env.
246+
if let pdLibDirEnvStr = getenv("SWIFTPM_PD_LIBS") {
247+
// We pick the first path which exists in a colon seperated list.
248+
let paths = pdLibDirEnvStr.split(separator: ":").map(String.init)
249+
for pathString in paths {
250+
if let path = try? AbsolutePath(validating: pathString), localFileSystem.exists(path) {
251+
pdLibDir = path
252+
break
253+
}
254+
}
248255
}
249256

250257
manifestResources = UserManifestResources(

0 commit comments

Comments
 (0)