Permalink
Browse files

Add OPAMROOT environment variable.

This enables:
* 'opam --root $dir config -env' to output the right $OPAMROOT variable;
* which means subsequents calls to 'opam' will use the right root path.

This help installing opam on multi-user computers (where root is set to /usr/lib/opam for instance).

This should fix #302
  • Loading branch information...
1 parent b83a005 commit c57e9b0a69712147f551d76b71465afd21074cef @samoht samoht committed Nov 19, 2012
Showing with 15 additions and 6 deletions.
  1. +0 −2 src/client/opamMain.ml
  2. +7 −0 src/client/opamState.ml
  3. +8 −4 src/core/opamGlobals.ml
View
@@ -28,8 +28,6 @@ let bad_argument cmd fmt =
let noanon cmd s =
raise (Bad (cmd, s ^ " is not expected"))
-let () = OpamGlobals.root_dir := OpamGlobals.default_opam_dir
-
(* Useful for switch, which can overwrite the default verbose flag *)
let quiet = ref false
View
@@ -552,6 +552,13 @@ let get_env t =
let add_to_env = expand_env t add_to_env in
let new_env = expand_env t new_env in
+ (* if --root <dir> is passed on the command line, or if OPAMROOT is set. *)
+ let new_env =
+ if !OpamGlobals.root_dir <> OpamGlobals.default_opam_dir then
+ ("OPAMROOT", !OpamGlobals.root_dir) :: new_env
+ else
+ new_env in
+
{ add_to_env; add_to_path; new_env }
let print_env_warning ?(add_profile = false) t =
View
@@ -42,12 +42,16 @@ let switch : string option ref = ref None
let opam_version = "1"
let home =
- try Unix.getenv "HOME"
- with _ -> Unix.getcwd ()
+ try Sys.getenv "HOME"
+ with _ -> Sys.getcwd ()
-let default_opam_dir = Filename.concat home ".opam"
+let default_opam_dir =
+ Filename.concat home ".opam"
-let root_dir = ref default_opam_dir
+let root_dir = ref (
+ try Sys.getenv "OPAMROOT"
+ with _ -> default_opam_dir
+)
let log section fmt =
Printf.ksprintf (fun str ->

0 comments on commit c57e9b0

Please sign in to comment.