This commit is contained in:
swrup 2025-11-11 02:07:51 +01:00
parent aa2ff7b2f0
commit 2f3113f55d
11742 changed files with 1223940 additions and 0 deletions

View file

@ -0,0 +1,83 @@
$ mkdir a
$ cd a
$ cat >dune-project <<EOF
> (lang dune 3.0)
> (expand_aliases_in_sandbox)
> EOF
$ echo old-contents > x
$ cat >dune <<EOF
> (alias
> (name a)
> (deps x))
> (rule
> (alias b)
> (deps (alias a))
> (action (system "printf \"running b: \"; cat x")))
> (rule
> (deps (alias a))
> (action
> (progn
> (system "printf \"running b: \"; cat x")
> (with-stdout-to b (system "cat x")))))
> EOF
$ dune build @b
running b: old-contents
$ dune build @b
$ echo new-contents > x
$ dune build @b
running b: new-contents
^ dune does re-run the action when a dependency declared
via an alias changes.
And the path does appear in the sandbox:
$ dune build @b --sandbox copy 2>&1 | grep -v 'cd _build/.sandbox'
running b: new-contents
However, this is only since 3.0, before that aliases where not
expanded when creating the sandbox:
$ echo '(lang dune 2.8)' > dune-project
$ dune clean
$ dune build @b --sandbox copy 2>&1 | grep -v 'cd _build/.sandbox'
File "dune", lines 4-7, characters 0-86:
4 | (rule
5 | (alias b)
6 | (deps (alias a))
7 | (action (system "printf \"running b: \"; cat x")))
running b: cat: x: No such file or directory
$ cat >dune-project <<EOF
> (lang dune 3.0)
> (expand_aliases_in_sandbox)
> EOF
Now test that including an alias into another alias includes its expansion:
$ cat >dune <<EOF
> (alias
> (name a0)
> (deps x))
> (alias
> (name a)
> (deps (alias a0)))
> (rule
> (alias b)
> (deps (alias a))
> (action (system "printf \"running b: \"; cat x")))
> (rule
> (deps (alias a))
> (action
> (progn
> (system "printf \"running b: \"; cat x")
> (with-stdout-to b (system "cat x")))))
> EOF
$ rm -r _build
$ echo old-contents > x
$ dune build @b
running b: old-contents
$ dune build @b
$ echo new-contents > x
$ dune build @b
running b: new-contents
The path still does appear in the sandbox:
$ dune build @b --sandbox copy 2>&1 | grep -v 'cd _build/.sandbox'
running b: new-contents

View file

@ -0,0 +1,32 @@
Setting (expand_aliases_in_sandbox) should re-run the action
First, we create an action and make it depend on an alias
$ cat >dune-project <<EOF
> (lang dune 3.11)
> EOF
$ export DUNE_SANDBOX=symlink
$ cat >dune <<EOF
> (rule
> (alias bar)
> (action (with-stdout-to alias-dep (echo ""))))
> (rule
> (alias foo)
> (deps (alias bar))
> (action (system "find . | sort")))
> EOF
$ dune build @foo
.
Now we set (expand_aliases_in_sandbox), and re-run the action.
$ cat >dune-project <<EOF
> (lang dune 3.11)
> (expand_aliases_in_sandbox)
> EOF
$ dune build @foo
.
./alias-dep
The above output should include the files that we depend on via the alias
expansion.

View file

@ -0,0 +1,83 @@
# Test dependency on installed package
$ mkdir a b prefix
$ cat >a/dune-project <<EOF
> (lang dune 2.9)
> (package (name a))
> EOF
$ cat >a/dune <<EOF
> (install (section share) (files CATME))
> EOF
$ cat >a/CATME <<EOF
> Miaou
> EOF
$ dune build --root a
Entering directory 'a'
Leaving directory 'a'
$ dune install --root a --prefix $PWD/prefix --display short
Installing $TESTCASE_ROOT/prefix/lib/a/META
Installing $TESTCASE_ROOT/prefix/lib/a/dune-package
Installing $TESTCASE_ROOT/prefix/share/a/CATME
$ cat >b/dune-project <<EOF
> (lang dune 2.9)
> (package (name b))
> EOF
$ cat >b/dune <<EOF
> (rule (alias runtest) (deps (package a)) (action (run cat $PWD/prefix/share/a/CATME)))
> EOF
$ OCAMLPATH=$PWD/prefix/lib/:$OCAMLPATH dune build --root b @runtest
Entering directory 'b'
Miaou
Leaving directory 'b'
$ OCAMLPATH=$PWD/prefix/lib/:$OCAMLPATH dune build --root b @runtest
Entering directory 'b'
Leaving directory 'b'
$ rm a/CATME
$ cat >a/CATME <<EOF
> Ouaf
> EOF
$ dune build --root a
Entering directory 'a'
Leaving directory 'a'
$ dune install --root a --prefix $PWD/prefix --display short
Deleting $TESTCASE_ROOT/prefix/lib/a/META
Installing $TESTCASE_ROOT/prefix/lib/a/META
Deleting $TESTCASE_ROOT/prefix/lib/a/dune-package
Installing $TESTCASE_ROOT/prefix/lib/a/dune-package
Deleting $TESTCASE_ROOT/prefix/share/a/CATME
Installing $TESTCASE_ROOT/prefix/share/a/CATME
$ OCAMLPATH=$PWD/prefix/lib/:$OCAMLPATH dune build --root b @runtest
Entering directory 'b'
Ouaf
Leaving directory 'b'
$ OCAMLPATH=$PWD/prefix/lib/:$OCAMLPATH dune build --root b @runtest
Entering directory 'b'
Leaving directory 'b'
$ cat >b/dune-project <<EOF
> (lang dune 2.8)
> (package (name b))
> EOF
$ OCAMLPATH=$PWD/prefix/lib/:$OCAMLPATH dune build --root b @runtest
Entering directory 'b'
File "dune", line 1, characters 37-38:
1 | (rule (alias runtest) (deps (package a)) (action (run cat $TESTCASE_ROOT/prefix/share/a/CATME)))
^
Error: Dependency on an installed package requires at least (lang dune 2.9)
Leaving directory 'b'
[1]

View file

@ -0,0 +1,27 @@
$ 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
contents
$ cat >dune <<EOF
> (rule
> (alias root)
> (deps x)
> (action (chdir a (bash "cat ../x"))))
> EOF
$ dune build @root --sandbox=copy
contents

View file

@ -0,0 +1,4 @@
(alias
(name x)
(deps (universe))
(action (echo "Hello, world!")))

View file

@ -0,0 +1,10 @@
$ dune build @x
Hello, world!
$ dune build @x
Hello, world!
$ dune build @x
Hello, world!
$ dune build @x
Hello, world!
$ dune build @x
Hello, world!