diff --git a/CHANGES.md b/CHANGES.md index 130408169c58..d53727917d25 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -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) ------------------ diff --git a/src/dune_rules/dune_env.ml b/src/dune_rules/dune_env.ml index e5b7e9f21b90..806c3b47d40a 100644 --- a/src/dune_rules/dune_env.ml +++ b/src/dune_rules/dune_env.ml @@ -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 = [] } diff --git a/test/blackbox-tests/test-cases/env/env-unused.t b/test/blackbox-tests/test-cases/env/env-unused.t new file mode 100644 index 000000000000..ef722d710c39 --- /dev/null +++ b/test/blackbox-tests/test-cases/env/env-unused.t @@ -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.