From 2be876cb491e320ae1a9dfcaf1aa83b9e008921d Mon Sep 17 00:00:00 2001 From: Xavier Clerc Date: Mon, 11 Dec 2017 13:05:20 +0000 Subject: [PATCH] Availability of "num" depends on the OCaml version (#358) --- src/findlib.ml | 6 ++++-- src/meta.ml | 13 +++++++++++-- src/meta.mli | 2 +- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/findlib.ml b/src/findlib.ml index e2450716..6ae60d76 100644 --- a/src/findlib.ml +++ b/src/findlib.ml @@ -202,6 +202,7 @@ type present_or_not_available = type t = { stdlib_dir : Path.t ; path : Path.t list + ; builtins : Meta.t String_map.t ; packages : (string, present_or_not_available) Hashtbl.t } @@ -210,6 +211,7 @@ let path t = t.path let create ~stdlib_dir ~path = { stdlib_dir ; path + ; builtins = Meta.builtins ~stdlib_dir ; packages = Hashtbl.create 1024 } @@ -313,7 +315,7 @@ let rec load_meta_rec t ~fq_name ~packages ~required_by = else loop dirs | [] -> - match String_map.find root_name Meta.builtins with + match String_map.find root_name t.builtins with | Some meta -> Some (t.stdlib_dir, meta) | None -> let required_by = @@ -532,7 +534,7 @@ let root_packages t = in let pkgs = String_set.union pkgs - (String_set.of_list (String_map.keys Meta.builtins)) + (String_set.of_list (String_map.keys t.builtins)) in String_set.elements pkgs diff --git a/src/meta.ml b/src/meta.ml index f5e1dbea..7b9ecc1f 100644 --- a/src/meta.ml +++ b/src/meta.ml @@ -160,7 +160,7 @@ let archives name = ; plugin "native" (name ^ ".cmxs") ] -let builtins = +let builtins ~stdlib_dir = let version = version "[distributed with Ocaml]" in let simple name ?dir ?(archive_name=name) deps = let archives = archives archive_name in @@ -216,7 +216,16 @@ let builtins = ] } in - List.map [ compiler_libs; str; unix; bigarray; threads; num ] ~f:(fun t -> t.name, t) + let libs = + (* We do not rely on an "exists_if" ocamlfind variable, + because it would produce an error message mentioning + a "hidden" package (which could be confusing). *) + if Path.exists (Path.relative stdlib_dir "nums.cma") then + [ compiler_libs; str; unix; bigarray; threads; num ] + else + [ compiler_libs; str; unix; bigarray; threads ] + in + List.map libs ~f:(fun t -> t.name, t) |> String_map.of_alist_exn let string_of_action = function diff --git a/src/meta.mli b/src/meta.mli index c47d0b98..a2a1b242 100644 --- a/src/meta.mli +++ b/src/meta.mli @@ -46,6 +46,6 @@ val simplify : t -> Simplified.t (** Builtin META files for libraries distributed with the compiler. For when ocamlfind is not installed. *) -val builtins : t String_map.t +val builtins : stdlib_dir:Path.t -> t String_map.t val pp : Format.formatter -> entry list -> unit