Implement targets resolution

Prepend _build/default only when a path is not a direct target. This
way "jbuilder build package.install" does produce the
"package.install" file
This commit is contained in:
Jeremie Dimino 2017-02-23 10:03:35 +00:00
parent 593bd4c1c1
commit 358c9ecbc6
3 changed files with 27 additions and 2 deletions

View File

@ -88,7 +88,6 @@ let build_package =
$ Arg.(required & pos 0 (some string) None name_))
, Term.info "build-package" ~doc ~man:help_secs)
let external_lib_deps packages =
let deps =
Path.Map.fold (Main.external_lib_deps ~packages) ~init:String_map.empty
@ -111,6 +110,28 @@ let external_lib_deps =
$ Arg.(non_empty & pos_all string [] name_))
, Term.info "external-lib-deps" ~doc ~man:help_secs)
let resolve_targets bs (ctx : Context.t) user_targets =
match user_targets with
| [] -> []
| _ ->
let user_targets = List.map user_targets ~f:(Path.relative Path.root) in
let real_targets =
List.map user_targets ~f:(fun path ->
if Path.is_in_build_dir path then
path
else if Path.is_local path &&
not (Build_system.is_target bs path) &&
not (Path.exists path) then
Path.append ctx.build_dir path
else
path)
in
Printf.printf "Building the following targets:\n";
List.iter real_targets ~f:(fun target ->
Printf.printf "- %s\n" (Path.to_string target));
flush stdout;
real_targets
let build_targets =
let doc = "build" in
let name_ = Arg.info [] in
@ -118,7 +139,7 @@ let build_targets =
set_common common;
Future.Scheduler.go
(Main.setup () >>= fun (bs, _, ctx) ->
let targets = List.map targets ~f:(Path.relative ctx.build_dir) in
let targets = resolve_targets bs ctx targets in
Build_system.do_build_exn bs targets) in
( Term.(const go
$ common

View File

@ -57,6 +57,8 @@ let find_file_exn t file =
Hashtbl.find_exn t.files file ~string_of_key:(fun fn -> sprintf "%S" (Path.to_string fn))
~table_desc:(fun _ -> "<target to rule>")
let is_target t file = Hashtbl.mem t.files file
module Build_error = struct
type t =
{ backtrace : Printexc.raw_backtrace

View File

@ -6,6 +6,8 @@ type t
val create : file_tree:File_tree.t -> rules:(unit, unit) Build.t list -> t
val is_target : t -> Path.t -> bool
module Build_error : sig
type t