From 9a8483c6154cb04fbefbc058ccfde4b561b2f6d5 Mon Sep 17 00:00:00 2001 From: Jeremie Dimino Date: Tue, 21 Mar 2017 10:21:18 +0000 Subject: [PATCH] Give ocamlfind precedence over opam If ocamlfind is present, don't try to call `opam config var lib`. The previous behavior was breaking Facebook builds. Also add ocamlfind as an optional dependency, to avoid race conditions when installing ocamlfind in parallel. --- jbuilder.opam | 6 ++++++ src/context.ml | 43 +++++++++++++++++++------------------------ 2 files changed, 25 insertions(+), 24 deletions(-) diff --git a/jbuilder.opam b/jbuilder.opam index 86b82654..f4ce6ec4 100644 --- a/jbuilder.opam +++ b/jbuilder.opam @@ -10,6 +10,12 @@ build: [ ["ocaml" "bootstrap.ml"] ["./boot.exe" "-j" jobs] ] +depopts: [ + # This dependency is here just to prevent a race condition + # as jbuilder calls `ocamlfind printconf path` + # when ocamlfind is present in the PATH + "ocamlfind" {build} +] available: [ ocaml-version >= "4.02.3" ] # CR-soon jdimino: uncomment this when opam 2 is the norm: diff --git a/src/context.ml b/src/context.ml index 35ffd571..e840af62 100644 --- a/src/context.ml +++ b/src/context.ml @@ -192,31 +192,26 @@ let create ~(kind : Kind.t) ~path ~base_env ~env_extra ~name ~merlin = Path.of_string (sprintf "_build/%s" name) in let ocamlc_config_cmd = sprintf "%s -config" (Path.to_string ocamlc) in + let findlib_path = + (* If ocamlfind is present, it has precedence over everything else. *) + match which "ocamlfind" with + | Some fn -> + (Future.run_capture_lines ~env Strict + (Path.to_string fn) ["printconf"; "path"] + >>| List.map ~f:Path.absolute) + | None -> + (* If there no ocamlfind in the PATH, check if we have opam and assume a standard + opam setup *) + opam_config_var ~env ~cache:opam_var_cache "lib" + >>| function + | Some s -> [Path.absolute s] + | None -> + (* If neither opam neither ocamlfind are present, assume that libraries are in + [dir ^ "/../lib"] *) + [Path.relative (Path.parent dir) "lib"] + in both - (both - (opam_config_var ~env ~cache:opam_var_cache "lib" - >>| function - | None -> [] - | Some s -> [Path.absolute s]) - (match which "ocamlfind" with - | None -> - return [] - | Some fn -> - Future.run_capture_lines ~env (Accept All) - (Path.to_string fn) ["printconf"; "path"] - >>| function - | Ok lines -> List.map lines ~f:Path.absolute - | Error _ -> []) - >>| fun (a, b) -> - match a @ b with - | [] -> [Path.relative (Path.parent dir) "lib"] - | l -> - List.fold_left l ~init:[] ~f:(fun acc x -> - if List.mem x ~set:acc then - acc - else - x :: acc) - |> List.rev) + findlib_path (Future.run_capture_lines ~env Strict (Path.to_string ocamlc) ["-config"]) >>= fun (findlib_path, ocamlc_config) -> let ocamlc_config =