bug-gnulib@gnu.org mirror (unofficial)
 help / color / mirror / Atom feed
From: Jim Meyering <jim@meyering.net>
To: Bruno Haible <bruno@clisp.org>
Cc: bug-gnulib@gnu.org, Collin Funk <collin.funk1@gmail.com>
Subject: Re: syntax-check rule to silence -Winclude-next-absolute-path warning
Date: Sun, 18 Feb 2024 21:02:27 -0800	[thread overview]
Message-ID: <CA+8g5KFVGSaLyzo6XGH6n7fP5wMBKwzCFxgbJLzOxywEeCs-=g@mail.gmail.com> (raw)
In-Reply-To: <68001545.3F2A3RajZp@nimes>

[-- Attachment #1: Type: text/plain, Size: 1814 bytes --]

On Sun, Feb 18, 2024 at 12:33 PM Bruno Haible <bruno@clisp.org> wrote:
> Collin Funk wrote:
> > I attached a patch that seems to work alright. I'm not the greatest with GNU Make so it isn't very pretty. Feel free to modify it as much as you would like.
> >
> > Here is some sample output from Coreutils. One or two are real so I'll submit a patch there.
> >
> > [collin@debian coreutils]$ make sc_verify_absolute_include_headers
> > verify_absolute_include_headers
> > maint.mk: Use #include <sys/stat.h> instead of  #include "sys/stat.h" in src/od.c
> > maint.mk: Use #include <error.h> instead of  #include "error.h" in src/od.c
> > maint.mk: Use #include <getopt.h> instead of  #include "getopt.h" in src/shuf.c
> > maint.mk: Use #include <getopt.h> instead of  #include "getopt.h" in src/stat.c
> > maint.mk: Use #include <error.h> instead of  #include "error.h" in src/system.h
>
> Very nice! I committed your patch, just at a different location in maint.mk (near
> the handling of <config.h>).
>
> Also, I added references to the Gnulib documentation:
>
> 2024-02-18  Bruno Haible  <bruno@clisp.org>
>
>         maint.mk: Add more comments.
>         * top/maint.mk: Reference the Gnulib documentation where suitable.

Thank you both. I've just pushed an improvement.
The new version runs grep only once rather than many times, and seems simpler.
The output is like this, now (from gnu grep, which I've just fixed):

src/grep.c:39:#include "error.h"
src/grep.c:44:#include "getopt.h"
src/grep.c:49:#include "search.h"
src/kwsearch.c:22:#include "search.h"
src/pcresearch.c:21:#include "search.h"
src/searchutils.c:23:#include "search.h"
maint.mk: Use #include <hdr.h>, not #include "hdr.h" for the above
make: *** [maint.mk:615: sc_prefer_angle_bracket_headers] Error 1

[-- Attachment #2: gl_prefer_angle_bracket_headers.diff --]
[-- Type: application/octet-stream, Size: 3150 bytes --]

From 6da9c0af52101930eba7b5c496d35111d29a6d04 Mon Sep 17 00:00:00 2001
From: Jim Meyering <meyering@meta.com>
Date: Sun, 18 Feb 2024 20:23:28 -0800
Subject: [PATCH] maint.mk: improve new syntax-check rule

* top/maint.mk (sc_prefer_angle_bracket_headers): Rename from
sc_verify_absolute_include_headers.  Simplify to run a single
invocation of grep, rather than usually many.  Derive a regular
expression matching the selected headers, and warn about any
offending matches via what is usually a single grep invocation.
---
 ChangeLog    |  9 +++++++++
 top/maint.mk | 27 +++++++++------------------
 2 files changed, 18 insertions(+), 18 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 3a8559bfb3..1fe354f2b0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2024-02-18  Jim Meyering  <meyering@meta.com>
+
+	maint.mk: improve new syntax-check rule
+	* top/maint.mk (sc_prefer_angle_bracket_headers): Rename from
+	sc_verify_absolute_include_headers.  Simplify to run a single
+	invocation of grep, rather than usually many.  Derive a regular
+	expression matching the selected headers, and warn about any
+	offending matches via what is usually a single grep invocation.
+
 2024-02-18  Bruno Haible  <bruno@clisp.org>

 	maint.mk: Add more comments.
diff --git a/top/maint.mk b/top/maint.mk
index 5746b911dd..2278619931 100644
--- a/top/maint.mk
+++ b/top/maint.mk
@@ -539,7 +539,7 @@ sc_require_config_h_first:

 # Generated headers that override system headers.
 # Keep sorted.
-gl_absolute_include_headers_ ?= \
+gl_prefer_angle_bracket_headers_ ?= \
   alloca.h		\
   arpa_inet.h		\
   assert.h		\
@@ -608,26 +608,17 @@ gl_absolute_include_headers_ ?= \
   wchar.h		\
   wctype.h

+# Remove each .h suffix and change each space to "|".
+angle_bracket_header_re = \
+  $(subst $(_sp),|,$(patsubst %.h,%,$(gl_prefer_angle_bracket_headers_)))
+
 # Suggest using '#include <header.h>' instead of '#include "header.h"' for
 # headers that override system headers.
 # Rationale: The Gnulib documentation, node 'Style of #include statements'.
-sc_verify_absolute_include_headers:
-	@if $(VC_LIST_EXCEPT) | $(GREP) '\.c$$' > /dev/null; then	\
-	  source_files=$$($(VC_LIST_EXCEPT) | $(GREP) '\.\(c\|h\)$$');	\
-	  for source_file in $$source_files; do				\
-	    local_includes=$$($(GREP) -h '^ *# *include "[^"]\+"' 	\
-                              $$source_file | $(SED) 			\
-                              -e 's/^[^"]\+"//g' -e 's/"$///g');	\
-	    for local_include in $$local_includes; do			\
-	      for header in $(gl_absolute_include_headers_); do         \
-	        if test "$$header" = "$$local_include";	then		\
-	          echo "$(ME): Use #include <$$header> instead of "     \
-	               "#include \"$$header\" in $$source_file" 2>&1;	\
-	        fi;							\
-	      done;							\
-	    done;							\
-          done;								\
-	fi;
+sc_prefer_angle_bracket_headers:
+	@prohibit='^ *# *include "($(angle_bracket_header_re))\.h"'	\
+	halt='Use #include <hdr.h>, not #include "hdr.h" for the above'	\
+	  $(_sc_search_regexp)

 sc_prohibit_HAVE_MBRTOWC:
 	@prohibit='\bHAVE_MBRTOWC\b'					\
-- 
2.41.0.376.gcba07a324d


  reply	other threads:[~2024-02-19  5:03 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-17  8:36 [PATCH] math: Silence -Winclude-next-absolute-path warning Collin Funk
2024-02-17 10:51 ` Bruno Haible
2024-02-17 12:26   ` Collin Funk
2024-02-17 13:17     ` Bruno Haible
2024-02-18 12:19     ` Bruno Haible
2024-02-18 12:44       ` syntax-check rule to silence " Bruno Haible
2024-02-18 20:12         ` Collin Funk
2024-02-18 20:33           ` Bruno Haible
2024-02-19  5:02             ` Jim Meyering [this message]
2024-02-19 18:11               ` Collin Funk
2024-02-19 18:32                 ` Jim Meyering
2024-02-19  8:45             ` Simon Josefsson via Gnulib discussion list
2024-02-19 20:39               ` Jim Meyering
2024-02-20 15:17               ` Bruno Haible
2024-02-20 20:23         ` Collin Funk
2024-02-20 20:49           ` Bruno Haible
2024-02-19  6:31       ` [PATCH] math: Silence " Paul Eggert
2024-02-19 11:03         ` Bruno Haible
2024-02-19 20:41           ` Paul Eggert
2024-02-19 21:24             ` Bruno Haible
2024-02-19 21:45               ` Paul Eggert

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://lists.gnu.org/mailman/listinfo/bug-gnulib

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CA+8g5KFVGSaLyzo6XGH6n7fP5wMBKwzCFxgbJLzOxywEeCs-=g@mail.gmail.com' \
    --to=jim@meyering.net \
    --cc=bruno@clisp.org \
    --cc=bug-gnulib@gnu.org \
    --cc=collin.funk1@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).