Skip to content

Commit

Permalink
Remove incorrect validation step for dir targets
Browse files Browse the repository at this point in the history
The validation in question was comparing directory targets discovered
in the project from directories that are the target of enabled rules
(rules which lack an `enabled_if` field, or whose `enabled_if` condition
is false). This was incorrect as it doesn't account for directory
targets which are the target of disabled rules so the validation fails
if any rule with a directory target is disabled. The validation step was
introduced in 1fd19d7 but there aren't any clues to why it was
necessary.

Fixes ocaml#10310

Signed-off-by: Stephen Sherratt <stephen@sherra.tt>
  • Loading branch information
gridbugs authored and vouillon committed Mar 29, 2024
1 parent 68e802f commit 1eea8de
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 33 deletions.
33 changes: 0 additions & 33 deletions src/dune_engine/load_rules.ml
Original file line number Diff line number Diff line change
Expand Up @@ -810,35 +810,6 @@ end = struct
]
;;

let validate_directory_targets ~dir ~real_directory_targets ~directory_targets =
if not
(Path.Build.Map.equal real_directory_targets directory_targets ~equal:(fun _ _ ->
(* The locations should match if the declaration knows which
rule will generate the directory, but it's not necessary
as the rule's actual location has higher priority. *)
true))
then (
let mismatched_directories =
let error message loc =
Dyn.record [ "message", Dyn.string message; "loc", Loc.to_dyn_hum loc ]
in
Path.Build.Map.merge
real_directory_targets
directory_targets
~f:(fun _ generated declared ->
match generated, declared with
| None, None | Some _, Some _ -> None
| Some loc, None -> Some (error "not declared" loc)
| None, Some loc -> Some (error "not generated" loc))
in
Code_error.raise
"gen_rules returned a set of directory targets that doesn't match the set of \
directory targets from returned rules"
[ "dir", Path.Build.to_dyn dir
; "mismatched_directories", Path.Build.Map.to_dyn Fun.id mismatched_directories
])
;;

let load_build_directory_exn
({ Dir_triage.Build_directory.dir; context_name; context_type; sub_dir } as build_dir)
=
Expand Down Expand Up @@ -893,10 +864,6 @@ end = struct
descendants_to_keep build_dir build_dir_only_sub_dirs ~source_dirs rules_produced
in
let rules_here = compile_rules ~dir ~source_dirs rules in
validate_directory_targets
~dir
~real_directory_targets:(Rules.directory_targets rules_produced)
~directory_targets;
(let subdirs_to_keep = Subdir_set.of_dir_set descendants_to_keep in
remove_old_artifacts ~dir ~rules_here ~subdirs_to_keep;
remove_old_sub_dirs_in_anonymous_actions_dir
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@


$ cat > dune-project <<EOF
> (lang dune 3.14)
> (using directory-targets 0.1)
> EOF

$ cat > dune <<EOF
> (rule
> (enabled_if false)
> (target (dir x))
> (action (run mkdir x)))
> EOF

$ dune build

0 comments on commit 1eea8de

Please sign in to comment.