Skip to content

Commit a7280fc

Browse files
committed
fix: --ignore-promoted-rules should work on internal rules
Internal promotion rules such as generating opam files weren't being ignored under --ignored-promoted-rules. Signed-off-by: Rudi Grinberg <me@rgrinberg.com> <!-- ps-id: af82808a-164d-4f37-aefc-155d2b6b4eca -->
1 parent fdc7f1a commit a7280fc

File tree

8 files changed

+44
-34
lines changed

8 files changed

+44
-34
lines changed

doc/changes/8518.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
- Ignore internal promote rules when `--ignore-promoted-rules` is set (#8518,
2+
fix #8417, @rgrinberg)

src/dune_rules/dune_file.ml

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2463,21 +2463,12 @@ type t =
24632463
; stanzas : Stanzas.t
24642464
}
24652465

2466-
let is_promoted_rule =
2467-
let is_promoted_mode version = function
2468-
| Rule.Mode.Promote { only = None; lifetime; _ } ->
2469-
if version >= (3, 5)
2470-
then (
2471-
match lifetime with
2472-
| Unlimited -> true
2473-
| Until_clean -> false)
2474-
else true
2475-
| _ -> false
2476-
in
2477-
fun version rule ->
2478-
match rule with
2479-
| Rule { mode; _ } | Menhir_stanza.T { mode; _ } -> is_promoted_mode version mode
2480-
| _ -> false
2466+
let is_promoted_rule version rule =
2467+
match rule with
2468+
| Rule { mode; _ } | Menhir_stanza.T { mode; _ } ->
2469+
let until_clean = if version >= (3, 5) then `Keep else `Ignore in
2470+
Rule_mode_decoder.is_ignored mode ~until_clean
2471+
| _ -> false
24812472
;;
24822473

24832474
let parse sexps ~dir ~file ~project =

src/dune_rules/rule_mode_decoder.ml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,3 +99,15 @@ end
9999

100100
let decode = sum mode_decoders
101101
let field = field "mode" decode ~default:Rule.Mode.Standard
102+
103+
let is_ignored (mode : Rule.Mode.t) ~until_clean =
104+
!Clflags.ignore_promoted_rules
105+
&&
106+
match mode with
107+
| Promote { only = None; lifetime = Unlimited; _ } -> true
108+
| Promote { only = None; lifetime = Until_clean; _ } ->
109+
(match until_clean with
110+
| `Ignore -> true
111+
| `Keep -> false)
112+
| _ -> false
113+
;;

src/dune_rules/rule_mode_decoder.mli

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ end
1515

1616
val decode : Rule.Mode.t Dune_lang.Decoder.t
1717
val field : Rule.Mode.t Dune_lang.Decoder.fields_parser
18+
val is_ignored : Rule.Mode.t -> until_clean:[ `Ignore | `Keep ] -> bool

src/dune_rules/simple_rules.ml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,7 @@ let user_rule sctx ?extra_bindings ~dir ~expander (rule : Rule.t) =
134134
else action
135135
in
136136
(match rule_kind ~rule ~action with
137-
| No_alias ->
138-
let+ targets = add_user_rule sctx ~dir ~rule ~action ~expander in
139-
Some targets
137+
| No_alias -> add_user_rule sctx ~dir ~rule ~action ~expander
140138
| Aliases_with_targets (aliases, alias_target) ->
141139
let* () =
142140
let aliases = List.map ~f:(Alias.make ~dir) aliases in
@@ -145,8 +143,7 @@ let user_rule sctx ?extra_bindings ~dir ~expander (rule : Rule.t) =
145143
alias
146144
(Action_builder.path (Path.build alias_target)))
147145
in
148-
let+ targets = add_user_rule sctx ~dir ~rule ~action ~expander in
149-
Some targets
146+
add_user_rule sctx ~dir ~rule ~action ~expander
150147
| Aliases_only aliases ->
151148
let aliases = List.map ~f:(Alias.make ~dir) aliases in
152149
let* action = interpret_and_add_locks ~expander rule.locks action.build in

src/dune_rules/super_context.ml

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -255,24 +255,31 @@ let extend_action t ~dir build =
255255
;;
256256

257257
let make_rule t ?mode ?loc ~dir { Action_builder.With_targets.build; targets } =
258-
let build = extend_action t build ~dir in
259-
Rule.make
260-
?mode
261-
~info:(Rule.Info.of_loc_opt loc)
262-
~context:(Some (Context.build_context (Env_tree.context t)))
263-
~targets
264-
build
258+
match mode with
259+
| Some mode when Rule_mode_decoder.is_ignored mode ~until_clean:`Keep -> None
260+
| _ ->
261+
let build = extend_action t build ~dir in
262+
Some
263+
(Rule.make
264+
?mode
265+
~info:(Rule.Info.of_loc_opt loc)
266+
~context:(Some (Context.build_context (Env_tree.context t)))
267+
~targets
268+
build)
265269
;;
266270

267271
let add_rule t ?mode ?loc ~dir build =
268-
let rule = make_rule t ?mode ?loc ~dir build in
269-
Rules.Produce.rule rule
272+
match make_rule t ?mode ?loc ~dir build with
273+
| None -> Memo.return ()
274+
| Some rule -> Rules.Produce.rule rule
270275
;;
271276

272277
let add_rule_get_targets t ?mode ?loc ~dir build =
273-
let rule = make_rule t ?mode ?loc ~dir build in
274-
let+ () = Rules.Produce.rule rule in
275-
rule.targets
278+
match make_rule t ?mode ?loc ~dir build with
279+
| None -> Memo.return None
280+
| Some rule ->
281+
let+ () = Rules.Produce.rule rule in
282+
Some rule.targets
276283
;;
277284

278285
let add_rules t ?loc ~dir builds = Memo.parallel_iter builds ~f:(add_rule ?loc t ~dir)

src/dune_rules/super_context.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ val add_rule_get_targets
6969
-> ?loc:Loc.t
7070
-> dir:Path.Build.t
7171
-> Action.Full.t Action_builder.With_targets.t
72-
-> Targets.Validated.t Memo.t
72+
-> Targets.Validated.t option Memo.t
7373

7474
val add_rules
7575
: t

test/blackbox-tests/test-cases/ignore-promoted-rules-internal-rules.t renamed to test/blackbox-tests/test-cases/ignore-promoted-internal-rules.t

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@ This should not modify the file now
1919

2020
$ dune build --ignore-promoted-rules foo.opam
2121
$ grep extra foo.opam
22-
[1]
22+
foobar_extra

0 commit comments

Comments
 (0)