diff --git a/CHANGES.md b/CHANGES.md index ee53731d701..f79b10a8227 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -113,6 +113,9 @@ Unreleased to be produced by the action. Old message is still produced on ENOENT, but other errors deserve a more detailed report. (#4501, @aalekseyev) +- Fixed a bug where a sandboxed action would fail if it declares no dependencies in + its initial working directory or any directory it `chdir`s into. (#4509, @aalekseyev) + 2.9.0 (unreleased) ------------------ diff --git a/src/dune_engine/build_system.ml b/src/dune_engine/build_system.ml index fa41a72b806..df46553cf24 100644 --- a/src/dune_engine/build_system.ml +++ b/src/dune_engine/build_system.ml @@ -1439,6 +1439,7 @@ end = struct let sandbox_suffix = rule_digest |> Digest.to_string in (Path.Build.relative sandbox_dir sandbox_suffix, mode)) in + let chdirs = Action.chdirs action in let* sandboxed, action = match sandbox with | None -> Fiber.return (None, action) @@ -1450,7 +1451,7 @@ end = struct let* () = Fiber.parallel_iter_set (module Path.Set) - (Dep.Facts.dirs deps) + (Path.Set.union (Dep.Facts.dirs deps) chdirs) ~f:(fun path -> Memo.Build.run (match Path.as_in_build_dir path with @@ -1470,7 +1471,6 @@ end = struct ( Some sandboxed , Action.sandbox action ~sandboxed ~mode:sandbox_mode ~deps ) and* () = - let chdirs = Action.chdirs action in Fiber.parallel_iter_set (module Path.Set) chdirs diff --git a/test/blackbox-tests/test-cases/depend-on/no-deps-in-cwd.t/run.t b/test/blackbox-tests/test-cases/depend-on/no-deps-in-cwd.t/run.t new file mode 100644 index 00000000000..d3a08776fda --- /dev/null +++ b/test/blackbox-tests/test-cases/depend-on/no-deps-in-cwd.t/run.t @@ -0,0 +1,31 @@ + + $ cat >dune-project < (lang dune 3.0) + > EOF + +You can `chdir` into a directory without declaring any dependencies +and dune makes sure that the directory exists inside the sandbox. + + $ mkdir a + $ echo contents > x + $ cat >a/dune < (rule + > (alias a) + > (deps ../x) + > (action (bash "cat ../x")) + > ) + > EOF + $ dune build @a --sandbox=copy + bash alias a/a + contents + + $ cat >dune < (rule + > (alias root) + > (deps x) + > (action (chdir a (bash "cat ../x"))) + > ) + > EOF + $ dune build @root --sandbox=copy + bash alias root + contents