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:
parent
593bd4c1c1
commit
358c9ecbc6
25
bin/main.ml
25
bin/main.ml
|
@ -88,7 +88,6 @@ let build_package =
|
||||||
$ Arg.(required & pos 0 (some string) None name_))
|
$ Arg.(required & pos 0 (some string) None name_))
|
||||||
, Term.info "build-package" ~doc ~man:help_secs)
|
, Term.info "build-package" ~doc ~man:help_secs)
|
||||||
|
|
||||||
|
|
||||||
let external_lib_deps packages =
|
let external_lib_deps packages =
|
||||||
let deps =
|
let deps =
|
||||||
Path.Map.fold (Main.external_lib_deps ~packages) ~init:String_map.empty
|
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_))
|
$ Arg.(non_empty & pos_all string [] name_))
|
||||||
, Term.info "external-lib-deps" ~doc ~man:help_secs)
|
, 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 build_targets =
|
||||||
let doc = "build" in
|
let doc = "build" in
|
||||||
let name_ = Arg.info [] in
|
let name_ = Arg.info [] in
|
||||||
|
@ -118,7 +139,7 @@ let build_targets =
|
||||||
set_common common;
|
set_common common;
|
||||||
Future.Scheduler.go
|
Future.Scheduler.go
|
||||||
(Main.setup () >>= fun (bs, _, ctx) ->
|
(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
|
Build_system.do_build_exn bs targets) in
|
||||||
( Term.(const go
|
( Term.(const go
|
||||||
$ common
|
$ common
|
||||||
|
|
|
@ -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))
|
Hashtbl.find_exn t.files file ~string_of_key:(fun fn -> sprintf "%S" (Path.to_string fn))
|
||||||
~table_desc:(fun _ -> "<target to rule>")
|
~table_desc:(fun _ -> "<target to rule>")
|
||||||
|
|
||||||
|
let is_target t file = Hashtbl.mem t.files file
|
||||||
|
|
||||||
module Build_error = struct
|
module Build_error = struct
|
||||||
type t =
|
type t =
|
||||||
{ backtrace : Printexc.raw_backtrace
|
{ backtrace : Printexc.raw_backtrace
|
||||||
|
|
|
@ -6,6 +6,8 @@ type t
|
||||||
|
|
||||||
val create : file_tree:File_tree.t -> rules:(unit, unit) Build.t list -> 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
|
module Build_error : sig
|
||||||
type t
|
type t
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue