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,47 @@
The pin stanza allows us to define packages that are not available
in any repository
$ . ../helpers.sh
$ mkrepo
$ add_mock_repo_if_needed
$ cat >dune-project <<EOF
> (lang dune 3.13)
> (pin
> (url "file://$PWD/_extra_source")
> (package
> (name foo)
> (version 1.0.0)))
> (package
> (name main)
> (depends foo))
> EOF
$ mkdir _extra_source
$ cat >_extra_source/dune-project <<EOF
> (lang dune 3.12)
> (package (name foo))
> EOF
$ dune pkg lock
Solution for dune.lock:
- foo.1.0.0
Now we verify the metadata we generated for the package. First we verify the
build instructions and version are set correctly.
We print the source separately for ease of post processing the output.
$ cat dune.lock/foo.pkg | sed "/source/,//d"
(version 1.0.0)
(dune)
(dev)
Now we make sure that the source is set correctly.
$ print_source "foo"
(source (fetch (url file://PWD/_extra_source)))

View file

@ -0,0 +1,79 @@
Demonstrate the build command we construct for different types of projects:
$ . ../helpers.sh
$ mkrepo
$ add_mock_repo_if_needed
$ mkdir _template _dune-only _mixed _opam-only
$ cat >_template/dune-project <<EOF
> (lang dune 3.13)
> (generate_opam_files true)
> (package (name template) (allow_empty))
> EOF
$ cat >_template/mixed.opam.template <<EOF
> build: [ "echo" "template" ]
> EOF
$ cat >_dune-only/dune-project <<EOF
> (lang dune 3.13)
> (package (name dune-only) (allow_empty))
> EOF
$ cat >_mixed/dune-project <<EOF
> (lang dune 3.13)
> EOF
$ cat >_mixed/mixed.opam <<EOF
> opam-version: "2.0"
> build: [ "echo" "mixed" ]
> EOF
$ cat > _opam-only/opam-only.opam <<EOF
> opam-version: "2.0"
> build: [ "echo" "opam only" ]
> EOF
$ cat >dune-project <<EOF
> (lang dune 3.13)
> (pin
> (url "$PWD/_template")
> (package (name template)))
> (pin
> (url "$PWD/_dune-only")
> (package (name dune-only)))
> (pin
> (url "$PWD/_mixed")
> (package (name mixed)))
> (pin
> (url "$PWD/_opam-only")
> (package (name opam-only)))
> (package
> (name main)
> (allow_empty)
> (depends dune-only mixed template opam-only))
> EOF
$ dune pkg lock
Solution for dune.lock:
- dune-only.dev
- mixed.dev
- opam-only.dev
- template.dev
$ build_command() {
> grep "$1" dune.lock/$2.pkg
> }
$ build_command "(dune)" dune-only
(dune)
$ build_command "(dune)" template
(dune)
$ build_command "(build" mixed
(build
$ build_command "(build" opam-only
(build
If we build the deps, everything works fine and we see the output of the opam
pins:
$ dune build @pkg-install
mixed
opam only

View file

@ -0,0 +1,49 @@
Demonstrate a cycle from package sources:
CR-rgrinberg: the cycle checking is disabled for now because it's not clear if
it's even worth checking for. What matters is that there are no cycles at the
package level, the sources can contain a cycle, we just need to make sure we
detect it and not descend into an infinite loop.
$ . ../helpers.sh
$ mkdir a b
$ cat >a/dune-project <<EOF
> (lang dune 3.13)
> (pin
> (url "$PWD/b")
> (package (name b)))
> (package
> (name a)
> (depends b))
> EOF
$ cat >b/dune-project <<EOF
> (lang dune 3.13)
> (pin
> (url "$PWD/a")
> (package (name a)))
> (package
> (name b)
> (depends a))
> EOF
$ runtest() {
> local res;
> res=$(cd $1 && mkrepo && add_mock_repo_if_needed && dune pkg lock 2>&1)
> local code=$?
> printf "$res" $res
> return $code
> }
$ runtest a
Error: Dune does not support packages outside the workspace depending on
packages in the workspace. The package "b" is not in the workspace but it
depends on the package "a" which is in the workspace.
[1]
$ runtest b
Error: Dune does not support packages outside the workspace depending on
packages in the workspace. The package "a" is not in the workspace but it
depends on the package "b" which is in the workspace.
[1]

View file

@ -0,0 +1,38 @@
Package sources can be set to git and be nested:
$ . ../../git-helpers.sh
$ . ../helpers.sh
$ mkrepo
$ add_mock_repo_if_needed
$ mkdir _repo
$ cd _repo
$ git init --quiet
$ cat >dune-project <<EOF
> (lang dune 3.13)
> (package (name foo))
> EOF
$ mkdir bar
$ cat >bar/dune-project <<EOF
> (lang dune 3.13)
> (package (name bar))
> EOF
$ git add -A
$ git commit -qm "initial commit"
$ cd ..
$ cat >dune-project <<EOF
> (lang dune 3.13)
> (pin
> (url "git+file://$PWD/_repo")
> (package (name foo))
> (package (name bar)))
> EOF
$ dune pkg lock 2>&1 | sed 's#git+file://.*/#$URL#'
File "dune-project", line 5, characters 1-21:
5 | (package (name bar)))
^^^^^^^^^^^^^^^^^^^^
Error: package bar doesn't exist in source
$URL_repo

View file

@ -0,0 +1,114 @@
Package sources can be set to git:
$ . ../../git-helpers.sh
$ . ../helpers.sh
$ mkrepo
$ add_mock_repo_if_needed
We create a repo with a fixed name for the default branch.
$ mkdir _repo
$ cd _repo
$ git init --initial-branch=duplicated --quiet
$ cat >dune-project <<EOF
> (lang dune 3.13)
> (package (name foo))
> EOF
$ git add -A
$ git commit -qm "initial commit"
$ cd ..
$ cat >dune-project <<EOF
> (lang dune 3.13)
> (pin
> (url "git+file://$PWD/_repo")
> (package (name foo)))
> (package
> (name main)
> (depends foo))
> EOF
$ dune pkg lock
Solution for dune.lock:
- foo.dev
We create a tag that clashes with the name of the branch (hence we needed to
fix the name of the branch eariler):
$ git -C _repo tag duplicated
This should work without issue, as we never reference the ambiguous reference:
$ dune pkg lock
Solution for dune.lock:
- foo.dev
If we use the duplicate reference in the config
$ cat >dune-project <<EOF
> (lang dune 3.13)
> (pin
> (url "git+file://$PWD/_repo#duplicated")
> (package (name foo)))
> (package
> (name main)
> (depends foo))
> EOF
This will work as both references point at the same revision, thus aren't
ambiguous:
$ dune pkg lock
Solution for dune.lock:
- foo.dev
If we then change the reference of the branch to point to a different revision
than the tag is pointing to (still the initial commit):
$ git -C _repo commit --quiet --allow-empty --message "New ref"
In this case Dune can't determine which reference to use and will error out:
$ dune pkg lock 2>&1 | sed "s|$PWD|\$PWD|"
Error: Reference "duplicated" in remote
"file://$PWD/_repo"
is ambiguous
Hint: If you want to specify a tag use refs/tags/duplicated
Hint: If you want to specify a branch use refs/branches/duplicated
Git also has unambibuous namespaces tags and branches, for tags it is `refs/tags/`.
$ cat >dune-project <<EOF
> (lang dune 3.13)
> (pin
> (url "git+file://$PWD/_repo#refs/tags/duplicated")
> (package (name foo)))
> (package
> (name main)
> (depends foo))
> EOF
Locking should work, as there are no ambiguous references.
$ dune pkg lock
Solution for dune.lock:
- foo.dev
For branches the namespace is `refs/heads/`:
$ cat >dune-project <<EOF
> (lang dune 3.13)
> (pin
> (url "git+file://$PWD/_repo#refs/heads/duplicated")
> (package (name foo)))
> (package
> (name main)
> (depends foo))
> EOF
Likewise locking a branch this way should work as well:
$ dune pkg lock
Solution for dune.lock:
- foo.dev

View file

@ -0,0 +1,39 @@
Pulling projects should respect ignored directories.
$ . ../helpers.sh
$ mkrepo
$ add_mock_repo_if_needed
$ cat >dune-project <<EOF
> (lang dune 3.13)
> (pin
> (url "file://$PWD/_foo")
> (package (name foo)))
> (package
> (name main)
> (depends foo))
> EOF
$ mkdir -p _foo/subproject
$ cat >_foo/dune-project <<EOF
> (lang dune 3.13)
> (package
> (name foo))
> EOF
Although subproject has a dune-project, it lives in a data_only_dirs, so it
should be ignored.
$ cat >_foo/dune <<EOF
> (data_only_dirs subproject)
> EOF
$ cat >_foo/subproject/dune-project <<EOF
> should not be parsed because it's ignored by the stanza above
> EOF
$ dune pkg lock
Solution for dune.lock:
- foo.dev

View file

@ -0,0 +1,49 @@
We try to use a project that has both opam files and a dune-project file. We
should favor the dune metadata in such a case.
$ . ../helpers.sh
$ mkrepo
$ add_mock_repo_if_needed
$ cat >dune-project <<EOF
> (lang dune 3.13)
> (pin
> (url "file://$PWD/_source")
> (package (name foo))
> (package (name bar)))
> (package
> (name main)
> (depends foo bar))
> EOF
$ mkdir _source
$ cat >_source/dune-project <<EOF
> (lang dune 3.13)
> (package (name foo))
> (package (name bar))
> EOF
$ cat >_source/bar.opam <<EOF
> opam-version: "2.0"
> build: [ "echo" "bar" ]
> EOF
$ dune pkg lock
Solution for dune.lock:
- bar.dev
- foo.dev
$ cat dune.lock/bar.pkg | sed "/source/,//d"
(version dev)
(dune)
(dev)
$ cat dune.lock/foo.pkg | sed "/source/,//d"
(version dev)
(dune)
(dev)

View file

@ -0,0 +1,30 @@
We can pull multiple packages from a single source
$ . ../helpers.sh
$ mkrepo
$ add_mock_repo_if_needed
$ mkdir _multiple
$ cat >_multiple/dune-project <<EOF
> (lang dune 3.13)
> (package (name foo))
> (package (name bar))
> EOF
$ cat >dune-project <<EOF
> (lang dune 3.13)
> (pin
> (url file://$PWD/_multiple)
> (package (name foo))
> (package (name bar)))
> (package
> (name main)
> (depends foo bar))
> EOF
$ dune pkg lock
Solution for dune.lock:
- bar.dev
- foo.dev

View file

@ -0,0 +1,29 @@
Here we try to pin a package to a source that doesn't define said package:
$ . ../helpers.sh
$ mkrepo
$ add_mock_repo_if_needed
$ mkdir _bar
$ cat >_bar/dune-project <<EOF
> (lang dune 3.13)
> (package (name no-bar))
> EOF
$ cat >dune-project <<EOF
> (lang dune 3.13)
> (pin
> (url "$PWD/_bar")
> (package (name bar)))
> (package
> (name main)
> (depends bar))
> EOF
$ dune pkg lock 2>&1 | sed 's#file://.*#$URL#g'
File "dune-project", line 4, characters 1-21:
4 | (package (name bar)))
^^^^^^^^^^^^^^^^^^^^
Error: package bar doesn't exist in source
$URL

View file

@ -0,0 +1,34 @@
We try to pull an opam package that isn't a dune project
$ . ../helpers.sh
$ mkrepo
$ add_mock_repo_if_needed
$ cat >dune-project <<EOF
> (lang dune 3.13)
> (pin
> (url "file://$PWD/_foo")
> (package (name foo)))
> (package
> (name main)
> (depends foo))
> EOF
$ mkdir _foo
$ cat >_foo/foo.opam <<EOF
> opam-version: "2.0"
> build: [ "echo" "foo" ]
> EOF
$ dune pkg lock
Solution for dune.lock:
- foo.dev
$ pkg="dune.lock/foo.pkg"
$ grep version $pkg
(version dev)
$ grep dev $pkg
(version dev)
(dev)
$ grep "file://" $pkg | sed "s#$PWD#PWD#g"
file://PWD/_foo)))

View file

@ -0,0 +1,41 @@
A user may set the build command using the opam template feature. This build
command is currently not respected when the package is pinned.
$ . ../helpers.sh
$ mkrepo
$ add_mock_repo_if_needed
$ dir=_opam_template
$ cat >dune-project <<EOF
> (lang dune 3.13)
> (pin
> (url $PWD/$dir)
> (package (name opam-template)))
> (package
> (name main)
> (depends opam-template))
> EOF
$ mkdir $dir
$ cat >$dir/dune-project <<EOF
> (lang dune 3.13)
> (generate_opam_files true)
> (package (allow_empty) (name opam-template))
> EOF
$ cat >$dir/opam-template.template <<EOF
> build: [ "echo" "run" "this" ]
> EOF
$ dune pkg lock
Solution for dune.lock:
- opam-template.dev
$ build_pkg opam-template
$ cat dune.lock/opam-template.pkg | sed "/source/,//d"
(version dev)
(dune)

View file

@ -0,0 +1,74 @@
Override a source when multiple projects in a workspace set it.
$ . ../helpers.sh
Here we demonstrate that projects override their sub projects:
$ mkdir a && cd a
$ mkrepo
$ add_mock_repo_if_needed
$ cat >dune-project <<EOF
> (lang dune 3.13)
> (pin
> (url "file://$PWD/_bar")
> (package (name bar)))
> (package
> (name main)
> (depends bar))
> EOF
$ mkdir sub
$ cat >sub/dune-project <<EOF
> (lang dune 3.13)
> (pin
> (url "file://$PWD/_bar_overriden")
> (package (name bar)))
> EOF
$ mkdir _bar
$ cat >_bar/dune-project <<EOF
> (lang dune 3.13)
> (package (name bar))
> EOF
$ dune pkg lock
Solution for dune.lock:
- bar.dev
$ print_source "bar"
(source (fetch (url file://PWD/_bar))) (dev)
$ cd ..
However, when two projects are at the same level, dune is unable to correctly
select a priority:
$ mkdir b && cd b
$ mkrepo
$ add_mock_repo_if_needed
$ mkdir prj1
$ cat >prj1/dune-project <<EOF
> (lang dune 3.13)
> (pin
> (url "file://$PWD/_bar1")
> (package (name bar)))
> EOF
$ mkdir prj2
$ cat >prj2/dune-project <<EOF
> (lang dune 3.13)
> (pin
> (url "file://$PWD/_bar2")
> (package (name bar)))
> EOF
$ dune pkg lock
File "prj1/dune-project", line 4, characters 1-21:
4 | (package (name bar)))
^^^^^^^^^^^^^^^^^^^^
Error: package "bar" is defined in more than one source
it is also defined in prj1/dune-project:4
[1]

View file

@ -0,0 +1,41 @@
We can override the sources set by packages we're fetching:
$ . ../helpers.sh
$ mkrepo
$ add_mock_repo_if_needed
$ cat >dune-project <<EOF
> (lang dune 3.13)
> (pin
> (url "file://$PWD/_bar")
> (package (name bar)))
> (pin
> (url "file://$PWD/_foo")
> (package (name foo)))
> (package
> (name main)
> (depends foo))
> EOF
$ mkdir _foo
$ cat >_foo/dune-project <<EOF
> (lang dune 3.13)
> (pin
> (url "file://$PWD/_fake_bar") ;; doesn't exist but unused
> (package (name bar)))
> (package
> (name foo)
> (depends bar))
> EOF
$ mkdir _bar
$ cat >_bar/dune-project <<EOF
> (lang dune 3.13)
> (package (name bar))
> EOF
$ dune pkg lock
Solution for dune.lock:
- bar.dev
- foo.dev

View file

@ -0,0 +1,36 @@
Setting the source of a package to a non dune package with pin-depends should
respect the pin-depends
$ . ../helpers.sh
$ mkrepo
$ add_mock_repo_if_needed
$ cat >dune-project <<EOF
> (lang dune 3.13)
> (pin
> (url "file://$PWD/_foo")
> (package (name foo)))
> (package
> (name main)
> (depends foo))
> EOF
$ mkdir _foo
$ cat >_foo/foo.opam <<EOF
> opam-version: "2.0"
> build: [ "echo" "foo" ]
> depends: [ "bar" ]
> pin-depends: [ "bar.1.0.0" "file://$PWD/_bar" ]
> EOF
$ mkdir _bar
$ cat >_bar/bar.opam <<EOF
> opam-version: "2.0"
> build: [ "echo" "bar" ]
> EOF
$ dune pkg lock
Solution for dune.lock:
- bar.1.0.0
- foo.dev

View file

@ -0,0 +1,31 @@
Test that it's possible to lock a project that depends on a pinned
package with depopts.
$ . ../helpers.sh
$ mkrepo
$ add_mock_repo_if_needed
$ mkdir pkg-with-depopts
$ cat > pkg-with-depopts/pkg-with-depopts.opam <<EOF
> opam-version: "2.0"
> depopts: [
> "option-a"
> "option-b"
> ]
> EOF
$ cat > dune-project <<EOF
> (lang dune 3.16)
> (pin
> (url "file://$PWD/pkg-with-depopts")
> (package
> (name pkg-with-depopts)
> (version 5.2.0)))
> (package
> (name foo)
> (depends pkg-with-depopts))
> EOF
$ dune pkg lock
Solution for dune.lock:
- pkg-with-depopts.5.2.0

View file

@ -0,0 +1,38 @@
Sources are traversed recursively (unlike pins)
$ . ../helpers.sh
$ mkrepo
$ add_mock_repo_if_needed
$ mkdir _foo
$ cat >_foo/dune-project <<EOF
> (lang dune 3.13)
> (pin
> (url "file://$PWD/_bar")
> (package (name bar)))
> (package
> (name foo)
> (depends bar))
> EOF
$ mkdir _bar
$ cat >_bar/dune-project <<EOF
> (lang dune 3.13)
> (package (name bar))
> EOF
$ cat >dune-project <<EOF
> (lang dune 3.13)
> (pin
> (url "file://$PWD/_foo")
> (package (name foo)))
> (package
> (name main)
> (depends foo))
> EOF
$ dune pkg lock
Solution for dune.lock:
- bar.dev
- foo.dev

View file

@ -0,0 +1,71 @@
Demonstrate that you can't use a relative path referring outside the workspace
in the pin stanza:
$ . ../helpers.sh
Make a package containing a library:
$ mkdir foo
$ cat > foo/dune-workspace <<EOF
> (lang dune 3.14)
> EOF
$ cat > foo/dune-project <<EOF
> (lang dune 3.14)
> (package
> (name foo))
> EOF
$ cat > foo/dune <<EOF
> (library
> (public_name foo))
> EOF
$ cat > foo/foo.ml <<EOF
> let foo = "foo"
> EOF
Make a second package depending on the first via a pin:
$ mkdir bar
$ cd bar
$ mkrepo
$ add_mock_repo_if_needed
$ cat > dune-project <<EOF
> (lang dune 3.14)
> (pin
> (url file://$PWD/../foo)
> (package (name foo)))
> (package
> (name bar)
> (depends foo))
> EOF
$ cat > dune <<EOF
> (executable
> (public_name bar)
> (libraries foo))
> EOF
$ cat > bar.ml <<EOF
> let () = print_endline Foo.foo
> EOF
Lock and build the second package to demonstrate that everything works so far:
$ dune pkg lock
Solution for dune.lock:
- foo.dev
$ dune exec ./bar.exe
foo
Now change the pin to use a relative path:
$ cat > dune-project <<EOF
> (lang dune 3.14)
> (pin
> (url file://../foo)
> (package (name foo)))
> (package
> (name bar)
> (depends foo))
> EOF
Solving the project now results in an error, though it's still possible to build the project:
$ dune clean
$ dune pkg lock
Error: path outside the workspace: ../foo from .
[1]
$ dune exec ./bar.exe
foo

View file

@ -0,0 +1,34 @@
We are unable to pin projects that the version of dune doesn't understand.
$ . ../helpers.sh
$ mkrepo
$ add_mock_repo_if_needed
$ cat >dune-project <<EOF
> (lang dune 3.13)
> (pin
> (url "$PWD/_b")
> (package (name a)))
> (package
> (name main)
> (depends a))
> EOF
$ mkdir _b
$ cat >_b/dune-project <<EOF
> (lang dune 100.1)
> ;; one day we'll get here
> EOF
# The location here is messed up b/c we are using a source path (incorrectly)
# to construct the project
$ dune pkg lock 2>&1 | sed -E 's/3.[0-9]+/3.XX/g'
File "dune-project", line 1, characters 11-16:
1 | (lang dune 3.XX)
^^^^^
Error: Version 100.1 of the dune language is not supported.
Supported versions of this extension in version 100.1 of the dune language:
- 1.0 to 1.12
- 2.0 to 2.9
- 3.XX to 3.XX

View file

@ -0,0 +1,66 @@
This demonstrates pinning a non-opam package and then modifying its sources.
Whenever the sources are modified, dune should rebuild the package in the
workspace where it's locked.
$ . ../helpers.sh
$ mkrepo
$ add_mock_repo_if_needed
$ cat >dune-project <<EOF
> (lang dune 3.13)
> (pin
> (url "file://$PWD/foo")
> (package (name foo)))
> (package
> (name main)
> (depends foo))
> EOF
Make a package "foo" whose build will fail after printing a message:
$ mkdir foo
$ cat >foo/foo.opam <<EOF
> opam-version: "2.0"
> build: [
> [ make ]
> ]
> EOF
$ cat >foo/Makefile <<EOF
> all:
> echo aaa
> false
> EOF
$ dune pkg lock
Solution for dune.lock:
- foo.dev
Attempt to build the package the first time:
(the error from make is grep'd out because it is not consistant across different systems)
$ build_pkg foo 2>&1 | grep -v -e "^make" -e "^gmake"
echo aaa
aaa
false
File "dune.lock/foo.pkg", line 4, characters 6-13:
4 | (run %{make}))
^^^^^^^
Error: Logs for package foo
Update the message that gets printed while building foo:
$ cat >foo/Makefile <<EOF
> all:
> echo bbb
> false
> EOF
The change to the package is picked up:
$ build_pkg foo 2>&1 | grep -v -e "^make" -e "^gmake"
echo bbb
bbb
false
File "dune.lock/foo.pkg", line 4, characters 6-13:
4 | (run %{make}))
^^^^^^^
Error: Logs for package foo

View file

@ -0,0 +1,44 @@
It should be possible to include custom repos from the workspace:
$ . ../helpers.sh
$ mkrepo
$ add_mock_repo_if_needed
$ mkdir _foo
$ cat >_foo/dune-project <<EOF
> (lang dune 3.13)
> (package (name foo))
> EOF
$ cat >dune-workspace<<EOF
> (lang dune 3.10)
> (pin
> (name foo)
> (url "file://$PWD/_foo")
> (package (name foo)))
> (lock_dir
> (pins foo)
> (repositories mock))
> (repository
> (name mock)
> (url "file://$(pwd)/mock-opam-repository"))
> EOF
$ mkrepo
Note that sources in the projects are overriden by the workspace
$ cat >dune-project <<EOF
> (lang dune 3.13)
> (pin ;; does not exist
> (url "file://$PWD/_does_not_exist")
> (package (name foo)))
> (package
> (name main)
> (depends foo))
> EOF
$ dune pkg lock
Solution for dune.lock:
- foo.dev