[ANN] opam build & opam test: the opam plugins that simplifies your dev setup

Hi everyone!

I’m pleased to announce the first release of opam-build and opam-test.
Those two plugins are highly experimental for the moment but aims at a simpler workflow for developers to get started building and testing their projects.

opam-build

builds any project easily with just one command:

opam build

The command will setup a local switch and install all the required dependencies, then build the project (as described in the opam files). So no matter your build system, calling opam build should be enough.

opam-test

opam-test does the same thing as opam-build but runs the tests on top of it. Just call:

opam test

to get started.

opam-test also circumvents issues with cyclic test dependencies in opam (where the tests require a package that needs the library it is trying to test). Such cyclic dependency is present in packages such as odoc or base. See [Proposal] Add a new `opam test` subcommand and change the behaviour of the `run-test` field · Issue #4594 · ocaml/opam · GitHub

If your package is in such a case, opam-test allows you to use the post variable to make that work. For instance:

In project A:

run-test: ["dune" "build "-p" name "-j" jobs] {post}
depends: [
  "B" {with-test & post}
]

In project B:

depends: [
  "A"
]

Without the {post} variable, opam alone would not be able to run the tests as the tests are run before the installation of the package and this would lead to a cyclic dependency. opam-test allows you to split the installation from the tests and thus makes that work.

Installation

To install, simply call

opam update
opam install opam-build opam-test

If the package do not exist, they might not have been merged in opam-repository yet (watch for 2 packages from kit-ty-kate/opam-build at 0.1.0 by kit-ty-kate · Pull Request #20085 · ocaml/opam-repository · GitHub). In the meantime, instead you can install it directly from the source repository:

opam pin add git+https://github.com/kit-ty-kate/opam-build

Again, these plugins are highly experimental and are looking for use-cases. If you think this can be useful, feel free to send some feedbacks here or on the bugtracker: Issues · kit-ty-kate/opam-build · GitHub

24 Likes

Hi everyone,

I’m pleased to announce the release of opam-build & opam-test 0.2.0 (soon 0.2.4 with all the latest improvements)

These two opam plugins now require your current client to be opam 2.2 (e.g. the latest 2.2.0~beta1).
If you use opam 2.2 you can install them using:

opam update && opam install 'opam-build>=0.2.0' 'opam-test>=0.2.0'

After that you can use them from any switches using:

opam build --help
opam test --help

The highlights of this version cycle are:

  • Vastly improved performance and UI
  • Added a new --global and --local command line argument to signify whether to use a local switch or a global switch
  • Add a new config file storing the user preference and which kind of switch to use by default
  • Lots of fixes and improvements

On a personal note, my main incentive with these changes was to finally use these plugins personally and in particular, while working on some packages for my work on the “OCaml 5.2 release readiness” (see a more general description of this work here), i encountered a couple of packages where the only way to compile them was using opam as they were using custom variables passed to their arguments. opam install was not what i wanted (i don’t want to install it, i just need to see if the local version compiles) but opam build fits the bill perfectly here (I don’t know what build-system it uses, i just want to compile it). The previous version however was using local switches, which i don’t personally use and is not suited for the type of work I’m personally doing, so instead i added the option to use the current global switch.

A demo of the new version (here 0.2.4) can be seen here:
demo

Disclaimer: As with version 0.1.0, these plugins are still experimental, however they should be a lot more polished and usable, hopefully if enough people report issues (big thanks to @gridbugs for the reports on the previous versions) next version should be deemed stable.

Happy hacking,

16 Likes