Skip to content

Commit

Permalink
Add OPAMROOT environment variable.
Browse files Browse the repository at this point in the history
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 ocaml#302
  • Loading branch information
samoht committed Nov 19, 2012
1 parent b83a005 commit c57e9b0
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
2 changes: 0 additions & 2 deletions src/client/opamMain.ml
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ let bad_argument cmd fmt =
let noanon cmd s = let noanon cmd s =
raise (Bad (cmd, s ^ " is not expected")) 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 *) (* Useful for switch, which can overwrite the default verbose flag *)
let quiet = ref false let quiet = ref false


Expand Down
7 changes: 7 additions & 0 deletions src/client/opamState.ml
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -552,6 +552,13 @@ let get_env t =
let add_to_env = expand_env t add_to_env in let add_to_env = expand_env t add_to_env in
let new_env = expand_env t new_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 } { add_to_env; add_to_path; new_env }


let print_env_warning ?(add_profile = false) t = let print_env_warning ?(add_profile = false) t =
Expand Down
12 changes: 8 additions & 4 deletions src/core/opamGlobals.ml
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -42,12 +42,16 @@ let switch : string option ref = ref None
let opam_version = "1" let opam_version = "1"


let home = let home =
try Unix.getenv "HOME" try Sys.getenv "HOME"
with _ -> Unix.getcwd () 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 = let log section fmt =
Printf.ksprintf (fun str -> Printf.ksprintf (fun str ->
Expand Down

0 comments on commit c57e9b0

Please sign in to comment.