Skip to content

Commit

Permalink
Fix a dune crash when subdir is an absolute path (ocaml#4366)
Browse files Browse the repository at this point in the history
Fix a dune crash when `subdir` is an absolute path

Signed-off-by: Antonio Nuno Monteiro <[email protected]>
  • Loading branch information
anmonteiro authored Mar 17, 2021
1 parent 422dd9a commit 0a454e3
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
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]

0 comments on commit 0a454e3

Please sign in to comment.