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
|
imported
|
||||||
|> Array.of_list
|
|> 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 env = extend_env ~env:base_env ~vars:env_extra in
|
||||||
let opam_var_cache = Hashtbl.create 128 in
|
let opam_var_cache = Hashtbl.create 128 in
|
||||||
(match kind with
|
(match kind with
|
||||||
|
@ -193,22 +193,25 @@ let create ~(kind : Kind.t) ~path ~base_env ~env_extra ~name ~merlin =
|
||||||
in
|
in
|
||||||
let ocamlc_config_cmd = sprintf "%s -config" (Path.to_string ocamlc) in
|
let ocamlc_config_cmd = sprintf "%s -config" (Path.to_string ocamlc) in
|
||||||
let findlib_path =
|
let findlib_path =
|
||||||
(* If ocamlfind is present, it has precedence over everything else. *)
|
if use_findlib then
|
||||||
match which "ocamlfind" with
|
(* If ocamlfind is present, it has precedence over everything else. *)
|
||||||
| Some fn ->
|
match which "ocamlfind" with
|
||||||
(Future.run_capture_lines ~env Strict
|
| Some fn ->
|
||||||
(Path.to_string fn) ["printconf"; "path"]
|
(Future.run_capture_lines ~env Strict
|
||||||
>>| List.map ~f:Path.absolute)
|
(Path.to_string fn) ["printconf"; "path"]
|
||||||
| None ->
|
>>| List.map ~f:Path.absolute)
|
||||||
(* 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 ->
|
| None ->
|
||||||
(* If neither opam neither ocamlfind are present, assume that libraries are in
|
(* If there no ocamlfind in the PATH, check if we have opam and assume a standard
|
||||||
[dir ^ "/../lib"] *)
|
opam setup *)
|
||||||
[Path.relative (Path.parent dir) "lib"]
|
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
|
in
|
||||||
both
|
both
|
||||||
findlib_path
|
findlib_path
|
||||||
|
@ -317,7 +320,7 @@ let initial_env = lazy (
|
||||||
Lazy.force Ansi_color.setup_env_for_ocaml_colors;
|
Lazy.force Ansi_color.setup_env_for_ocaml_colors;
|
||||||
Unix.environment ())
|
Unix.environment ())
|
||||||
|
|
||||||
let default ?(merlin=true) () =
|
let default ?(merlin=true) ?(use_findlib=true) () =
|
||||||
let env = Lazy.force initial_env in
|
let env = Lazy.force initial_env in
|
||||||
let rec find_path i =
|
let rec find_path i =
|
||||||
if i = Array.length env then
|
if i = Array.length env then
|
||||||
|
@ -330,7 +333,7 @@ let default ?(merlin=true) () =
|
||||||
in
|
in
|
||||||
let path = find_path 0 in
|
let path = find_path 0 in
|
||||||
create ~kind:Default ~path ~base_env:env ~env_extra:String_map.empty
|
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) () =
|
let create_for_opam ?root ~switch ~name ?(merlin=false) () =
|
||||||
match Bin.opam with
|
match Bin.opam with
|
||||||
|
@ -355,7 +358,7 @@ let create_for_opam ?root ~switch ~name ?(merlin=false) () =
|
||||||
in
|
in
|
||||||
let env = Lazy.force initial_env in
|
let env = Lazy.force initial_env in
|
||||||
create ~kind:(Opam { root; switch }) ~path ~base_env:env ~env_extra:vars
|
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
|
let which t s = which ~cache:t.which_cache ~path:t.path s
|
||||||
|
|
||||||
|
|
|
@ -126,7 +126,10 @@ val create_for_opam
|
||||||
-> unit
|
-> unit
|
||||||
-> t Future.t
|
-> 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
|
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
|
let setup ?(log=Log.no_log) ?filter_out_optional_stanzas_with_missing_deps
|
||||||
?workspace ?(workspace_file="jbuild-workspace")
|
?workspace ?(workspace_file="jbuild-workspace")
|
||||||
|
?(use_findlib=true)
|
||||||
?only_packages () =
|
?only_packages () =
|
||||||
let conf = Jbuild_load.load () in
|
let conf = Jbuild_load.load () in
|
||||||
Option.iter only_packages ~f:(fun set ->
|
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
|
Future.all
|
||||||
(List.map workspace.contexts ~f:(function
|
(List.map workspace.contexts ~f:(function
|
||||||
| Workspace.Context.Default ->
|
| 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 } ->
|
| Opam { name; switch; root; merlin } ->
|
||||||
Context.create_for_opam ~name ~switch ?root ~merlin ()))
|
Context.create_for_opam ~name ~switch ?root ~merlin ()))
|
||||||
>>= fun contexts ->
|
>>= fun contexts ->
|
||||||
|
@ -143,7 +145,8 @@ let bootstrap () =
|
||||||
anon "Usage: boot.exe [-j JOBS] [--dev]\nOptions are:";
|
anon "Usage: boot.exe [-j JOBS] [--dev]\nOptions are:";
|
||||||
let log = Log.create () in
|
let log = Log.create () in
|
||||||
Future.Scheduler.go ~log
|
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; _ } ->
|
>>= fun { build_system = bs; _ } ->
|
||||||
Build_system.do_build_exn bs [Path.(relative root) (pkg ^ ".install")])
|
Build_system.do_build_exn bs [Path.(relative root) (pkg ^ ".install")])
|
||||||
in
|
in
|
||||||
|
@ -152,3 +155,5 @@ let bootstrap () =
|
||||||
with exn ->
|
with exn ->
|
||||||
Format.eprintf "%a@?" (report_error ?map_fname:None) exn;
|
Format.eprintf "%a@?" (report_error ?map_fname:None) exn;
|
||||||
exit 1
|
exit 1
|
||||||
|
|
||||||
|
let setup = setup ~use_findlib:true
|
||||||
|
|
Loading…
Reference in New Issue