From a392b59fcd0a2db237c087e0c44f3368b3a94a7c Mon Sep 17 00:00:00 2001 From: Jeremie Dimino Date: Mon, 5 Jun 2017 12:10:39 +0100 Subject: [PATCH] copy-and-add-line-directive --> copy# --- CHANGES.md | 2 ++ doc/jbuild.rst | 21 +++++++++++++++++++-- src/action.ml | 7 +++++-- src/sexp.ml | 19 ++++++++++++------- src/sexp.mli | 13 +++++++++++++ vendor/opam-file-format/src/jbuild | 2 +- 6 files changed, 52 insertions(+), 12 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index db001741..6528e6eb 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -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 ...)` diff --git a/doc/jbuild.rst b/doc/jbuild.rst index 933e9e38..f28957fe 100644 --- a/doc/jbuild.rst +++ b/doc/jbuild.rst @@ -914,13 +914,30 @@ The following constructions are available: - ``(echo )`` to output a string on stdout - ``(cat )`` to print the contents of a file to stdout - ``(copy )`` to copy a file -- ``(copy-and-add-line-directive )`` to copy a file and add a line - directive at the beginning +- ``(copy# )`` to copy a file and add a line directive at + the beginning - ``(system )`` to execute a command using the system shell: ``sh`` on Unix and ``cmd`` on Windows - ``(bash )`` 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 "" + +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 ``${:...}`` 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``: diff --git a/src/action.ml b/src/action.ml index 3d33793d..40bf1ddf 100644 --- a/src/action.ml +++ b/src/action.ml @@ -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] diff --git a/src/sexp.ml b/src/sexp.ml index 478860f1..b3bc019c 100644 --- a/src/sexp.ml +++ b/src/sexp.ml @@ -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 diff --git a/src/sexp.mli b/src/sexp.mli index be5a96bf..31bd4520 100644 --- a/src/sexp.mli +++ b/src/sexp.mli @@ -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 diff --git a/vendor/opam-file-format/src/jbuild b/vendor/opam-file-format/src/jbuild index ff7943fb..8e9094cd 100644 --- a/vendor/opam-file-format/src/jbuild +++ b/vendor/opam-file-format/src/jbuild @@ -9,4 +9,4 @@ (rule ((targets (opamParserTypes.ml)) (deps (opamParserTypes.mli)) - (action (copy-and-add-line-directive ${<} ${@})))) + (action (copy# ${<} ${@}))))