Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mkdir the initial working directory in sandbox #4509

Merged
merged 4 commits into from
Apr 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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