Skip to content

Commit

Permalink
Add support for opam-0install-cudf 0.5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
kit-ty-kate committed Jul 30, 2024
1 parent 0ea9e2d commit 933b321
Showing 1 changed file with 44 additions and 15 deletions.
59 changes: 44 additions & 15 deletions src/solver/opamBuiltin0install.ml
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ let command_name = None
let preemptive_check = false

let default_criteria = {
crit_default = "";
crit_upgrade = "";
crit_fixup = "";
crit_default = "-changed,\
-count[avoid-version,solution]";
crit_upgrade = "-count[avoid-version,solution]";
crit_fixup = "-count[avoid-version,solution]";
crit_best_effort_prefix = None;
}

Expand Down Expand Up @@ -90,25 +91,53 @@ let reconstruct_universe universe selections =
type options = {
drop_installed_packages : bool;
prefer_oldest : bool;
handle_avoid_version : bool;
prefer_installed : bool;
}

let parse_criteria criteria =
let default = {drop_installed_packages = false; prefer_oldest = false} in
match criteria with
| "" -> default
| "+removed" -> {drop_installed_packages = true; prefer_oldest = false}
| "+count[version-lag,solution]" -> {drop_installed_packages = false; prefer_oldest = true}
| "+removed,+count[version-lag,solution]" ->
{drop_installed_packages = true; prefer_oldest = true}
| _ ->
OpamConsole.warning "Criteria '%s' is not supported by the 0install solver" criteria;
default
let default =
{
drop_installed_packages = false;
prefer_oldest = false;
handle_avoid_version = false;
prefer_installed = false;
}
in
let rec parse default = function
| [] | [""] -> default
| "+removed"::xs ->
parse {default with drop_installed_packages = true} xs
| "+count[version-lag"::"solution]"::xs ->
parse {default with prefer_oldest = true} xs
| "-count[avoid-version"::"solution]"::xs ->
parse {default with handle_avoid_version = true} xs
| "-changed"::xs ->
parse {default with prefer_installed = true} xs
| criteria::xs ->
OpamConsole.warning
"Criteria '%s' is not supported by the 0install solver"
criteria;
parse default xs
in
parse default (String.split_on_char ',' criteria)

let call ~criteria ?timeout:_ (preamble, universe, request) =
let {drop_installed_packages; prefer_oldest} = parse_criteria criteria in
let {
drop_installed_packages;
prefer_oldest;
handle_avoid_version;
prefer_installed;
} =
parse_criteria criteria
in
let timer = OpamConsole.timer () in
let pkgs, constraints = create_spec ~drop_installed_packages universe request in
let context = Opam_0install_cudf.create ~prefer_oldest ~constraints universe in
let context =
Opam_0install_cudf.create
~prefer_oldest ~handle_avoid_version ~prefer_installed
~constraints universe
in
match Opam_0install_cudf.solve context pkgs with
| Ok selections ->
let universe = reconstruct_universe universe selections in
Expand Down

0 comments on commit 933b321

Please sign in to comment.