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

Add a --download-only flag to "opam install" #4071

Merged
merged 3 commits into from
Dec 12, 2020
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions master_changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ New option/command/subcommand are prefixed with ◈.
## Install
* The stdout of `pre-` and `post-session` hooks is now propagated to the user [#4382 @AltGr - fix #4359]
* `post-install` hooks are allowed to modify or remove installed files, the but not add new ones. Those changes are integrated in changes file [#4388 @lefessan]
* ◈ Add `--download-only` flag [#4071 @Armael @rjbou - fix #4036]

## Remove
* Fix `opam remove --autoremove <PKG>` to not autoremove unrelated packages [#4369 @AltGr - fix #4250 #4332]
Expand Down
9 changes: 5 additions & 4 deletions src/client/opamClient.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1076,7 +1076,7 @@ let filter_unpinned_locally t atoms f =
atoms

let install_t t ?ask ?(ignore_conflicts=false) ?(depext_only=false)
atoms add_to_roots ~deps_only ~assume_built =
?(download_only=false) atoms add_to_roots ~deps_only ~assume_built =
log "INSTALL %a" (slog OpamFormula.string_of_atoms) atoms;
let names = OpamPackage.Name.Set.of_list (List.rev_map fst atoms) in

Expand Down Expand Up @@ -1229,22 +1229,23 @@ let install_t t ?ask ?(ignore_conflicts=false) ?(depext_only=false)
in
let t, res =
OpamSolution.apply ?ask t ~requested:names ?add_roots
~assume_built solution in
~download_only ~assume_built solution in
t, Some (Success res)
in
OpamStd.Option.iter (OpamSolution.check_solution t) solution;
t

let install t ?autoupdate ?add_to_roots
?(deps_only=false) ?(ignore_conflicts=false) ?(assume_built=false)
?(depext_only=false) names =
?(download_only=false) ?(depext_only=false) names =
let atoms = OpamSolution.sanitize_atom_list ~permissive:true t names in
let autoupdate_atoms = match autoupdate with
| None -> atoms
| Some a -> OpamSolution.sanitize_atom_list ~permissive:true t a
in
let t = update_dev_packages_t autoupdate_atoms t in
install_t t ~ignore_conflicts ~depext_only atoms add_to_roots ~deps_only ~assume_built
install_t t atoms add_to_roots
~ignore_conflicts ~depext_only ~deps_only ~download_only ~assume_built

let remove_t ?ask ~autoremove ~force atoms t =
log "REMOVE autoremove:%b %a" autoremove
Expand Down
7 changes: 4 additions & 3 deletions src/client/opamClient.mli
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,15 @@ val reinit:
val install:
rw switch_state ->
?autoupdate:atom list -> ?add_to_roots:bool -> ?deps_only:bool ->
?ignore_conflicts:bool -> ?assume_built:bool -> ?depext_only:bool ->
atom list ->
?ignore_conflicts:bool -> ?assume_built:bool -> ?download_only:bool ->
?depext_only:bool -> atom list ->
rw switch_state

(** Low-level version of [reinstall], bypassing the package name sanitization
and dev package update, and offering more control *)
val install_t:
rw switch_state -> ?ask:bool -> ?ignore_conflicts:bool -> ?depext_only:bool ->
rw switch_state ->
?ask:bool -> ?ignore_conflicts:bool -> ?depext_only:bool -> ?download_only:bool ->
atom list -> bool option -> deps_only:bool -> assume_built:bool ->
rw switch_state

Expand Down
13 changes: 9 additions & 4 deletions src/client/opamCommands.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1515,6 +1515,10 @@ let install cli =
mk_flag ~cli (cli_from cli2_1) ["ignore-conflicts"]
"Used with $(b,--deps-only), ignores conflicts of given package"
in
let download_only =
mk_flag ~cli (cli_from cli2_1) ["download-only"]
"Fetch the sources of the packages, but don't build or install anything."
in
let restore =
mk_flag ~cli cli_original ["restore"]
"Attempt to restore packages that were marked for installation but have \
Expand Down Expand Up @@ -1545,7 +1549,7 @@ let install cli =
let install
global_options build_options add_to_roots deps_only ignore_conflicts
restore destdir assume_built check recurse subpath depext_only
atoms_or_locals () =
download_only atoms_or_locals () =
apply_global_options global_options;
apply_build_options build_options;
if atoms_or_locals = [] && not restore then
Expand Down Expand Up @@ -1606,7 +1610,7 @@ let install cli =
let st =
OpamClient.install st atoms
~autoupdate:pure_atoms ?add_to_roots ~deps_only ~ignore_conflicts
~assume_built ~depext_only
~assume_built ~depext_only ~download_only
in
match destdir with
| None -> `Ok ()
Expand All @@ -1619,7 +1623,7 @@ let install cli =
Term.(const install $global_options cli $build_options cli
$add_to_roots $deps_only $ignore_conflicts $restore $destdir
$assume_built cli $check $recurse cli $subpath cli $depext_only
$atom_or_local_list)
$download_only $atom_or_local_list)

(* REMOVE *)
let remove_doc = "Remove a list of packages."
Expand Down Expand Up @@ -2701,7 +2705,8 @@ let switch cli =
if no_action || OpamFormula.satisfies_depends st.installed invariant
then st
else OpamClient.install_t
st ~ask:true [] None ~deps_only:false ~assume_built:false
st ~ask:true [] None
~deps_only:false ~assume_built:false
in
OpamSwitchState.drop st;
`Ok ())
Expand Down
35 changes: 27 additions & 8 deletions src/client/opamSolution.ml
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,8 @@ end

(* Process the atomic actions in a graph in parallel, respecting graph order,
and report to user. Takes a graph of atomic actions *)
let parallel_apply t ~requested ?add_roots ~assume_built ?(force_remove=false)
let parallel_apply t
~requested ?add_roots ~assume_built ~download_only ?(force_remove=false)
action_graph =
log "parallel_apply";

Expand Down Expand Up @@ -418,14 +419,29 @@ let parallel_apply t ~requested ?add_roots ~assume_built ?(force_remove=false)

(* 1/ process the package actions (fetch, build, installations and removals) *)

let action_graph = (* Add build actions *)
let action_graph = (* Add build and fetch actions *)
let noop_remove nv =
OpamAction.noop_remove_package t nv in
PackageActionGraph.explicit
~noop_remove
~sources_needed:(fun p -> OpamPackage.Set.mem p sources_needed)
action_graph
in
let action_graph =
if download_only then
(* remove actions other than fetches *)
let g = PackageActionGraph.copy action_graph in
PackageActionGraph.iter_vertex (fun v ->
match v with
| `Fetch _ -> ()
| `Install _ | `Reinstall _ | `Change _
| `Remove _ | `Build _ ->
PackageActionGraph.remove_vertex g v
) action_graph;
g
else action_graph
in

(match OpamSolverConfig.(!r.cudf_file) with
| None -> ()
| Some f ->
Expand Down Expand Up @@ -1099,8 +1115,8 @@ let install_depexts ?(force_depext=false) ?(confirm=true) t packages =
sys_packages)

(* Apply a solution *)
let apply ?ask t ~requested ?add_roots ?(assume_built=false) ?force_remove
solution =
let apply ?ask t ~requested ?add_roots ?(assume_built=false)
?(download_only=false) ?force_remove solution =
log "apply";
if OpamSolver.solution_is_empty solution then
(* The current state satisfies the request contraints *)
Expand Down Expand Up @@ -1147,7 +1163,7 @@ let apply ?ask t ~requested ?add_roots ?(assume_built=false) ?force_remove
OpamConsole.msg "===== %s =====\n" (OpamSolver.string_of_stats stats);
);
if not OpamClientConfig.(!r.show) &&
confirmation ?ask requested action_graph
(download_only || confirmation ?ask requested action_graph)
then (
let t =
install_depexts t @@ OpamPackage.Set.inter
Expand Down Expand Up @@ -1195,7 +1211,8 @@ let apply ?ask t ~requested ?add_roots ?(assume_built=false) ?force_remove
OpamStd.Sys.exit_because `Configuration_error;
let t0 = t in
let t, r =
parallel_apply t ~requested ?add_roots ~assume_built ?force_remove
parallel_apply t
~requested ?add_roots ~assume_built ~download_only ?force_remove
action_graph
in
let success = match r with | OK _ -> true | _ -> false in
Expand Down Expand Up @@ -1235,7 +1252,7 @@ let resolve t action ~orphans ?reinstall ~requested request =
r

let resolve_and_apply ?ask t action ~orphans ?reinstall ~requested ?add_roots
?(assume_built=false) ?force_remove request =
?(assume_built=false) ?download_only ?force_remove request =
match resolve t action ~orphans ?reinstall ~requested request with
| Conflicts cs ->
log "conflict!";
Expand All @@ -1245,6 +1262,8 @@ let resolve_and_apply ?ask t action ~orphans ?reinstall ~requested ?add_roots
t, Conflicts cs
| Success solution ->
let t, res =
apply ?ask t ~requested ?add_roots ~assume_built ?force_remove solution
apply ?ask t
~requested ?add_roots ~assume_built ?download_only ?force_remove
solution
in
t, Success res
2 changes: 2 additions & 0 deletions src/client/opamSolution.mli
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ val apply:
requested:OpamPackage.Name.Set.t ->
?add_roots:OpamPackage.Name.Set.t ->
?assume_built:bool ->
?download_only:bool ->
?force_remove:bool ->
OpamSolver.solution ->
rw switch_state * solution_result
Expand All @@ -52,6 +53,7 @@ val resolve_and_apply:
requested:OpamPackage.Name.Set.t ->
?add_roots:OpamPackage.Name.Set.t ->
?assume_built:bool ->
?download_only:bool ->
?force_remove:bool ->
atom request ->
rw switch_state * (solution_result, OpamCudf.conflict) result
Expand Down