Skip to content

Commit 7e0f5e6

Browse files
authored
Make the lookup of the PackageDescription dylib fall back on the versioned location if needed (#3560)
This makes the use of the Manifest API directory (the directory in which PackageDescription.dylib and its interface is located) more robust, so that it works with mismatching toolchains. This is a little tricky to unit-test from inside the codebase, since it involves having an old toolchain compared with the expected one. Existing unit tests make sure there are no regressions.
1 parent 20eba12 commit 7e0f5e6

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

Sources/PackageLoading/ManifestLoader.swift

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -938,7 +938,18 @@ public final class ManifestLoader: ManifestLoaderProtocol {
938938
/// Returns the runtime path given the manifest version and path to libDir.
939939
private func runtimePath(for version: ToolsVersion) -> AbsolutePath {
940940
// Bin dir will be set when developing swiftpm without building all of the runtimes.
941-
return resources.binDir ?? resources.libDir.appending(component: "ManifestAPI")
941+
if let binDir = resources.binDir {
942+
return binDir
943+
}
944+
945+
// Otherwise we use the standard location of the manifest API in the toolchain, if it exists.
946+
let manifestAPIDir = resources.libDir.appending(component: "ManifestAPI")
947+
if localFileSystem.exists(manifestAPIDir) {
948+
return manifestAPIDir
949+
}
950+
951+
// Otherwise, fall back on the old location (this would indicate that we're using an old toolchain).
952+
return resources.libDir.appending(version.runtimeSubpath)
942953
}
943954

944955
/// Returns path to the manifest database inside the given cache directory.

0 commit comments

Comments
 (0)