Skip to content

Commit

Permalink
pkg: version field in lockfile is mandatory (ocaml#9509)
Browse files Browse the repository at this point in the history
Signed-off-by: Stephen Sherratt <[email protected]>
  • Loading branch information
gridbugs authored Dec 18, 2023
1 parent 63cfd15 commit 93beff6
Show file tree
Hide file tree
Showing 31 changed files with 81 additions and 33 deletions.
3 changes: 1 addition & 2 deletions src/dune_pkg/lock_dir.ml
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,7 @@ module Pkg = struct
let open Decoder in
enter
@@ fields
@@ let+ version =
field ~default:Pkg_info.default_version Fields.version Package_version.decode
@@ let+ version = field Fields.version Package_version.decode
and+ install_command = field_o Fields.install Action.decode_pkg
and+ build_command = field_o Fields.build Action.decode_pkg
and+ deps = field ~default:[] Fields.deps (repeat (located Package_name.decode))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Create a directory containing a shell script and add the directory to PATH.
Create a lockdir with a lockfile that runs the shell script in a build command.
$ make_lockdir
$ cat >dune.lock/test.pkg <<'EOF'
> (version 0.0.1)
> (build (run hello))
> EOF

Expand Down
3 changes: 2 additions & 1 deletion test/blackbox-tests/test-cases/pkg/default-exported-env.t
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ Some environment variables are automatically exported by packages:
$ . ./helpers.sh

$ make_lockdir
$ touch dune.lock/test.pkg
$ echo "(version 0.0.1)" > dune.lock/test.pkg
$ cat >dune.lock/usetest.pkg <<'EOF'
> (version 0.0.1)
> (deps test)
> (build
> (system "\| echo MANPATH=$MANPATH
Expand Down
1 change: 1 addition & 0 deletions test/blackbox-tests/test-cases/pkg/exported-env.t
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Packages can export environment variables

$ make_lockdir
$ cat >dune.lock/test.pkg <<EOF
> (version 0.0.1)
> (exported_env
> (= FOO bar)
> (= BAR xxx)
Expand Down
1 change: 1 addition & 0 deletions test/blackbox-tests/test-cases/pkg/external-source.t
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Test that can fetch the sources from an external dir

$ make_lockdir
$ cat >dune.lock/test.pkg <<EOF
> (version 0.0.1)
> (source (copy $PWD/foo))
> (build
> (progn
Expand Down
1 change: 1 addition & 0 deletions test/blackbox-tests/test-cases/pkg/extra-sources.t
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Fetch from more than one source
> EOF

$ cat >dune.lock/test.pkg <<EOF
> (version 0.0.1)
> (source (copy $PWD/foo))
> (extra_sources (mybaz (copy $PWD/baz)))
> (build
Expand Down
2 changes: 2 additions & 0 deletions test/blackbox-tests/test-cases/pkg/file-depends.t
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ the files found in files-depend.

$ foo=$PWD/foo
> cat > dune.lock/file-depends.pkg <<EOF
> (version 0.0.1)
> (build
> (system "\| echo Building file-depends
> "\| cat > file-depends.config <<EOF
Expand All @@ -24,6 +25,7 @@ checksum is not parsable.
Now we make a package depending on file-depends.
$ cat > dune.lock/dep.pkg <<EOF
> (version 0.0.1)
> (deps file-depends)
> (build
> (system "echo Building dep"))
Expand Down
3 changes: 3 additions & 0 deletions test/blackbox-tests/test-cases/pkg/gh8325.t
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ If we have a package we depend on

$ mkdir dependency-source
$ cat >dune.lock/dependency.pkg <<EOF
> (version 0.0.1)
> (source (copy $PWD/dependency-source))
> EOF

And we have a package we want to build

$ mkdir test-source
$ cat >dune.lock/test.pkg <<EOF
> (version 0.0.1)
> (source (copy $PWD/test-source))
> (build
> (system "command -v cat > /dev/null 2>&1 || echo no cat"))
Expand All @@ -24,6 +26,7 @@ And we have a package we want to build
Now it fails since adding the dependency modified PATH.

$ cat >dune.lock/test.pkg <<EOF
> (version 0.0.1)
> (source (copy $PWD/test-source))
> ; adding deps breaks cat
> (deps dependency)
Expand Down
1 change: 1 addition & 0 deletions test/blackbox-tests/test-cases/pkg/git-source.t
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Test fetching from git
$ mkdir foo && cd foo
$ make_lockdir
$ cat >dune.lock/test.pkg <<EOF
> (version 0.0.1)
> (source (fetch (url "git+file://$MYGITREPO")))
> (build (run cat foo))
> EOF
Expand Down
1 change: 1 addition & 0 deletions test/blackbox-tests/test-cases/pkg/install-action-dirs.t
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Install actions should have the switch directory prepared:

$ make_lockdir
$ cat >dune.lock/test.pkg <<'EOF'
> (version 0.0.1)
> (install (system "find %{prefix} | sort"))
> EOF

Expand Down
1 change: 1 addition & 0 deletions test/blackbox-tests/test-cases/pkg/install-action.t
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Testing install actions

$ make_lockdir
$ cat >dune.lock/test.pkg <<'EOF'
> (version 0.0.1)
> (install (system "echo foobar; mkdir -p %{lib}; touch %{lib}/xxx"))
> EOF

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Use build paths in the install entries of a package
$ make_lockdir

$ cat >dune.lock/test.pkg <<EOF
> (version 0.0.1)
> (build
> (system "\| cat >test.install <<EOF
> "\| bin: [ "?_build/install/default/bin/foo" ]
Expand Down
1 change: 1 addition & 0 deletions test/blackbox-tests/test-cases/pkg/install-missing-entry.t
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Test missing entries in the .install file
$ make_lockdir
$ lockfile() {
> cat >dune.lock/test.pkg <<EOF
> (version 0.0.1)
> (build
> (system "echo 'lib: [ \"$1\" ]' > test.install"))
> EOF
Expand Down
2 changes: 2 additions & 0 deletions test/blackbox-tests/test-cases/pkg/installed-binary.t
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Test that installed binaries are visible in dependent packages

$ make_lockdir
$ cat >dune.lock/test.pkg <<EOF
> (version 0.0.1)
> (build
> (system "\| echo "#!/bin/sh\necho from test package" > foo;
> "\| chmod +x foo;
Expand All @@ -18,6 +19,7 @@ Test that installed binaries are visible in dependent packages
> EOF

$ cat >dune.lock/usetest.pkg <<EOF
> (version 0.0.1)
> (deps test)
> (build
> (progn
Expand Down
1 change: 1 addition & 0 deletions test/blackbox-tests/test-cases/pkg/libraries.t
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ Now we set up a lock file with this package and then attempt to use it:
> EOF

$ cat >dune.lock/mypkg.pkg <<EOF
> (version 0.0.1)
> (source (copy $PWD/external_sources))
> (build (run dune build --promote-install-file=true . @install))
> EOF
Expand Down
16 changes: 10 additions & 6 deletions test/blackbox-tests/test-cases/pkg/lockdir-validation.t
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,31 @@ package graph then it's caught when loading the lockdir.
$ make_lockdir

$ cat >dune.lock/a.pkg <<EOF
> (version 0.0.1)
> (deps b)
> EOF
$ cat >dune.lock/b.pkg <<EOF
> (version 0.0.1)
> (deps c)
> EOF
$ cat >dune.lock/c.pkg <<EOF
> (version 0.0.1)
> (deps a)
> EOF

$ dune describe pkg lock
Contents of dune.lock:
- a.dev
- b.dev
- c.dev
- a.0.0.1
- b.0.0.1
- c.0.0.1

$ cat >dune.lock/c.pkg <<EOF
> (version 0.0.1)
> (deps a d)
> EOF

$ dune describe pkg lock
File "dune.lock/c.pkg", line 1, characters 8-9:
File "dune.lock/c.pkg", line 2, characters 8-9:
The package "c" depends on the package "d", but "d" does not appear in the
lockdir dune.lock.
Error: At least one package dependency is itself not present as a package in
Expand All @@ -39,10 +43,10 @@ package graph then it's caught when loading the lockdir.
$ rm dune.lock/a.pkg

$ dune describe pkg lock
File "dune.lock/c.pkg", line 1, characters 6-7:
File "dune.lock/c.pkg", line 2, characters 6-7:
The package "c" depends on the package "a", but "a" does not appear in the
lockdir dune.lock.
File "dune.lock/c.pkg", line 1, characters 8-9:
File "dune.lock/c.pkg", line 2, characters 8-9:
The package "c" depends on the package "d", but "d" does not appear in the
lockdir dune.lock.
Error: At least one package dependency is itself not present as a package in
Expand Down
1 change: 1 addition & 0 deletions test/blackbox-tests/test-cases/pkg/make.t
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Build a package with make
> EOF
$ make_lockdir
$ cat >dune.lock/foo.pkg <<EOF
> (version 0.0.1)
> (build (run %{make}))
> (source (copy $PWD/foo))
> EOF
Expand Down
1 change: 1 addition & 0 deletions test/blackbox-tests/test-cases/pkg/ocaml-compiler.t
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ Now we finally make the OCaml package for testing through the lock file:
> (ocaml mycaml)
> EOF
$ cat >dune.lock/mycaml.pkg <<EOF
> (version 0.0.1)
> (source (copy $PWD/mycamlsources))
> (build
> (system "\| cat >mycaml.install <<EOF
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ file copying step rather than the build step.
> (lang package 0.1)
> EOF

$ touch dune.lock/foo.files/foo.install dune.lock/foo.pkg
$ touch dune.lock/foo.files/foo.install
$ echo "(version 0.0.1)" > dune.lock/foo.pkg

The foo.install file in files/ should have been copied over.
$ build_pkg foo 2>&1 | sed 's/copyfile/open/'
3 changes: 3 additions & 0 deletions test/blackbox-tests/test-cases/pkg/package-cycle.t
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@ Package resolution creating a cycle
$ make_lockdir

$ cat >dune.lock/a.pkg <<EOF
> (version 0.0.1)
> (deps b)
> EOF
$ cat >dune.lock/b.pkg <<EOF
> (version 0.0.1)
> (deps c)
> EOF
$ cat >dune.lock/c.pkg <<EOF
> (version 0.0.1)
> (deps a)
> EOF

Expand Down
1 change: 1 addition & 0 deletions test/blackbox-tests/test-cases/pkg/package-files.t
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Additional files overlaid on top of the source can be found in the

$ make_lockdir
$ cat >dune.lock/test.pkg <<EOF
> (version 0.0.1)
> (source
> (copy $PWD/test-source))
> (build
Expand Down
1 change: 1 addition & 0 deletions test/blackbox-tests/test-cases/pkg/patch.t
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Applying patches
$ mkdir test-source
$ make_lockdir
$ cat >dune.lock/test.pkg <<EOF
> (version 0.0.1)
> (source (copy $PWD/test-source))
> (build
> (progn
Expand Down
1 change: 1 addition & 0 deletions test/blackbox-tests/test-cases/pkg/per-context.t
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ TODO: versioning will be added once this feature is stable
> (repositories (complete true))
> EOF
$ cat >foo.lock/test.pkg <<EOF
> (version 0.0.1)
> (build
> (system "echo building from %{context_name}"))
> EOF
Expand Down
1 change: 1 addition & 0 deletions test/blackbox-tests/test-cases/pkg/pkg-action-when.t
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Testing the when action in lockfiles

Case with a mix of uncoditional and conditional actions in a progn action
$ cat >dune.lock/test.pkg <<'EOF'
> (version 0.0.1)
> (install
> (progn
> (when (= foo foo)
Expand Down
2 changes: 2 additions & 0 deletions test/blackbox-tests/test-cases/pkg/pkg-deps.t
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ We should be able to specify (package ..) deps on locally built packages.

$ make_lockdir
$ cat >dune.lock/foo.pkg <<EOF
> (version 0.0.1)
> (install
> (progn
> (run mkdir -p %{prefix}/bin)
Expand Down Expand Up @@ -46,6 +47,7 @@ Now we define the external package using a dune project:
> EOF

$ cat >dune.lock/foo.pkg <<EOF
> (version 0.0.1)
> (source (copy $PWD/external_sources))
> (build (run dune build @install --promote-install-files))
> EOF
Expand Down
1 change: 1 addition & 0 deletions test/blackbox-tests/test-cases/pkg/simple-lock.t
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Test that we run the build command

$ make_lockdir
$ cat >dune.lock/test.pkg <<EOF
> (version 0.0.1)
> (build
> (progn
> (run mkdir -p %{prefix}/bin)
Expand Down
Loading

0 comments on commit 93beff6

Please sign in to comment.