ocaml / dune

A composable build system for OCaml.
https://dune.build/
MIT License
1.6k stars 395 forks source link

Error solving project with deps specified in opam file when deps contain a disjunction #10837

Open gridbugs opened 3 weeks ago

gridbugs commented 3 weeks ago

If a project defines a local package in an opam file instead of its dune-project file, and the opam file specifies a disjunction of packages among its dependencies, dune prints an error while solving:

Error: Expected formula to be a conjunction of atoms but encountered non-atom
term 'extlib {build} | extlib-compat {build}'

To reproduce:

$ opam source lutin.2.71.15
$ cd lutin.2.71.15
$ dune pkg lock
File "lutin.opam", line 1, characters 0-0:
Error: Expected formula to be a conjunction of atoms but encountered non-atom
term 'extlib {build} | extlib-compat {build}'

The package lutin contains this disjunction in its dependencies:

"extlib" {build} | "extlib-compat" {build}

Note that there's no way to describe a package disjunction in the DSL for specifying dependencies in dune-project, but opam files allow it. Dune can handle the case when an external package (ie. a dependency of the project) has a package disjunction in its dependencies, but not when the current project itself has a package disjunction in its dependencies.

I think it would be valid to just improve the error message here to make it clear that this case is not supported.

rgrinberg commented 3 weeks ago

Improving the error message is a good first step. Although there's no fundamental reason not to support this. If a package uses opam to define its metadata, then it should not be a problem for us to pass along the metadata to the solver without interpreting anything.

ElectreAAS commented 2 weeks ago

This same error also occurs when trying to build some highly dependend-upon packages:

Package functoria-runtime (4340 revdeps) fails with

---> Building package n°18: package "functoria-runtime.4.4.2":
Successfully extracted to /tmp/pkg-coverage-f9e828-builder/functoria-runtime.4.4.2
File "mirage-runtime.opam", line 1, characters 0-0:
Error: Expected formula to be a conjunction of atoms but encountered non-atom
term 'result < "1.5" | ppxlib = "0.29.0"'

Package io-page (4340 revdeps) fails with

---> Building package n°22: package "io-page.3.0.0":
Successfully extracted to /tmp/pkg-coverage-9be759-builder/io-page.3.0.0
File "io-page.opam", line 1, characters 0-0:
Error: Expected formula to be a conjunction of atoms but encountered non-atom
term 'mirage-xen < "6.0.0" | ocaml-freestanding < "0.4.1"'

The revdep count is according to check.ci.ocaml.org

Leonidas-from-XIV commented 2 days ago

I looked at it and this looks like it should be fairly easy to fix as we parse the dependencies from a filtered_formula into an dependency set, use this set mostly for hashing and taking out a random element and then reconstruct a filtered_formula to give to the solver.