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.
This commit is contained in:
Jeremie Dimino 2017-03-21 10:21:18 +00:00
parent 2d91a7f060
commit 9a8483c615
2 changed files with 25 additions and 24 deletions

View File

@ -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:

View File

@ -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 =