Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pkg: fix bug where multiple conflicts causes conlficts to be ignored #11492

Merged
merged 1 commit into from
Feb 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/dune_pkg/dependency_formula.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ open Import

type t = OpamTypes.filtered_formula

let of_dependencies deps = Package_dependency.list_to_opam_filtered_formula deps
let of_dependencies deps =
List.map deps ~f:Package_dependency.to_opam_filtered_formula |> OpamFormula.ands
;;

let to_filtered_formula v = v
let of_filtered_formula v = v
let to_dyn = Opam_dyn.filtered_formula
Expand Down
6 changes: 4 additions & 2 deletions src/dune_pkg/local_package.ml
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,13 @@ module For_solver = struct
|> OpamFile.OPAM.with_name (Package_name.to_opam_package_name name)
|> OpamFile.OPAM.with_depends (Dependency_formula.to_filtered_formula dependencies)
|> OpamFile.OPAM.with_conflicts
(Package_dependency.list_to_opam_filtered_formula conflicts)
(List.map conflicts ~f:Package_dependency.to_opam_filtered_formula
|> OpamFormula.ors)
|> OpamFile.OPAM.with_conflict_class
(List.map conflict_class ~f:Package_name.to_opam_package_name)
|> OpamFile.OPAM.with_depopts
(Package_dependency.list_to_opam_filtered_formula depopts)
(List.map depopts ~f:Package_dependency.to_opam_filtered_formula
|> OpamFormula.ands)
;;

let non_local_dependencies local_deps =
Expand Down
4 changes: 3 additions & 1 deletion src/dune_pkg/opam_solver.ml
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,9 @@ module Context = struct
List.map constraints ~f:(fun (constraint_ : Package_dependency.t) ->
constraint_.name, constraint_)
|> Package_name.Map.of_list_multi
|> Package_name.Map.map ~f:Package_dependency.list_to_opam_filtered_formula
|> Package_name.Map.map ~f:(fun formulae ->
List.map formulae ~f:Package_dependency.to_opam_filtered_formula
|> OpamFormula.ands)
in
let available_cache =
Table.create
Expand Down
18 changes: 8 additions & 10 deletions src/dune_pkg/package_dependency.ml
Original file line number Diff line number Diff line change
Expand Up @@ -210,16 +210,14 @@ let opam_depend { name; constraint_ } =
| Some c -> nopos (OpamParserTypes.FullPos.Option (pkg, nopos [ c ]))
;;

let list_to_opam_filtered_formula ts =
List.map ts ~f:(fun { name; constraint_ } ->
let opam_package_name = Package_name.to_opam_package_name name in
let condition =
match constraint_ with
| None -> OpamTypes.Empty
| Some constraint_ -> Constraint.to_opam_condition constraint_
in
OpamFormula.Atom (opam_package_name, condition))
|> OpamFormula.ands
let to_opam_filtered_formula { name; constraint_ } =
let opam_package_name = Package_name.to_opam_package_name name in
let condition =
match constraint_ with
| None -> OpamTypes.Empty
| Some constraint_ -> Constraint.to_opam_condition constraint_
in
OpamFormula.Atom (opam_package_name, condition)
;;

let list_of_opam_filtered_formula loc kind filtered_formula =
Expand Down
2 changes: 1 addition & 1 deletion src/dune_pkg/package_dependency.mli
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type t = Dune_lang.Package_dependency.t =
include module type of Dune_lang.Package_dependency with type t := t

val opam_depend : t -> OpamParserTypes.FullPos.value
val list_to_opam_filtered_formula : t list -> OpamTypes.filtered_formula
val to_opam_filtered_formula : t -> OpamTypes.filtered_formula

(** Attempt to interpret a [OpamTypes.filtered_formula] as a list of [t]s by
treating the formula as a conjunction of packages with constraints. *)
Expand Down
12 changes: 9 additions & 3 deletions test/blackbox-tests/test-cases/pkg/gh11265.t
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ A package which depends on a single package and also conflicts with the same pac
bar.0.0.1: Package does not satisfy constraints of local package foo
[1]

Now add an additional conflict on a non-existant package "baz". Dune will choose the package "bar" despite it being a conflict:
Now add an additional conflict on a non-existant package "baz". Dune should continue to fail to find a solution due to the conflict with "bar".
$ solve_project << EOF
> (lang dune 3.11)
> (package
Expand All @@ -31,6 +31,12 @@ Now add an additional conflict on a non-existant package "baz". Dune will choose
> (depends bar)
> (conflicts bar baz))
> EOF
Solution for dune.lock:
- bar.0.0.1
Error: Unable to solve dependencies for the following lock directories:
Lock directory dune.lock:
Couldn't solve the package dependency formula.
Selected candidates: foo.dev
- bar -> (problem)
No usable implementations:
bar.0.0.1: Package does not satisfy constraints of local package foo
[1]

Loading