Remove build-package in favor of --only-packages

This commit is contained in:
Jeremie Dimino 2017-03-02 18:21:19 +00:00
parent 591bc9f724
commit 4fa0844e42
10 changed files with 102 additions and 55 deletions

View File

@ -51,7 +51,11 @@ packages. When building via [[https://opam.ocaml.org/][opam]], it is able to cor
libraries that were previously installed even if they are already libraries that were previously installed even if they are already
present in the source tree. present in the source tree.
The magic invocation is =jbuilder build-package <package-name>=. The magic invocation is:
#+begin_src sh
$ jbuilder build --only-packages <package-name> @install
#+end_src
*** Building against several configurations at once *** Building against several configurations at once

View File

@ -17,6 +17,7 @@ type common =
; workspace_file : string option ; workspace_file : string option
; root : string ; root : string
; target_prefix : string ; target_prefix : string
; only_packages : String_set.t option
} }
let prefix_target common s = common.target_prefix ^ s let prefix_target common s = common.target_prefix ^ s
@ -34,8 +35,10 @@ let set_common c =
module Main = struct module Main = struct
include Jbuilder.Main include Jbuilder.Main
let setup ?only_package ?filter_out_optional_stanzas_with_missing_deps common = let setup ?filter_out_optional_stanzas_with_missing_deps common =
setup ?workspace_file:common.workspace_file ?only_package setup
?workspace_file:common.workspace_file
?only_packages:common.only_packages
?filter_out_optional_stanzas_with_missing_deps () ?filter_out_optional_stanzas_with_missing_deps ()
end end
@ -104,8 +107,16 @@ let help_secs =
] ]
let common = let common =
let make concurrency debug_rules debug_dep_path debug_findlib dev_mode let make
workspace_file root = concurrency
only_packages
debug_rules
debug_dep_path
debug_findlib
dev_mode
workspace_file
root
=
let root, to_cwd = let root, to_cwd =
match root with match root with
| Some dn -> (dn, []) | Some dn -> (dn, [])
@ -119,6 +130,9 @@ let common =
; workspace_file ; workspace_file
; root ; root
; target_prefix = String.concat ~sep:"" (List.map to_cwd ~f:(sprintf "%s/")) ; target_prefix = String.concat ~sep:"" (List.map to_cwd ~f:(sprintf "%s/"))
; only_packages =
Option.map only_packages
~f:(fun s -> String_set.of_list (String.split s ~on:','))
} }
in in
let docs = copts_sect in let docs = copts_sect in
@ -129,6 +143,16 @@ let common =
~doc:{|Run no more than $(i,JOBS) commands simultaneously.|} ~doc:{|Run no more than $(i,JOBS) commands simultaneously.|}
) )
in in
let only_packages =
Arg.(value
& opt (some string) None
& info ["only-packages"] ~docs ~docv:"PACKAGES"
~doc:{|Ignore stanzas referring to a package that is not in $(b,PACKAGES).
$(b,PACKAGES) is a coma-separated list of package name. You need to
use this option in your $(i,<package>.opam) file if your project
contains several packages.|}
)
in
let drules = let drules =
Arg.(value Arg.(value
& flag & flag
@ -173,6 +197,7 @@ let common =
in in
Term.(const make Term.(const make
$ concurrency $ concurrency
$ only_packages
$ drules $ drules
$ ddep_path $ ddep_path
$ dfindlib $ dfindlib
@ -210,34 +235,6 @@ let resolve_package_install setup pkg =
| Error () -> | Error () ->
die "Unknown package %s!%s" pkg (hint pkg (String_map.keys setup.packages)) die "Unknown package %s!%s" pkg (hint pkg (String_map.keys setup.packages))
let build_package common pkg =
Future.Scheduler.go ~log:(create_log ())
(Main.setup common ~only_package:pkg >>= fun setup ->
do_build setup [resolve_package_install setup pkg])
let build_package =
let doc = "Build a single package in release mode." in
let man =
[ `S "DESCRIPTION"
; `P {|This command is meant to be used in $(i,<package>.opam) files.
It builds the given package as if all the definitions in
the source tree that are for another package didn't existed.
|}
; `P {|More precisely, this is what you should use in your $(i,<package>.opam) file:|}
; `Pre {| build: ["jbuilder" "build-package" "<package>" "-j" jobs|}
; `Blocks help_secs
]
in
let name_ = Arg.info [] ~docv:"PACKAGE-NAME" in
let go common pkg =
set_common common;
build_package common pkg
in
( Term.(const go
$ common
$ Arg.(required & pos 0 (some string) None name_))
, Term.info "build-package" ~doc ~man)
type target = type target =
| File of Path.t | File of Path.t
| Alias of Path.t * Alias.t | Alias of Path.t * Alias.t
@ -558,7 +555,6 @@ let exec =
let all = let all =
[ installed_libraries [ installed_libraries
; build_package
; external_lib_deps ; external_lib_deps
; build_targets ; build_targets
; runtest ; runtest

View File

@ -4,7 +4,6 @@ open StdLabels
let commands = let commands =
[ "build" [ "build"
; "build-package"
; "external-lib-deps" ; "external-lib-deps"
; "install" ; "install"
; "installed-libraries" ; "installed-libraries"

View File

@ -1021,6 +1021,34 @@ So for instance:
=foo= build context =foo= build context
- =jbuilder build @runtest= will run the tests for all build contexts - =jbuilder build @runtest= will run the tests for all build contexts
** Restricting the set of packages
You can restrict the set of packages from your workspace that Jbuilder
can see with the =--only-packages= option:
#+begin_src sh
$ jbuilder build --only-packages pkg1,pkg2,... @install
#+end_src
This option acts as if you went through all the jbuild files and
commented out the stanzas refering to a package that is not in the
list given to =jbuilder=.
** Invocation from opam
You should set the =build:= field of your =<package>.opam= file as
follow:
#+begin_src
build: [["jbuilder" "build" "--only-packages" "<package>" "--root" "." "-j" jobs @install]]
#+end_src
This has the following effects:
- it tells jbuilder to build everything that is installable and to
ignore packages other than =<package>= defined in your project
- it sets the root to prevent jbuilder from looking it up
- it uses whatever concurrency option opam provides
** Workspace configuration ** Workspace configuration
By default, a workspace has only one build context named =default= By default, a workspace has only one build context named =default=

View File

@ -179,14 +179,14 @@ let styles_of_tag = function
let setup_err_formatter_colors () = let setup_err_formatter_colors () =
let open Format in let open Format in
if Lazy.force stderr_supports_colors then begin if Lazy.force stderr_supports_colors then begin
let ppf = err_formatter in List.iter [err_formatter; die_ppf] ~f:(fun ppf ->
let funcs = pp_get_formatter_tag_functions ppf () in let funcs = pp_get_formatter_tag_functions ppf () in
pp_set_mark_tags ppf true; pp_set_mark_tags ppf true;
pp_set_formatter_tag_functions ppf pp_set_formatter_tag_functions ppf
{ funcs with { funcs with
mark_close_tag = (fun _ -> ansi_escape_of_styles [Reset]) mark_close_tag = (fun _ -> ansi_escape_of_styles [Reset])
; mark_open_tag = (fun tag -> ansi_escape_of_styles (styles_of_tag tag)) ; mark_open_tag = (fun tag -> ansi_escape_of_styles (styles_of_tag tag))
} })
end end
let output_filename = [Bold; Foreground Green] let output_filename = [Bold; Foreground Green]

View File

@ -1806,7 +1806,7 @@ module Gen(P : Params) = struct
end end
let gen ~contexts ?(filter_out_optional_stanzas_with_missing_deps=true) let gen ~contexts ?(filter_out_optional_stanzas_with_missing_deps=true)
?only_package conf = ?only_packages conf =
let open Future in let open Future in
let { Jbuild_load. file_tree; tree; jbuilds; packages } = conf in let { Jbuild_load. file_tree; tree; jbuilds; packages } = conf in
let module Common = struct let module Common = struct
@ -1816,23 +1816,28 @@ let gen ~contexts ?(filter_out_optional_stanzas_with_missing_deps=true)
~f:(fun ~key:_ ~data:{ Package. path; _ } acc -> ~f:(fun ~key:_ ~data:{ Package. path; _ } acc ->
Path.Set.add path acc) Path.Set.add path acc)
let file_tree = file_tree let file_tree = file_tree
let packages = packages let packages =
match only_packages with
| None -> packages
| Some pkgs ->
String_map.filter packages ~f:(fun _ { Package.name; _ } ->
String_set.mem name pkgs)
let filter_out_optional_stanzas_with_missing_deps = let filter_out_optional_stanzas_with_missing_deps =
filter_out_optional_stanzas_with_missing_deps filter_out_optional_stanzas_with_missing_deps
end in end in
List.map contexts ~f:(fun context -> List.map contexts ~f:(fun context ->
Jbuild_load.Jbuilds.eval ~context jbuilds >>| fun stanzas -> Jbuild_load.Jbuilds.eval ~context jbuilds >>| fun stanzas ->
let stanzas = let stanzas =
match only_package with match only_packages with
| None -> stanzas | None -> stanzas
| Some pkg -> | Some pkgs ->
List.map stanzas ~f:(fun (dir, stanzas) -> List.map stanzas ~f:(fun (dir, stanzas) ->
(dir, (dir,
List.filter stanzas ~f:(fun stanza -> List.filter stanzas ~f:(fun stanza ->
match (stanza : Stanza.t) with match (stanza : Stanza.t) with
| Library { public = Some { package; _ }; _ } -> | Library { public = Some { package; _ }; _ }
package = pkg | Install { package = Some package; _ } ->
| Install { package = Some name; _ } -> name = pkg String_set.mem package pkgs
| _ -> true))) | _ -> true)))
in in
let module M = let module M =

View File

@ -3,7 +3,7 @@ open! Import
val gen val gen
: contexts:Context.t list : contexts:Context.t list
-> ?filter_out_optional_stanzas_with_missing_deps:bool (** default: true *) -> ?filter_out_optional_stanzas_with_missing_deps:bool (** default: true *)
-> ?only_package:string -> ?only_packages:String_set.t
-> Jbuild_load.conf -> Jbuild_load.conf
-> (Build_interpret.Rule.t list * -> (Build_interpret.Rule.t list *
(* Evaluated jbuilds per context names *) (* Evaluated jbuilds per context names *)

View File

@ -341,7 +341,16 @@ let lines_of_file fn = with_file_in fn ~f:input_lines
let write_file fn data = with_file_out fn ~f:(fun oc -> output_string oc data) let write_file fn data = with_file_out fn ~f:(fun oc -> output_string oc data)
exception Fatal_error of string exception Fatal_error of string
let die fmt = ksprintf (fun msg -> raise (Fatal_error msg)) fmt let die_buf = Buffer.create 128
let die_ppf (* Referenced in Ansi_color *) = Format.formatter_of_buffer die_buf
let die fmt =
Format.kfprintf
(fun ppf ->
Format.pp_print_flush ppf ();
let s = Buffer.contents die_buf in
Buffer.clear die_buf;
raise (Fatal_error s))
die_ppf fmt
let warn fmt = let warn fmt =
ksprintf (fun msg -> ksprintf (fun msg ->

View File

@ -15,8 +15,14 @@ let package_install_file { packages; _ } pkg =
let setup ?filter_out_optional_stanzas_with_missing_deps let setup ?filter_out_optional_stanzas_with_missing_deps
?workspace ?(workspace_file="jbuild-workspace") ?workspace ?(workspace_file="jbuild-workspace")
?only_package () = ?only_packages () =
let conf = Jbuild_load.load () in let conf = Jbuild_load.load () in
Option.iter only_packages ~f:(fun set ->
String_set.iter set ~f:(fun pkg ->
if not (String_map.mem pkg conf.packages) then
die "@{<error>Error@}: I don't know about package %s \
(passed through --only-packages)%s"
pkg (hint pkg (String_map.keys conf.packages))));
let workspace = let workspace =
match workspace with match workspace with
| Some w -> w | Some w -> w
@ -34,7 +40,7 @@ let setup ?filter_out_optional_stanzas_with_missing_deps
Context.create_for_opam ~name ~switch ?root ~merlin ())) Context.create_for_opam ~name ~switch ?root ~merlin ()))
>>= fun contexts -> >>= fun contexts ->
Gen_rules.gen conf ~contexts Gen_rules.gen conf ~contexts
?only_package ?only_packages
?filter_out_optional_stanzas_with_missing_deps ?filter_out_optional_stanzas_with_missing_deps
>>= fun (rules, stanzas) -> >>= fun (rules, stanzas) ->
let build_system = Build_system.create ~contexts ~file_tree:conf.file_tree ~rules in let build_system = Build_system.create ~contexts ~file_tree:conf.file_tree ~rules in

View File

@ -15,7 +15,7 @@ val setup
: ?filter_out_optional_stanzas_with_missing_deps:bool : ?filter_out_optional_stanzas_with_missing_deps:bool
-> ?workspace:Workspace.t -> ?workspace:Workspace.t
-> ?workspace_file:string -> ?workspace_file:string
-> ?only_package:string -> ?only_packages:String_set.t
-> unit -> unit
-> setup Future.t -> setup Future.t
val external_lib_deps val external_lib_deps