Check that no targets are generated outside of the current dir

This commit is contained in:
Jeremie Dimino 2017-05-31 10:34:17 +01:00
parent 745e58039b
commit 1c8ffaa3aa
2 changed files with 47 additions and 0 deletions

View File

@ -297,6 +297,45 @@ currently don't support patterns, such as a rule to produce ``%.y``
from ``%.x`` for any given ``%``. This might be supported in the
future.
do (inferred rules)
-------------------
When using the action DSL (see `User actions`_), it is most of the
time obvious what are the dependencies and targets.
For instance:
.. code:: scheme
(rule
((targets (b)
(deps (a)
(action (copy ${<} ${@}))))))
In this example it is obvious by inspecting the action what the
dependencies and targets are. For this reason Jbuilder provides a
simpler way to define rules where Jbuilder infers dependencies and
targets for you. This is available through the ``do`` stanza:
.. code:: scheme
(do <action>)
For instance:
.. code:: scheme
(do (copy a b))
Note that in Jbuilder, targets must always be known
statically. Especially, this mean that Jbuilder must be able to
statically determine all targets. For instance, this ``(do ...)``
stanza is rejected by Jbuilder:
.. code:: scheme
(do (copy a b.${read:file}))
ocamllex
--------

View File

@ -613,6 +613,14 @@ module Action = struct
{ deps; targets = Pset.union targets targets_written_by_user }
in
let targets = Pset.elements targets in
List.iter targets ~f:(fun target ->
if Path.parent target <> dir then
Loc.fail (Loc.in_file (Utils.jbuild_name_in ~dir))
"A rule in this jbuild has targets in a different directory \
than the current one, this is not allowed by Jbuilder at the moment:\n%s"
(List.map targets ~f:(fun target ->
sprintf "- %s" (Utils.describe_target target))
|> String.concat ~sep:"\n"));
let build =
Build.record_lib_deps_simple ~dir forms.lib_deps
>>>