Skip to content

Commit

Permalink
refactor: evaluate directory targets enabled_if in parallel map (#10402)
Browse files Browse the repository at this point in the history
Signed-off-by: Rudi Grinberg <me@rgrinberg.com>
  • Loading branch information
rgrinberg authored Apr 8, 2024
1 parent 1e51ffa commit d19d928
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 28 deletions.
29 changes: 14 additions & 15 deletions src/dune_rules/dir_status.ml
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,9 @@ let error_no_module_consumer ~loc (qualification : Include_subdirs.qualification
;;

let extract_directory_targets ~dir stanzas =
Memo.List.fold_left stanzas ~init:Path.Build.Map.empty ~f:(fun acc stanza ->
Memo.parallel_map stanzas ~f:(fun stanza ->
match Stanza.repr stanza with
| Rule_conf.T { targets = Static { targets = l; _ }; loc = rule_loc; enabled_if; _ }
->
| Rule_conf.T { targets = Static { targets; _ }; loc = rule_loc; enabled_if; _ } ->
(match enabled_if with
| Blang.Const const -> Memo.return const
| _ ->
Expand All @@ -99,13 +98,13 @@ let extract_directory_targets ~dir stanzas =
let* expander = Expander0.get ~dir in
Expander0.eval_blang expander enabled_if)
>>| (function
| false -> acc
| false -> Path.Build.Map.empty
| true ->
List.fold_left l ~init:acc ~f:(fun acc (target, kind) ->
let loc = String_with_vars.loc target in
List.fold_left targets ~init:Path.Build.Map.empty ~f:(fun acc (target, kind) ->
match (kind : Targets_spec.Kind.t) with
| File -> acc
| Directory ->
let loc = String_with_vars.loc target in
(match String_with_vars.text_only target with
| None ->
User_error.raise
Expand All @@ -126,15 +125,15 @@ let extract_directory_targets ~dir stanzas =
(* It's unfortunate that we need to pull in the coq rules here. But
we don't have a generic mechanism for this yet. *)
Coq_doc.coqdoc_directory_targets ~dir m
>>| Path.Build.Map.union acc ~f:(fun path loc1 loc2 ->
User_error.raise
~loc:loc1
[ Pp.textf
"The following both define the same directory target: %s"
(Path.Build.to_string path)
; Pp.enumerate ~f:Loc.pp_file_colon_line [ loc1; loc2 ]
])
| _ -> Memo.return acc)
| _ -> Memo.return Path.Build.Map.empty)
>>| Path.Build.Map.union_all ~f:(fun path loc1 loc2 ->
User_error.raise
~loc:loc1
[ Pp.textf
"The following both define the same directory target: %s"
(Path.Build.to_string path)
; Pp.enumerate ~f:Loc.pp_file_colon_line [ loc1; loc2 ]
])
;;

module rec DB : sig
Expand Down
22 changes: 11 additions & 11 deletions test/blackbox-tests/test-cases/coq/coqdoc-dir-target-clash.t/run.t
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
We try to build the documentation but there will be a clash between the
directory targets. Notice how the tex one fails before html one.
directory targets.
$ dune build @check
Warning: Coq Language Versions lower than 0.8 have been deprecated in Dune
3.8 and will be removed in an upcoming Dune version.
Hint: To disable this warning, add the following to your dune-project file:
(warnings (deprecated_coq_lang_lt_08 disabled))
File "dune", lines 9-15, characters 0-116:
9 | (rule
10 | (targets
11 | (dir base.tex))
12 | (action
13 | (progn
14 | (run mkdir base.tex)
15 | (run touch base.tex/base.base.tex))))
File "dune", lines 1-7, characters 0-120:
1 | (rule
2 | (targets
3 | (dir base.html))
4 | (action
5 | (progn
6 | (run mkdir base.html)
7 | (run touch base.html/base.base.html))))
Error: The following both define the same directory target:
_build/default/base.tex
- dune:9
_build/default/base.html
- dune:1
- dune:17
[1]
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
Duplicate directory targets

$ dune build
Error: Multiple rules generated for _build/default/foo:
- dune:5
File "dune", lines 1-3, characters 0-53:
1 | (rule
2 | (targets (dir foo))
3 | (action (run mkdir foo)))
Error: The following both define the same directory target:
_build/default/foo
- dune:1
- dune:5
[1]

0 comments on commit d19d928

Please sign in to comment.