Skip to content

Commit 0a454e3

Browse files
authored
Fix a dune crash when subdir is an absolute path (#4366)
Fix a dune crash when `subdir` is an absolute path Signed-off-by: Antonio Nuno Monteiro <anmonteiro@gmail.com>
1 parent 422dd9a commit 0a454e3

File tree

3 files changed

+26
-3
lines changed

3 files changed

+26
-3
lines changed

CHANGES.md

+2
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ Unreleased
9494

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

97+
- Fix dune crash when `subdir` is an absolute path (#4366, @anmonteiro)
98+
9799
2.8.2 (21/01/2021)
98100
------------------
99101

src/dune_engine/sub_dirs.ml

+8-3
Original file line numberDiff line numberDiff line change
@@ -188,9 +188,14 @@ module Dir_map = struct
188188
let merge_all = List.fold_left ~f:merge ~init:empty
189189
end
190190

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

195200
let strict_subdir field_name =
196201
let open Dune_lang.Decoder in
@@ -263,7 +268,7 @@ let decode =
263268
in
264269
let rec subdir () =
265270
let* () = Dune_lang.Syntax.since Stanza.syntax (2, 5) in
266-
let* subdir = descedant_path in
271+
let* subdir = descendant_path in
267272
let+ node = fields (decode ~allow_ignored_subdirs:false) in
268273
Dir_map.make_at_path subdir node
269274
and decode ~allow_ignored_subdirs =

test/blackbox-tests/test-cases/subdir-stanza.t/run.t

+16
Original file line numberDiff line numberDiff line change
@@ -118,3 +118,19 @@ Include stanzas within subdir stanzas
118118
$ dune build --root . a/hello.txt
119119
$ cat _build/default/a/hello.txt
120120
Hello!
121+
122+
123+
$ echo "(lang dune 2.5)" > dune-project
124+
$ cat >dune <<EOF
125+
> (rule (with-stdout-to foo.txt (echo "bar")))
126+
> (subdir /absolute/path/to/bar
127+
> (rule (with-stdout-to foo.txt (echo "bar"))))
128+
> EOF
129+
$ dune build ./foo.txt ./bar/foo.txt
130+
File "dune", line 2, characters 8-29:
131+
2 | (subdir /absolute/path/to/bar
132+
^^^^^^^^^^^^^^^^^^^^^
133+
Error: invalid sub-directory path "/absolute/path/to/bar"
134+
Hint: sub-directory path must be relative
135+
[1]
136+

0 commit comments

Comments
 (0)