Skip to content

Commit

Permalink
Merge branch 'master' of github.com:OCamlPro/opam
Browse files Browse the repository at this point in the history
  • Loading branch information
samoht committed Aug 13, 2012
2 parents 840e753 + 767e290 commit 705cfb3
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 47 deletions.
64 changes: 34 additions & 30 deletions src/client.ml
Original file line number Diff line number Diff line change
Expand Up @@ -103,29 +103,28 @@ let update_available_current t =
{ t with available_current =
(* Remove the package which does not fullfil the compiler constraints *)
let ocaml_version =
if File.Config.ocaml_version t.config = Alias.of_string Globals.default_compiler_version then
let v =
match File.Config.last_ocaml_in_path t.config with
| None -> (*assert false*) Globals.error_and_exit "the OCaml version from config has been manually removed"
| Some v -> v in
if File.Config.ocaml_version t.config = Alias.of_string Globals.default_compiler_version then (
let current = OCaml_V.current () in

(match current with
| None ->
if confirm "No OCaml compiler found in path. Continue ?" then
()
else
Globals.exit 66
| Some current ->
if v <> current then
if confirm "The current OCaml version %S is not the same as the first in config %S. Continue ?"
(OCaml_V.to_string current)
(OCaml_V.to_string v) then
()
else
Globals.exit 66);
v
else
let system = File.Config.system_ocaml_version t.config in
match current, system with
| None , None -> Globals.error_and_exit "No OCaml compiler installed."
| None , Some s ->
if not (confirm "No OCaml compiler found. Continue ?") then
Globals.exit 1
else
s
| Some c, Some s ->
if s <> c
&& not (confirm "The version of OCaml in your path (%S) \
is not the same as the one OPAM has been \
initialized with (%S). Continue ?"
(OCaml_V.to_string c)
(OCaml_V.to_string s)) then
Globals.exit 1
else
s
| Some c, None -> c
) else
current_ocaml_version t in
let filter nv =
let opam = File.OPAM.read (Path.G.opam t.global nv) in
Expand Down Expand Up @@ -537,17 +536,21 @@ let add_alias alias ocaml_version =

(* We assume that we have the right ocaml-version in $opam/config. Then we:
- create $opam/$alias
- compiles and install $opam/compiler/$descr.comp *)
let init_ocaml f_exists alias (default_allowed, ocaml_version) =
- 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 f_exists alias default_allowed ocaml_version =
log "init_ocaml";
let t = load_state () in

let default = OCaml_V.of_string Globals.default_compiler_version in
let last_ocaml, ocaml_version =
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 last_ocaml -> Some last_ocaml, default in
| Some system_ocaml -> Some system_ocaml, default in

match ocaml_version with
| None -> current ()
Expand Down Expand Up @@ -647,7 +650,7 @@ let init_ocaml f_exists alias (default_allowed, ocaml_version) =

(* write the new version in the configuration file *)
let config = File.Config.with_ocaml_version t.config alias in
let config = File.Config.with_last_ocaml_in_path config last_ocaml 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
Expand Down Expand Up @@ -1300,11 +1303,12 @@ let init repo alias ocaml_version cores =
update_repo ();
let ocaml_version = init_ocaml
(fun alias_p ->
Globals.error_and_exit "%s does not exist whereas %s already exist"
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
false
ocaml_version in
update_package ();
let t = update_available_current (load_state ()) in
let wish_install = Heuristic.get_packages t ocaml_version Heuristic.v_any in
Expand Down Expand Up @@ -1729,7 +1733,7 @@ let switch clone alias ocaml_version =
let ocaml_version, exists =
let exists = ref false in
let ocaml_version =
init_ocaml (fun _ -> exists := true) (Some alias) (true, Some ocaml_version) in
init_ocaml (fun _ -> exists := true) (Some alias) true (Some ocaml_version) in
ocaml_version, !exists in

(* install new package
Expand Down
33 changes: 21 additions & 12 deletions src/file.ml
Original file line number Diff line number Diff line change
Expand Up @@ -329,43 +329,45 @@ module Config = struct
opam_version : OPAM_V.t ;
repositories : repository list ;
ocaml_version : Alias.t option ;
last_ocaml_in_path : OCaml_V.t option ;
system_ocaml_version: OCaml_V.t option ;
cores : int;
}

let with_repositories t repositories = { t with repositories }
let with_ocaml_version t ocaml_version = { t with ocaml_version = Some ocaml_version }
let with_last_ocaml_in_path t last_ocaml_in_path = { t with last_ocaml_in_path }
let with_system_ocaml_version t system_ocaml_version = { t with system_ocaml_version }

let opam_version t = t.opam_version
let repositories t = t.repositories
let ocaml_version t = match t.ocaml_version with None -> Alias.of_string "<none>" | Some v -> v
let last_ocaml_in_path t = t.last_ocaml_in_path
let system_ocaml_version t = t.system_ocaml_version
let cores t = t.cores

let create opam_version repositories cores =
{ opam_version ; repositories ; ocaml_version = None ; last_ocaml_in_path = None ; cores }
{ opam_version ; repositories ; ocaml_version = None ; system_ocaml_version = None ; cores }

let empty = {
opam_version = OPAM_V.of_string Globals.opam_version;
repositories = [];
ocaml_version = None;
last_ocaml_in_path = None;
system_ocaml_version = None;
cores = Globals.default_cores;
}

open File_format

let s_repositories = "repositories"
let s_ocaml_version = "ocaml-version"
let s_last_ocaml_in_path = "system_ocaml-version"
let s_system_ocaml_version = "system-ocaml-version"
let s_system_ocaml_version2 = "system_ocaml-version"
let s_cores = "cores"

let valid_fields = [
s_opam_version;
s_repositories;
s_ocaml_version;
s_last_ocaml_in_path;
s_system_ocaml_version;
s_system_ocaml_version2;
s_cores;
]

Expand All @@ -379,10 +381,17 @@ module Config = struct
(parse_list (parse_string_option parse_string_pair_of_list |> to_repo)) in
let ocaml_version =
assoc_option s.contents s_ocaml_version (parse_string |> Alias.of_string) in
let last_ocaml_in_path =
assoc_option s.contents s_last_ocaml_in_path (parse_string |> OCaml_V.of_string) in
let system_ocaml_version =
assoc_option s.contents s_system_ocaml_version (parse_string |> OCaml_V.of_string) in
let system_ocaml_version2 =
assoc_option s.contents s_system_ocaml_version2 (parse_string |> OCaml_V.of_string) in
let system_ocaml_version =
match system_ocaml_version, system_ocaml_version2 with
| Some v, _
| _ , Some v -> Some v
| None , None -> None in
let cores = assoc s.contents s_cores parse_int in
{ opam_version; repositories; ocaml_version; last_ocaml_in_path; cores }
{ opam_version; repositories; ocaml_version; system_ocaml_version; cores }

let to_string filename t =
let s = {
Expand All @@ -398,9 +407,9 @@ module Config = struct
| Some v -> [ Variable (s_ocaml_version, make_string (Alias.to_string v)) ]
)
@ (
match t.last_ocaml_in_path with
match t.system_ocaml_version with
| None -> []
| Some v -> [ Variable (s_last_ocaml_in_path, make_string (OCaml_V.to_string v)) ]
| Some v -> [ Variable (s_system_ocaml_version, make_string (OCaml_V.to_string v)) ]
)
} in
Syntax.to_string filename s
Expand Down
9 changes: 4 additions & 5 deletions src/file.mli
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,8 @@ module Config: sig
(** Repository updates *)
val with_repositories: t -> repository list -> t

(** OCaml version updates *)
val with_last_ocaml_in_path: t -> OCaml_V.t option -> t

(** system-wide's OCaml version updates *)
val with_system_ocaml_version: t -> OCaml_V.t option -> t

(** Return the OPAM version *)
val opam_version: t -> OPAM_V.t
Expand All @@ -70,8 +69,8 @@ module Config: sig
(** Return the OCaml alias *)
val ocaml_version: t -> Alias.t

(** Return the OCaml version *)
val last_ocaml_in_path: t -> OCaml_V.t option
(** Return the system's OCaml version *)
val system_ocaml_version: t -> OCaml_V.t option

(** Return the number of cores *)
val cores: t -> int
Expand Down

0 comments on commit 705cfb3

Please sign in to comment.