add an install alias
This commit is contained in:
parent
bdcc86d7a8
commit
e148f75ee4
10
bin/main.ml
10
bin/main.ml
|
@ -135,6 +135,11 @@ type target =
|
||||||
| File of Path.t
|
| File of Path.t
|
||||||
| Alias of Path.t * Alias.t
|
| Alias of Path.t * Alias.t
|
||||||
|
|
||||||
|
let aliases_in_source_tree =
|
||||||
|
String_set.of_list
|
||||||
|
[ "install"
|
||||||
|
]
|
||||||
|
|
||||||
let resolve_targets (setup : Main.setup) user_targets =
|
let resolve_targets (setup : Main.setup) user_targets =
|
||||||
match user_targets with
|
match user_targets with
|
||||||
| [] -> []
|
| [] -> []
|
||||||
|
@ -147,14 +152,15 @@ let resolve_targets (setup : Main.setup) user_targets =
|
||||||
if Path.is_root path then
|
if Path.is_root path then
|
||||||
die "@ on the command line must be followed by a valid alias name"
|
die "@ on the command line must be followed by a valid alias name"
|
||||||
else
|
else
|
||||||
|
let name = Path.basename path in
|
||||||
let path =
|
let path =
|
||||||
if Path.is_in_build_dir path then
|
if Path.is_in_build_dir path ||
|
||||||
|
String_set.mem name aliases_in_source_tree then
|
||||||
path
|
path
|
||||||
else
|
else
|
||||||
Path.append setup.context.build_dir path
|
Path.append setup.context.build_dir path
|
||||||
in
|
in
|
||||||
let dir = Path.parent path in
|
let dir = Path.parent path in
|
||||||
let name = Path.basename path in
|
|
||||||
Alias (path, Alias.make ~dir name)
|
Alias (path, Alias.make ~dir name)
|
||||||
else
|
else
|
||||||
File (
|
File (
|
||||||
|
|
|
@ -130,7 +130,16 @@ Jbuilder doesn't read =<package>.opam= files, however when a
|
||||||
=<package>.opam= is present, Jbuilder will knows that the package
|
=<package>.opam= is present, Jbuilder will knows that the package
|
||||||
named =<package>= exists. It will know how to construct a
|
named =<package>= exists. It will know how to construct a
|
||||||
=<package>.install= file in the same directory, to handle installation
|
=<package>.install= file in the same directory, to handle installation
|
||||||
via [[https://opam.ocaml.org/][opam]].
|
via [[https://opam.ocaml.org/][opam]]. In addition, Jbuilder will also know how to build
|
||||||
|
=<package>.install= at the root of the workspace, for
|
||||||
|
convenience. Jbuilder also defines the =install= alias, which depends
|
||||||
|
on all the buildable =<package>.install= at the root of the
|
||||||
|
workspace. So for instance to build everything that is installable in
|
||||||
|
a workspace, run:
|
||||||
|
|
||||||
|
#+begin_src
|
||||||
|
$ jbuilder build @install
|
||||||
|
#+end_src
|
||||||
|
|
||||||
Declaring a package this way will allow you to add elements such as
|
Declaring a package this way will allow you to add elements such as
|
||||||
libraries, executables, documentations, ... to your package by
|
libraries, executables, documentations, ... to your package by
|
||||||
|
|
|
@ -1658,13 +1658,25 @@ module Gen(P : Params) = struct
|
||||||
install_file package_path package)
|
install_file package_path package)
|
||||||
|
|
||||||
let () =
|
let () =
|
||||||
if Path.basename ctx.build_dir = "default" then
|
let install_alias = Alias.make ~dir:ctx.build_dir "install" in
|
||||||
String_map.iter P.packages ~f:(fun ~key:pkg ~data:path ->
|
let global_install_alias = Alias.make ~dir:Path.root "install" in
|
||||||
let install_file = Path.relative path (pkg ^ ".install") in
|
let is_default = Path.basename ctx.build_dir = "default" in
|
||||||
add_rule
|
String_map.iter P.packages ~f:(fun ~key:pkg ~data:path ->
|
||||||
(Build.copy
|
let install_fn = pkg ^ ".install" in
|
||||||
~src:(Path.append ctx.build_dir install_file)
|
let in_source_dir = Path.relative path install_fn in
|
||||||
~dst:install_file))
|
let orig = Path.append ctx.build_dir in_source_dir in
|
||||||
|
let at_root_of_build_context = Path.relative ctx.build_dir install_fn in
|
||||||
|
if not (Path.is_root path) then
|
||||||
|
add_rule (Build.copy ~src:orig ~dst:at_root_of_build_context);
|
||||||
|
Alias.add_deps install_alias [at_root_of_build_context];
|
||||||
|
|
||||||
|
if is_default then begin
|
||||||
|
add_rule (Build.copy ~src:orig ~dst:in_source_dir);
|
||||||
|
let at_root = Path.relative Path.root install_fn in
|
||||||
|
if not (Path.is_root path) then
|
||||||
|
add_rule (Build.copy ~src:orig ~dst:at_root);
|
||||||
|
Alias.add_deps global_install_alias [at_root]
|
||||||
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
let gen ~context ~file_tree ~tree ~stanzas ~packages
|
let gen ~context ~file_tree ~tree ~stanzas ~packages
|
||||||
|
|
|
@ -80,7 +80,7 @@ module Local = struct
|
||||||
| t ->
|
| t ->
|
||||||
let len = String.length t in
|
let len = String.length t in
|
||||||
match String.rindex_from t (len - 1) '/' with
|
match String.rindex_from t (len - 1) '/' with
|
||||||
| exception Not_found -> ""
|
| exception Not_found -> t
|
||||||
| i -> String.sub t ~pos:(i + 1) ~len:(len - i - 1)
|
| i -> String.sub t ~pos:(i + 1) ~len:(len - i - 1)
|
||||||
|
|
||||||
let relative initial_t path =
|
let relative initial_t path =
|
||||||
|
|
Loading…
Reference in New Issue