Skip to content
Browse files

[switch] import/export of configurations.

This commit fixes #152
  • Loading branch information...
1 parent f19736d commit bfd686a7f70e768e15391178c8db1974b23bc892 @samoht samoht committed Oct 1, 2012
Showing with 25 additions and 18 deletions.
  1. +13 −13 src/client.ml
  2. +5 −2 src/client.mli
  3. +7 −3 src/opam.ml
View
26 src/client.ml
@@ -2602,19 +2602,12 @@ let compiler_switch quiet alias =
OpamFile.Config.write (Path.G.config t.global) config;
print_env_warning (load_state ())
-let compiler_clone alias =
- log "compiler_clone alias=%s" (Alias.to_string alias);
+let compiler_import filename =
+ log "compiler_clone alias=%s" (Filename.to_string filename);
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;
- );
- OpamFile.Installed.safe_read (Path.C.installed comp_p) in
-
- let new_packages = NV.Set.diff installed_in_alias t.installed in
+ let imported = OpamFile.Installed.read filename in
+ let new_packages = NV.Set.diff imported t.installed in
let installed =
NV.Set.filter (fun nv ->
let name = NV.name nv in
@@ -2632,6 +2625,10 @@ let compiler_clone alias =
) in
()
+let compiler_export filename =
+ let t = update_available_current (load_state ()) in
+ OpamFile.Installed.write filename t.installed
+
let compiler_current () =
let t = load_state () in
let current = OpamFile.Config.ocaml_version t.config in
@@ -2701,8 +2698,11 @@ let remote action =
let compiler_install quiet alias ocaml_version =
check (Write_lock (fun () -> compiler_install quiet alias ocaml_version))
-let compiler_clone alias =
- check (Write_lock (fun () -> compiler_clone alias))
+let compiler_import filename =
+ check (Write_lock (fun () -> compiler_import filename))
+
+let compiler_export filename =
+ check (Write_lock (fun () -> compiler_export filename))
let compiler_remove alias =
check (Write_lock (fun () -> compiler_remove alias))
View
7 src/client.mli
@@ -66,8 +66,11 @@ val remote : remote -> unit
(** Install the given compiler. Take the global file lock. *)
val compiler_install: bool -> Alias.t -> OCaml_V.t -> unit
-(** Clone the packages from the given compiler. Take the global file lock. *)
-val compiler_clone: Alias.t -> unit
+(** Import the packages from a file. Take the global file lock. *)
+val compiler_import: filename -> unit
+
+(** Export the packages to a file. Take the global file lock. *)
+val compiler_export: filename -> unit
(** Remove the given compiler. Take the global file lock. *)
val compiler_remove: Alias.t -> unit
View
10 src/opam.ml
@@ -375,7 +375,8 @@ let switch =
("-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");
+ ("-export" , Arg.String (fun s -> set (`export s) ()), " Export the libraries installed with the given alias");
+ ("-import" , Arg.String (fun s -> set (`import s) ()), " Import the libraries installed with 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");
@@ -385,9 +386,12 @@ let switch =
match !command, args with
| `install, [alias] ->
Client.compiler_install !quiet (Alias.of_string alias) (mk_comp alias)
- | `clone, [alias] ->
+ | `export f, [] ->
no_alias_of ();
- Client.compiler_clone (Alias.of_string alias)
+ Client.compiler_export (Filename.of_string f)
+ | `import f, [] ->
+ no_alias_of ();
+ Client.compiler_import (Filename.of_string f)
| `remove, aliases ->
no_alias_of ();
List.iter (fun alias -> Client.compiler_remove (Alias.of_string alias)) aliases

0 comments on commit bfd686a

Please sign in to comment.
Something went wrong with that request. Please try again.