This commit is contained in:
Jeremie Dimino 2017-05-19 14:16:00 +01:00
parent b11638690e
commit 4dd0de1723
7 changed files with 53 additions and 24 deletions

View File

@ -54,6 +54,8 @@
- `_build`
- `_opam` (opam 2 local switches)
- Fix the hint for `jbuilder external-lib-deps` (#72)
1.0+beta8 (17/04/2017)
----------------------

View File

@ -18,11 +18,13 @@ type common =
; root : string
; target_prefix : string
; only_packages : String_set.t option
; (* Original arguments for the external-lib-deps hint *)
orig_args : string list
}
let prefix_target common s = common.target_prefix ^ s
let set_common c =
let set_common c ~targets =
Clflags.concurrency := c.concurrency;
Clflags.debug_dep_path := c.debug_dep_path;
Clflags.debug_findlib := c.debug_findlib;
@ -30,7 +32,13 @@ let set_common c =
Clflags.verbose := c.verbose;
Clflags.workspace_root := c.root;
if c.root <> Filename.current_dir_name then
Sys.chdir c.root
Sys.chdir c.root;
Clflags.external_lib_deps_hint :=
List.concat
[ ["jbuilder"; "external-lib-deps"; "--missing"]
; c.orig_args
; targets
]
module Main = struct
include Jbuilder.Main
@ -90,6 +98,11 @@ let help_secs =
]
let common =
let dump_opt name value =
match value with
| None -> []
| Some s -> [name; s]
in
let make
concurrency
debug_dep_path
@ -97,13 +110,20 @@ let common =
dev_mode
verbose
workspace_file
(root, only_packages)
(root, only_packages, orig)
=
let root, to_cwd =
match root with
| Some dn -> (dn, [])
| None -> find_root ()
in
let orig_args =
List.concat
[ if dev_mode then ["--dev"] else []
; dump_opt "--workspace" workspace_file
; orig
]
in
{ concurrency
; debug_dep_path
; debug_findlib
@ -111,6 +131,7 @@ let common =
; verbose
; workspace_file
; root
; orig_args
; target_prefix = String.concat ~sep:"" (List.map to_cwd ~f:(sprintf "%s/"))
; only_packages =
Option.map only_packages
@ -197,9 +218,13 @@ let common =
"Cannot use %s and --only-packages simultaneously"
for_release)
| Some pkgs, None, None ->
`Ok (Some ".", Some pkgs)
`Ok (Some ".", Some pkgs, ["-p"; pkgs])
| None, _, _ ->
`Ok (root, only_packages)
`Ok (root, only_packages,
List.concat
[ dump_opt "--root" root
; dump_opt "--only-packages" only_packages
])
in
Term.(ret (const merge
$ root
@ -219,7 +244,7 @@ let common =
let installed_libraries =
let doc = "Print out libraries installed on the system." in
let go common na =
set_common common;
set_common common ~targets:[];
Future.Scheduler.go ~log:(Log.create ())
(Context.default () >>= fun ctx ->
let findlib = ctx.findlib in
@ -360,7 +385,7 @@ let build_targets =
in
let name_ = Arg.info [] ~docv:"TARGET" in
let go common targets =
set_common common;
set_common common ~targets;
let log = Log.create () in
Future.Scheduler.go ~log
(Main.setup ~log common >>= fun setup ->
@ -382,7 +407,11 @@ let runtest =
in
let name_ = Arg.info [] ~docv:"DIR" in
let go common dirs =
set_common common;
set_common common
~targets:(List.map dirs ~f:(function
| "" | "." -> "@runtest"
| dir when dir.[String.length dir - 1] = '/' -> sprintf "@%sruntest" dir
| dir -> sprintf "@%s/runtest" dir));
let log = Log.create () in
Future.Scheduler.go ~log
(Main.setup ~log common >>= fun setup ->
@ -416,7 +445,7 @@ let external_lib_deps =
]
in
let go common only_missing targets =
set_common common;
set_common common ~targets:[];
let log = Log.create () in
Future.Scheduler.go ~log
(Main.setup ~log common ~filter_out_optional_stanzas_with_missing_deps:false
@ -509,7 +538,7 @@ let rules =
]
in
let go common out recursive makefile_syntax targets =
set_common common;
set_common common ~targets;
let log = Log.create () in
Future.Scheduler.go ~log
(Main.setup ~log common ~filter_out_optional_stanzas_with_missing_deps:false
@ -603,7 +632,7 @@ let install_uninstall ~what =
in
let name_ = Arg.info [] ~docv:"PACKAGE" in
let go common prefix pkgs =
set_common common;
set_common common ~targets:[];
let opam_installer = opam_installer () in
let log = Log.create () in
Future.Scheduler.go ~log
@ -676,7 +705,7 @@ let exec =
]
in
let go common context prog args =
set_common common;
set_common common ~targets:[];
let log = Log.create () in
Future.Scheduler.go ~log
(Main.setup ~log common >>= fun setup ->
@ -730,7 +759,7 @@ let subst =
]
in
let go common name =
set_common common;
set_common common ~targets:[];
Future.Scheduler.go (Watermarks.subst ?name ())
in
( Term.(const go

View File

@ -7,3 +7,5 @@ let warnings = ref "-40"
let debug_dep_path = ref false
let dev_mode = ref false
let workspace_root = ref "."
let external_lib_deps_hint = ref []

View File

@ -26,3 +26,6 @@ val dev_mode : bool ref
(** The path to the workspace root *)
val workspace_root : string ref
(** The command line for "Hint: try: jbuilder external-lib-deps ..." *)
val external_lib_deps_hint : string list ref

View File

@ -13,7 +13,7 @@ let standard () = pretty () @ sourcemap ()
let install_jsoo_hint = "opam install js_of_ocaml-compiler"
let in_build_dir ~ctx =
let init = Path.of_string (sprintf "_build/.js/%s" ctx.Context.name) in
let init = Path.relative ctx.Context.build_dir ".js" in
List.fold_left ~init ~f:Path.relative
let runtime_file ~sctx ~dir fname =

View File

@ -111,17 +111,10 @@ let report_error ?(map_fname=fun x->x) ppf exn ~backtrace =
Format.fprintf ppf "- %-*s -> %a@\n" longest na.package
Findlib.Package_not_available.explain na.reason)
end;
let cmdline_suggestion =
(* CR-someday jdimino: this is ugly *)
match Array.to_list Sys.argv with
| prog :: "build" :: args ->
prog :: "external-lib-deps" :: "--missing" :: args
| _ ->
["jbuilder"; "external-lib-deps"; "--missing"]
in
Format.fprintf ppf
"Hint: try: %s\n"
(List.map cmdline_suggestion ~f:quote_for_shell |> String.concat ~sep:" ")
(List.map !Clflags.external_lib_deps_hint ~f:quote_for_shell
|> String.concat ~sep:" ")
| Findlib.External_dep_conflicts_with_local_lib
{ package; required_by; required_locally_in; defined_locally_in } ->
Format.fprintf ppf

View File

@ -197,7 +197,7 @@ let create
; cxx_flags
; vars
; ppx_drivers = Hashtbl.create 32
; ppx_dir = Path.of_string (sprintf "_build/.ppx/%s" context.name)
; ppx_dir = Path.relative context.build_dir ".ppx"
; external_dirs = Hashtbl.create 1024
}