bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] maint.mk: allow fine-grained syntax-check exclusion via Make var


From: Jim Meyering
Subject: [PATCH] maint.mk: allow fine-grained syntax-check exclusion via Make variables
Date: Wed, 16 Mar 2011 12:20:07 +0100

Jim Meyering wrote:
> Reuben Thomas wrote:
>> make syntax-check is complaining about space-tabs (sc_space_tab) in a
>> sort of file where this is perfectly permissable: a .diff file. Why do
>> I have a diff file in version control? Because I'm patching gnulib.
>>
>> Of course, I can add this to VC_LIST_ALWAYS_EXCLUDE_REGEX, but maybe
>> .diff files should be excluded from this check anyway?
>
> They're expected only in .diff files for which
> the original has context lines that start with a TAB.
> For that reason (in gnulib, that is only a very small fraction
> of all files), I think it's slightly better to let those who
> need it add a line like this to a file named .x-sc_space_tab
>
> ^gl/lib/.*\.c\.diff$
>
> However, I find that adding a whole new .x-sc_* file
> just to exempt an exceptional source file from one of the
> many syntax checks is a disproportionate burden.
> It has always bothered me to do that.
>
> So finally, here's a proposed maint.mk patch to implement a better way,
> followed by the change induced in coreutils where I remove its 24
> .x-sc_* files, replacing them with just 30 lines at the end of cfg.mk:
>
> Notes on the naming of these new exception-specifying variables:
>   - the resulting variable names are rather long.  I erred on the side
>   of being too descriptive.  They're going to be used at most once, then
>   probably forgotten forever.
>
>   - I don't like the fact that they have a common *suffix* rather
>   than a common prefix.  That's just what I did in the first cut.
>   They do have a common sc_ suffix, so maybe that's ok,
>   but the long common part, -exclude_file_name_regexp is at the end,
>   and that makes the list in cfg.mk harder to read, so I'm leaning
>   towards reversing, i.e., changing this
>     sc_space_tab-exclude_file_name_regexp = \
>   to this
>     _exclude_file_name_regexp--sc_space_tab = \
>   Note the leading underscore and two hyphens.  The former to make
>   it less likely to collied with application names, and the latter
>   to make it clearer where the long common prefix ends and the
>   variable suffix starts.
>
> Plus I'll have to split the long line 10 lines down:

I've done the above and have just pushed this change.
Thanks for inspiring me to do this, Reuben.

>From 0baae9cadd08c9704e3c704dd69fb75640293e9d Mon Sep 17 00:00:00 2001
From: Jim Meyering <address@hidden>
Date: Wed, 16 Mar 2011 12:14:21 +0100
Subject: [PATCH] maint.mk: allow fine-grained syntax-check exclusion via Make
 variables

Before, you would have had to create one .x-sc_ file per rule in order
to exempt offending files.  Now, you may instead use a Make variable --
usually defined in cfg.mk -- whose name identifies the affected rule.
* top/maint.mk (_sc_excl): Define.
(VC_LIST_EXCEPT): Use it to exclude names on a per-rule basis.
(_sc_search_regexp): When not using VC_LIST_EXCEPT, exclude here, too.
---
 ChangeLog    |   10 ++++++++++
 top/maint.mk |   17 +++++++++++++++--
 2 files changed, 25 insertions(+), 2 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index a7c00b4..917e834 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2011-03-16  Jim Meyering  <address@hidden>
+
+       maint.mk: allow fine-grained syntax-check exclusion via Make variables
+       Before, you would have had to create one .x-sc_ file per rule in order
+       to exempt offending files.  Now, you may instead use a Make variable --
+       usually defined in cfg.mk -- whose name identifies the affected rule.
+       * top/maint.mk (_sc_excl): Define.
+       (VC_LIST_EXCEPT): Use it to exclude names on a per-rule basis.
+       (_sc_search_regexp): When not using VC_LIST_EXCEPT, exclude here, too.
+
 2011-03-13  Bruno Haible  <address@hidden>

        ignore-value tests: Avoid warnings.
diff --git a/top/maint.mk b/top/maint.mk
index 303e9c1..1df8c7a 100644
--- a/top/maint.mk
+++ b/top/maint.mk
@@ -57,11 +57,13 @@ endif
 # In order to be able to consistently filter "."-relative names,
 # (i.e., with no $(srcdir) prefix), this definition is careful to
 # remove any $(srcdir) prefix, and to restore what it removes.
+_sc_excl = \
+  $(if $(exclude_file_name_regexp--$@),$(exclude_file_name_regexp--$@),^$$)
 VC_LIST_EXCEPT = \
   $(VC_LIST) | sed 's|^$(_dot_escaped_srcdir)/||' \
        | if test -f $(srcdir)/.x-$@; then grep -vEf $(srcdir)/.x-$@; \
          else grep -Ev -e "$${VC_LIST_EXCEPT_DEFAULT-ChangeLog}"; fi \
-       | grep -Ev -e '$(VC_LIST_ALWAYS_EXCLUDE_REGEX)' \
+       | grep -Ev -e '($(VC_LIST_ALWAYS_EXCLUDE_REGEX)|$(_sc_excl))' \
        $(_prepend_srcdir_prefix)

 ifeq ($(origin prev_version_file), undefined)
@@ -196,6 +198,16 @@ syntax-check: $(local-check)
 #  halt
 #
 #     Message to display before to halting execution.
+#
+# Finally, you may exempt files based on an ERE matching file names.
+# For example, to exempt from the sc_space_tab check all files with the
+# .diff suffix, set this Make variable:
+#
+# exclude_file_name_regexp--sc_space_tab = \.diff$
+#
+# Note that while this functionality is mostly inherited via VC_LIST_EXCEPT,
+# when filtering by name via in_files, we explicitly filter out matching
+# names here as well.

 # By default, _sc_search_regexp does not ignore case.
 export ignore_case =
@@ -233,7 +245,8 @@ define _sc_search_regexp
                                                                        \
    : Filter by file name;                                              \
    if test -n "$$in_files"; then                                       \
-     files=$$(find $(srcdir) | grep -E "$$in_files");                  \
+     files=$$(find $(srcdir) | grep -E "$$in_files"                    \
+              | grep -Ev '$(exclude_file_name_regexp--$@)');           \
    else                                                                        
\
      files=$$($(VC_LIST_EXCEPT));                                      \
      if test -n "$$in_vc_files"; then                                  \
--
1.7.4.1.408.gb6b16



reply via email to

[Prev in Thread] Current Thread [Next in Thread]