Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a dune crash when subdir is an absolute path #4366

Merged
merged 3 commits into from
Mar 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ Unreleased

- Add support for sandboxing using hard links (#4360, @snowleopard)

- Fix dune crash when `subdir` is an absolute path (#4366, @anmonteiro)

2.8.2 (21/01/2021)
------------------

Expand Down
11 changes: 8 additions & 3 deletions src/dune_engine/sub_dirs.ml
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,14 @@ module Dir_map = struct
let merge_all = List.fold_left ~f:merge ~init:empty
end

let descedant_path =
let descendant_path =
Dune_lang.Decoder.plain_string (fun ~loc fn ->
Path.Local.parse_string_exn ~loc fn |> Path.Local.explode)
if Filename.is_relative fn then
Path.Local.parse_string_exn ~loc fn |> Path.Local.explode
else
let msg = [ Pp.textf "invalid sub-directory path %S" fn ] in
let hints = [ Pp.textf "sub-directory path must be relative" ] in
User_error.raise ~loc ~hints msg)

let strict_subdir field_name =
let open Dune_lang.Decoder in
Expand Down Expand Up @@ -263,7 +268,7 @@ let decode =
in
let rec subdir () =
let* () = Dune_lang.Syntax.since Stanza.syntax (2, 5) in
let* subdir = descedant_path in
let* subdir = descendant_path in
let+ node = fields (decode ~allow_ignored_subdirs:false) in
Dir_map.make_at_path subdir node
and decode ~allow_ignored_subdirs =
Expand Down
16 changes: 16 additions & 0 deletions test/blackbox-tests/test-cases/subdir-stanza.t/run.t
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,19 @@ Include stanzas within subdir stanzas
$ dune build --root . a/hello.txt
$ cat _build/default/a/hello.txt
Hello!


$ echo "(lang dune 2.5)" > dune-project
$ cat >dune <<EOF
> (rule (with-stdout-to foo.txt (echo "bar")))
> (subdir /absolute/path/to/bar
> (rule (with-stdout-to foo.txt (echo "bar"))))
> EOF
$ dune build ./foo.txt ./bar/foo.txt
File "dune", line 2, characters 8-29:
2 | (subdir /absolute/path/to/bar
^^^^^^^^^^^^^^^^^^^^^
Error: invalid sub-directory path "/absolute/path/to/bar"
Hint: sub-directory path must be relative
[1]