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,16 @@
When the version is absent, we print the empty string
$ cat >dune-project <<EOF
> (lang dune 3.13)
> (package (name foo))
> EOF
$ cat >dune <<EOF
> (rule
> (alias foo)
> (action (echo foo is '%{version:foo}')))
> EOF
$ dune build @foo
foo is ''

View file

@ -0,0 +1,72 @@
Using a package that is installed needs 2.9 and above
$ cat >dune <<EOF
> (rule
> (alias foo)
> (deps (universe))
> (action (echo foo is '%{version:foo}')))
> EOF
$ runtest() {
> cat >dune-project <<EOF
> (lang dune $1)
> EOF
> dune build @foo
> }
$ runtest 2.8
File "dune", line 4, characters 23-37:
4 | (action (echo foo is '%{version:foo}')))
^^^^^^^^^^^^^^
Error: Package "foo" doesn't exist in the current project.
Hint: If you want to refer to an installed package, or more generally to a
package from another project, you need at least (lang dune 2.9).
[1]
$ runtest 2.9
File "dune", line 4, characters 23-37:
4 | (action (echo foo is '%{version:foo}')))
^^^^^^^^^^^^^^
Error: Package "foo" doesn't exist in the current project and isn't installed
either.
[1]
Now we install foo without a library
$ dir=_without_lib
$ mkdir $dir && cd $dir
$ cat >dune-project <<EOF
> (lang dune 3.13)
> (package (name foo))
> EOF
$ cat >dune <<EOF
> (rule (with-stdout-to foo (echo "")))
> (install (section share) (files foo))
> EOF
$ dune build @install
$ dune install --prefix ./_install
$ cd ..
$ OCAMLPATH="$PWD/$dir/_install/lib:$OCAMLPATH" runtest 2.9
File "dune", line 4, characters 23-37:
4 | (action (echo foo is '%{version:foo}')))
^^^^^^^^^^^^^^
Error: Package "foo" doesn't exist in the current project and isn't installed
either.
[1]
Now we install foo with a library
$ dir=with_lib
$ mkdir $dir && cd $dir
$ cat >dune-project <<EOF
> (lang dune 3.13)
> (package (name foo))
> EOF
$ cat >dune <<EOF
> (library (public_name foo))
> EOF
$ touch foo.ml
$ dune build @install
$ dune install --prefix ./_install
$ cd ..
$ OCAMLPATH="$PWD/$dir/_install/lib:$OCAMLPATH" runtest 2.9
foo is ''

View file

@ -0,0 +1,43 @@
Here we are referring to a package that is external with -p, but we are still
allowed to access it:
$ make_project() {
> cat >dune-project <<EOF
> (lang dune 3.13)
> (package (name a))
> (package (name b))
> (version $1)
> EOF
> }
$ make_project 1.0.0
$ mkdir a b
$ cat >a/dune <<EOF
> (library (public_name a))
> EOF
$ cat >b/dune <<EOF
> (library (public_name b))
> EOF
$ cat >dune <<EOF
> (rule
> (alias foo)
> (deps (universe))
> (action (echo version a is '%{version:a}')))
> EOF
$ dune build @foo -p b
version a is '1.0.0'
Not only that the above is inconsistent with how we handle external packages,
it will also give the wrong answer if a was installed.
$ dune build @install -p a
$ dune install a --prefix _install
The answer should be 1.0.0, bceause that's the version we installed
$ make_project 2.0.0
$ OCAMLPATH="$PWD/_install/lib:$OCAMLPATH" dune build @foo -p b
version a is '2.0.0'

View file

@ -0,0 +1,20 @@
Print a version while we're in the same project
$ cat >dune-project <<EOF
> (lang dune 3.13)
> (package
> (name foo))
> (package
> (name bar))
> (version 1.0.0)
> EOF
$ cat >dune <<EOF
> (rule
> (alias foo)
> (action (echo foo is '%{version:foo}' bar is '%{version:bar}')))
> EOF
$ dune build @foo
foo is '1.0.0' bar is '1.0.0'