Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[opam init] add the new field "system_ocaml-version" in "config" if "…

…system" is the target
  • Loading branch information...
commit 494fb4ea2b65929110f00ec46a85717bfb5f7d2f 1 parent a4d01ec
@tuong tuong authored
Showing with 32 additions and 14 deletions.
  1. +8 −8 src/client.ml
  2. +16 −4 src/file.ml
  3. +8 −2 src/file.mli
View
16 src/client.ml
@@ -487,11 +487,11 @@ let init_ocaml alias (default_allowed, ocaml_version) =
let t = load_state () in
let default = OCaml_V.of_string Globals.default_compiler_version in
- let ocaml_version =
+ let last_ocaml, ocaml_version =
let current () =
match OCaml_V.current () with
- | None -> Globals.error_and_exit "No OCaml compiler found in path"
- | Some _ -> default in
+ | None -> Globals.error_and_exit "No OCaml compiler found in path"
+ | Some last_ocaml -> Some last_ocaml, default in
match ocaml_version with
| None -> current ()
@@ -510,7 +510,7 @@ let init_ocaml alias (default_allowed, ocaml_version) =
Globals.exit 2
end
else
- ocaml_version in
+ None, ocaml_version in
let alias =
match alias with
@@ -570,7 +570,7 @@ let init_ocaml alias (default_allowed, ocaml_version) =
if not !Globals.debug then
Dirname.rmdir (Path.C.root alias_p);
raise e);
- alias, ocaml_version
+ (alias, ocaml_version), last_ocaml
let indent_left s nb =
let nb = nb - String.length s in
@@ -1226,9 +1226,9 @@ let init repo alias ocaml_version cores =
else
()
| None -> ());
- let alias, ocaml_version = init_ocaml alias (false, ocaml_version) in
+ let (alias, ocaml_version), last_ocaml = init_ocaml alias (false, ocaml_version) in
let opam_version = OPAM_V.of_string Globals.opam_version in
- File.Config.write config_f (File.Config.create opam_version [repo] alias cores);
+ File.Config.write config_f (File.Config.create opam_version [repo] alias last_ocaml cores);
let t = load_state () in
add_alias t alias ocaml_version;
update_package ();
@@ -1661,7 +1661,7 @@ let switch clone alias ocaml_version =
let exists = Dirname.exists (Path.C.root alias_p) in
if not exists then begin
try
- let alias, ocaml_version = init_ocaml (Some alias) (true, Some ocaml_version) in
+ let (alias, ocaml_version), _ = init_ocaml (Some alias) (true, Some ocaml_version) in
add_alias t alias ocaml_version
with e ->
(* restore the previous configuration *)
View
20 src/file.ml
@@ -270,6 +270,7 @@ module Config = struct
opam_version : OPAM_V.t ;
repositories : repository list ;
ocaml_version : Alias.t ;
+ last_ocaml_in_path : OCaml_V.t option ;
cores : int;
}
@@ -279,15 +280,17 @@ module Config = struct
let opam_version t = t.opam_version
let repositories t = t.repositories
let ocaml_version t = t.ocaml_version
+ let last_ocaml_in_path t = t.last_ocaml_in_path
let cores t = t.cores
- let create opam_version repositories ocaml_version cores =
- { opam_version ; repositories ; ocaml_version ; cores }
+ let create opam_version repositories ocaml_version last_ocaml_in_path cores =
+ { opam_version ; repositories ; ocaml_version ; last_ocaml_in_path ; cores }
let empty = {
opam_version = OPAM_V.of_string Globals.opam_version;
repositories = [];
ocaml_version = Alias.of_string "<none>";
+ last_ocaml_in_path = None;
cores = Globals.default_cores;
}
@@ -295,12 +298,14 @@ module Config = struct
let s_repositories = "repositories"
let s_ocaml_version = "ocaml-version"
+ let s_last_ocaml_in_path = "system_ocaml-version"
let s_cores = "cores"
let valid_fields = [
s_opam_version;
s_repositories;
s_ocaml_version;
+ s_last_ocaml_in_path;
s_cores;
]
@@ -314,8 +319,10 @@ module Config = struct
(parse_list (parse_string_option parse_string_pair_of_list |> to_repo)) in
let ocaml_version =
assoc 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 cores = assoc s.contents s_cores parse_int in
- { opam_version; repositories; ocaml_version; cores }
+ { opam_version; repositories; ocaml_version; last_ocaml_in_path; cores }
let to_string filename t =
let s = {
@@ -325,7 +332,11 @@ module Config = struct
Variable (s_repositories , make_list of_repo t.repositories);
Variable (s_ocaml_version, make_string (Alias.to_string t.ocaml_version));
Variable (s_cores , make_int t.cores);
- ]
+ ] @ (
+ match t.last_ocaml_in_path with
+ | None -> []
+ | Some v -> [ Variable (s_last_ocaml_in_path, make_string (OCaml_V.to_string v)) ]
+ )
} in
Syntax.to_string filename s
end
@@ -436,6 +447,7 @@ module OPAM = struct
let build_env t = t.build_env
let with_depends t depends = { t with depends }
+ let with_depopts t depopts = { t with depopts }
let with_build t build = { t with build }
let with_remove t remove = { t with remove }
View
10 src/file.mli
@@ -49,7 +49,7 @@ module Config: sig
include IO_FILE
(** Creation *)
- val create: OPAM_V.t -> repository list -> Alias.t -> int -> t
+ val create: OPAM_V.t -> repository list -> Alias.t -> OCaml_V.t option -> int -> t
(** OCaml version updates *)
val with_ocaml_version : t -> Alias.t -> t
@@ -64,9 +64,12 @@ module Config: sig
(** Return the list of repository *)
val repositories: t -> repository list
- (** Return the OCaml version *)
+ (** 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 number of cores *)
val cores: t -> int
@@ -128,6 +131,9 @@ module OPAM: sig
(** Construct as [depends] *)
val with_depends : t -> cnf_formula -> t
+ (** Construct as [depopts] *)
+ val with_depopts : t -> cnf_formula -> t
+
(** Construct as [build] *)
val with_build: t -> string list list -> t
Please sign in to comment.
Something went wrong with that request. Please try again.