Permalink
Browse files

Much better algorithm to print the causes of actions

It is passed the user-specified packages, and tries to deduce the reason
for all actions from there by propagating in the action graph
  • Loading branch information...
1 parent 5a6b688 commit 4d1a79a0a92456872e4986de6d7cfc07a7ce4c7c @AltGr AltGr committed Feb 11, 2014
@@ -497,12 +497,12 @@ module API = struct
let to_upgrade = t.installed -- to_remove in
let action = Upgrade to_reinstall in
action,
- OpamSolution.resolve t action
+ OpamSolution.resolve t action ~requested:OpamPackage.Name.Set.empty
{ wish_install = [];
wish_remove = OpamSolution.eq_atoms_of_packages unavailable;
wish_upgrade = OpamSolution.atoms_of_packages to_upgrade }
| Some names ->
- let names = OpamSolution.atoms_of_names t names in
+ let atoms = OpamSolution.atoms_of_names t names in
let to_upgrade =
let packages =
OpamMisc.filter_map (fun (n,_) ->
@@ -513,7 +513,7 @@ module API = struct
"%s is not installed.\n" (OpamPackage.Name.to_string n);
None
)
- ) names in
+ ) atoms in
(OpamPackage.Set.of_list packages) in
let t, removed, bad_versions = removed_from_upstream t in
let conflicts = OpamPackage.Set.inter to_upgrade removed in
@@ -527,9 +527,11 @@ module API = struct
let to_remove, unavailable = must_be_removed t to_upgrade bad_versions in
let to_upgrade = to_upgrade -- to_remove in
let installed_roots = t.installed -- to_upgrade -- to_remove in
+ let requested =
+ OpamPackage.Name.Set.of_list (List.rev_map fst atoms) in
let action = Upgrade to_reinstall in
action,
- OpamSolution.resolve t action
+ OpamSolution.resolve t action ~requested
{ wish_install = OpamSolution.eq_atoms_of_packages installed_roots;
wish_remove = OpamSolution.eq_atoms_of_packages unavailable;
wish_upgrade = OpamSolution.atoms_of_packages to_upgrade }
@@ -920,7 +922,7 @@ module API = struct
if add_to_roots = Some false || deps_only then
Install OpamPackage.Name.Set.empty
else Install names in
- let solution = OpamSolution.resolve t action request in
+ let solution = OpamSolution.resolve t action ~requested:names request in
let solution = match solution with
| Conflicts cs ->
log "conflict!"; OpamGlobals.msg "%s\n" (cs()); No_solution
@@ -1041,17 +1043,18 @@ module API = struct
them. But that may re-include packages that we wanted removed, so we
need to remove them again *)
let to_keep = OpamPackage.Set.diff to_keep to_remove in
- let to_remove =
+ let to_remove, requested =
if autoremove then
let to_remove = OpamPackage.Set.diff t.installed to_keep in
- if atoms = [] then to_remove
+ if atoms = [] then to_remove, OpamPackage.names_of_packages to_remove
else (* restrict to the dependency cone of removed pkgs *)
OpamPackage.Set.inter to_remove
(OpamPackage.Set.of_list
(OpamSolver.dependencies
- ~depopts:true ~installed:true universe to_remove))
- else to_remove in
- let solution = OpamSolution.resolve_and_apply t Remove
+ ~depopts:true ~installed:true universe to_remove)),
+ OpamPackage.names_of_packages packages
+ else to_remove, OpamPackage.names_of_packages packages in
+ let solution = OpamSolution.resolve_and_apply t Remove ~requested
{ wish_install = OpamSolution.eq_atoms_of_packages to_keep;
wish_remove = OpamSolution.atoms_of_packages to_remove;
wish_upgrade = [] } in
@@ -480,10 +480,8 @@ let apply ?(force = false) t action solution =
);
let continue =
- if !OpamGlobals.dryrun then (
- OpamGlobals.msg "Dry run: exiting now.\n";
- false
- ) else if !OpamGlobals.external_tags <> [] then (
+ if !OpamGlobals.dryrun then false
+ else if !OpamGlobals.external_tags <> [] then (
let packages = OpamSolver.new_packages solution in
let external_tags = OpamMisc.StringSet.of_list !OpamGlobals.external_tags in
let values =
@@ -519,11 +517,11 @@ let apply ?(force = false) t action solution =
Aborted
)
-let resolve ?(verbose=true) t action request =
- OpamSolver.resolve ~verbose (OpamState.universe t action) request
+let resolve ?(verbose=true) t action ~requested request =
+ OpamSolver.resolve ~verbose (OpamState.universe t action) ~requested request
-let resolve_and_apply ?(force=false) t action request =
- match resolve t action request with
+let resolve_and_apply ?(force=false) t action ~requested request =
+ match resolve t action ~requested request with
| Conflicts cs ->
log "conflict!";
OpamGlobals.msg "%s\n" (cs ());
@@ -23,6 +23,7 @@ val resolve:
?verbose:bool ->
OpamState.state ->
user_action ->
+ requested:OpamPackage.Name.Set.t ->
atom request ->
(solution, string) result
@@ -39,6 +40,7 @@ val resolve_and_apply:
?force:bool ->
OpamState.state ->
user_action ->
+ requested:OpamPackage.Name.Set.t ->
atom request ->
solver_result
@@ -214,6 +214,7 @@ let install_packages ~packages switch compiler =
match bad_packages with
| [] ->
let solution = OpamSolution.resolve_and_apply ~force:true t (Switch roots)
+ ~requested:roots
{ wish_install = [];
wish_remove = [];
wish_upgrade = to_install } in
@@ -301,6 +302,7 @@ let import_t filename t =
OpamPackage.names_of_packages (OpamPackage.Set.union import_roots to_keep) in
let solution = OpamSolution.resolve_and_apply t (Import roots)
+ ~requested:(OpamPackage.names_of_packages imported)
{ wish_install = to_keep;
wish_remove = [];
wish_upgrade = to_import } in
@@ -396,7 +396,9 @@ type 'a action =
type 'a cause =
| Use of 'a list
| Required_by of 'a list
+ | Conflicts_with of 'a list
| Upstream_changes
+ | Requested
| Unknown
let action_contents = function
@@ -428,6 +430,7 @@ module type ACTION_GRAPH = sig
}
val dump_solution: solution -> unit
+ val output_dot: out_channel -> t -> unit
end
@@ -479,6 +482,8 @@ module MakeActionGraph (Pkg: PKG) = struct
let dump_solution g =
Dot.output_graph stdout g.to_process
+ let output_dot = Dot.output_graph
+
end
@@ -492,8 +497,10 @@ module PackageAction = struct
let string_of_cause = function
| Upstream_changes -> "[upstream changes]"
- | Use pkgs -> Printf.sprintf "[use %s]" (string_of_names pkgs)
+ | Use pkgs -> Printf.sprintf "[uses %s]" (string_of_names pkgs)
| Required_by pkgs -> Printf.sprintf "[required by %s]" (string_of_names pkgs)
+ | Conflicts_with pkgs -> Printf.sprintf "[conflicts with %s]" (string_of_names pkgs)
+ | Requested -> ""
| Unknown -> ""
let string_of_raw_action = function
@@ -210,7 +210,9 @@ type 'a action =
type 'a cause =
| Use of 'a list
| Required_by of 'a list
+ | Conflicts_with of 'a list
| Upstream_changes
+ | Requested
| Unknown
(** Extract a package from a package action. *)
@@ -245,6 +247,7 @@ module type ACTION_GRAPH = sig
(** Dump a solution graph *)
val dump_solution: solution -> unit
+ val output_dot: out_channel -> t -> unit
end
@@ -95,16 +95,17 @@ let resolve_deps index names =
OpamPackage.Map.empty
(OpamFilename.Attribute.Set.elements index) in
let packages = OpamPackage.Set.of_list (OpamPackage.Map.keys opams) in
+ let requested = OpamPackage.Name.Set.of_list (List.map fst atoms) in
let universe = {
OpamSolver.empty_universe with
u_packages = packages;
u_available = packages; (* XXX add a compiler/OS option ? *)
u_depends = OpamPackage.Map.map OpamFile.OPAM.depends opams;
u_conflicts = OpamPackage.Map.map OpamFile.OPAM.conflicts opams;
- u_action = Install (OpamPackage.Name.Set.of_list (List.map fst atoms));
+ u_action = Install requested;
} in
let request = { wish_install = atoms; wish_remove = []; wish_upgrade = [] } in
- match OpamSolver.resolve ~verbose:true universe request with
+ match OpamSolver.resolve ~verbose:true universe ~requested request with
| Success solution ->
PackageActionGraph.fold_vertex (fun act acc -> match act with
| To_change (_, p) -> OpamPackage.Set.add p acc
Oops, something went wrong.

0 comments on commit 4d1a79a

Please sign in to comment.