Skip to content

Commit 893f6b2

Browse files
committed
Generate a path-safe, canonical name for package identifiers when loading manifests
Non-legacy package identifiers may include slashes, which cause precondition failures when constructing AbsolutePath values
1 parent 7ee8d62 commit 893f6b2

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

Sources/PackageLoading/ManifestLoader.swift

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -761,7 +761,14 @@ public final class ManifestLoader: ManifestLoaderProtocol {
761761
#else
762762
let executableSuffix = ""
763763
#endif
764-
let compiledManifestFile = tmpDir.appending(component: "\(packageIdentity)-manifest\(executableSuffix)")
764+
// Create a canonical package name that's suitable as a path component
765+
let canonicalPackageName = packageIdentity.description
766+
.split(separator: "/", omittingEmptySubsequences: true)
767+
.joined(separator: "-")
768+
.map { $0.isASCII ? "\($0)" : "-" }
769+
.joined()
770+
771+
let compiledManifestFile = tmpDir.appending(component: "\(canonicalPackageName)-manifest\(executableSuffix)")
765772
cmd += ["-o", compiledManifestFile.pathString]
766773

767774
// Compile the manifest.
@@ -775,7 +782,7 @@ public final class ManifestLoader: ManifestLoaderProtocol {
775782
}
776783

777784
// Pass an open file descriptor of a file to which the JSON representation of the manifest will be written.
778-
let jsonOutputFile = tmpDir.appending(component: "\(packageIdentity)-output.json")
785+
let jsonOutputFile = tmpDir .appending(component: "\(canonicalPackageName)-output.json")
779786
guard let jsonOutputFileDesc = fopen(jsonOutputFile.pathString, "w") else {
780787
throw StringError("couldn't create the manifest's JSON output file")
781788
}

0 commit comments

Comments
 (0)