Skip to content

Commit

Permalink
fix: --ignore-promoted-rules should work on internal rules
Browse files Browse the repository at this point in the history
Internal promotion rules such as generating opam files weren't being
ignored under --ignored-promoted-rules.

Signed-off-by: Rudi Grinberg <[email protected]>

<!-- ps-id: af82808a-164d-4f37-aefc-155d2b6b4eca -->
  • Loading branch information
rgrinberg committed Aug 26, 2023
1 parent fdc7f1a commit 9c2705c
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 19 deletions.
8 changes: 8 additions & 0 deletions src/dune_rules/rule_mode_decoder.ml
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,11 @@ end

let decode = sum mode_decoders
let field = field "mode" decode ~default:Rule.Mode.Standard

let is_ignored (mode : Rule.Mode.t) =
!Clflags.ignore_promoted_rules
&&
match mode with
| Promote { only = None; lifetime = Unlimited; _ } -> true
| _ -> false
;;
1 change: 1 addition & 0 deletions src/dune_rules/rule_mode_decoder.mli
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ end

val decode : Rule.Mode.t Dune_lang.Decoder.t
val field : Rule.Mode.t Dune_lang.Decoder.fields_parser
val is_ignored : Rule.Mode.t -> bool
7 changes: 2 additions & 5 deletions src/dune_rules/simple_rules.ml
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,7 @@ let user_rule sctx ?extra_bindings ~dir ~expander (rule : Rule.t) =
else action
in
(match rule_kind ~rule ~action with
| No_alias ->
let+ targets = add_user_rule sctx ~dir ~rule ~action ~expander in
Some targets
| No_alias -> add_user_rule sctx ~dir ~rule ~action ~expander
| Aliases_with_targets (aliases, alias_target) ->
let* () =
let aliases = List.map ~f:(Alias.make ~dir) aliases in
Expand All @@ -145,8 +143,7 @@ let user_rule sctx ?extra_bindings ~dir ~expander (rule : Rule.t) =
alias
(Action_builder.path (Path.build alias_target)))
in
let+ targets = add_user_rule sctx ~dir ~rule ~action ~expander in
Some targets
add_user_rule sctx ~dir ~rule ~action ~expander
| Aliases_only aliases ->
let aliases = List.map ~f:(Alias.make ~dir) aliases in
let* action = interpret_and_add_locks ~expander rule.locks action.build in
Expand Down
31 changes: 19 additions & 12 deletions src/dune_rules/super_context.ml
Original file line number Diff line number Diff line change
Expand Up @@ -255,24 +255,31 @@ let extend_action t ~dir build =
;;

let make_rule t ?mode ?loc ~dir { Action_builder.With_targets.build; targets } =
let build = extend_action t build ~dir in
Rule.make
?mode
~info:(Rule.Info.of_loc_opt loc)
~context:(Some (Context.build_context (Env_tree.context t)))
~targets
build
match mode with
| Some mode when Rule_mode_decoder.is_ignored mode -> None
| _ ->
let build = extend_action t build ~dir in
Some
(Rule.make
?mode
~info:(Rule.Info.of_loc_opt loc)
~context:(Some (Context.build_context (Env_tree.context t)))
~targets
build)
;;

let add_rule t ?mode ?loc ~dir build =
let rule = make_rule t ?mode ?loc ~dir build in
Rules.Produce.rule rule
match make_rule t ?mode ?loc ~dir build with
| None -> Memo.return ()
| Some rule -> Rules.Produce.rule rule
;;

let add_rule_get_targets t ?mode ?loc ~dir build =
let rule = make_rule t ?mode ?loc ~dir build in
let+ () = Rules.Produce.rule rule in
rule.targets
match make_rule t ?mode ?loc ~dir build with
| None -> Memo.return None
| Some rule ->
let+ () = Rules.Produce.rule rule in
Some rule.targets
;;

let add_rules t ?loc ~dir builds = Memo.parallel_iter builds ~f:(add_rule ?loc t ~dir)
Expand Down
2 changes: 1 addition & 1 deletion src/dune_rules/super_context.mli
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ val add_rule_get_targets
-> ?loc:Loc.t
-> dir:Path.Build.t
-> Action.Full.t Action_builder.With_targets.t
-> Targets.Validated.t Memo.t
-> Targets.Validated.t option Memo.t

val add_rules
: t
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ This should not modify the file now

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

0 comments on commit 9c2705c

Please sign in to comment.