Skip to content

Commit

Permalink
mkdir the initial working directory in sandbox (#4509)
Browse files Browse the repository at this point in the history
Fix bug when chdir fails if the dir has no dependencies

Signed-off-by: Arseniy Alekseyev <[email protected]>
  • Loading branch information
aalekseyev authored Apr 21, 2021
1 parent 5584146 commit 8e62f25
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
------------------

Expand Down
4 changes: 2 additions & 2 deletions src/dune_engine/build_system.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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
Expand Down
31 changes: 31 additions & 0 deletions test/blackbox-tests/test-cases/depend-on/no-deps-in-cwd.t/run.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

$ cat >dune-project <<EOF
> (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
> (rule
> (alias a)
> (deps ../x)
> (action (bash "cat ../x"))
> )
> EOF
$ dune build @a --sandbox=copy
bash alias a/a
contents

$ cat >dune <<EOF
> (rule
> (alias root)
> (deps x)
> (action (chdir a (bash "cat ../x")))
> )
> EOF
$ dune build @root --sandbox=copy
bash alias root
contents

0 comments on commit 8e62f25

Please sign in to comment.