Skip to content

Commit

Permalink
[fix] [directory targets] Fix promotion of directory targets in some …
Browse files Browse the repository at this point in the history
…cases

When the promoted directory has sub-directories with only other
sub-directories inside, the map will miss that directory and it will
not be properly re-created, failing at children creation time.

I am not sure I fully follow the logic here (cc: @rleshchinskiy), for
example, I did have trouble making a testcase fail without using `npm`
to generate a large directory.

Regression in b1c339b / #9407

Signed-off-by: Emilio Jesus Gallego Arias <e+git@x80.org>
  • Loading branch information
ejgallego committed Sep 17, 2024
1 parent 4f86203 commit f04877d
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 5 deletions.
3 changes: 3 additions & 0 deletions doc/changes/xxxxx.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- Fix promotion of directory targets when the promoted directory has
sub-directories with only other sub-directories inside; regression
in b1c339b / #9407 (@ejgallego, closes #10609)
4 changes: 1 addition & 3 deletions src/dune_targets/dune_targets.ml
Original file line number Diff line number Diff line change
Expand Up @@ -243,9 +243,7 @@ module Produced = struct
acc_filenames, Path.Local.Map.union_exn acc_dirs dir
| _ -> Error (Unsupported_file (Path.Build.relative dir filename, kind)))
in
if not (Filename.Map.is_empty filenames)
then Path.Local.Map.add_exn dirs local filenames
else dirs
Path.Local.Map.add_exn dirs local filenames
in
let directory root dirname =
let open Result.O in
Expand Down
28 changes: 28 additions & 0 deletions test/blackbox-tests/test-cases/directory-targets/github10609/run.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
We test that a directory target with only other subdirs can be
properly promoted.

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

$ cat > dune <<EOF
> (rule
> (targets (dir node_modules))
> (mode (promote (until-clean)))
> (action (system "mkdir -p node_modules/@clusterws/cws && mkdir -p node_modules/@clusterws/cws/build && mkdir -p node_modules/@clusterws/cws/dist && mkdir -p node_modules/@clusterws/cws/src && touch node_modules/@clusterws/cws/foo.txt && touch node_modules/@clusterws/cws/bar.txt")))
> EOF

$ dune build node_modules
$ ls _build/default/node_modules/@clusterws/cws
bar.txt
build
dist
foo.txt
src
$ ls node_modules/@clusterws/cws
bar.txt
build
dist
foo.txt
src
4 changes: 2 additions & 2 deletions test/blackbox-tests/test-cases/directory-targets/main.t
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ Error message when the matching directory target is empty.
2 | (deps (sandbox always))
3 | (targets (dir output))
4 | (action (bash "mkdir output")))
Error: Rule produced directory "output" that contains no files nor non-empty
subdirectories
Error: This rule defines a directory target "output" that matches the
requested path "output/x" but the rule's action didn't produce it
[1]

Error message when the matching directory target doesn't contain a requested path.
Expand Down

0 comments on commit f04877d

Please sign in to comment.