Skip to content

Commit

Permalink
Update vendored opam to remove OpamScript module
Browse files Browse the repository at this point in the history
Signed-off-by: Stephen Sherratt <stephen@sherra.tt>
  • Loading branch information
gridbugs committed May 17, 2023
1 parent f6e974a commit 4652b5b
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 151 deletions.
136 changes: 0 additions & 136 deletions vendor/opam/src/state/opamEnv.ml
Original file line number Diff line number Diff line change
Expand Up @@ -530,19 +530,6 @@ let init_file = function
| SH_pwsh _ | SH_win_cmd ->
(* N/A because not present in `shells_list` yet *) "init.sh"

let complete_script = function
| SH_sh | SH_bash -> Some OpamScript.complete
| SH_zsh -> Some OpamScript.complete_zsh
| SH_csh | SH_fish -> None
| SH_pwsh _ | SH_win_cmd -> None

let env_hook_script_base = function
| SH_sh | SH_bash -> Some OpamScript.env_hook
| SH_zsh -> Some OpamScript.env_hook_zsh
| SH_csh -> Some OpamScript.env_hook_csh
| SH_fish -> Some OpamScript.env_hook_fish
| SH_pwsh _ | SH_win_cmd -> None

let export_in_shell shell =
let make_comment comment_opt =
OpamStd.Option.to_string (Printf.sprintf "# %s\n") comment_opt
Expand Down Expand Up @@ -593,12 +580,6 @@ let export_in_shell shell =
| SH_pwsh _ -> pwsh
| SH_win_cmd -> win_cmd

let env_hook_script shell =
OpamStd.Option.map (fun script ->
export_in_shell shell ("OPAMNOENVNOTICE", "true", None)
^ script)
(env_hook_script_base shell)

