bug-gnulib
[Top][All Lists]
Advanced

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

[PATCH] maint.mk: syntax-check: prohibit HAVE_<header>_H that are always


From: Jim Meyering
Subject: [PATCH] maint.mk: syntax-check: prohibit HAVE_<header>_H that are always true
Date: Tue, 27 Apr 2010 14:15:20 +0200

I've just pushed the patch below.
It exposed a few unnecessary #if tests in coreutils:

  http://git.sv.gnu.org/gitweb/?p=coreutils.git;a=commitdiff;h=2191fe8f8d84e3

Initially I planned to have one rule per checked header,
in order to give diagnostics saying precisely what HAVE_HEADER_H
symbols is unnecessary (especially useful on long #if lines
that test more than one symbol), but that would have meant
making one pass over all source files for each and every symbol.
Currently we have 51 such header files.  No thank you.
Hence the compromise of searching for all of them at once,
with the downside that occasionally you'll be warned about
a line like this one (from the patch above)

  # if HAVE_NETINET_IN_H && HAVE_NFS_NFS_CLNT_H && HAVE_NFS_VFS_H

and it'll be up to you to determine which it's talking about.

One solution would be to use grep's --color option,
if a test determines it's available.  Alternatively,
write some perl to do something similar.  I haven't been
motivated to do that yet.  Patches welcome.

>From e98ea566d814c4e7df9f8988a01e4f970a427745 Mon Sep 17 00:00:00 2001
From: Jim Meyering <address@hidden>
Date: Fri, 9 Apr 2010 19:07:57 +0200
Subject: [PATCH] maint.mk: syntax-check: prohibit HAVE_<header>_H that are 
always true

Derive the list of guaranteed header names from gnulib/lib/*.in.h,
and use that to create a regexp used to detect all #if HAVE_..._H uses.
* top/maint.mk (sc_prohibit_always_true_header_tests): New rule.
(gl_assured_headers_, az_, AZ_): Define.
(gl_header_upper_case_or_, gl_have_header_regex_): Define.
---
 ChangeLog    |    9 +++++++++
 top/maint.mk |   22 ++++++++++++++++++++++
 2 files changed, 31 insertions(+), 0 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 06a4ce4..64a9a3e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2010-04-27  Jim Meyering  <address@hidden>
+
+       maint.mk: syntax-check: prohibit HAVE_<header>_H that are always true
+       Derive the list of guaranteed header names from gnulib/lib/*.in.h,
+       and use that to create a regexp used to detect all #if HAVE_..._H uses.
+       * top/maint.mk (sc_prohibit_always_true_header_tests): New rule.
+       (gl_assured_headers_, az_, AZ_): Define.
+       (gl_header_upper_case_or_, gl_have_header_regex_): Define.
+
 2010-04-26  Jim Meyering  <address@hidden>
            Bruno Haible  <address@hidden>

diff --git a/top/maint.mk b/top/maint.mk
index 33803f3..159fe83 100644
--- a/top/maint.mk
+++ b/top/maint.mk
@@ -645,6 +645,28 @@ sc_useless_cpp_parens:
        halt='found useless parentheses in cpp directive'               \
          $(_sc_search_regexp)

+# List headers for which HAVE_HEADER_H is always true, assuming you are
+# using the appropriate gnulib module.  CAUTION: for each "unnecessary"
+# #if HAVE_HEADER_H that you remove, be sure that your project explicitly
+# requires the gnulib module that guarantees the usability of that header.
+gl_assured_headers_ := \
+  $(shell cd $(gnulib_dir)/lib && ls -1 *.in.h|sed 's/\.in\.h$$/ \\/')
+
+# Convert the list of names to upper case, and replace each space with "|".
+az_ = abcdefghijklmnopqrstuvwxyz
+AZ_ = ABCDEFGHIJKLMNOPQRSTUVWXYZ
+gl_header_upper_case_or_ := \
+  $(shell echo $(gl_assured_headers_)                                  \
+    | tr $(az_)/.- $(AZ_)___                                           \
+    | tr -s ' ' '|'                                                    \
+   )
+gl_have_header_regex_ = HAVE_($(gl_header_upper_case_or_))_H
+sc_prohibit_always_true_header_tests:
+       @prohibit='\<$(gl_have_header_regex_)\>'                        \
+       halt='do not test the above HAVE_<header>_H symbol(s);\n'\
+'  with the corresponding gnulib module, they are always true'         \
+         $(_sc_search_regexp)
+
 # Prohibit checked in backup files.
 sc_prohibit_backup_files:
        @$(VC_LIST) | grep '~$$' &&                             \
--
1.7.1.328.g9993c




reply via email to

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