Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only enable package in short-form rules on dune lang 3.8+ #7476

Merged
merged 3 commits into from
Apr 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions src/dune_rules/dune_file.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -1622,7 +1623,7 @@ module Rule = struct
; ("aliases", Field)
; ("alias", Field)
; ("enabled_if", Field)
; ("package", Field)
; ("package", Since ((3, 8), Field))
]

let short_form =
Expand Down Expand Up @@ -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
Expand All @@ -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 (<atom> ...) expected" ]
Expand Down
18 changes: 17 additions & 1 deletion test/blackbox-tests/test-cases/package-rule.t/run.t
Original file line number Diff line number Diff line change
@@ -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 <<EOF
> (lang dune 3.8)
> EOF
$ mv dune-project-3.8 dune-project
$ dune build --only-packages a @runtest
A
A