let source root shell f =
let fname = OpamFilename.to_string (OpamPath.init root // f) in
match shell with
Expand Down Expand Up @@ -686,32 +667,6 @@ let write_init_shell_scripts root =
in
List.iter (write_script (OpamPath.init root)) scripts

let write_static_init_scripts root ?completion ?env_hook ?(inplace=false) () =
write_init_shell_scripts root;
let update_scripts filef scriptf enable =
let scripts =
OpamStd.List.filter_map (fun shell ->
match filef shell, scriptf shell with
| Some f, Some s -> Some (f, s)
| _ -> None)
shells_list
in
match enable, inplace with
| Some true, _ ->
List.iter (write_script (OpamPath.init root)) scripts
| _, true ->
List.iter (fun ((f,_) as fs) ->
if OpamFilename.exists (OpamPath.init root // f) then
write_script (OpamPath.init root) fs)
scripts
| Some false, _ ->
List.iter (fun (f,_) ->
OpamFilename.remove (OpamPath.init root // f)) scripts
| None, _ -> ()
in
update_scripts complete_file complete_script completion;
update_scripts env_hook_file env_hook_script env_hook

let write_custom_init_scripts root custom =
let hookdir = OpamPath.hooks_dir root in
let kind = `MD5 in
Expand Down Expand Up @@ -828,97 +783,6 @@ let check_and_print_env_warning st =
(OpamConsole.colorise `bold (eval_string st.switch_global
(Some st.switch)))

let setup
root ~interactive ?dot_profile ?update_config ?env_hook ?completion
?inplace shell =
let opam_root_msg =
let current = OpamFilename.prettify_dir root in
if root = OpamStateConfig.(default.root_dir) then
current
else
let default = OpamFilename.prettify_dir OpamStateConfig.(default.root_dir) in
Printf.sprintf "your opam root\n (%s by default; currently %s)" default current
in
let shell, update_dot_profile, env_hook =
match update_config, dot_profile, interactive with
| Some false, _, _ -> shell, None, env_hook
| _, None, _ -> invalid_arg "OpamEnv.setup"
| Some true, Some dot_profile, _ -> shell, Some dot_profile, env_hook
| None, _, false -> shell, None, env_hook
| None, Some dot_profile, true ->
OpamConsole.header_msg "Required setup - please read";

OpamConsole.msg
"\n\
\ In normal operation, opam only alters files within %s.\n\
\n\
\ However, to best integrate with your system, some environment variables\n\
\ should be set. If you allow it to, this initialisation step will update\n\
\ your %s configuration by adding the following line to %s:\n\
\n\
\ %s\
\n\
\ You can always re-run this setup with 'opam init' later.\n\n"
opam_root_msg
(OpamConsole.colorise `bold @@ string_of_shell shell)
(OpamConsole.colorise `cyan @@ OpamFilename.prettify dot_profile)
(OpamConsole.colorise `bold @@ source root shell (init_file shell));
if OpamCoreConfig.answer_is_yes () then begin
OpamConsole.warning "Shell not updated in non-interactive mode: use --shell-setup";
shell, None, env_hook
end else
let rec menu shell dot_profile default =
let opam_env_inv =
OpamConsole.colorise `bold @@ shell_eval_invocation shell (opam_env_invocation shell)
in
match
OpamConsole.menu "Do you want opam to configure %s?"
(OpamConsole.colorise `bold (string_of_shell shell))
~default ~no:`No ~options:[
`Yes, Printf.sprintf "Yes, update %s"
(OpamConsole.colorise `cyan (OpamFilename.prettify dot_profile));
`No_hooks, Printf.sprintf "Yes, but don't setup any hooks. You'll \
have to run %s whenever you change \
your current 'opam switch'"
opam_env_inv;
`Change_shell, "Select a different shell";
`Change_file, "Specify another config file to update instead";
`No, Printf.sprintf "No, I'll remember to run %s when I need opam"
opam_env_inv;
]
with
| `No -> shell, None, env_hook
| `Yes -> shell, Some dot_profile, Some true
| `No_hooks -> shell, Some dot_profile, Some false
| `Change_shell ->
let shell = OpamConsole.menu ~default:shell ~no:shell
"Please select a shell to configure"
~options: (List.map (fun s -> s, string_of_shell s) OpamStd.Sys.all_shells)
in
menu shell (OpamFilename.of_string (OpamStd.Sys.guess_dot_profile shell))
default
| `Change_file ->
let open OpamStd.Option.Op in
let dot_profile =
(OpamConsole.read "Enter the name of the file to update:"
>>| (fun f ->
if Filename.is_implicit f then Filename.concat (OpamStd.Sys.home ()) f
else f)
>>| OpamFilename.of_string)
+! dot_profile
in
menu shell dot_profile `Yes
in
let default = match env_hook with
| Some true -> `Yes
| Some false -> `No_hooks
| None -> `No
in
menu shell dot_profile default
in
update_user_setup root ?dot_profile:update_dot_profile shell;
write_static_init_scripts root ?completion ?env_hook ?inplace ()

let hook_env root =
let hook_vnam = OpamVariable.of_string "hooks" in
let hook_vval = Some (OpamVariable.dirname (OpamPath.hooks_dir root)) in
Expand Down
14 changes: 0 additions & 14 deletions vendor/opam/src/state/opamEnv.mli
Original file line number Diff line number Diff line change
Expand Up @@ -99,27 +99,13 @@ val env_expansion: ?opam:OpamFile.OPAM.t -> 'a switch_state -> env_update -> env

(** {2 Shell and initialisation support} *)

(** Sets the opam configuration in the user shell, after detailing the process
and asking the user if either [update_config] or [shell_hook] are unset *)
val setup:
dirname -> interactive:bool -> ?dot_profile:filename ->
?update_config:bool -> ?env_hook:bool -> ?completion:bool -> ?inplace:bool ->
shell -> unit

(* (\** Display the global and user configuration for OPAM. *\)
* val display_setup: dirname -> dot_profile:filename -> shell -> unit *)

(** Update the user configuration in $HOME for good opam integration. *)
val update_user_setup:
dirname -> ?dot_profile:filename -> shell -> unit

(** Write the generic scripts in ~/.opam/opam-init needed to import state for
various shells. If specified, completion and env_hook files can also be
written or removed (the default is to keep them as they are). If [inplace]
is true, they are updated if they exist. *)
val write_static_init_scripts:
dirname -> ?completion:bool -> ?env_hook:bool -> ?inplace:bool -> unit -> unit

(** Write into [OpamPath.hooks_dir] the given custom scripts (listed as
(filename, content)), normally provided by opamrc ([OpamFile.InitConfig]) *)
val write_custom_init_scripts:
Expand Down
2 changes: 1 addition & 1 deletion vendor/update-opam.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash

version=cc62e68712e04def2716a1808d515160b2917b19
version=fa798147bb4d4b15972c5c348131c1b11a441964

set -e -o pipefail

Expand Down

0 comments on commit 4652b5b

Please sign in to comment.