ocaml / opam

opam is a source-based package manager. It supports multiple simultaneous compiler installations, flexible package constraints, and a Git-friendly development workflow.
https://opam.ocaml.org
Other
1.25k stars 365 forks source link

[Feature request] Allow `--with-test` to introduce cyclic dependencies #4267

Closed craigfe closed 4 years ago

craigfe commented 4 years ago

It's occasionally nice to be able to test a package using one or more its rev-deps. This results in a "cyclic" dependency set of the following type:

Unfortunately, the Opam solver will reject this set of constraints with an error message like the following:

The actions to process have cyclic dependencies:
  - install package.dev -> install rev-dep.dev -> install package.dev

As I understand it, there's no fundamental reason to reject these constraints (opam-0install-solver will accept them). It'd be nice if Opam could support this scenario.


To provide some motivation, here's two examples of this pattern happening in the wild:

  1. LIbrary PPXs. package is a PPX that provides helper functions for using a particular library rev-dep, and so the PPX depends on the library in test only in order to ensure that the generated code compiles with the library API. Developers of rev-dep want to be able to use the PPX when working on the library itself, creating the situation above. (For instance, this blocks usage of ppx_irmin inside irmin.)

  2. Backend-generic libraries. package provides a functor f parameterised over some signature S, and various rev-deps provide instantiations of f for specific backends S. When testing package, it's necessary to first instantiate it with a "simple" backend rev-dep, creating the situation above. (For instance, irmin end-to-end tests would ideally use irmin-mem as a reference backend implementation.)

AltGr commented 4 years ago

You can mark the dependencies as {post} to break the cycles.

depends: "foo" {with-test & post}
AltGr commented 4 years ago

there's no fundamental reason to reject these constraints

Not for binary package managers, but we need a well-founded build order to compile the packages; the constraint is actually not with the solver, but checked afterwards by opam.

craigfe commented 4 years ago

Flagging such test dependencies with {post} appears to result in them not being made available when running tests (as I believe has been discussed offline).

This is possibly a duplicate of https://github.com/ocaml/opam/issues/4099, but if not I think it can be re-opened as I don't think Opam currently supports this workflow.