Permalink
Browse files

[switch] Add some test-cases, the ENV things seems to work

  • Loading branch information...
1 parent 2f59c67 commit d2b2ee1eedc7ad5b4ee1fd77b8c16e114a7e1161 @samoht samoht committed Jun 12, 2012
Showing with 68 additions and 16 deletions.
  1. +6 −9 src/client.ml
  2. +31 −5 src/file.ml
  3. +2 −0 src/file_format.ml
  4. +3 −0 src/file_format.mli
  5. +17 −1 tests/Makefile
  6. +3 −1 tests/packages/P4/build.sh
  7. +6 −0 tests/packages/P4/p4.ml
View
@@ -295,8 +295,8 @@ let init_ocaml alias ocaml_version =
let aliases_f = Path.G.aliases t.global in
let aliases = File.Aliases.safe_read aliases_f in
File.Aliases.write aliases_f ((alias, ocaml_version) :: aliases);
- if OCaml_V.current () <> Some ocaml_version then begin
- let comp = File.Comp.read (Path.G.compiler t.global ocaml_version) in
+ 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
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);
@@ -329,9 +329,9 @@ let init_ocaml alias ocaml_version =
"The compilation of compiler version %s failed"
(OCaml_V.to_string ocaml_version)
end else
- File.Comp.write
- (Path.G.compiler t.global ocaml_version)
- (File.Comp.create_preinstalled ocaml_version)
+ 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)
end
let init repo alias ocaml_version cores =
@@ -837,10 +837,7 @@ let remove name =
if name = N.of_string Globals.default_package then
Globals.error_and_exit "Package %s can not be removed" Globals.default_package;
let t = load_state () in
- let map_installed = NV.to_map t.installed in
- if not (N.Map.mem name map_installed) then
- Globals.error_and_exit "Package %s is not installed" (N.to_string name);
- let nv = NV.create name (V.Set.choose_one (N.Map.find name map_installed)) in
+ let nv = nv_of_name t name in
let universe = Solver.U (NV.Set.fold (fun nv l -> (debpkg_of_nv `remove t nv) :: l) t.available []) in
let depends = Solver.filter_forward_dependencies universe (Solver.P [debpkg_of_nv `remove t nv]) in
let depends =
View
@@ -763,6 +763,25 @@ module Comp = struct
let s_env = "env"
let s_preinstalled = "preinstalled"
+ let valid_fields = [
+ s_opam_version;
+ s_name;
+ s_src;
+ s_patches;
+ s_configure;
+ s_make;
+ s_build;
+ s_bytecomp;
+ s_asmcomp;
+ s_bytelink;
+ s_asmlink;
+ s_packages;
+ s_requires;
+ s_pp;
+ s_env;
+ s_preinstalled;
+ ]
+
let name t = t.name
let patches t = t.patches
let configure t = t.configure
@@ -781,6 +800,7 @@ module Comp = struct
let of_string filename str =
let file = Syntax.of_string filename str in
+ Syntax.check file valid_fields;
let s = file.contents in
let parse_camlp4 = function
| List ( Ident "CAMLP4" :: l ) ->
@@ -794,12 +814,12 @@ module Comp = struct
let opam_version =
assoc s s_opam_version (parse_string |> OPAM_V.of_string) in
let name = assoc s s_name (parse_string |> OCaml_V.of_string) in
- let src = assoc s s_src parse_string in
+ let src = assoc_default "" s s_src parse_string in
let patches = assoc_string_list s s_patches in
let configure = assoc_string_list s s_configure in
let make = assoc_string_list s s_make in
let build = assoc_list s s_build (parse_list parse_string_list) in
- let env = assoc_default [] s s_env (parse_list parse_string_pair) in
+ let env = assoc_list s s_env (parse_list parse_string_pair) in
let bytecomp = assoc_string_list s s_bytecomp in
let asmcomp = assoc_string_list s s_asmcomp in
let bytelink = assoc_string_list s s_bytecomp in
@@ -813,13 +833,18 @@ module Comp = struct
Globals.error_and_exit "%S is an internal reserved name. Indeed, this package will be installed at the beginning and automatically." Globals.default_package
else
N.of_string name))) in
- if build <> [] && (configure @ make) <> [] then
- Globals.error_and_exit "You cannot use 'build' and 'make'/'configure' \
- fields at the same time.";
let requires =
assoc_list s s_requires (parse_list (parse_string |> Section.of_string)) in
let pp = assoc_default None s s_pp parse_ppflags in
let preinstalled = assoc_default false s s_preinstalled parse_bool in
+
+ if build <> [] && (configure @ make) <> [] then
+ Globals.error_and_exit "You cannot use 'build' and 'make'/'configure' \
+ fields at the same time.";
+ if not preinstalled && src = "" then
+ Globals.error_and_exit "You should either specify an url (with 'sources') \
+ or use 'preinstalled: true' to pick the already installed \
+ compiler version.";
{ opam_version; name; src;
patches; configure; make; build;
bytecomp; asmcomp; bytelink; asmlink; packages;
@@ -848,6 +873,7 @@ module Comp = struct
Variable (s_asmlink , make_list make_string s.asmlink);
Variable (s_packages , make_list (N.to_string |> make_string) s.packages);
Variable (s_requires , make_list (Section.to_string |> make_string) s.requires);
+ Variable (s_env , make_list (make_pair make_string) s.env);
] @ match s.pp with
| None -> []
| Some pp -> [ Variable (s_pp, make_ppflag pp) ]
View
@@ -174,6 +174,8 @@ let make_group fn g = Group (List.map fn g)
let make_option f g (v,l) = Option (f v, List.map g l)
+let make_pair f (k,v) = List [f k; f v]
+
(* Printing *)
let rec string_of_value = function
View
@@ -138,6 +138,9 @@ val make_group : ('a -> value) -> 'a list -> value
(** Create a value and its optional arguments *)
val make_option : ('a -> value) -> ('b -> value) -> 'a * 'b list -> value
+(** Create a pair *)
+val make_pair: ('a -> value) -> ('a * 'a) -> value
+
(** {2 Printing functions} *)
(** Print a value *)
View
@@ -20,6 +20,8 @@ BINARIES = opam opam-server opam-check \
opam-git-init opam-git-update opam-git-download opam-git-upload
PACKAGES = P1-1 P1-2 P2 P3 P4 P5
+OCAMLVERSION = $(shell ocamlc -version)
+
# opam in the path should not be a requirement
ENV = OCAMLRUNPARAM=b OPAMDEBUG=1 OPAM_ROOT=$(OPAM_ROOT) PATH=$(BIN):$(PATH)
OPAM = $(ENV) opam --yes --root $(OPAM_ROOT)
@@ -51,7 +53,10 @@ run:
$(MAKE) upgrade && \
$(MAKE) list && \
$(MAKE) downgrade && \
- $(MAKE) list
+ $(MAKE) list && \
+ $(MAKE) switch-alias && \
+ $(MAKE) list && \
+ $(MAKE) switch-env
rsync:
$(MAKE) REPOKIND=rsync run
@@ -200,6 +205,17 @@ downgrade:
$(OPAM) install P4.2
$(CHECK) -l downgrade P1.1 P2.1 P3.1~weird-version.test P4.2
+switch-alias:
+ $(OPAM) remove P3.1~weird-version.test P4.2
+ $(CHECK) -l switch-alias P1.1 P2.1
+ $(OPAM) switch -alias test $(OCAMLVERSION) -clone
+ $(CHECK) -l switch-alias P1.1 P2.1
+ $(OPAM) switch -list
+
+switch-env:
+ $(OPAM) switch dummy
+ $(OPAM) install P4
+
switch:
$(MAKE) fresh
$(MAKE) binaries
@@ -7,4 +7,6 @@ LINK0="`${OPAM} config -r -asmlink P2 P3`"
COMP=${COMP0// /,}
LINK=${LINK0// /,}
-ocamlbuild -cflags ${COMP} -lflags ${LINK} p4.native
+ocamlbuild -cflags ${COMP} -lflags ${LINK} p4.native
+
+echo "TEST=${TEST}"
View
@@ -1,3 +1,9 @@
let f =
try P3_bar.f (); P1.x ()
with _ -> P3.z ()
+
+let () =
+ let t =
+ try Sys.getenv "TEST"
+ with _ -> "<not found>" in
+ Printf.printf "TEST=%s\n%!" t

0 comments on commit d2b2ee1

Please sign in to comment.