Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Revised windows init2 #21

Closed
wants to merge 17 commits into from
Closed
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
3 changes: 1 addition & 2 deletions src/client/opamAction.ml
Original file line number Diff line number Diff line change
Expand Up @@ -528,9 +528,8 @@ let compilation_env t opam =
(OpamFile.OPAM.build_env opam)
in
let cygwin_env =
match OpamSysInteract.Cygwin.cygbin_opt t.switch_global.config with
match OpamCoreConfig.(!r.cygbin) with
| Some cygbin ->
let cygbin = OpamFilename.Dir.to_string cygbin in
[ OpamTypesBase.env_update_resolved "PATH" Cygwin cygbin
~comment:"Cygwin path"
] @ (match OpamCoreConfig.(!r.git_location) with
Expand Down
1,352 changes: 888 additions & 464 deletions src/client/opamClient.ml

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion src/client/opamInitDefaults.ml
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@ let required_tools ~sandboxing () =
let required_packages_for_cygwin =
[
"diffutils";
"git"; (* XXX hg & mercurial ? *)
"make";
"patch";
"tar";
Expand Down
60 changes: 35 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 @@ -1212,6 +1189,8 @@ let install_depexts ?(force_depext=false) ?(confirm=true) t packages =
| `Ignore -> bypass t
| `Quit -> give_up_msg (); OpamStd.Sys.exit_because `Aborted
and print_command sys_packages =
if OpamSysPoll.os_distribution env = Some "cygwin" then
OpamSysInteract.Cygwin.check_setup None;
let commands =
OpamSysInteract.install_packages_commands ~env config sys_packages
|> List.map (fun ((`AsAdmin c | `AsUser c), a) -> c::a)
Expand Down Expand Up @@ -1242,6 +1221,8 @@ let install_depexts ?(force_depext=false) ?(confirm=true) t packages =
| `Quit -> give_up ()
and auto_install t sys_packages =
try
if OpamSysPoll.os_distribution env = Some "cygwin" then
OpamSysInteract.Cygwin.check_setup None;
OpamSysInteract.install ~env config sys_packages; (* handles dry_run *)
map_sysmap (fun _ -> OpamSysPkg.Set.empty) t
with Failure msg ->
Expand Down Expand Up @@ -1297,6 +1278,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
18 changes: 18 additions & 0 deletions src/core/opamCompat.ml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,24 @@ module String = struct
include Stdlib.String
end

module Seq = struct
[@@@warning "-32"]

(** NOTE: OCaml >= 4.14 *)
let rec find_map f xs =
match xs() with
| Seq.Nil ->
None
| Seq.Cons (x, xs) ->
match f x with
| None ->
find_map f xs
| Some _ as result ->
result

include Seq
end

module Either = struct
(** NOTE: OCaml >= 4.12 *)
type ('a, 'b) t =
Expand Down
5 changes: 5 additions & 0 deletions src/core/opamCompat.mli
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ module String : sig
val exists: (char -> bool) -> string -> bool
end

module Seq : sig
(* NOTE: OCaml >= 4.14 *)
val find_map: ('a -> 'b option) -> 'a Seq.t -> 'b option
end

module Either : sig
(* NOTE: OCaml >= 4.12 *)
type ('a, 'b) t =
Expand Down
15 changes: 6 additions & 9 deletions src/core/opamProcess.ml
Original file line number Diff line number Diff line change
Expand Up @@ -302,21 +302,18 @@ let string_of_info ?(color=`yellow) info =
(OpamConsole.colorise color k) v) info;
Buffer.contents b

let resolve_command_fn = ref (fun ?env:_ ?dir:_ _ -> None)
let set_resolve_command =
let called = ref false in
fun resolve_command ->
if !called then invalid_arg "Just what do you think you're doing, Dave?";
called := true;
resolve_command_fn := resolve_command
let resolve_command cmd = !resolve_command_fn cmd
let resolve_command ?env ?dir name =
let env = match env with None -> default_env () | Some e -> e in
match OpamStd.Sys.resolve_command ~env ?dir name with
| `Cmd cmd -> Some cmd
| `Denied | `Not_found -> None

let create_process_env =
if Sys.win32 then
fun cmd ->
if OpamStd.Option.map_default
(OpamStd.Sys.is_cygwin_variant
~cygbin:(OpamCoreConfig.(!r.cygbin)))
?search_in_first:(OpamCoreConfig.(!r.cygbin)))
false
(resolve_command cmd) then
cygwin_create_process_env cmd
Expand Down
5 changes: 3 additions & 2 deletions src/core/opamProcess.mli
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,9 @@ end
type 'a job = 'a Job.Op.job

(**/**)
val set_resolve_command :
(?env:string array -> ?dir:string -> string -> string option) -> unit
(** As {!OpamStd.Sys.resolve_command}, except the default for [~env] is
{!default_env}. *)
val resolve_command: ?env:string array -> ?dir:string -> string -> string option

(** Like Unix.create_process_env, but with correct escaping of arguments when
invoking a cygwin executable from a native Windows executable. *)
Expand Down
Loading
Loading