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

opam-0install-cudf: Add support for the avoid-version flag #35

Closed
wants to merge 1 commit into from
Closed
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
52 changes: 46 additions & 6 deletions lib-cudf/opam_0install_cudf.ml
Original file line number Diff line number Diff line change
Expand Up @@ -72,18 +72,58 @@ type diagnostics = Input.requirements (* So we can run another solve *)
let create ?(prefer_oldest=false) ~constraints universe =
{ Context.universe; constraints; prefer_oldest }

let packages_of_result sels =
sels
|> Solver.Output.to_map |> Solver.Output.RoleMap.to_seq |> List.of_seq
|> List.filter_map (fun (_role, sel) -> Input.version (Solver.Output.unwrap sel))

let tagged_with_avoid_version pkg =
List.exists (function
| "avoid-version", `Bool b -> b
| _ -> false
) pkg.Cudf.pkg_extra

let selection_contains_new_avoid_versions {Context.universe; _} selections =
packages_of_result selections |>
List.exists (fun (pkgname, v) ->
let pkg = Cudf.lookup_package universe (pkgname, v) in
let installed = Cudf.get_installed universe pkgname in
tagged_with_avoid_version pkg &&
not (List.exists tagged_with_avoid_version installed)
)

let remove_new_avoid_versions {Context.universe; _} =
let new_universe = Cudf.empty_universe ~size:(Cudf.universe_size universe) () in
Cudf.iter_packages_by_name (fun pkg pkgs ->
let installed = Cudf.get_installed universe pkg in
let installed_with_avoid_version = List.exists tagged_with_avoid_version installed in
if installed_with_avoid_version then
List.iter (Cudf.add_package new_universe) pkgs
else
List.iter (fun pkg ->
if not (tagged_with_avoid_version pkg) then
Cudf.add_package new_universe pkg
) pkgs
) universe;
new_universe

let solve context pkgs =
let req = requirements ~context pkgs in
match Solver.do_solve ~closest_match:false req with
| Some sels -> Ok sels
| Some sels ->
if selection_contains_new_avoid_versions context sels then
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test looks backwards to me.

Ok sels
else
let universe_without_new_avoid_versions = remove_new_avoid_versions context in
let context = { context with Context.universe = universe_without_new_avoid_versions } in
let req = requirements ~context pkgs in
begin match Solver.do_solve ~closest_match:false req with
| Some sels -> Ok sels
| None -> Ok sels
end
| None -> Error req

let diagnostics ?verbose req =
Solver.do_solve req ~closest_match:true
|> Option.get
|> Diagnostics.get_failure_reason ?verbose

let packages_of_result sels =
sels
|> Solver.Output.to_map |> Solver.Output.RoleMap.to_seq |> List.of_seq
|> List.filter_map (fun (_role, sel) -> Input.version (Solver.Output.unwrap sel))