Skip to content

Commit

Permalink
opam tree: Allow packages with a specific version, directories or loc…
Browse files Browse the repository at this point in the history
…al opam files, as input
  • Loading branch information
kit-ty-kate committed Jul 24, 2023
1 parent 22b9c38 commit dbfa1df
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 17 deletions.
15 changes: 11 additions & 4 deletions src/client/opamCommands.ml
Original file line number Diff line number Diff line change
Expand Up @@ -821,28 +821,35 @@ let tree ?(why=false) cli =
switch to draw the forest"
in
let tree global_options mode filter post dev doc test dev_setup no_constraint
no_switch names () =
if names = [] && no_switch then
no_switch atoms_or_locals () =
if atoms_or_locals = [] && no_switch then
`Error
(true, "--no-switch can't be used without specifying a name")
else
(apply_global_options cli global_options;
OpamGlobalState.with_ `Lock_none @@ fun gt ->
OpamSwitchState.with_ `Lock_none gt @@ fun st ->
let recurse = false in (* TODO *)
let subpath = None in (* TODO *)
let st, atoms =
OpamAuxCommands.simulate_autopin
st ~recurse ?subpath ~quiet:true
?locked:OpamStateConfig.(!r.locked) atoms_or_locals
in
let tog = OpamListCommand.{
post; test; doc; dev; dev_setup;
recursive = false;
depopts = false;
build = true;
} in
OpamTreeCommand.run st tog ~no_constraint ~no_switch mode filter names;
OpamTreeCommand.run st tog ~no_constraint ~no_switch mode filter atoms;
`Ok ())
in
mk_command_ret ~cli (cli_from cli2_2) "tree" ~doc ~man
Term.(const tree $global_options cli $mode $filter
$post cli $dev cli $doc_flag cli $test cli $dev_setup cli
$no_cstr $no_switch
$name_list)
$atom_or_local_list)

(* SHOW *)
let show_doc = "Display information about specific packages."
Expand Down
26 changes: 15 additions & 11 deletions src/client/opamTreeCommand.ml
Original file line number Diff line number Diff line change
Expand Up @@ -406,15 +406,13 @@ let simulate_new_state tog st universe install names =
(OpamSwitchState.unavailable_reason st) cs);
OpamStd.Sys.exit_because `No_solution

let dry_install tog st universe missing =
let install = missing |> List.map (fun name -> name, None) in
let dry_install tog st universe install =
simulate_new_state tog st universe install
(OpamPackage.Name.Set.of_list missing)
(OpamPackage.Name.Set.of_list (List.map fst install))

let raw_state tog st names =
let raw_state tog st install =
let OpamListCommand.{doc; test; dev_setup; _} = tog in
let install = List.map (fun name -> name, None) names in
let names = OpamPackage.Name.Set.of_list names in
let names = OpamPackage.Name.Set.of_list (List.map fst install) in
let requested =
OpamPackage.packages_of_names
(Lazy.force st.available_packages)
Expand All @@ -430,9 +428,15 @@ let raw_state tog st names =
in
simulate_new_state tog st universe install names

let run st tog ?no_constraint ?(no_switch=false) mode filter names =
let run st tog ?no_constraint ?(no_switch=false) mode filter atoms =
let select, missing =
List.partition (OpamSwitchState.is_name_installed st) names
List.fold_left (fun (select, missing) atom ->
if OpamPackage.Set.disjoint
(OpamSwitchState.packages_of_atoms st [atom])
st.installed
then (select, atom :: missing)
else (fst atom :: select, missing)
) ([], []) atoms
in
let st, universe =
let universe = get_universe tog st in
Expand All @@ -450,16 +454,16 @@ let run st tog ?no_constraint ?(no_switch=false) mode filter names =
OpamConsole.warning "Not installed package%s %s, skipping"
(match missing with | [_] -> "" | _ -> "s")
(OpamStd.Format.pretty_list
(List.map OpamPackage.Name.to_string missing));
if select = [] && names <> [] then
(List.map (fun (name, _) -> OpamPackage.Name.to_string name) missing));
if select = [] && atoms <> [] then
OpamConsole.error_and_exit `Not_found "No package to display"
else
st, universe
in
if OpamPackage.Set.is_empty st.installed then
OpamConsole.error_and_exit `Not_found "No package is installed"
else
let forest = build st universe tog mode filter names in
let forest = build st universe tog mode filter (select @ List.map fst missing) in
print ?no_constraint forest;
if OpamClientConfig.(!r.json_out) <> None then
(if not no_switch then
Expand Down
3 changes: 1 addition & 2 deletions src/client/opamTreeCommand.mli
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

(** Functions handling the "opam tree" subcommand *)

open OpamTypes
open OpamStateTypes

(** Speficy the type of the forest to build *)
Expand All @@ -37,4 +36,4 @@ val run :
?no_constraint:bool ->
(* do no keep switch consistency *)
?no_switch:bool ->
mode -> tree_filter -> name list -> unit
mode -> tree_filter -> OpamTypes.atom list -> unit

0 comments on commit dbfa1df

Please sign in to comment.