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

API: Allow explicit installation of system packages #5994

Merged
merged 2 commits into from
Jun 7, 2024
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
2 changes: 2 additions & 0 deletions master_changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,8 @@ users)
# API updates
## opam-client
* `OpamClient.init` and `OpamClient.reinit`: now can have additional cygwin packages to install [#5930 @moyodiallo]
* Expose `OpamSolution.print_depext_msg` [#5994 @dra27]
* Extracted `OpamSolution.install_sys_packages` from `OpamSolution.install_depexts` [#5994 @dra27]

## opam-repository

Expand Down
56 changes: 31 additions & 25 deletions src/client/opamSolution.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1146,34 +1146,11 @@ let get_depexts ?(force=false) ?(recover=false) t packages =
print_depext_msg (avail, nf);
avail

let install_depexts ?(force_depext=false) ?(confirm=true) t packages =
let confirm =
confirm && not (OpamSysInteract.Cygwin.is_internal t.switch_global.config)
in
let sys_packages =
get_depexts ~force:force_depext ~recover:force_depext t packages
in
let env = t.switch_global.global_variables in
let config = t.switch_global.config in
let map_sysmap f t =
let sys_packages =
OpamPackage.Set.fold (fun nv sys_map ->
match OpamPackage.Map.find_opt nv sys_map with
| Some status ->
OpamPackage.Map.add
nv { status with OpamSysPkg.s_available =
f status.OpamSysPkg.s_available }
sys_map
| None -> sys_map)
packages
(Lazy.force t.sys_packages)
in
{ t with sys_packages = lazy sys_packages }
in
let install_sys_packages ~map_sysmap ~confirm env config sys_packages t =
let rec entry_point t sys_packages =
if OpamClientConfig.(!r.fake) then
(print_command sys_packages; t)
else if OpamFile.Config.depext_run_installs t.switch_global.config then
else if OpamFile.Config.depext_run_installs config then
if confirm then menu t sys_packages else auto_install t sys_packages
else
manual_install t sys_packages
Expand Down Expand Up @@ -1297,6 +1274,35 @@ let install_depexts ?(force_depext=false) ?(confirm=true) t packages =
entry_point t sys_packages
with Sys.Break as e -> OpamStd.Exn.finalise e give_up_msg

let install_depexts ?(force_depext=false) ?(confirm=true) t packages =
let map_sysmap f t =
let sys_packages =
OpamPackage.Set.fold (fun nv sys_map ->
match OpamPackage.Map.find_opt nv sys_map with
| Some status ->
OpamPackage.Map.add
nv { status with OpamSysPkg.s_available =
f status.OpamSysPkg.s_available }
sys_map
| None -> sys_map)
packages
(Lazy.force t.sys_packages)
in
{ t with sys_packages = lazy sys_packages }
in
let confirm =
confirm && not (OpamSysInteract.Cygwin.is_internal t.switch_global.config)
in
let sys_packages =
get_depexts ~force:force_depext ~recover:force_depext t packages
in
let env = t.switch_global.global_variables in
let config = t.switch_global.config in
install_sys_packages ~map_sysmap ~confirm env config sys_packages t

let install_sys_packages ~confirm =
install_sys_packages ~map_sysmap:(fun _ () -> ()) ~confirm

(* Apply a solution *)
let apply ?ask t ~requested ?print_requested ?add_roots
?(skip=OpamPackage.Map.empty)
Expand Down
14 changes: 12 additions & 2 deletions src/client/opamSolution.mli
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,22 @@ val check_solution:
without actually performing the action(s) on disk. *)
val dry_run: 'a switch_state -> OpamSolver.solution -> 'a switch_state

(** Given [(available, not_found)] (see {!OpamSysInteract.packages_status}),
displays appropriate warnings/messages on the console if either set is
non-empty. *)
val print_depext_msg : OpamSysPkg.Set.t * OpamSysPkg.Set.t -> unit

(** As {!install_depexts}, but supplied with a set of system packages to be
installed. *)
val install_sys_packages: confirm:bool -> OpamStateTypes.gt_variables ->
OpamFile.Config.t -> OpamSysPkg.Set.t -> unit -> unit

(* Install external dependencies of the given package set, according the depext
configuration. If [confirm] is false, install commands are directly
launched, without asking user (used by the `--depext-only` option). If
[force_depext] is true, it overrides [OpamFile.Config.depext] value. *)
val install_depexts:
?force_depext:bool -> ?confirm:bool -> rw switch_state -> package_set -> rw switch_state
val install_depexts: ?force_depext:bool -> ?confirm:bool -> rw switch_state ->
package_set -> rw switch_state

(** {2 Atoms} *)

Expand Down
Loading