Permalink
Browse files

Improve OpamCudf API

  • Loading branch information...
samoht committed Mar 29, 2013
1 parent 0e6b40a commit e4c4e2d03def2788567f539ab04ff3c9999b7684
Showing with 23 additions and 16 deletions.
  1. +13 −11 src/solver/opamCudf.ml
  2. +10 −5 src/solver/opamCudf.mli
View
@@ -302,23 +302,25 @@ let default_preamble =
] in
Common.CudfAdd.add_properties Cudf.default_preamble l
-let uninstall universe name =
+let remove universe name =
let packages = Cudf.get_packages universe in
let packages = List.filter (fun p -> p.Cudf.package <> name) packages in
Cudf.load_universe packages
+let uninstall_all universe =
+ let packages = Cudf.get_packages universe in
+ let packages = List.rev_map (fun p -> { p with Cudf.installed = false }) packages in
+ Cudf.load_universe packages
+
let install universe package =
- let versions = Cudf.lookup_packages universe package.Cudf.package in
- let versions = List.map (fun p ->
- if p.Cudf.version = package.Cudf.version then
- { p with Cudf.installed = true }
- else
- { p with Cudf.installed = false }
- ) versions in
+ let p = Cudf.lookup_package universe (package.Cudf.package, package.Cudf.version) in
+ let p = { p with Cudf.installed = true } in
let packages =
- let filter p = p.Cudf.package <> package.Cudf.package in
+ let filter p =
+ p.Cudf.package <> package.Cudf.package
+ && p.Cudf.version <> package.Cudf.version in
Cudf.get_packages ~filter universe in
- Cudf.load_universe (versions @ packages)
+ Cudf.load_universe (p :: packages)
let remove_all_uninstalled_versions_but name constr universe =
let filter p =
@@ -357,7 +359,7 @@ let call_external_solver ~explain univ req =
let get_final_universe univ req =
let open Algo.Depsolver in
match call_external_solver ~explain:true univ req with
- | Sat (_,u) -> Success (uninstall u "dose-dummy-request")
+ | Sat (_,u) -> Success (remove u "dose-dummy-request")
| Error str -> OpamGlobals.error_and_exit "solver error: %s" str
| Unsat r ->
let open Algo.Diagnostic in
View
@@ -98,15 +98,20 @@ val resolve:
Cudf_types.vpkg request ->
(Cudf.package action list, Algo.Diagnostic.reason list) result
-(** Remove a package from an universe *)
-val uninstall: Cudf.universe -> Cudf_types.pkgname -> Cudf.universe
+(** Remove all the packages having a given universe *)
+val remove: Cudf.universe -> Cudf_types.pkgname -> Cudf.universe
-(** Install a package in the universe. Keep the invariant than only
- one version of a package can be installed. *)
+(** Uninstall all the package in the universe. *)
+val uninstall_all: Cudf.universe -> Cudf.universe
+
+(** Install a package in the universe. We don't care about any
+ invariant here (eg. the resulting universe can have mutliple
+ versions of the same package installed). *)
val install: Cudf.universe -> Cudf.package -> Cudf.universe
(** Remove all the versions of a given package, but the one given as argument. *)
-val remove_all_uninstalled_versions_but: string -> Cudf_types.constr -> Cudf.universe -> Cudf.universe
+val remove_all_uninstalled_versions_but:
+ string -> Cudf_types.constr -> Cudf.universe -> Cudf.universe
(** The "reinstall" string *)
val s_reinstall: string

0 comments on commit e4c4e2d

Please sign in to comment.