diff --git a/src/dune_pkg/opam_solver.ml b/src/dune_pkg/opam_solver.ml index ea1c894c9bc..0ab95c1d08e 100644 --- a/src/dune_pkg/opam_solver.ml +++ b/src/dune_pkg/opam_solver.ml @@ -551,25 +551,27 @@ let opam_file_is_compiler (opam_package : OpamFile.OPAM.t) = ;; let resolve_depopts ~resolve depopts = - (let rec collect acc depopts = - match (depopts : OpamTypes.filtered_formula) with - | Or ((Atom (_, _) as dep), depopts) -> collect (dep :: acc) depopts - | Atom (_, _) -> depopts :: acc - | Empty -> acc - | _ -> - (* We rely on depopts always being a list of or'ed package names. Opam - verifies this for us at parsing time. Dune projects have this - restriction for depopts and regular deps *) - Code_error.raise "invalid depopts" [ "depopts", Opam_dyn.filtered_formula depopts ] - in - collect [] depopts) - |> List.rev - |> List.concat_map ~f:(fun depopt -> - match resolve depopt with - | Error _ -> [] - | Ok { Resolve_opam_formula.post = _; regular } -> - (* CR-someday rgrinberg: think about post deps *) - regular) + let rec collect acc depopts = + match (depopts : OpamTypes.filtered_formula) with + | Or ((Atom (_, _) as dep), depopts) -> collect (dep :: acc) depopts + | Atom (_, _) as dep -> dep :: acc + | Empty -> acc + | _ -> + (* We rely on depopts always being a list of or'ed package names. Opam + verifies this for us at parsing time. Packages defined in dune-project + files have this restriction for depopts and regular deps *) + Code_error.raise "invalid depopts" [ "depopts", Opam_dyn.filtered_formula depopts ] + in + OpamFormula.ors_to_list depopts + |> List.concat_map ~f:(fun x -> + collect [] x + |> List.rev + |> List.concat_map ~f:(fun depopt -> + match resolve depopt with + | Error _ -> [] + | Ok { Resolve_opam_formula.post = _; regular } -> + (* CR-someday rgrinberg: think about post deps *) + regular)) ;; let opam_package_to_lock_file_pkg diff --git a/test/blackbox-tests/test-cases/pkg/depopts/gh11058.t b/test/blackbox-tests/test-cases/pkg/depopts/gh11058.t new file mode 100644 index 00000000000..b5fc51beb93 --- /dev/null +++ b/test/blackbox-tests/test-cases/pkg/depopts/gh11058.t @@ -0,0 +1,43 @@ +Reproduce github issue #11058 + +Handling of more than one depopt: + + $ . ../helpers.sh + + $ mkpkg a + $ mkpkg b + $ mkpkg c + $ mkpkg d + $ mkpkg e + $ mkpkg f + + $ runtest() { + > mkpkg bar <<'EOF' + > depopts: [ "a" "b" "c" ] + > EOF + > solve bar + > } + + $ runtest <<'EOF' + > depopts: [ "a" "b" "c" ] + > EOF + Solution for dune.lock: + - bar.0.0.1 + + $ runtest <<'EOF' + > depopts: [ "a" "b" "c" "d" ] + > EOF + Solution for dune.lock: + - bar.0.0.1 + + $ runtest <<'EOF' + > depopts: [ ("a" | "b") "c" "d" ] + > EOF + Solution for dune.lock: + - bar.0.0.1 + + $ runtest <<'EOF' + > depopts: [ (("e" | "a") | ("d" | "f")) "b" "c" ] + > EOF + Solution for dune.lock: + - bar.0.0.1