Skip to content

Commit

Permalink
Merge pull request #11090 from ocaml/11058
Browse files Browse the repository at this point in the history
fix(pkg): handle nested [Or] in depopts
  • Loading branch information
rgrinberg authored Nov 5, 2024
2 parents 8933b30 + 04b9b39 commit 5707bf0
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 19 deletions.
40 changes: 21 additions & 19 deletions src/dune_pkg/opam_solver.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
43 changes: 43 additions & 0 deletions test/blackbox-tests/test-cases/pkg/depopts/gh11058.t
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 5707bf0

Please sign in to comment.