Make sure the build of jbuilder doesn't call ocamlfind or opam
This commit is contained in:
parent
acd041f72e
commit
48970caca3
|
@ -160,7 +160,7 @@ let extend_env ~vars ~env =
|
|||
imported
|
||||
|> Array.of_list
|
||||
|
||||
let create ~(kind : Kind.t) ~path ~base_env ~env_extra ~name ~merlin =
|
||||
let create ~(kind : Kind.t) ~path ~base_env ~env_extra ~name ~merlin ~use_findlib =
|
||||
let env = extend_env ~env:base_env ~vars:env_extra in
|
||||
let opam_var_cache = Hashtbl.create 128 in
|
||||
(match kind with
|
||||
|
@ -193,22 +193,25 @@ let create ~(kind : Kind.t) ~path ~base_env ~env_extra ~name ~merlin =
|
|||
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]
|
||||
if use_findlib then
|
||||
(* 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 neither opam neither ocamlfind are present, assume that libraries are in
|
||||
[dir ^ "/../lib"] *)
|
||||
[Path.relative (Path.parent dir) "lib"]
|
||||
(* 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"]
|
||||
else
|
||||
return []
|
||||
in
|
||||
both
|
||||
findlib_path
|
||||
|
@ -317,7 +320,7 @@ let initial_env = lazy (
|
|||
Lazy.force Ansi_color.setup_env_for_ocaml_colors;
|
||||
Unix.environment ())
|
||||
|
||||
let default ?(merlin=true) () =
|
||||
let default ?(merlin=true) ?(use_findlib=true) () =
|
||||
let env = Lazy.force initial_env in
|
||||
let rec find_path i =
|
||||
if i = Array.length env then
|
||||
|
@ -330,7 +333,7 @@ let default ?(merlin=true) () =
|
|||
in
|
||||
let path = find_path 0 in
|
||||
create ~kind:Default ~path ~base_env:env ~env_extra:String_map.empty
|
||||
~name:"default" ~merlin
|
||||
~name:"default" ~merlin ~use_findlib
|
||||
|
||||
let create_for_opam ?root ~switch ~name ?(merlin=false) () =
|
||||
match Bin.opam with
|
||||
|
@ -355,7 +358,7 @@ let create_for_opam ?root ~switch ~name ?(merlin=false) () =
|
|||
in
|
||||
let env = Lazy.force initial_env in
|
||||
create ~kind:(Opam { root; switch }) ~path ~base_env:env ~env_extra:vars
|
||||
~name ~merlin
|
||||
~name ~merlin ~use_findlib:true
|
||||
|
||||
let which t s = which ~cache:t.which_cache ~path:t.path s
|
||||
|
||||
|
|
|
@ -126,7 +126,10 @@ val create_for_opam
|
|||
-> unit
|
||||
-> t Future.t
|
||||
|
||||
val default : ?merlin:bool -> unit -> t Future.t
|
||||
(** If [use_findlib] is [false], don't try to guess the library search path with opam or
|
||||
ocamlfind. This is only for building jbuilder itself, so that its build is completely
|
||||
independent of the user setup. *)
|
||||
val default : ?merlin:bool -> ?use_findlib:bool -> unit -> t Future.t
|
||||
|
||||
val which : t -> string -> Path.t option
|
||||
|
||||
|
|
|
@ -15,6 +15,7 @@ let package_install_file { packages; _ } pkg =
|
|||
|
||||
let setup ?(log=Log.no_log) ?filter_out_optional_stanzas_with_missing_deps
|
||||
?workspace ?(workspace_file="jbuild-workspace")
|
||||
?(use_findlib=true)
|
||||
?only_packages () =
|
||||
let conf = Jbuild_load.load () in
|
||||
Option.iter only_packages ~f:(fun set ->
|
||||
|
@ -35,7 +36,8 @@ let setup ?(log=Log.no_log) ?filter_out_optional_stanzas_with_missing_deps
|
|||
Future.all
|
||||
(List.map workspace.contexts ~f:(function
|
||||
| Workspace.Context.Default ->
|
||||
Context.default ~merlin:(workspace.merlin_context = Some "default") ()
|
||||
Context.default ~merlin:(workspace.merlin_context = Some "default")
|
||||
~use_findlib ()
|
||||
| Opam { name; switch; root; merlin } ->
|
||||
Context.create_for_opam ~name ~switch ?root ~merlin ()))
|
||||
>>= fun contexts ->
|
||||
|
@ -143,7 +145,8 @@ let bootstrap () =
|
|||
anon "Usage: boot.exe [-j JOBS] [--dev]\nOptions are:";
|
||||
let log = Log.create () in
|
||||
Future.Scheduler.go ~log
|
||||
(setup ~log ~workspace:{ merlin_context = Some "default"; contexts = [Default] } ()
|
||||
(setup ~log ~workspace:{ merlin_context = Some "default"; contexts = [Default] }
|
||||
~use_findlib:false ()
|
||||
>>= fun { build_system = bs; _ } ->
|
||||
Build_system.do_build_exn bs [Path.(relative root) (pkg ^ ".install")])
|
||||
in
|
||||
|
@ -152,3 +155,5 @@ let bootstrap () =
|
|||
with exn ->
|
||||
Format.eprintf "%a@?" (report_error ?map_fname:None) exn;
|
||||
exit 1
|
||||
|
||||
let setup = setup ~use_findlib:true
|
||||
|
|
Loading…
Reference in New Issue