Skip to content

Commit

Permalink
Make target or targets optional fields of rule stanzas
Browse files Browse the repository at this point in the history
Fixes #2469

Signed-off-by: Nathan Rebours <nathan.p.rebours@gmail.com>
  • Loading branch information
NathanReb committed Aug 1, 2019
1 parent 29458b1 commit 690714c
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 7 deletions.
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
2.0.0 (unreleased)
------------------

- Infer targets for rule stanzas expressed in long form (#2494, fixes #2469,
@NathanReb)

- Indicate the progress of the initial file tree loading (#2459, fixes #2374,
@bobot)

Expand Down
1 change: 1 addition & 0 deletions src/dune_file.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1703,6 +1703,7 @@ module Rule = struct

let fields_parser =
fields_mutually_exclusive
~default:Infer
[ "targets", decode_static
; "target", decode_one_static
]
Expand Down
7 changes: 5 additions & 2 deletions src/dune_lang/dune_lang.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1048,7 +1048,7 @@ module Decoder = struct
[@@inline never]

let fields_mutually_exclusive
?on_dup fields ((Fields (loc, _, _) : _ context) as ctx) state =
?on_dup ?default fields ((Fields (loc, _, _) : _ context) as ctx) state =
let res, state =
traverse ~f:(fun (name, parser) ->
field_o name ?on_dup parser
Expand All @@ -1060,7 +1060,10 @@ module Decoder = struct
~f:(function (name, Some x) -> Some(name, x) | (_, None) -> None) with
| [] ->
let names = List.map fields ~f:fst in
fields_missing_need_exactly_one loc names
( match default with
| None -> fields_missing_need_exactly_one loc names
| Some default -> default, state
)
| [ (_name, res) ] ->
res, state
| (_ :: _ :: _ as results) ->
Expand Down
3 changes: 3 additions & 0 deletions src/dune_lang/dune_lang.mli
Original file line number Diff line number Diff line change
Expand Up @@ -433,8 +433,11 @@ module Decoder : sig
-> 'a t
-> 'a option fields_parser

(** Parser for mutually exclusive fields. If [default] is provided, allow
fields absence. *)
val fields_mutually_exclusive
: ?on_dup:(Univ_map.t -> string -> Ast.t list -> unit)
-> ?default:'a
-> (string * 'a t) list
-> 'a fields_parser

Expand Down
6 changes: 1 addition & 5 deletions test/blackbox-tests/test-cases/rule-target-inferrence/run.t
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,4 @@ But should work with the long form as well:

$ dune build @infer --root long-form
Entering directory 'long-form'
File "dune", line 1, characters 0-57:
1 | (rule
2 | (action (write-file b "It should work as well!")))
Error: fields targets, target are all missing (exactly one is needed)
[1]
It should work as well!

0 comments on commit 690714c

Please sign in to comment.