Skip to content

Commit

Permalink
Env stanza: warn if some rules are ignored
Browse files Browse the repository at this point in the history
Since matching is sequential, anything after `_` cannot be reached.

Closes ocaml#5886

Signed-off-by: Etienne Millon <[email protected]>
  • Loading branch information
emillon committed Jun 20, 2022
1 parent 71fd5a6 commit 999db90
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
- [ctypes] Add support for the `errno` parameter using the `errno_policy` field
in the ctypes settings. (#5827, @droyo)

- env stanza: warn if some rules are ignored because they appear after a
wildcard rule. (#...., fix #5886, @emillon)

3.3.1 (19-06-2022)
------------------

Expand Down
19 changes: 18 additions & 1 deletion src/dune_rules/dune_env.ml
Original file line number Diff line number Diff line change
Expand Up @@ -226,10 +226,27 @@ module Stanza = struct
and+ configs = fields config in
(pat, configs))

let check_rules ~version ~loc rules =
let has_after_any l =
let is_any = function
| Any, _ -> true
| Profile _, _ -> false
in
List.split_while l ~f:is_any |> snd |> List.is_non_empty
in
if version >= (3, 4) && has_after_any rules then
User_warning.emit ~loc
[ Pp.text
"This stanza contains rules after a wildcard rule. These are going \
to be ignored."
]

let decode =
let+ () = Dune_lang.Syntax.since Stanza.syntax (1, 0)
and+ loc = loc
and+ rules = repeat rule in
and+ rules = repeat rule
and+ version = Dune_lang.Syntax.get_exn Stanza.syntax in
check_rules ~version ~loc rules;
{ loc; rules }

let empty = { loc = Loc.none; rules = [] }
Expand Down
32 changes: 32 additions & 0 deletions test/blackbox-tests/test-cases/env/env-unused.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
$ cat > dune-project << EOF
> (lang dune 3.3)
> EOF

(env) is evaluated sequentially:

$ cat > dune << 'EOF'
> (rule
> (alias runtest)
> (action (system "echo $VAR")))
>
> (env
> (_ (env-vars (VAR default )))
> (dev (env-vars (VAR specific))))
> EOF

$ dune runtest
default

In 3.4, a warning is added for that case:

$ cat > dune-project << EOF
> (lang dune 3.4)
> EOF

$ dune runtest
File "dune", line 5, characters 0-71:
5 | (env
6 | (_ (env-vars (VAR default )))
7 | (dev (env-vars (VAR specific))))
Warning: This stanza contains rules after a wildcard rule. These are going to
be ignored.

0 comments on commit 999db90

Please sign in to comment.