Skip to content

Commit

Permalink
change: never ignore promote until-clean under -p
Browse files Browse the repository at this point in the history
This extends ocaml#5956 to all versions of `(lang dune)`, since this is a
property of the CLI.

Signed-off-by: Etienne Millon <me@emillon.org>
  • Loading branch information
emillon committed Sep 21, 2023
1 parent a5fdf20 commit cf29e8e
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 39 deletions.
3 changes: 3 additions & 0 deletions promote-until-clean-always.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- Never ignore `(promote (until-clean))` if `--ignore-promoted-rules` is
passed. This was previously done depending on `(lang dune)`. (#8721,
@emillon)
23 changes: 10 additions & 13 deletions src/dune_rules/dune_file.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2472,24 +2472,21 @@ type t =
; stanzas : Stanzas.t
}

let is_promoted_rule version rule =
match rule with
| Rule { mode; _ } | Menhir_stanza.T { mode; _ } ->
let until_clean = if version >= (3, 5) then `Keep else `Ignore in
Rule_mode_decoder.is_ignored mode ~until_clean
| _ -> false
let stanza_mode = function
| Rule { mode; _ } | Menhir_stanza.T { mode; _ } -> Some mode
| _ -> None
;;

let is_ignored_stanza s =
match stanza_mode s with
| Some mode -> Rule_mode_decoder.is_ignored mode
| None -> false
;;

let parse sexps ~dir ~file ~project =
let open Memo.O in
let+ stanzas = Stanzas.parse ~file ~dir project sexps in
let stanzas =
if !Clflags.ignore_promoted_rules
then (
let version = Dune_project.dune_version project in
List.filter stanzas ~f:(fun s -> not (is_promoted_rule version s)))
else stanzas
in
let stanzas = List.filter stanzas ~f:(fun s -> not (is_ignored_stanza s)) in
{ dir; project; stanzas }
;;

Expand Down
6 changes: 1 addition & 5 deletions src/dune_rules/rule_mode_decoder.ml
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,10 @@ end
let decode = sum mode_decoders
let field = field "mode" decode ~default:Rule.Mode.Standard

let is_ignored (mode : Rule.Mode.t) ~until_clean =
let is_ignored (mode : Rule.Mode.t) =
!Clflags.ignore_promoted_rules
&&
match mode with
| Promote { only = None; lifetime = Unlimited; _ } -> true
| Promote { only = None; lifetime = Until_clean; _ } ->
(match until_clean with
| `Ignore -> true
| `Keep -> false)
| _ -> false
;;
10 changes: 3 additions & 7 deletions src/dune_rules/rule_mode_decoder.mli
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@ end
val decode : Rule.Mode.t Dune_lang.Decoder.t
val field : Rule.Mode.t Dune_lang.Decoder.fields_parser

(** [is_ignored mode ~until_clean] will return if a rule with [mode] should be
ignored whenever [--ignored-promoted-rules] is set.
[until_clean] is used to set if [(promote (until-clean))] is ignored as
considered by this function. Old versions of dune would incorrectly ignore
this, so we need to maintain the old behavior for now. *)
val is_ignored : Rule.Mode.t -> until_clean:[ `Ignore | `Keep ] -> bool
(** [is_ignored mode] will return if a rule with [mode] should be
ignored, considering whether [--ignored-promoted-rules] is set. *)
val is_ignored : Rule.Mode.t -> bool
2 changes: 1 addition & 1 deletion src/dune_rules/super_context.ml
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ let extend_action t ~dir action =

let make_rule t ?mode ?loc ~dir { Action_builder.With_targets.build; targets } =
match mode with
| Some mode when Rule_mode_decoder.is_ignored mode ~until_clean:`Keep -> None
| Some mode when Rule_mode_decoder.is_ignored mode -> None
| _ ->
let build = extend_action t build ~dir in
Some
Expand Down
14 changes: 1 addition & 13 deletions test/blackbox-tests/test-cases/github4401.t
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
When --ignore-promoted-rules is passed, rules marked `(promote (until-clean))`
are ignored. See #4401.
are not ignored, independently of dune-lang. See #4401.

$ cat > dune-project << EOF
> (lang dune 3.4)
Expand All @@ -18,15 +18,3 @@ are ignored. See #4401.
> EOF

$ dune runtest --ignore-promoted-rules
Error: No rule found for test
-> required by alias runtest in dune:5
[1]

This is correctly ignored if `dune-lang` is bumped to 3.5.

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

$ dune clean
$ dune runtest --ignore-promoted-rules

0 comments on commit cf29e8e

Please sign in to comment.