From 6a257d76801d42c38312c44c5074907d166b673e Mon Sep 17 00:00:00 2001 From: Arseniy Alekseyev Date: Wed, 21 Apr 2021 12:46:18 +0100 Subject: [PATCH 1/3] add a test Signed-off-by: Arseniy Alekseyev --- .../depend-on/no-deps-in-cwd.t/run.t | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 test/blackbox-tests/test-cases/depend-on/no-deps-in-cwd.t/run.t 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..d5c4d18a508 --- /dev/null +++ b/test/blackbox-tests/test-cases/depend-on/no-deps-in-cwd.t/run.t @@ -0,0 +1,18 @@ + + $ cat >dune-project < (lang dune 3.0) + > EOF + + $ mkdir a + $ echo contents > x + $ cat >a/dune < (rule + > (alias default) + > (deps ../x) + > (action (bash "cat ../x")) + > ) + > EOF + $ dune build @default --sandbox=copy + Error: chdir: _build/.sandbox/4feb8bb98e202b4343a8ae2ce24c4614/default/a: No + such file or directory + [1] From db207147430106b5fc4967d7a606aac9c573da7e Mon Sep 17 00:00:00 2001 From: Arseniy Alekseyev Date: Wed, 21 Apr 2021 13:03:42 +0100 Subject: [PATCH 2/3] add another case Signed-off-by: Arseniy Alekseyev --- .../depend-on/no-deps-in-cwd.t/run.t | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) 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 index d5c4d18a508..fb8965b05f3 100644 --- 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 @@ -7,12 +7,24 @@ $ echo contents > x $ cat >a/dune < (rule - > (alias default) + > (alias a) > (deps ../x) > (action (bash "cat ../x")) > ) > EOF - $ dune build @default --sandbox=copy - Error: chdir: _build/.sandbox/4feb8bb98e202b4343a8ae2ce24c4614/default/a: No + $ dune build @a --sandbox=copy + Error: chdir: _build/.sandbox/54e7c39ec539e048ba2218cceb055bf6/default/a: No + such file or directory + [1] + + $ cat >dune < (rule + > (alias root) + > (deps x) + > (action (chdir a (bash "cat ../x"))) + > ) + > EOF + $ dune build @root --sandbox=copy + Error: chdir: _build/.sandbox/cba1cf593884e3c67471e7bb90263e06/default/a: No such file or directory [1] From 864d0e5931ed1ec331db670aef50473af9a3d0d6 Mon Sep 17 00:00:00 2001 From: Arseniy Alekseyev Date: Wed, 21 Apr 2021 14:53:32 +0100 Subject: [PATCH 3/3] Fix bug when chdir fails if the dir has no dependencies Signed-off-by: Arseniy Alekseyev --- CHANGES.md | 3 +++ src/dune_engine/build_system.ml | 4 ++-- .../test-cases/depend-on/no-deps-in-cwd.t/run.t | 13 +++++++------ 3 files changed, 12 insertions(+), 8 deletions(-) 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 index fb8965b05f3..d3a08776fda 100644 --- 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 @@ -3,6 +3,9 @@ > (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 < ) > EOF $ dune build @a --sandbox=copy - Error: chdir: _build/.sandbox/54e7c39ec539e048ba2218cceb055bf6/default/a: No - such file or directory - [1] + bash alias a/a + contents $ cat >dune < (rule @@ -25,6 +27,5 @@ > ) > EOF $ dune build @root --sandbox=copy - Error: chdir: _build/.sandbox/cba1cf593884e3c67471e7bb90263e06/default/a: No - such file or directory - [1] + bash alias root + contents