Skip to content

Commit

Permalink
Merge pull request #12430 from DeterminateSystems/relative-path-literals
Browse files Browse the repository at this point in the history
Parser: Respect the accessor of the source file for relative paths
  • Loading branch information
Ericson2314 authored Feb 10, 2025
2 parents 967d7b9 + 7096acc commit 1f485b6
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/libexpr/parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -359,11 +359,18 @@ string_parts_interpolated

path_start
: PATH {
Path path(absPath(std::string_view{$1.p, $1.l}, state->basePath.path.abs()));
std::string_view literal({$1.p, $1.l});
Path path(absPath(literal, state->basePath.path.abs()));
/* add back in the trailing '/' to the first segment */
if ($1.p[$1.l-1] == '/' && $1.l > 1)
path += "/";
$$ = new ExprPath(ref<SourceAccessor>(state->rootFS), std::move(path));
if (literal.size() > 1 && literal.back() == '/')
path += '/';
$$ =
/* Absolute paths are always interpreted relative to the
root filesystem accessor, rather than the accessor of the
current Nix expression. */
literal.front() == '/'
? new ExprPath(state->rootFS, std::move(path))
: new ExprPath(state->basePath.accessor, std::move(path));
}
| HPATH {
if (state->settings.pureEval) {
Expand Down

0 comments on commit 1f485b6

Please sign in to comment.