Skip to content

Commit

Permalink
refactor: gen_rules pattern matching (#6604)
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, 2022
1 parent ef58825 commit 7e0cba9
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions src/dune_rules/gen_rules.ml
Original file line number Diff line number Diff line change
Expand Up @@ -253,20 +253,22 @@ let gen_rules sctx dir_contents cctxs expander
| true -> (
let* ml_sources = Dir_contents.ocaml dir_contents in
match
List.find_map (Menhir_rules.module_names m) ~f:(fun name ->
Option.bind (Ml_sources.find_origin ml_sources name)
~f:(fun origin ->
List.find_map cctxs ~f:(fun (loc, cctx) ->
Option.some_if
(Loc.equal loc (Ml_sources.Origin.loc origin))
cctx)))
Menhir_rules.module_names m
|> List.find_map ~f:(fun name ->
let open Option.O in
let* origin = Ml_sources.find_origin ml_sources name in
List.find_map cctxs ~f:(fun (loc, cctx) ->
Option.some_if
(Loc.equal loc (Ml_sources.Origin.loc origin))
cctx))
with
| Some cctx -> Menhir_rules.gen_rules cctx m ~dir:ctx_dir
| None ->
(* This happens often when passing a [-p ...] option that hides a
library *)
let file_targets =
List.map (Menhir_stanza.targets m)
~f:(Path.Build.relative ctx_dir)
Menhir_stanza.targets m
|> List.map ~f:(Path.Build.relative ctx_dir)
in
Super_context.add_rule sctx ~dir:ctx_dir
(Action_builder.fail
Expand All @@ -278,8 +280,7 @@ let gen_rules sctx dir_contents cctxs expander
files produced by this stanza are part of."
])
}
|> Action_builder.with_file_targets ~file_targets)
| Some cctx -> Menhir_rules.gen_rules cctx m ~dir:ctx_dir))
|> Action_builder.with_file_targets ~file_targets)))
| Coq_stanza.Theory.T m -> (
Expander.eval_blang expander m.enabled_if >>= function
| false -> Memo.return ()
Expand Down

0 comments on commit 7e0cba9

Please sign in to comment.