Commit 16a009a7 authored by Louis Gesbert's avatar Louis Gesbert
Browse files

Cleanup for latest opam-libs

(required functions are now exported, and the duplication would have
needed patching for small API changes anyway)
parent 88c57260
......@@ -15,166 +15,6 @@ open OpamPackage.Set.Op
let custom_install_doc =
"Install a package using a custom command."
module OpamClient = struct
include OpamClient
(* Functions that should be exported from OpamClient, copied verbatim
(as of 20544c6) *)
open OpamTypes
open OpamStateTypes
open OpamStd.Op
open OpamPackage.Set.Op
let log fmt = OpamConsole.log "CLIENT" fmt
let slog = OpamConsole.slog
let orphans ?changes ?(transitive=false) t =
let all = t.packages ++ t.installed in
let available = Lazy.force t.available_packages in
let allnames = OpamPackage.names_of_packages all in
let invalidated = Lazy.force t.invalidated in
let universe =
OpamSwitchState.universe t ~requested:OpamPackage.Name.Set.empty Reinstall
in
(* Basic definition of orphan packages *)
let orphans =
t.installed -- available
in
log "Base orphans: %a" (slog OpamPackage.Set.to_string) orphans;
(* Restriction to the request-related packages *)
let changes = match changes with
| None -> None
| Some ch ->
Some
(OpamPackage.Name.Set.fold (fun name ch ->
try
OpamPackage.Set.add
(OpamPackage.package_of_name t.installed name) ch
with Not_found -> ch)
(OpamPackage.names_of_packages ch)
ch)
in
let orphans = match changes with
| None -> orphans
| Some ch ->
if OpamPackage.Set.is_empty orphans then orphans else
let recompile_cone =
OpamPackage.Set.of_list @@
OpamSolver.reverse_dependencies
~depopts:true ~installed:true ~unavailable:true
~build:true ~post:false
universe ch
in
orphans %% recompile_cone
in
(* invalidated packages forbid changes of their reverse dependencies, while
basic orphans do not *)
let orphans = orphans ++ invalidated in
(* Pinned versions of packages remain always available *)
let orphans = orphans -- OpamPinned.packages t in
(* Splits between full orphans (no version left) and partial ones *)
let full_partition orphans =
let orphan_names = (* names for which there is no available version left *)
OpamPackage.Name.Set.diff
allnames
(OpamPackage.names_of_packages (available -- orphans)) in
OpamPackage.Set.partition
(fun nv -> OpamPackage.Name.Set.mem nv.name orphan_names)
orphans
in
let full_orphans, orphan_versions = full_partition orphans in
(* Closure *)
let full_orphans, orphan_versions =
if not transitive then full_orphans, orphan_versions else
let rec add_trans full_orphans orphan_versions =
(* fixpoint to check all packages with no available version *)
let new_orphans =
OpamPackage.Set.of_list @@
OpamSolver.reverse_dependencies
~depopts:false ~installed:false ~unavailable:true
~build:true ~post:false
universe full_orphans
in
let full, versions = full_partition (new_orphans++orphan_versions) in
if OpamPackage.Set.equal full_orphans full
then full, versions
else add_trans full versions
in
add_trans full_orphans orphan_versions
in
(* Installed packages outside the set of changes are otherwise safe:
re-add them to the universe *)
let t =
if changes = None then t else
let available_packages = lazy (available ++ (t.installed -- orphans)) in
{ t with available_packages }
in
log "Orphans: (changes: %a, transitive: %b) -> full %a, versions %a"
(slog @@ OpamStd.Option.to_string OpamPackage.Set.to_string) changes
transitive
(slog @@ OpamPackage.Name.Set.to_string @* OpamPackage.names_of_packages)
full_orphans
(slog OpamPackage.Set.to_string) orphan_versions;
t, full_orphans, orphan_versions
(* Checks a request for [atoms] for conflicts with the orphan packages *)
let check_conflicts t atoms =
let changes = OpamSwitchState.packages_of_atoms t atoms in
let t, full_orphans, orphan_versions = orphans ~changes t in
let available = Lazy.force t.available_packages in
let available_changes = changes %% available in
(* packages which still have local data are OK for install/reinstall if still
"available" *)
let full_orphans_reinstallable, full_orphans =
OpamPackage.Set.partition (fun nv ->
match OpamPackage.Map.find_opt nv t.opams with
| None -> false
| Some opam ->
OpamFilter.eval_to_bool ~default:false
(OpamPackageVar.resolve_switch ~package:nv t)
(OpamFile.OPAM.available opam))
full_orphans
in
let orphan_versions_reinstallable, orphan_versions =
OpamPackage.Set.partition (fun nv ->
not (OpamPackage.has_name available_changes nv.name) &&
match OpamPackage.Map.find_opt nv t.opams with
| None -> false
| Some opam ->
OpamFilter.eval_to_bool ~default:false
(OpamPackageVar.resolve_switch ~package:nv t)
(OpamFile.OPAM.available opam))
orphan_versions
in
let orphans = full_orphans ++ orphan_versions in
let conflict_atoms =
let non_orphans = lazy (t.packages -- full_orphans -- orphan_versions) in
List.filter
(fun (name,_ as a) ->
not (OpamPackage.has_name t.pinned name) &&
OpamPackage.Set.exists (OpamFormula.check a) orphans && (*optim*)
not (OpamPackage.Set.exists (OpamFormula.check a) (* real check *)
(Lazy.force non_orphans)))
atoms
in
if conflict_atoms <> [] then
(* Atoms that were unavailable to begin with should be already filtered out
at this point (by [sanitize_atom_list]) *)
OpamConsole.error_and_exit `Not_found
"Sorry, these packages are no longer available from the repositories: \
%s"
(OpamStd.Format.pretty_list
(List.map OpamFormula.string_of_atom conflict_atoms))
else
{t with available_packages = lazy
(available ++
full_orphans_reinstallable ++
orphan_versions_reinstallable)},
full_orphans,
orphan_versions
end
let custom_install =
let doc = custom_install_doc in
let man = [
......
......@@ -9,15 +9,7 @@ tags: ["org:ocamlpro" "org:opam"]
license: "LGPL-2.1-only with OCaml-LGPL-linking-exception"
depends: [
"dune"
"opam-client" {>= "2.1.0~beta2"}
"opam-client" {>= "2.1.0~beta3"}
]
build: ["dune" "build" "-p" name "-j" jobs]
flags: plugin
pin-depends: [
["opam-client.2.1.0~beta2" "git+https://github.com/ocaml/opam.git#2.1.0-beta2"]
["opam-state.2.1.0~beta2" "git+https://github.com/ocaml/opam.git#2.1.0-beta2"]
["opam-solver.2.1.0~beta2" "git+https://github.com/ocaml/opam.git#2.1.0-beta2"]
["opam-repository.2.1.0~beta2" "git+https://github.com/ocaml/opam.git#2.1.0-beta2"]
["opam-format.2.1.0~beta2" "git+https://github.com/ocaml/opam.git#2.1.0-beta2"]
["opam-core.2.1.0~beta2" "git+https://github.com/ocaml/opam.git#2.1.0-beta2"]
]
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment