Skip to content

Commit d7df401

Browse files
committed
PackageLoading: anchor relative paths for Windows
We currently cannot use `..` as a header search path for Windows even though it may be contained within the package root. This is due to the fact that the path itself was unanchored, and a raw `..` would be treated as the drive root which will almost always be outside of the package root. Construct the absolute path relative to the target root rather than appending, permitting us to form a well-formed path which can be checked for ancestry.
1 parent f25e138 commit d7df401

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

Sources/PackageLoading/PackageBuilder.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1036,9 +1036,10 @@ public final class PackageBuilder {
10361036
}
10371037

10381038
// Ensure that the search path is contained within the package.
1039-
let subpath = try RelativePath(validating: value)
1040-
guard targetRoot.appending(subpath).isDescendantOfOrEqual(to: self.packagePath) else {
1041-
throw ModuleError.invalidHeaderSearchPath(subpath.pathString)
1039+
_ = try RelativePath(validating: value)
1040+
let path = try AbsolutePath(value, relativeTo: targetRoot)
1041+
guard path.isDescendantOfOrEqual(to: self.packagePath) else {
1042+
throw ModuleError.invalidHeaderSearchPath(value)
10421043
}
10431044

10441045
case .define(let value):

0 commit comments

Comments
 (0)