Skip to content

Commit

Permalink
pkg: don't use "compiler" flag to identify compiler (#10521)
Browse files Browse the repository at this point in the history
Opam's "compiler" flag is used too broadly to accurately identify
packages containing ocaml compilers. For example this flag is set for
compiler options packages such as ocaml-option-flambda which configure
the ocaml-variants package, effectively preventing the use of compiler
options packages, as ocaml-variants also has the "compiler" flag set,
and dune only permits a single compiler package in a solution.

This change fixes this problem by using the presence of the
"ocaml-core-compiler" conflict class to identify compiler
packages.

Signed-off-by: Stephen Sherratt <[email protected]>
  • Loading branch information
gridbugs authored May 14, 2024
1 parent 6984b16 commit 28de4eb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
17 changes: 12 additions & 5 deletions src/dune_pkg/opam_solver.ml
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,17 @@ let available_depopts solver_env version_by_package_name (opam_package : OpamFil
else None))
;;

(* Heuristic to determine whether a package is an ocaml compiler *)
let opam_file_is_compiler (opam_package : OpamFile.OPAM.t) =
(* Identify compiler packages by using the fact that all compiler
Packages declare conflicts with other compiler packages. note
that relying on the "compiler" flag to identify compiler packages
will not work, as compiler options packages (such as
ocaml-option-flambda) also have this flag. *)
let ocaml_core_compiler = OpamPackage.Name.of_string "ocaml-core-compiler" in
List.mem opam_package.conflict_class ocaml_core_compiler ~equal:OpamPackage.Name.equal
;;

let opam_package_to_lock_file_pkg
solver_env
stats_updater
Expand Down Expand Up @@ -676,11 +687,7 @@ let opam_package_to_lock_file_pkg
let exported_env =
OpamFile.OPAM.env opam_file |> List.map ~f:opam_env_update_to_env_update
in
let kind =
if List.mem (OpamFile.OPAM.flags opam_file) ~equal:Poly.equal Pkgflag_Compiler
then `Compiler
else `Non_compiler
in
let kind = if opam_file_is_compiler opam_file then `Compiler else `Non_compiler in
kind, { Lock_dir.Pkg.build_command; install_command; depends; info; exported_env }
;;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ The ocaml compiler needs to be marked inside the lock dir:
$ . ./helpers.sh
$ mkrepo

To mark it, we use flags: compiler:
To mark it, we use `conflict-class: "ocaml-core-compiler"`

$ mkpkg foocaml <<EOF
> flags: compiler
> conflict-class: "ocaml-core-compiler"
> EOF

$ solve foocaml
Expand Down

0 comments on commit 28de4eb

Please sign in to comment.