copy-and-add-line-directive --> copy#

This commit is contained in:
Jeremie Dimino 2017-06-05 12:10:39 +01:00
parent 7ec081419c
commit a392b59fcd
6 changed files with 52 additions and 12 deletions

View File

@ -16,6 +16,8 @@
- Deprecate `per_file` in preprocessing specifications and
rename it `per_module`
- Deprecate `copy-and-add-line-directive` and rename it `copy#`
- Inside user actions, `${^}` now includes files matches by
`(glob_files ...)` or `(file_recursively_in ...)`

View File

@ -914,13 +914,30 @@ The following constructions are available:
- ``(echo <string>)`` to output a string on stdout
- ``(cat <file>)`` to print the contents of a file to stdout
- ``(copy <src> <dst>)`` to copy a file
- ``(copy-and-add-line-directive <src> <dst>)`` to copy a file and add a line
directive at the beginning
- ``(copy# <src> <dst>)`` to copy a file and add a line directive at
the beginning
- ``(system <cmd>)`` to execute a command using the system shell: ``sh`` on Unix
and ``cmd`` on Windows
- ``(bash <cmd>)`` to execute a command using ``/bin/bash``. This is obviously
not very portable
As mentioned ``copy#`` inserts a line directive at the beginning of
the destination file. More precisely, it inserts the following line:
.. code:: ocaml
# 1 "<source file name>"
Most languages recognize such lines and update their current location,
in order to report errors in the original file rather than the
copy. This is important as the copy exists only under the ``_build``
directory and in order for editors to jump to errors when parsing the
output of the build system, errors must point to files that exist in
the source tree. In the beta versions of jbuilder, ``copy#`` was
called ``copy-and-add-line-directive``. However, most of time one
wants this behavior rather than a bare copy, so it was renamed to
something shorter.
Note: expansion of the special ``${<kind>:...}`` is done relative to the current
working directory of the part of the DSL being executed. So for instance if you
have this action in a ``src/foo/jbuild``:

View File

@ -138,7 +138,10 @@ struct
(* We don't expose symlink to the user yet since this might complicate things *)
; cstr "symlink" (a @> a @> nil) (fun src dst -> Symlink (dst, Cat src))
*)
; cstr "copy-and-add-line-directive" (path @> path @> nil) (fun src dst ->
; cstr "copy#" (path @> path @> nil) (fun src dst ->
Copy_and_add_line_directive (src, dst))
; cstr_loc "copy-and-add-line-directive" (path @> path @> nil) (fun loc src dst ->
Loc.warn loc "copy-and-add-line-directive is deprecated, use copy# instead";
Copy_and_add_line_directive (src, dst))
; cstr "system" (string @> nil) (fun cmd -> System cmd)
; cstr "bash" (string @> nil) (fun cmd -> Bash cmd)
@ -169,7 +172,7 @@ struct
| Symlink (x, y) ->
List [Atom "symlink"; path x; path y]
| Copy_and_add_line_directive (x, y) ->
List [Atom "copy-and-add-line-directive"; path x; path y]
List [Atom "copy#"; path x; path y]
| System x -> List [Atom "system"; string x]
| Bash x -> List [Atom "bash"; string x]
| Update_file (x, y) -> List [Atom "update-file"; path x; string y]

View File

@ -427,17 +427,22 @@ module Of_sexp = struct
{ name : string
; args : ('a, 'b) Constructor_args_spec.t
; rest : ('b, 'c) rest
; make : 'a
; make : Loc.t -> 'a
}
type 'a t = T : (_, _, 'a) unpacked -> 'a t
end
let cstr_rest name args rest make =
let cstr_loc name args make =
Constructor_spec.T { name; args; make; rest = No_rest }
let cstr_rest_loc name args rest make =
Constructor_spec.T { name; args; make; rest = Many rest }
let cstr name args make =
Constructor_spec.T { name; args; make; rest = No_rest }
cstr_loc name args (fun _ -> make)
let cstr_rest name args rest make =
cstr_rest_loc name args rest (fun _ -> make)
let equal_cstr_name a b = Name.compare a b = 0
@ -457,17 +462,17 @@ module Of_sexp = struct
let sum cstrs sexp =
match sexp with
| Atom (_, s) -> begin
| Atom (loc, s) -> begin
let (Constructor_spec.T c) = find_cstr cstrs sexp s in
Constructor_args_spec.convert c.args c.rest sexp [] c.make
Constructor_args_spec.convert c.args c.rest sexp [] (c.make loc)
end
| List (_, []) -> of_sexp_error sexp "non-empty list expected"
| List (_, name_sexp :: args) ->
| List (loc, name_sexp :: args) ->
match name_sexp with
| List _ -> of_sexp_error name_sexp "Atom expected"
| Atom (_, s) ->
let (Constructor_spec.T c) = find_cstr cstrs sexp s in
Constructor_args_spec.convert c.args c.rest sexp args c.make
Constructor_args_spec.convert c.args c.rest sexp args (c.make loc)
let enum cstrs sexp =
match sexp with

View File

@ -105,6 +105,19 @@ module Of_sexp : sig
-> 'a
-> 'c Constructor_spec.t
val cstr_loc
: string
-> ('a, 'b) Constructor_args_spec.t
-> (Loc.t -> 'a)
-> 'b Constructor_spec.t
val cstr_rest_loc
: string
-> ('a, 'b list -> 'c) Constructor_args_spec.t
-> 'b t
-> (Loc.t -> 'a)
-> 'c Constructor_spec.t
val sum
: 'a Constructor_spec.t list
-> 'a t

View File

@ -9,4 +9,4 @@
(rule
((targets (opamParserTypes.ml))
(deps (opamParserTypes.mli))
(action (copy-and-add-line-directive ${<} ${@}))))
(action (copy# ${<} ${@}))))