Skip to content

Commit

Permalink
chore: use with-dev-setup to manage opam test deps (#10744)
Browse files Browse the repository at this point in the history
The goal is to simplify setting up the test dependencies. We use
`{with-dev-setup}` in `dune.opam`. By default, these dependencies are
not installed, but passing `--with-dev-setup` will install them.

Because the test dependencies are now expressed in an opam file, this is
more expressive, and it makes it possible to use opam filters to install
different dependencies on different configurations for example (#10712
is an example).

`make dev-deps` continues working as before, but it can now be expressed
as an opam command. `make dev-switch` is now an idempotent way to
keep the switch in sync (which should cover #6939 as it was reported).

Fixes #6939

Signed-off-by: Etienne Millon <me@emillon.org>
  • Loading branch information
emillon authored Jul 18, 2024
1 parent c6d090d commit 5475609
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 29 deletions.
41 changes: 12 additions & 29 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,6 @@ DESTDIR_ARG := $(if $(DESTDIR),--destdir $(DESTDIR),)
INSTALL_ARGS := $(PREFIX_ARG) $(LIBDIR_ARG) $(DESTDIR_ARG)
BIN := ./_boot/dune.exe

# Dependencies used for testing dune, when developed locally and
# when tested in CI
TEST_DEPS := \
lwt \
cinaps \
"csexp>=1.3.0" \
js_of_ocaml \
js_of_ocaml-compiler \
"mdx>=2.3.0" \
menhir \
ocamlfind \
ocamlformat.$$(awk -F = '$$1 == "version" {print $$2}' .ocamlformat) \
"odoc>=2.4.0" \
"ppx_expect>=v0.16.0" \
ppx_inline_test \
ppxlib \
ctypes \
"utop>=2.6.0" \
"melange>=4.0.0-414"
# Dependencies recommended for developing dune locally,
# but not wanted in CI
DEV_DEPS := \
Expand Down Expand Up @@ -68,31 +49,33 @@ uninstall:
.PHONY: reinstall
reinstall: uninstall install

.PHONY: install-ocamlformat
install-ocamlformat:
opam install -y ocamlformat.$$(awk -F = '$$1 == "version" {print $$2}' .ocamlformat)

dev-depext:
opam depext -y $(TEST_DEPS)

.PHONY: dev-deps
dev-deps:
opam install -y $(TEST_DEPS)
dev-deps: install-ocamlformat
opam install -y . --deps-only --with-dev-setup

.PHONY: coverage-deps
coverage-deps:
opam install -y bisect_ppx

.PHONY: dev-deps-sans-melange
dev-deps-sans-melange:
opam install -y $(TEST_DEPS)
dev-deps-sans-melange: dev-deps

.PHONY: dev-switch
dev-switch:
opam update
# Ensuring that either a dev switch already exists or a new one is created
test "$(shell opam switch show)" = "$(shell pwd)" || \
opam switch create -y . $(TEST_OCAMLVERSION) --deps-only --with-test
opam install -y --update-invariant ocaml.$(TEST_OCAMLVERSION) $(TEST_DEPS) $(DEV_DEPS)
if test -d _opam ; then \
opam install -y --update-invariant ocaml.$(TEST_OCAMLVERSION); \
else \
opam switch create -y . $(TEST_OCAMLVERSION) --no-install ; \
fi
opam install -y . --deps-only --with-test --with-dev-setup
$(MAKE) install-ocamlformat
opam install -y $(DEV_DEPS)

.PHONY: test
test: $(BIN)
Expand Down
6 changes: 6 additions & 0 deletions doc/hacking.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ To create a directory-local opam switch with the dependencies necessary to build
$ make dev-switch
This can also be used to keep the switch updated when dependencies change.

The ``Makefile`` also has a ``make dev-deps`` which will install just the
dependencies used by tests. These are marked ``{ with-dev-setup }`` in Dune's
opam file.

Bootstrapping
=============

Expand Down
15 changes: 15 additions & 0 deletions dune.opam
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,19 @@ depends: [
("ocaml" {>= "4.08"} | ("ocaml" {>= "4.02" & < "4.08~~"} & "ocamlfind-secondary"))
"base-unix"
"base-threads"
"lwt" { with-dev-setup & os != "win32" }
"cinaps" { with-dev-setup }
"csexp" { with-dev-setup & >= "1.3.0" }
"js_of_ocaml" { with-dev-setup & os != "win32" }
"js_of_ocaml-compiler" { with-dev-setup & os != "win32" }
"mdx" { with-dev-setup & >= "2.3.0" & os != "win32" }
"menhir" { with-dev-setup & os != "win32" }
"ocamlfind" { with-dev-setup & os != "win32" }
"odoc" { with-dev-setup & >= "2.4.0" & os != "win32" }
"ppx_expect" { with-dev-setup & >= "v0.16.0" & os != "win32" }
"ppx_inline_test" { with-dev-setup & os != "win32" }
"ppxlib" { with-dev-setup & os != "win32" }
"ctypes" { with-dev-setup & os != "win32" }
"utop" { with-dev-setup & >= "2.6.0" & os != "win32" }
"melange" { with-dev-setup & >= "4.0.0-414" & os != "win32" }
]
15 changes: 15 additions & 0 deletions dune.opam.template
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,19 @@ depends: [
("ocaml" {>= "4.08"} | ("ocaml" {>= "4.02" & < "4.08~~"} & "ocamlfind-secondary"))
"base-unix"
"base-threads"
"lwt" { with-dev-setup & os != "win32" }
"cinaps" { with-dev-setup }
"csexp" { with-dev-setup & >= "1.3.0" }
"js_of_ocaml" { with-dev-setup & os != "win32" }
"js_of_ocaml-compiler" { with-dev-setup & os != "win32" }
"mdx" { with-dev-setup & >= "2.3.0" & os != "win32" }
"menhir" { with-dev-setup & os != "win32" }
"ocamlfind" { with-dev-setup & os != "win32" }
"odoc" { with-dev-setup & >= "2.4.0" & os != "win32" }
"ppx_expect" { with-dev-setup & >= "v0.16.0" & os != "win32" }
"ppx_inline_test" { with-dev-setup & os != "win32" }
"ppxlib" { with-dev-setup & os != "win32" }
"ctypes" { with-dev-setup & os != "win32" }
"utop" { with-dev-setup & >= "2.6.0" & os != "win32" }
"melange" { with-dev-setup & >= "4.0.0-414" & os != "win32" }
]

0 comments on commit 5475609

Please sign in to comment.