Skip to content

Commit

Permalink
refactor: put expander locks in action builder (#9312)
Browse files Browse the repository at this point in the history
Signed-off-by: Rudi Grinberg <[email protected]>
  • Loading branch information
rgrinberg authored Nov 29, 2023
1 parent 1216068 commit dfeb7ee
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 12 deletions.
4 changes: 1 addition & 3 deletions src/dune_rules/cram/cram_rules.ml
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,7 @@ let rules ~sctx ~expander ~dir tests =
let+ more_locks =
(* XXX wrong expander? this should be the expander in the
directory of the cram stanzas *)
Expander.expand_locks ~base expander stanza.locks
|> Action_builder.of_memo
>>| Path.Set.of_list
Expander.expand_locks ~base expander stanza.locks >>| Path.Set.of_list
and+ locks = acc.locks in
Path.Set.union locks more_locks
in
Expand Down
2 changes: 1 addition & 1 deletion src/dune_rules/expander.ml
Original file line number Diff line number Diff line change
Expand Up @@ -958,5 +958,5 @@ let expand_lock ~base expander (Locks.Lock sw) =
;;

let expand_locks ~base expander locks =
Memo.List.map locks ~f:(expand_lock ~base expander)
Memo.List.map locks ~f:(expand_lock ~base expander) |> Action_builder.of_memo
;;
2 changes: 1 addition & 1 deletion src/dune_rules/expander.mli
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,4 @@ val expand_locks
: base:[ `Of_expander | `This of Path.t ]
-> t
-> Locks.t
-> Path.t list Memo.t
-> Path.t list Action_builder.t
1 change: 0 additions & 1 deletion src/dune_rules/mdx.ml
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,6 @@ let gen_rules_for_single_file stanza ~sctx ~dir ~expander ~mdx_prog ~mdx_prog_ge
command_line
and+ locks =
Expander.expand_locks expander ~base:`Of_expander stanza.locks
|> Action_builder.of_memo
|> Action_builder.with_no_targets
in
Action.Full.add_locks locks action |> Action.Full.add_sandbox sandbox
Expand Down
15 changes: 9 additions & 6 deletions src/dune_rules/simple_rules.ml
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,9 @@ let rule_kind ~(rule : Rule.t) ~(action : _ Action_builder.With_targets.t) =
;;

let interpret_and_add_locks ~expander locks action =
let open Action_builder.O in
Expander.expand_locks expander ~base:`Of_expander locks
>>| function
>>= function
| [] -> action
| locks -> Action_builder.map action ~f:(Action.Full.add_locks locks)
;;
Expand All @@ -66,8 +67,10 @@ let add_user_rule
~(action : _ Action_builder.With_targets.t)
~expander
=
let* build = interpret_and_add_locks ~expander rule.locks action.build in
let action = { action with Action_builder.With_targets.build } in
let action =
let build = interpret_and_add_locks ~expander rule.locks action.build in
{ action with Action_builder.With_targets.build }
in
Super_context.add_rule_get_targets sctx ~dir ~mode:rule.mode ~loc:rule.loc action
;;

Expand Down Expand Up @@ -145,7 +148,7 @@ let user_rule sctx ?extra_bindings ~dir ~expander (rule : Rule.t) =
Some targets
| Aliases_only aliases ->
let+ () =
let* action = interpret_and_add_locks ~expander rule.locks action.build in
let action = interpret_and_add_locks ~expander rule.locks action.build in
Memo.parallel_iter aliases ~f:(fun alias ->
let alias = Alias.make ~dir alias in
Alias_rules.add sctx ~alias ~loc:rule.loc action)
Expand Down Expand Up @@ -287,6 +290,6 @@ let alias sctx ?extra_bindings ~dir ~expander (alias_conf : Alias_conf.t) =
~deps:alias_conf.deps
~what:"aliases"
in
let* action = interpret_and_add_locks ~expander alias_conf.locks action in
Alias_rules.add sctx ~loc action ~alias)
interpret_and_add_locks ~expander alias_conf.locks action
|> Alias_rules.add sctx ~loc ~alias)
;;

0 comments on commit dfeb7ee

Please sign in to comment.