Add a "default" alias defined as follow:
- if "default" is specified by the user explicitely, use this definition - otherwise assume the following definition: (alias (name default) (deps (alias_rec install))) Signed-off-by: Jeremie Dimino <jeremie@dimino.org>
This commit is contained in:
parent
0a970aba35
commit
81bcd0f3e1
|
@ -95,6 +95,13 @@ next
|
||||||
|
|
||||||
- Version `dune-workspace` and `~/.config/dune/config` files (#..., @diml)
|
- Version `dune-workspace` and `~/.config/dune/config` files (#..., @diml)
|
||||||
|
|
||||||
|
- Add the ability to build an alias non-recursively from the command
|
||||||
|
line by writing `@@alias` (#926, @diml)
|
||||||
|
|
||||||
|
- Add a special `default` alias that defaults to `(alias_rec install)`
|
||||||
|
when not defined by the user and make `@@default` be the default
|
||||||
|
target (#926, @diml)
|
||||||
|
|
||||||
1.0+beta20 (10/04/2018)
|
1.0+beta20 (10/04/2018)
|
||||||
-----------------------
|
-----------------------
|
||||||
|
|
||||||
|
|
47
bin/main.ml
47
bin/main.ml
|
@ -26,6 +26,7 @@ type common =
|
||||||
; (* Original arguments for the external-lib-deps hint *)
|
; (* Original arguments for the external-lib-deps hint *)
|
||||||
orig_args : string list
|
orig_args : string list
|
||||||
; config : Config.t
|
; config : Config.t
|
||||||
|
; default_target : string
|
||||||
}
|
}
|
||||||
|
|
||||||
let prefix_target common s = common.target_prefix ^ s
|
let prefix_target common s = common.target_prefix ^ s
|
||||||
|
@ -234,6 +235,7 @@ let common =
|
||||||
ignore_promoted_rules,
|
ignore_promoted_rules,
|
||||||
config_file,
|
config_file,
|
||||||
profile,
|
profile,
|
||||||
|
default_target,
|
||||||
orig)
|
orig)
|
||||||
x
|
x
|
||||||
display
|
display
|
||||||
|
@ -296,6 +298,7 @@ let common =
|
||||||
; x
|
; x
|
||||||
; config
|
; config
|
||||||
; build_dir
|
; build_dir
|
||||||
|
; default_target
|
||||||
}
|
}
|
||||||
in
|
in
|
||||||
let docs = copts_sect in
|
let docs = copts_sect in
|
||||||
|
@ -484,6 +487,20 @@ let common =
|
||||||
in
|
in
|
||||||
Term.(ret (const merge $ config_file $ no_config))
|
Term.(ret (const merge $ config_file $ no_config))
|
||||||
in
|
in
|
||||||
|
let default_target_default =
|
||||||
|
match Which_program.t with
|
||||||
|
| Dune -> "@@default"
|
||||||
|
| Jbuilder -> "@install"
|
||||||
|
in
|
||||||
|
let default_target =
|
||||||
|
Arg.(value
|
||||||
|
& opt (some string) None
|
||||||
|
& info ["default-target"] ~docs ~docv:"TARGET"
|
||||||
|
~doc:(sprintf
|
||||||
|
{|Set the default target that when none is specified to
|
||||||
|
$(b,dune build). It defaults to %s.|}
|
||||||
|
default_target_default))
|
||||||
|
in
|
||||||
let for_release = "for-release-of-packages" in
|
let for_release = "for-release-of-packages" in
|
||||||
let frop =
|
let frop =
|
||||||
Arg.(value
|
Arg.(value
|
||||||
|
@ -496,33 +513,37 @@ let common =
|
||||||
packages as well as getting reproducible builds.|})
|
packages as well as getting reproducible builds.|})
|
||||||
in
|
in
|
||||||
let merge root only_packages ignore_promoted_rules
|
let merge root only_packages ignore_promoted_rules
|
||||||
(config_file_opt, config_file) profile release =
|
(config_file_opt, config_file) profile default_target release =
|
||||||
let fail opt = incompatible ("-p/--" ^ for_release) opt in
|
let fail opt = incompatible ("-p/--" ^ for_release) opt in
|
||||||
match release, root, only_packages, ignore_promoted_rules,
|
match release, root, only_packages, ignore_promoted_rules,
|
||||||
profile, config_file_opt with
|
profile, default_target, config_file_opt with
|
||||||
| Some _, Some _, _, _, _, _ -> fail "--root"
|
| Some _, Some _, _, _, _, _, _ -> fail "--root"
|
||||||
| Some _, _, Some _, _, _, _ -> fail "--only-packages"
|
| Some _, _, Some _, _, _, _, _ -> fail "--only-packages"
|
||||||
| Some _, _, _, true , _, _ -> fail "--ignore-promoted-rules"
|
| Some _, _, _, true , _, _, _ -> fail "--ignore-promoted-rules"
|
||||||
| Some _, _, _, _, Some _, _ -> fail "--profile"
|
| Some _, _, _, _, Some _, _, _ -> fail "--profile"
|
||||||
| Some _, _, _, _, _, Some s -> fail s
|
| Some _, _, _, _, _, Some s, _ -> fail s
|
||||||
| Some pkgs, None, None, false, None, None ->
|
| Some _, _, _, _, _, _, Some _ -> fail "--default-target"
|
||||||
|
| Some pkgs, None, None, false, None, None, None ->
|
||||||
`Ok (Some ".",
|
`Ok (Some ".",
|
||||||
Some pkgs,
|
Some pkgs,
|
||||||
true,
|
true,
|
||||||
No_config,
|
No_config,
|
||||||
Some "release",
|
Some "release",
|
||||||
|
"@install",
|
||||||
["-p"; pkgs]
|
["-p"; pkgs]
|
||||||
)
|
)
|
||||||
| None, _, _, _, _, _ ->
|
| None, _, _, _, _, _, _ ->
|
||||||
`Ok (root,
|
`Ok (root,
|
||||||
only_packages,
|
only_packages,
|
||||||
ignore_promoted_rules,
|
ignore_promoted_rules,
|
||||||
config_file,
|
config_file,
|
||||||
profile,
|
profile,
|
||||||
|
Option.value default_target ~default:default_target_default,
|
||||||
List.concat
|
List.concat
|
||||||
[ dump_opt "--root" root
|
[ dump_opt "--root" root
|
||||||
; dump_opt "--only-packages" only_packages
|
; dump_opt "--only-packages" only_packages
|
||||||
; dump_opt "--profile" profile
|
; dump_opt "--profile" profile
|
||||||
|
; dump_opt "--default-target" default_target
|
||||||
; if ignore_promoted_rules then
|
; if ignore_promoted_rules then
|
||||||
["--ignore-promoted-rules"]
|
["--ignore-promoted-rules"]
|
||||||
else
|
else
|
||||||
|
@ -540,6 +561,7 @@ let common =
|
||||||
$ ignore_promoted_rules
|
$ ignore_promoted_rules
|
||||||
$ config_file
|
$ config_file
|
||||||
$ profile
|
$ profile
|
||||||
|
$ default_target
|
||||||
$ frop))
|
$ frop))
|
||||||
in
|
in
|
||||||
let x =
|
let x =
|
||||||
|
@ -771,9 +793,14 @@ let build_targets =
|
||||||
(Main.setup ~log common >>= fun setup ->
|
(Main.setup ~log common >>= fun setup ->
|
||||||
let targets = resolve_targets_exn ~log common setup targets in
|
let targets = resolve_targets_exn ~log common setup targets in
|
||||||
do_build setup targets) in
|
do_build setup targets) in
|
||||||
|
let default_target =
|
||||||
|
match Which_program.t with
|
||||||
|
| Dune -> "@@default"
|
||||||
|
| Jbuilder -> "@install"
|
||||||
|
in
|
||||||
( Term.(const go
|
( Term.(const go
|
||||||
$ common
|
$ common
|
||||||
$ Arg.(value & pos_all string ["@install"] name_))
|
$ Arg.(value & pos_all string [default_target] name_))
|
||||||
, Term.info "build" ~doc ~man)
|
, Term.info "build" ~doc ~man)
|
||||||
|
|
||||||
let runtest =
|
let runtest =
|
||||||
|
|
|
@ -531,6 +531,8 @@ menhir
|
||||||
A ``menhir`` stanza is available to support the menhir_ parser generator. See
|
A ``menhir`` stanza is available to support the menhir_ parser generator. See
|
||||||
the :ref:`menhir-main` section for details.
|
the :ref:`menhir-main` section for details.
|
||||||
|
|
||||||
|
.. _alias-stanza:
|
||||||
|
|
||||||
alias
|
alias
|
||||||
-----
|
-----
|
||||||
|
|
||||||
|
|
|
@ -50,6 +50,9 @@ Terminology
|
||||||
alias in all children directories recursively. Jbuilder defines the
|
alias in all children directories recursively. Jbuilder defines the
|
||||||
following standard aliases:
|
following standard aliases:
|
||||||
|
|
||||||
|
- ``default`` which is the alias build by default when no targets
|
||||||
|
are specified on the command line. See :ref:`default-alias` for
|
||||||
|
details
|
||||||
- ``runtest`` which runs user defined tests
|
- ``runtest`` which runs user defined tests
|
||||||
- ``install`` which depends on everything that should be installed
|
- ``install`` which depends on everything that should be installed
|
||||||
- ``doc`` which depends on the generated HTML
|
- ``doc`` which depends on the generated HTML
|
||||||
|
|
|
@ -68,8 +68,9 @@ directory as this is normally the case.
|
||||||
Interpretation of targets
|
Interpretation of targets
|
||||||
=========================
|
=========================
|
||||||
|
|
||||||
This section describes how ``jbuilder`` interprets the targets given on
|
This section describes how ``dune`` interprets the targets given on
|
||||||
the command line.
|
the command line. When no targets are specified, ``dune`` builds the
|
||||||
|
``default`` alias, see :ref:`default-alias` for more details.
|
||||||
|
|
||||||
Resolution
|
Resolution
|
||||||
----------
|
----------
|
||||||
|
@ -128,6 +129,31 @@ You can also build an alias non-recursively by using ``@@`` instead of
|
||||||
|
|
||||||
dune build @@runtest
|
dune build @@runtest
|
||||||
|
|
||||||
|
.. _default-alias:
|
||||||
|
|
||||||
|
Default alias
|
||||||
|
-------------
|
||||||
|
|
||||||
|
When no targets are given to ``dune build``, it builds the special
|
||||||
|
``default`` alias. Effectively ``dune build`` is equivalent to:
|
||||||
|
|
||||||
|
.. code::
|
||||||
|
|
||||||
|
dune build @@default
|
||||||
|
|
||||||
|
When a directory doesn't explicitly define what the ``default`` alias
|
||||||
|
means via an :ref:`alias-stanza` stanza, the following implicit
|
||||||
|
definition is assumed:
|
||||||
|
|
||||||
|
.. code::
|
||||||
|
|
||||||
|
(alias
|
||||||
|
(name default)
|
||||||
|
(deps (alias_rec install)))
|
||||||
|
|
||||||
|
Which means that by default ``dune build`` will build everything that
|
||||||
|
is installable.
|
||||||
|
|
||||||
Finding external libraries
|
Finding external libraries
|
||||||
==========================
|
==========================
|
||||||
|
|
||||||
|
@ -214,7 +240,7 @@ follows:
|
||||||
build: [["dune" "build" "-p" name "-j" jobs]]
|
build: [["dune" "build" "-p" name "-j" jobs]]
|
||||||
|
|
||||||
``-p pkg`` is a shorthand for ``--root . --only-packages pkg --profile
|
``-p pkg`` is a shorthand for ``--root . --only-packages pkg --profile
|
||||||
release``. ``-p`` is the short version of
|
release --default-target @install``. ``-p`` is the short version of
|
||||||
``--for-release-of-packages``.
|
``--for-release-of-packages``.
|
||||||
|
|
||||||
This has the following effects:
|
This has the following effects:
|
||||||
|
@ -224,6 +250,7 @@ This has the following effects:
|
||||||
- it sets the root to prevent jbuilder from looking it up
|
- it sets the root to prevent jbuilder from looking it up
|
||||||
- it sets the build profile to ``release``
|
- it sets the build profile to ``release``
|
||||||
- it uses whatever concurrency option opam provides
|
- it uses whatever concurrency option opam provides
|
||||||
|
- it sets the default target to ``@install`` rather than ``@@default``
|
||||||
|
|
||||||
Note that ``name`` and ``jobs`` are variables expanded by opam. ``name``
|
Note that ``name`` and ``jobs`` are variables expanded by opam. ``name``
|
||||||
expands to the package name and ``jobs`` to the number of jobs available
|
expands to the package name and ``jobs`` to the number of jobs available
|
||||||
|
|
|
@ -271,7 +271,7 @@ module Alias0 = struct
|
||||||
stamp_file (make ~dir name)))
|
stamp_file (make ~dir name)))
|
||||||
|
|
||||||
let is_standard = function
|
let is_standard = function
|
||||||
| "runtest" | "install" | "doc" | "doc-private" | "lint" -> true
|
| "runtest" | "install" | "doc" | "doc-private" | "lint" | "default" -> true
|
||||||
| _ -> false
|
| _ -> false
|
||||||
|
|
||||||
open Build.O
|
open Build.O
|
||||||
|
@ -318,7 +318,7 @@ module Alias0 = struct
|
||||||
It is not defined in %s or any of its descendants."
|
It is not defined in %s or any of its descendants."
|
||||||
name (Path.to_string_maybe_quoted src_dir)
|
name (Path.to_string_maybe_quoted src_dir)
|
||||||
|
|
||||||
let default = make "DEFAULT"
|
let default = make "default"
|
||||||
let runtest = make "runtest"
|
let runtest = make "runtest"
|
||||||
let install = make "install"
|
let install = make "install"
|
||||||
let doc = make "doc"
|
let doc = make "doc"
|
||||||
|
@ -914,7 +914,28 @@ and load_dir_step2_exn t ~dir ~collector ~lazy_generators =
|
||||||
let alias_dir = Path.append (Path.relative alias_dir context_name) sub_dir in
|
let alias_dir = Path.append (Path.relative alias_dir context_name) sub_dir in
|
||||||
let alias_rules, alias_stamp_files =
|
let alias_rules, alias_stamp_files =
|
||||||
let open Build.O in
|
let open Build.O in
|
||||||
String.Map.foldi collector.aliases ~init:([], Path.Set.empty)
|
let aliases = collector.aliases in
|
||||||
|
let aliases =
|
||||||
|
if String.Map.mem collector.aliases "default" then
|
||||||
|
aliases
|
||||||
|
else
|
||||||
|
match Path.extract_build_context_dir dir with
|
||||||
|
| None -> aliases
|
||||||
|
| Some (_, src_dir) ->
|
||||||
|
match File_tree.find_dir t.file_tree src_dir with
|
||||||
|
| None -> aliases
|
||||||
|
| Some _ ->
|
||||||
|
String.Map.add aliases "default"
|
||||||
|
{ deps = Path.Set.empty
|
||||||
|
; dyn_deps =
|
||||||
|
Alias0.dep_rec (Alias0.install ~dir) ~loc:Loc.none
|
||||||
|
~file_tree:t.file_tree
|
||||||
|
>>>
|
||||||
|
Build.return Path.Set.empty
|
||||||
|
; actions = []
|
||||||
|
}
|
||||||
|
in
|
||||||
|
String.Map.foldi aliases ~init:([], Path.Set.empty)
|
||||||
~f:(fun name { Dir_status. deps; dyn_deps; actions } (rules, alias_stamp_files) ->
|
~f:(fun name { Dir_status. deps; dyn_deps; actions } (rules, alias_stamp_files) ->
|
||||||
let base_path = Path.relative alias_dir name in
|
let base_path = Path.relative alias_dir name in
|
||||||
let rules, deps =
|
let rules, deps =
|
||||||
|
|
Loading…
Reference in New Issue