2016-11-13 12:25:45 +00:00
|
|
|
open Import
|
2016-12-02 13:54:32 +00:00
|
|
|
open Future
|
|
|
|
|
2016-12-15 13:00:30 +00:00
|
|
|
let setup ?filter_out_optional_stanzas_with_missing_deps () =
|
2016-12-31 15:12:39 +00:00
|
|
|
let { Jbuild_load. file_tree; tree; stanzas; packages } = Jbuild_load.load () in
|
2016-12-02 13:54:32 +00:00
|
|
|
Lazy.force Context.default >>= fun ctx ->
|
2016-12-15 13:00:30 +00:00
|
|
|
let rules =
|
2016-12-31 15:12:39 +00:00
|
|
|
Gen_rules.gen ~context:ctx ~file_tree ~tree ~stanzas ~packages
|
2016-12-15 13:00:30 +00:00
|
|
|
?filter_out_optional_stanzas_with_missing_deps ()
|
|
|
|
in
|
2016-12-31 15:12:39 +00:00
|
|
|
let bs = Build_system.create ~file_tree ~rules in
|
2016-12-15 11:20:46 +00:00
|
|
|
return (bs, stanzas, ctx)
|
2016-12-02 13:54:32 +00:00
|
|
|
|
2017-02-23 11:45:03 +00:00
|
|
|
let external_lib_deps ?log ~packages =
|
|
|
|
Future.Scheduler.go ?log
|
2016-12-15 13:00:30 +00:00
|
|
|
(setup () ~filter_out_optional_stanzas_with_missing_deps:false
|
|
|
|
>>| fun (bs, stanzas, _) ->
|
2016-12-15 11:20:46 +00:00
|
|
|
Path.Map.map
|
|
|
|
(Build_system.all_lib_deps bs
|
|
|
|
(List.map packages ~f:(fun pkg ->
|
|
|
|
Path.(relative root) (pkg ^ ".install"))))
|
2016-12-15 13:00:30 +00:00
|
|
|
~f:(fun deps ->
|
|
|
|
let internals = Jbuild_types.Stanza.lib_names stanzas in
|
|
|
|
String_map.filter deps ~f:(fun name _ -> not (String_set.mem name internals))))
|
2016-12-02 13:54:32 +00:00
|
|
|
|
|
|
|
let report_error ?(map_fname=fun x->x) ppf exn ~backtrace =
|
|
|
|
match exn with
|
2016-11-13 12:32:12 +00:00
|
|
|
| Loc.Error ({ start; stop }, msg) ->
|
|
|
|
let start_c = start.pos_cnum - start.pos_bol in
|
|
|
|
let stop_c = stop.pos_cnum - start.pos_bol in
|
2016-12-02 13:54:32 +00:00
|
|
|
Format.fprintf ppf
|
2016-11-13 12:32:12 +00:00
|
|
|
"File \"%s\", line %d, characters %d-%d:\n\
|
2016-12-02 13:54:32 +00:00
|
|
|
Error: %s\n"
|
|
|
|
(map_fname start.pos_fname) start.pos_lnum start_c stop_c msg
|
2017-02-23 11:55:14 +00:00
|
|
|
| Fatal_error "" -> ()
|
2016-12-02 13:54:32 +00:00
|
|
|
| Fatal_error msg ->
|
|
|
|
Format.fprintf ppf "%s\n" (String.capitalize msg)
|
|
|
|
| Findlib.Package_not_found pkg ->
|
2016-12-15 11:20:46 +00:00
|
|
|
Format.fprintf ppf "Findlib package %S not found.\n" pkg
|
2016-12-02 13:54:32 +00:00
|
|
|
| Code_error msg ->
|
|
|
|
let bt = Printexc.raw_backtrace_to_string backtrace in
|
|
|
|
Format.fprintf ppf "Internal error, please report upstream.\n\
|
|
|
|
Description: %s\n\
|
|
|
|
Backtrace:\n\
|
|
|
|
%s" msg bt
|
|
|
|
| _ ->
|
|
|
|
let s = Printexc.to_string exn in
|
|
|
|
let bt = Printexc.raw_backtrace_to_string backtrace in
|
|
|
|
if String.is_prefix s ~prefix:"File \"" then
|
|
|
|
Format.fprintf ppf "%s\nBacktrace:\n%s" s bt
|
|
|
|
else
|
|
|
|
Format.fprintf ppf "Error: exception %s\nBacktrace:\n%s" s bt
|
2016-11-13 12:32:12 +00:00
|
|
|
|
2016-12-02 13:54:32 +00:00
|
|
|
let report_error ?map_fname ppf exn =
|
|
|
|
match exn with
|
|
|
|
| Build_system.Build_error.E err ->
|
|
|
|
let module E = Build_system.Build_error in
|
|
|
|
report_error ?map_fname ppf (E.exn err) ~backtrace:(E.backtrace err);
|
|
|
|
if !Clflags.debug_dep_path then
|
|
|
|
Format.fprintf ppf "Dependency path:\n %s\n"
|
|
|
|
(String.concat ~sep:"\n--> "
|
|
|
|
(List.map (E.dependency_path err) ~f:Path.to_string))
|
|
|
|
| exn ->
|
|
|
|
let backtrace = Printexc.get_raw_backtrace () in
|
|
|
|
report_error ?map_fname ppf exn ~backtrace
|
|
|
|
|
2017-02-23 11:45:03 +00:00
|
|
|
let create_log () =
|
|
|
|
if not (Sys.file_exists "_build") then
|
|
|
|
Unix.mkdir "_build" 0o777;
|
|
|
|
let oc = open_out_bin "_build/log" in
|
|
|
|
Printf.fprintf oc "# %s\n%!"
|
|
|
|
(String.concat (List.map (Array.to_list Sys.argv) ~f:quote_for_shell) ~sep:" ");
|
|
|
|
oc
|
|
|
|
|
2017-02-21 15:09:58 +00:00
|
|
|
(* Called by the script generated by ../build.ml *)
|
|
|
|
let bootstrap () =
|
|
|
|
let pkg = "jbuilder" in
|
|
|
|
let main () =
|
|
|
|
let anon s = raise (Arg.Bad (Printf.sprintf "don't know what to do with %s\n" s)) in
|
|
|
|
Arg.parse [ "-j", Set_int Clflags.concurrency, "JOBS concurrency" ]
|
|
|
|
anon "Usage: boot.exe [-j JOBS]\nOptions are:";
|
2017-02-23 11:45:03 +00:00
|
|
|
Future.Scheduler.go ~log:(create_log ())
|
2017-02-21 15:09:58 +00:00
|
|
|
(setup () >>= fun (bs, _, _) ->
|
|
|
|
Build_system.do_build_exn bs [Path.(relative root) (pkg ^ ".install")])
|
|
|
|
in
|
2016-12-02 13:54:32 +00:00
|
|
|
try
|
|
|
|
main ()
|
|
|
|
with exn ->
|
|
|
|
Format.eprintf "%a@?" (report_error ?map_fname:None) exn;
|
|
|
|
exit 1
|