diff --git a/src/dune_rules/dune_file.ml b/src/dune_rules/dune_file.ml index b1fc4954b51..b98d97033c3 100644 --- a/src/dune_rules/dune_file.ml +++ b/src/dune_rules/dune_file.ml @@ -1588,6 +1588,7 @@ module Rule = struct type action_or_field = | Action | Field + | Since of Syntax.Version.t * action_or_field let atom_table = String.Map.of_list_exn @@ -1622,7 +1623,7 @@ module Rule = struct ; ("aliases", Field) ; ("alias", Field) ; ("enabled_if", Field) - ; ("package", Field) + ; ("package", Since ((3, 8), Field)) ] let short_form = @@ -1731,6 +1732,14 @@ module Rule = struct }) let decode = + let rec interpret atom = function + | Field -> fields long_form + | Action -> short_form + | Since (version, inner) -> + let what = Printf.sprintf "'%s' in short-form 'rule'" atom in + let* () = Dune_lang.Syntax.since ~what Stanza.syntax version in + interpret atom inner + in peek_exn >>= function | List (_, Atom (loc, A s) :: _) -> ( match String.Map.find atom_table s with @@ -1740,8 +1749,7 @@ module Rule = struct ~hints: (User_message.did_you_mean s ~candidates:(String.Map.keys atom_table)) - | Some Field -> fields long_form - | Some Action -> short_form) + | Some w -> interpret s w) | sexp -> User_error.raise ~loc:(Dune_lang.Ast.loc sexp) [ Pp.textf "S-expression of the form ( ...) expected" ] diff --git a/test/blackbox-tests/test-cases/package-rule.t/run.t b/test/blackbox-tests/test-cases/package-rule.t/run.t index f5996486b33..7abac380df1 100644 --- a/test/blackbox-tests/test-cases/package-rule.t/run.t +++ b/test/blackbox-tests/test-cases/package-rule.t/run.t @@ -1,5 +1,21 @@ -When --only-packages is passed, it runs +When --only-packages is passed, it runs, as long as the version is new enough + $ dune build --only-packages a @runtest + File "dune", line 10, characters 0-61: + 10 | (rule + 11 | (package a) + 12 | (action (copy test_temp.ml test_b.ml))) + Error: 'package' in short-form 'rule' is only available since version 3.8 of + the dune language. Please update your dune-project file to have (lang dune + 3.8). + [1] + +The version is too old, bump it to 3.8 where this was fixed: + + $ cat > dune-project-3.8 < (lang dune 3.8) + > EOF + $ mv dune-project-3.8 dune-project $ dune build --only-packages a @runtest A A