Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[switch] Improved design of switch

This fix #106

The new commands are:

$ opam switch -install {compiler}           //to install
$ opam switch -clone {compiler}             //to clone the packages from {compiler} to the current tree
$ opam switch -remove {compiler}            //to remove a compiler
$ opam switch -reinstall {compiler}         //to reinstall a compiler
$ opam switch {compiler}                    //to switch
$ opam switch -list                         //to list all available compilers
$ opam switch -current                      //to display the current compiler
  • Loading branch information...
commit 5632a1077eef9b7a5ef3dd15f1685943c528f578 1 parent acc01fc
@samoht samoht authored
View
412 src/client.ml
@@ -74,7 +74,7 @@ let print_state t =
log "COMPILER : %s" (Dirname.to_string (Path.C.root t.compiler));
log "REPO : %s" (string_of_repos t.repositories);
log "AVAILABLE : %s" (NV.Set.to_string t.available);
- log "AVAILABLE_CURRENT : %s" (match t.available_current with None -> "<none>" | Some set -> NV.Set.to_string set);
+ log "AV_CURRENT: %s" (match t.available_current with None -> "<none>" | Some set -> NV.Set.to_string set);
log "INSTALLED : %s" (NV.Set.to_string t.installed);
log "REINSTALL : %s" (NV.Set.to_string t.reinstall);
log "REPO_INDEX: %s" (N.Map.to_string (String.concat ",") t.repo_index)
@@ -632,127 +632,101 @@ let add_alias alias ocaml_version =
File.Aliases.write aliases_f ((alias, ocaml_version) :: aliases);
end
-(* We assume that we have the right ocaml-version in $opam/config. Then we:
- - create $opam/$alias
- - compiles and install $opam/compiler/$descr.comp
- Some explanations:
- - [f_exists] is called if alias already exists
- - if [default_allowed] is set, then 'system' is an allowed alias argument
-*)
-let init_ocaml t quiet f_exists alias default_allowed ocaml_version =
- log "init_ocaml";
-
- let default = OCaml_V.of_string Globals.default_compiler_version in
- let system_ocaml_version, ocaml_version =
- let current () =
- match OCaml_V.current () with
- | None -> Globals.error_and_exit "No OCaml compiler found in path"
- | Some system_ocaml -> Some system_ocaml, default in
-
- match ocaml_version with
- | None -> current ()
- | Some ocaml_version when default_allowed && ocaml_version = default -> current ()
- | Some ocaml_version ->
- let comp_f = Path.G.compiler t.global ocaml_version in
- if not default_allowed && ocaml_version = default || not (Filename.exists comp_f) then
- begin
- Globals.msg
- " %S is not a valid compiler description%s. The available compilers descriptions are:\n"
- (OCaml_V.to_string ocaml_version)
- (if ocaml_version = default then " (because it is a reserved name)" else "");
- OCaml_V.Set.iter
- (fun v -> Globals.msg " - %s\n" (OCaml_V.to_string v))
- (Path.G.available_compilers t.global);
- Globals.exit 2
- end
- else
- None, ocaml_version in
+(* - compiles and install $opam/compiler/[ocaml_version].comp in $opam/[alias]
+ - update $opam/alias
+ - update $opam/config *)
+let init_ocaml t quiet alias ocaml_version =
+ log "init_ocaml alias=%s ocaml_version=%s"
+ (Alias.to_string alias)
+ (OCaml_V.to_string ocaml_version);
- let alias =
- match alias with
- | None -> Alias.of_string (OCaml_V.to_string ocaml_version)
- | Some alias -> alias in
+ if ocaml_version = OCaml_V.of_string Globals.default_compiler_version then
+ create_default_compiler_description t;
- log "init_ocaml (alias=%s, ocaml_version=%s)" (Alias.to_string alias) (OCaml_V.to_string ocaml_version);
+ let comp_f = Path.G.compiler t.global ocaml_version in
+ if not (Filename.exists comp_f) then (
+ Globals.msg "Cannot find %s: %s is not a valid compiler name.\n"
+ (Filename.to_string comp_f)
+ (OCaml_V.to_string ocaml_version);
+ Globals.exit 0;
+ );
let alias_p = Path.C.create alias in
let alias_p_dir = Path.C.root alias_p in
- if Dirname.exists alias_p_dir then
- f_exists alias_p_dir
- else
- begin
- Dirname.mkdir alias_p_dir;
- (if ocaml_version <> default then
- try
- let comp_f = Path.G.compiler t.global ocaml_version in
- let comp = File.Comp.read comp_f in
- if not (File.Comp.preinstalled comp) then begin
-
- Globals.verbose := not quiet;
-
- (* Install the compiler *)
- let comp_src = File.Comp.src comp in
- let build_dir = Path.C.build_ocaml alias_p in
- Dirname.with_tmp_dir (fun download_dir ->
- begin match Filename.download comp_src download_dir with
+ if Dirname.exists alias_p_dir then (
+ Globals.msg "The compiler %s is already installed.\n" (Alias.to_string alias);
+ Globals.exit 0;
+ );
+ Dirname.mkdir alias_p_dir;
+
+ let comp = File.Comp.read comp_f in
+ begin try
+ if not (File.Comp.preinstalled comp) then begin
+
+ Globals.verbose := not quiet;
+
+ (* Install the compiler *)
+ let comp_src = File.Comp.src comp in
+ let build_dir = Path.C.build_ocaml alias_p in
+ Dirname.with_tmp_dir (fun download_dir ->
+ begin match Filename.download comp_src download_dir with
| None -> Globals.error_and_exit "Cannot download %s" (Filename.to_string comp_src)
| Some f -> Filename.extract f build_dir
- end;
- let patches = File.Comp.patches comp in
- let patches =
- Utils.filter_map (fun f ->
- match Filename.download f build_dir with
- | None -> Globals.error_and_exit "Cannot download %s" (Filename.to_string f)
- | Some f -> Some f
- ) patches in
- List.iter (fun f ->
- if not (Filename.patch f build_dir) then
- Globals.error_and_exit "Cannot apply %s" (Filename.to_string f)
- ) patches;
- let err =
- let t =
- { t with
- compiler = alias_p;
- installed =
- let name = N.of_string Globals.default_package in
- let version = V.of_string (Alias.to_string alias) in
- let nv = NV.create name version in
- NV.Set.add nv NV.Set.empty } in
- install_conf_ocaml_config t;
- if File.Comp.configure comp @ File.Comp.make comp <> [] then begin
- Dirname.exec build_dir
- [ ( "./configure" :: File.Comp.configure comp )
- @ [ "-prefix"; Dirname.to_string alias_p_dir ]
- (*-bindir %s/bin -libdir %s/lib -mandir %s/man*)
- (* NOTE In case it exists 2 '-prefix', in general the script
- ./configure will only consider the last one, others will be
- discarded. *)
- ; ( "make" :: File.Comp.make comp )
- ; [ "make" ; "install" ]
- ]
- end else begin
- let builds =
- List.map (List.map (substitute_string t)) (File.Comp.build comp) in
- Dirname.exec build_dir builds
- end in
- if err <> 0 then
- Globals.error_and_exit
- "The compilation of compiler version %s failed"
- (OCaml_V.to_string ocaml_version)
- )
- end
- with e ->
- if not !Globals.debug then
- Dirname.rmdir alias_p_dir;
- raise e);
- end;
+ end;
+ let patches = File.Comp.patches comp in
+ let patches =
+ Utils.filter_map (fun f ->
+ match Filename.download f build_dir with
+ | None -> Globals.error_and_exit "Cannot download %s" (Filename.to_string f)
+ | Some f -> Some f
+ ) patches in
+ List.iter (fun f ->
+ if not (Filename.patch f build_dir) then
+ Globals.error_and_exit "Cannot apply %s" (Filename.to_string f)
+ ) patches;
+ let err =
+ let t =
+ { t with
+ compiler = alias_p;
+ installed =
+ let name = N.of_string Globals.default_package in
+ let version = V.of_string (Alias.to_string alias) in
+ let nv = NV.create name version in
+ NV.Set.add nv NV.Set.empty } in
+ install_conf_ocaml_config t;
+ if File.Comp.configure comp @ File.Comp.make comp <> [] then begin
+ Dirname.exec build_dir
+ [ ( "./configure" :: File.Comp.configure comp )
+ @ [ "-prefix"; Dirname.to_string alias_p_dir ]
+ (*-bindir %s/bin -libdir %s/lib -mandir %s/man*)
+ (* NOTE In case it exists 2 '-prefix', in general the script
+ ./configure will only consider the last one, others will be
+ discarded. *)
+ ; ( "make" :: File.Comp.make comp )
+ ; [ "make" ; "install" ]
+ ]
+ end else begin
+ let builds =
+ List.map (List.map (substitute_string t)) (File.Comp.build comp) in
+ Dirname.exec build_dir builds
+ end in
+ if err <> 0 then
+ Globals.error_and_exit
+ "The compilation of compiler version %s failed"
+ (OCaml_V.to_string ocaml_version)
+ )
+ end;
- (* write the new version in the configuration file *)
- let config = File.Config.with_ocaml_version t.config alias in
- let config = File.Config.with_system_ocaml_version config system_ocaml_version in
- File.Config.write (Path.G.config t.global) config;
- add_alias alias ocaml_version;
- ocaml_version
+ (* write the new version in the configuration file *)
+ let config = File.Config.with_ocaml_version t.config alias in
+ File.Config.write (Path.G.config t.global) config;
+ add_alias alias ocaml_version
+
+ with e ->
+ if not !Globals.debug then
+ Dirname.rmdir alias_p_dir;
+ raise e
+ end
let indent_left s nb =
let nb = nb - String.length s in
@@ -1327,17 +1301,20 @@ module Heuristic = struct
| None -> vpkg_of_nv_eq n (V.Set.max_elt set)
| Some v -> vpkg_of_nv_ge n v
- let get_installed t f_h =
+ let get t packages f_h =
let available = get_available_current t in
let available_map = NV.to_map available in
- let installed =
+ let packages =
NV.Set.filter
(fun nv -> NV.Set.mem nv available)
- t.installed in
- let installed_map = NV.to_map installed in
+ packages in
+ let map = NV.to_map packages in
N.Map.mapi
(fun n vs -> f_h (Some (V.Set.choose_one vs)) (N.Map.find n available_map) n)
- installed_map
+ map
+
+ let get_installed t f_h =
+ get t t.installed f_h
let get_comp_packages t ocaml_version f_h =
let comp_f = Path.G.compiler t.global ocaml_version in
@@ -1540,7 +1517,7 @@ module Heuristic = struct
end
-let init repo alias ocaml_version cores =
+let init repo ocaml_version cores =
log "init %s" (Repository.to_string repo);
let root = Path.G.create () in
let config_f = Path.G.config root in
@@ -1560,14 +1537,23 @@ let init repo alias ocaml_version cores =
Dirname.mkdir (Path.G.compilers_dir root);
let t = load_state () in
update_repositories t ~show_compilers:false t.repositories;
- let ocaml_version = init_ocaml t true
- (fun alias_p ->
- Globals.error_and_exit "%s does not exist whereas %s already exists"
- (Filename.to_string config_f)
- (Dirname.to_string alias_p))
- alias
- false
- ocaml_version in
+ let system_ocaml_version = OCaml_V.current () in
+ begin match system_ocaml_version with
+ | None -> ()
+ | Some v ->
+ let config = File.Config.with_system_ocaml_version t.config v in
+ File.Config.write (Path.G.config t.global) config
+ end;
+ let t = load_state () in
+ let ocaml_version = match ocaml_version, system_ocaml_version with
+ | None , Some _ -> OCaml_V.of_string Globals.default_compiler_version
+ | Some v, _ -> v
+ | None , None ->
+ Globals.msg "No compiler found.\n";
+ Globals.exit 1 in
+ let alias = Alias.of_string (OCaml_V.to_string ocaml_version) in
+ let quiet = (system_ocaml_version = Some ocaml_version) in
+ init_ocaml t quiet alias ocaml_version;
update_packages t ~show_packages:false;
let t = update_available_current (load_state ()) in
let wish_install = Heuristic.get_comp_packages t ocaml_version Heuristic.v_any in
@@ -2108,86 +2094,47 @@ let compiler_list () =
Globals.msg " %s %s\n" preinstalled (OCaml_V.to_string c)
) descrs
-let switch ~clone ~quiet alias ocaml_version =
- log "switch %B %B %s %s" clone quiet
+let compiler_switch alias =
+ log "compiler_switch alias=%s" (Alias.to_string alias);
+ let t = load_state () in
+ let comp_p = Path.C.create alias in
+ let comp_dir = Path.C.root comp_p in
+ if not (Dirname.exists comp_dir) then (
+ Globals.msg "The compiler alias %s does not exists.\n" (Alias.to_string alias);
+ Globals.exit 1;
+ );
+ let config = File.Config.with_ocaml_version t.config alias in
+ File.Config.write (Path.G.config t.global) config;
+ print_env_warning ()
+
+let compiler_install quiet alias ocaml_version =
+ log "compiler_switch %b %s %s" quiet
(Alias.to_string alias)
(OCaml_V.to_string ocaml_version);
- let t = load_state () in
(* install the new OCaml version *)
- let ocaml_version, exists =
- let exists = ref false in
- let ocaml_version =
- init_ocaml t quiet (fun _ -> exists := true) (Some alias) true (Some ocaml_version) in
- ocaml_version, !exists in
-
- (* install new package
- - the packages specified in the compiler description file if
- the compiler was not previously installed
- - also attempt to replicate the previous state, if required
- with -clone *)
- let t_new = update_available_current (load_state ()) in
-
- let comp_constraints =
+ init_ocaml (load_state ()) quiet alias ocaml_version;
+
+ (* install the compiler packages *)
+ let t = update_available_current (load_state ()) in
+ let packages =
N.Map.of_list
(List.rev_map
(function (name, _), _ as nv -> N.of_string name, nv)
- (Heuristic.get_comp_packages t_new ocaml_version Heuristic.v_eq)) in
-
- let clone_constraints =
- if clone then
- (* we filter from "futur requested packages",
- packages that are present in the OLD version of OCaml
- and absent in the NEW version of OCaml *)
- let available = NV.to_map (get_available_current t_new) in
- let new_installed = NV.to_map t_new.installed in
- N.Map.mapi
- (fun n _ ->
- Heuristic.v_eq
- (if N.Map.mem n new_installed then
- Some (V.Set.choose_one (N.Map.find n new_installed))
- else
- None)
- (N.Map.find n available)
- n)
- (NV.to_map t.installed)
- else N.Map.empty in
-
- let installed_constraints =
- Heuristic.get_installed t_new Heuristic.v_eq in
-
- let (++) c1 c2 =
- N.Map.merge_max
- (fun pkg p_clone p_comp ->
- (* NOTE
- - both [p_clone] and [p_comp] constraints are valid
- - the intersection of these 2 constraints should not be empty *)
- if p_clone = p_comp then
- Some p_comp
- else
- let () = Globals.warning "package %s : we reject the constraint to clone %s and we take the constraint from compiler %s"
- (N.to_string pkg)
- (string_of_atom_formula p_clone)
- (string_of_atom_formula p_comp) in
- (* we arbitrarily take the constraint from the compiler *)
- Some p_comp)
- c1 c2 in
-
- let all_constraints = clone_constraints ++ comp_constraints ++ installed_constraints in
+ (Heuristic.get_comp_packages t ocaml_version Heuristic.v_eq)) in
let is_ok =
N.Map.for_all (fun n c ->
- if mem_installed_package_by_name t n then
+ if mem_installed_package_by_name t n then (
let nv = find_installed_package_by_name t n in
c = Heuristic.vpkg_of_nv_eq n (NV.version nv)
- else (
+ ) else (
false
)
- ) all_constraints in
-
+ ) packages in
if not is_ok then (
- let _solution = Heuristic.resolve `switch t_new
- [ { wish_install = N.Map.values all_constraints
+ let _solution = Heuristic.resolve `switch t
+ [ { wish_install = N.Map.values packages
; wish_remove = []
; wish_upgrade = [] } ] in
()
@@ -2195,6 +2142,69 @@ let switch ~clone ~quiet alias ocaml_version =
print_env_warning ()
+let compiler_clone alias =
+ log "compiler_clone alias=%s" (Alias.to_string alias);
+ let t = update_available_current (load_state ()) in
+
+ let installed_in_alias =
+ let comp_p = Path.C.create alias in
+ if not (Dirname.exists (Path.C.root comp_p)) then (
+ Globals.msg "%s is not a valid compiler name.\n" (Alias.to_string alias);
+ Globals.exit 1;
+ );
+ File.Installed.safe_read (Path.C.installed comp_p) in
+
+ let new_packages = NV.Set.diff installed_in_alias t.installed in
+ let installed =
+ NV.Set.filter (fun nv ->
+ let name = NV.name nv in
+ not (NV.Set.exists (fun nv -> name = NV.name nv) new_packages)
+ ) t.installed in
+
+ let constraints f_h = Heuristic.get t (NV.Set.union new_packages installed) f_h in
+
+ let _solution = Heuristic.resolve `switch t
+ (List.map (fun f_h ->
+ { wish_install = N.Map.values (constraints f_h);
+ wish_remove = [];
+ wish_upgrade = [] })
+ [ Heuristic.v_eq; Heuristic.v_ge; Heuristic.v_any ]
+ ) in
+ ()
+
+let compiler_current () =
+ let t = load_state () in
+ let current = File.Config.ocaml_version t.config in
+ Globals.msg "%s\n" (Alias.to_string current)
+
+let compiler_remove alias =
+ log "compiler_remove alias=%s" (Alias.to_string alias);
+ let t = load_state () in
+ let comp_p = Path.C.create alias in
+ let comp_dir = Path.C.root comp_p in
+ if not (Dirname.exists comp_dir) then (
+ Globals.msg "The compiler alias %s does not exists.\n" (Alias.to_string alias);
+ Globals.exit 1;
+ );
+ if File.Config.ocaml_version t.config = alias then (
+ Globals.msg "Cannot remove %s as it is the current compiler.\n" (Alias.to_string alias);
+ Globals.exit 1;
+ );
+ let aliases = List.filter (fun (a,_) -> a <> alias) t.aliases in
+ File.Aliases.write (Path.G.aliases t.global) aliases;
+ Dirname.rmdir comp_dir
+
+let compiler_reinstall alias =
+ log "compiler_remove alias=%s" (Alias.to_string alias);
+ let t = load_state () in
+ if not (List.mem_assoc alias t.aliases) then (
+ Globals.msg "The compiler alias %s does not exists.\n" (Alias.to_string alias);
+ Globals.exit 1;
+ );
+ let ocaml_version = List.assoc alias t.aliases in
+ compiler_remove alias;
+ compiler_install false alias ocaml_version
+
(** We protect each main functions with a lock depending on its access
on some read/write data. *)
@@ -2228,8 +2238,20 @@ let remove name =
let remote action =
check (Write_lock (fun () -> remote action))
-let switch ~clone ~quiet alias ocaml_version =
- check (Write_lock (fun () -> switch ~clone ~quiet alias ocaml_version))
+let compiler_switch alias =
+ check (Write_lock (fun () -> compiler_switch alias))
+
+let compiler_install quiet alias ocaml_version =
+ check (Write_lock (fun () -> compiler_install quiet alias ocaml_version))
+
+let compiler_reinstall alias =
+ check (Write_lock (fun () -> compiler_reinstall alias))
+
+let compiler_remove alias =
+ check (Write_lock (fun () -> compiler_remove alias))
+
+let compiler_clone alias =
+ check (Write_lock (fun () -> compiler_clone alias))
let compiler_list () =
check (Read_only compiler_list)
View
29 src/client.mli
@@ -20,10 +20,10 @@ open Types
(** Initializes the client a consistent state.
[init repo alias oversion cores] means:
- [repo] is the initial repository description,
- - [alias] the compiler alias
- - [oversion] is the version of the compiler
+ - [oversion] is the version of the compiler. [None] means we
+ are using the system-wide installed compiler.
- [cores] is the number of cores *)
-val init : repository -> Alias.t option -> OCaml_V.t option -> int -> unit
+val init : repository -> OCaml_V.t option -> int -> unit
(** Displays all available packages that matches [string]. *)
val list : print_short:bool -> installed_only:bool -> name_only:bool
@@ -63,16 +63,27 @@ val remove : N.Set.t -> unit
(** Manage remote repositories. Take the global file lock. *)
val remote : remote -> unit
-(** [switch and_clone alias descr] switch to an OCaml compiler
- and clone at the end in case [and_clone] is [true]. It creates
- {i $opam/$alias} if it does not exists by reading the contents
- of {i $opam/compilers/$descr.comp}.
- It takes the global file lock. *)
-val switch: clone:bool -> quiet:bool -> Alias.t -> OCaml_V.t -> unit
+(** Install the given compiler *)
+val compiler_install: bool -> Alias.t -> OCaml_V.t -> unit
+
+(** Clone the packages from the given compiler *)
+val compiler_clone: Alias.t -> unit
+
+(** Remove the given compiler *)
+val compiler_remove: Alias.t -> unit
+
+(** Switch to the given compiler *)
+val compiler_switch: Alias.t -> unit
+
+(** Reinstall the given compiler *)
+val compiler_reinstall: Alias.t -> unit
(** [compiler_list] list the available compiler descriptions *)
val compiler_list: unit -> unit
+(** [compiler_current] display the name of the current compiler *)
+val compiler_current: unit -> unit
+
(** Pin a package to a specific version. Take the global file lock. *)
val pin: pin -> unit
View
4 src/file.ml
@@ -401,8 +401,8 @@ module Config = struct
}
let with_repositories t repositories = { t with repositories }
- let with_ocaml_version t ocaml_version = { t with ocaml_version = Some ocaml_version }
- let with_system_ocaml_version t system_ocaml_version = { t with system_ocaml_version }
+ let with_ocaml_version t v = { t with ocaml_version = Some v }
+ let with_system_ocaml_version t v = { t with system_ocaml_version = Some v}
let opam_version t = t.opam_version
let repositories t = t.repositories
View
2  src/file.mli
@@ -56,7 +56,7 @@ module Config: sig
val with_repositories: t -> repository list -> t
(** system-wide's OCaml version updates *)
- val with_system_ocaml_version: t -> OCaml_V.t option -> t
+ val with_system_ocaml_version: t -> OCaml_V.t -> t
(** Return the OPAM version *)
val opam_version: t -> OPAM_V.t
View
66 src/opam.ml
@@ -76,7 +76,6 @@ let guess_repository_kind kind address =
(* opam init [-kind $kind] $repo $adress *)
let init =
let kind = ref None in
- let alias = ref None in
let comp = ref None in
let cores = ref Globals.default_cores in
{
@@ -86,7 +85,6 @@ let init =
help = "Create the initial config files";
specs = [
("-comp" , Arg.String (fun s -> comp := Some (OCaml_V.of_string s)), " Which compiler version to use");
- ("-alias", Arg.String (fun s -> alias := Some (Alias.of_string s)), " Set the compiler alias name");
("-cores", Arg.Set_int cores , " Set the nomber of cores");
("-kind" , Arg.String (fun s -> kind := Some s) , " Set the repository kind");
("-no-base-packages", Arg.Clear Globals.base_packages, " Do not install the base packages");
@@ -95,16 +93,16 @@ let init =
main =
parse_args (function
| [] ->
- Client.init Repository.default !alias !comp !cores
+ Client.init Repository.default !comp !cores
| [address] ->
let name = Globals.default_repository_name in
let kind = guess_repository_kind !kind address in
let repo = Repository.create ~name ~address ~kind in
- Client.init repo !alias !comp !cores
+ Client.init repo !comp !cores
| [name; address] ->
let kind = guess_repository_kind !kind address in
let repo = Repository.create ~name ~address ~kind in
- Client.init repo !alias !comp !cores
+ Client.init repo !comp !cores
| _ -> bad_argument "init" "Need a repository name and address")
}
@@ -346,30 +344,58 @@ let remote =
(* opam switch [-clone] OVERSION *)
let switch =
- let command : [`switch|`list] ref = ref `switch in
- let clone = ref false in
- let alias = ref "" in
- let set c () = command := c in
+ let alias_of = ref "" in
+ let command = ref `switch in
+ let set c () =
+ if !command <> `switch then
+ bad_argument "switch" "two many sub-commands";
+ command := c in
+ let no_alias_of () =
+ if !alias_of <> "" then
+ bad_argument "switch" "invalid -alias-of option" in
{
name = "switch";
usage = "[compiler-name]";
- synopsis = "Switch to an other compiler version";
+ synopsis = "Manage multiple installation of compilers";
help = "";
specs = [
- ("-clone" , Arg.Set clone , " Try to keep the same installed packages");
- ("-list" , Arg.Unit (set `list) , " List the available compiler descriptions");
- ("-alias" , Arg.Set_string alias , " Set the compiler name");
+ ("-alias-of" , Arg.Set_string alias_of , " Compiler name");
("-no-base-packages", Arg.Clear Globals.base_packages, " Do not install the base packages");
+ ("-install" , Arg.Unit (set `install) , " Install the given compiler");
+ ("-remove" , Arg.Unit (set `remove) , " Remove the given compiler");
+ ("-clone" , Arg.Unit (set `clone) , " Clone the content of the given alias");
+ ("-reinstall" , Arg.Unit (set `reinstall) , " Reinstall the given compiler");
+ ("-list" , Arg.Unit (set `list) , " List the available compilers");
+ ("-current" , Arg.Unit (set `current) , " Display the current compiler");
];
anon;
- main = parse_args (fun args ->
+ main = parse_args (function args ->
match !command, args with
- | `list , [] -> Client.compiler_list ()
- | `switch, [] -> bad_argument "switch" "Compiler name is missing"
- | `switch, [name] ->
- let alias = if !alias = "" then name else !alias in
- Client.switch ~clone:!clone ~quiet:!quiet (Alias.of_string alias) (OCaml_V.of_string name)
- | _ -> bad_argument "switch" "Too many compiler names")
+ | `install, [alias] ->
+ let comp = match !alias_of with
+ | "" -> OCaml_V.of_string alias
+ | comp -> OCaml_V.of_string comp in
+ Client.compiler_install !quiet (Alias.of_string alias) comp
+ | `clone, [alias] ->
+ no_alias_of ();
+ Client.compiler_clone (Alias.of_string alias)
+ | `remove, aliases ->
+ no_alias_of ();
+ List.iter (fun alias -> Client.compiler_remove (Alias.of_string alias)) aliases
+ | `reinstall, [alias] ->
+ no_alias_of ();
+ Client.compiler_reinstall (Alias.of_string alias)
+ | `list, [] ->
+ no_alias_of ();
+ Client.compiler_list ()
+ | `current, [] ->
+ no_alias_of ();
+ Client.compiler_current ()
+ | `switch, [alias] ->
+ no_alias_of ();
+ Client.compiler_switch (Alias.of_string alias)
+ | _ -> bad_argument "switch" "too many arguments"
+ )
}
(* opam pin [-list|<package> <version>|<package> <path>] *)
View
13 tests/Makefile
@@ -14,8 +14,6 @@ BINARIES = opam-check opam
PACKAGES = P1-1 P1-2 P2 P3 P4 P5
-OCAMLVERSION = system
-
# opam in the path should not be a requirement
ENV = OCAMLRUNPARAM=b OPAMDEBUG=2 OPAM_ROOT=$(OPAM_ROOT) PATH=$(BIN):$(PATH)
OPAM = $(ENV) opam --yes --root $(OPAM_ROOT)
@@ -198,14 +196,17 @@ downgrade:
switch-alias:
$(OPAM) remove P3.1~weird-version.test P4.2
$(CHECK) -l switch-alias P1.1 P2.1
- $(OPAM) switch -alias test $(OCAMLVERSION) -clone -no-base-packages
- $(CHECK) -l switch-alias-test P1.1 P2.1
- $(OPAM) switch 4.00.0
+ $(OPAM) switch -install test -alias-of system -no-base-packages
+ $(OPAM) switch -clone system
+ $(CHECK) -l switch-alias-clone P1.1 P2.1
+ $(OPAM) switch -install test2 -alias-of 4.00.0
$(OPAM) install P1
$(CHECK) -l switch-alias-4.00 P1.1
+ $(OPAM) switch system
+ $(OPAM) switch -remove test test2
switch-env-packages:
- $(OPAM) switch 3.12.1
+ $(OPAM) switch -install 3.12.1
ifeq ($(REPOKIND), git)
$(CHECK) -l switch-env-packages P1.1 P2.1 P3.1~weird-version.test P4.3
else
Please sign in to comment.
Something went wrong with that request. Please try again.