Skip to content
Browse files

Install a default "system" compiler description on init.

Then, we do not test whether the compiler version in the path is the same as the one we want to install to try to optimize things: we always download and install compilers, when we switch to a compiler description which is different of 'system'.

This will make the switch between different compiler versions much safer.
  • Loading branch information...
1 parent a4362ed commit 46c067d2a1460ce5dc43518b9f7be67dfe1da14d @samoht samoht committed Jul 4, 2012
Showing with 49 additions and 29 deletions.
  1. +45 −27 src/client.ml
  2. +2 −0 src/globals.ml
  3. +1 −1 src/opam.ml
  4. +1 −1 tests/Makefile
View
72 src/client.ml
@@ -34,6 +34,9 @@ type t = {
(* ~/.opam/opam/ files *)
available: NV.Set.t;
+ (* ~/.opam/aliases *)
+ aliases: (Alias.t * OCaml_V.t) list;
+
(* ~/.opam/$oversion/installed contents *)
installed: NV.Set.t;
@@ -73,6 +76,7 @@ let load_state () =
let global = Path.G.create () in
let config = File.Config.read (Path.G.config global) in
let ocaml_version = File.Config.ocaml_version config in
+ let aliases = File.Aliases.safe_read (Path.G.aliases global) in
let compiler = Path.C.create ocaml_version in
let repositories = File.Config.repositories config in
let repositories = List.map (fun r -> r, Path.R.create r) repositories in
@@ -83,7 +87,7 @@ let load_state () =
let t = {
global; compiler; repositories;
available; installed; reinstall;
- repo_index; config
+ repo_index; config; aliases;
} in
print_state t;
t
@@ -247,7 +251,8 @@ let update () =
if !has_error then
Globals.exit 66
-let install_initial_package () =
+let install_conf_ocaml () =
+ log "installing conf-ocaml";
let t = load_state () in
let name = N.of_string Globals.default_package in
let version = V.of_string (Alias.to_string (File.Config.ocaml_version t.config)) in
@@ -312,33 +317,47 @@ let substitute_file t f =
let substitute_string t s =
File.Subst.replace_string s (contents_of_variable t)
+let create_default_compiler_description t =
+ let ocaml_version = OCaml_V.of_string Globals.default_compiler_version in
+ let f = File.Comp.create_preinstalled ocaml_version in
+ let comp = Path.G.compiler t.global ocaml_version in
+ File.Comp.write comp f
+
+let add_alias t alias ocaml_version =
+ log "adding alias %s %s" (Alias.to_string alias) (OCaml_V.to_string ocaml_version);
+ let aliases_f = Path.G.aliases t.global in
+ let aliases = File.Aliases.safe_read aliases_f in
+ if not (List.mem_assoc alias aliases) then begin
+ (* Install the initial package and reload the global state *)
+ install_conf_ocaml ();
+ (* Update the list of aliases *)
+ 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 if $descr <> current version *)
+ - compiles and install $opam/compiler/$descr.comp *)
let init_ocaml alias ocaml_version =
+ log "init_ocaml %s %s" (Alias.to_string alias) (OCaml_V.to_string ocaml_version);
+ let t = load_state () in
let alias_p = Path.C.create alias in
- if not (Dirname.exists (Path.C.root alias_p)) then
- let t = load_state () in
- let aliases_f = Path.G.aliases t.global in
- let aliases = File.Aliases.safe_read aliases_f in
- try
+ if not (Dirname.exists (Path.C.root alias_p)) then begin
+
Dirname.mkdir (Path.C.root alias_p);
- File.Installed.write (Path.C.installed alias_p) File.Installed.empty;
+ add_alias t alias ocaml_version;
- (* Write the default alias *)
- File.Aliases.write aliases_f ((alias, ocaml_version) :: aliases);
+ if ocaml_version = OCaml_V.of_string Globals.default_compiler_version then begin
- (* Install the initial package and reload the global state *)
- install_initial_package ();
- let t = load_state () in
+ (* we create a dummy compiler description file the the system-wide
+ OCaml configuration *)
+ create_default_compiler_description t;
- (* Update the configuration files *)
- update ();
+ end else
+ let comp = File.Comp.safe_read (Path.G.compiler t.global ocaml_version) in
+ if not (File.Comp.preinstalled comp) then try
- (* Install the compiler if necessary *)
- let comp = File.Comp.safe_read (Path.G.compiler t.global ocaml_version) in
- if OCaml_V.current () <> Some ocaml_version && not (File.Comp.preinstalled comp) then begin
+ (* Install the compiler *)
let comp_src = File.Comp.src comp in
let build_dir = Path.C.build_ocaml alias_p in
Run.download comp_src (Dirname.to_string build_dir);
@@ -370,15 +389,13 @@ let init_ocaml alias ocaml_version =
Globals.error_and_exit
"The compilation of compiler version %s failed"
(OCaml_V.to_string ocaml_version)
- end else
- let comp = Path.G.compiler t.global ocaml_version in
- if not (Filename.exists comp) then
- File.Comp.write comp (File.Comp.create_preinstalled ocaml_version)
- with e ->
- if not !Globals.debug then
+
+ with e ->
+ if not !Globals.debug then
Dirname.rmdir (Path.C.root alias_p);
- File.Aliases.write aliases_f aliases;
- raise e
+ File.Aliases.write (Path.G.aliases t.global) t.aliases;
+ raise e
+ end
let indent_left s nb =
let nb = nb - String.length s in
@@ -950,6 +967,7 @@ let init repo alias ocaml_version cores =
Dirname.mkdir (Path.G.archive_dir root);
Dirname.mkdir (Path.G.compiler_dir root);
init_ocaml alias ocaml_version;
+ update ();
let t = load_state () in
let wish_install = Heuristic.get_packages t ocaml_version Heuristic.v_any in
Heuristic.resolve `init t
View
2 src/globals.ml
@@ -32,6 +32,8 @@ let default_build_command = [ [ "./build.sh" ] ]
let default_package = "conf-ocaml"
+let default_compiler_version = "system"
+
let opam_version = "1"
let home = Unix.getenv "HOME"
View
2 src/opam.ml
@@ -71,7 +71,7 @@ let init =
if !comp <> "" then OCaml_V.of_string !comp
else match OCaml_V.current () with
| None -> bad_argument "init" "No OCaml compiler found in path"
- | Some c -> c in
+ | Some _ -> OCaml_V.of_string Globals.default_compiler_version in
let alias =
if !alias <> "" then Alias.of_string !alias
else Alias.of_string (OCaml_V.to_string comp) in
View
2 tests/Makefile
@@ -22,7 +22,7 @@ BINARIES = opam opam-server opam-check \
PACKAGES = P1-1 P1-2 P2 P3 P4 P5
-OCAMLVERSION = $(shell ocamlc -version)
+OCAMLVERSION = system
# opam in the path should not be a requirement
ENV = OCAMLRUNPARAM=b OPAMDEBUG=1 OPAM_ROOT=$(OPAM_ROOT) PATH=$(BIN):$(PATH)

0 comments on commit 46c067d

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