[libvirt] [PATCHv2 0/2] Rewrite prohibit-duplicate-header in perl

v2: * use minuses instead of underscores in make target * actually call it during syntax-check * output file name and line for ViM integration Ján Tomko (2): syntax-check: rewrite prohibit-duplicate-header in perl prohibit-duplicate-header: print file name and line build-aux/prohibit-duplicate-header.pl | 26 ++++++++++++++++++++++++++ cfg.mk | 32 +++++++------------------------- 2 files changed, 33 insertions(+), 25 deletions(-) create mode 100644 build-aux/prohibit-duplicate-header.pl -- 2.7.3

Invoke the script only once instead of once for every file. --- build-aux/prohibit-duplicate-header.pl | 22 ++++++++++++++++++++++ cfg.mk | 32 +++++++------------------------- 2 files changed, 29 insertions(+), 25 deletions(-) create mode 100644 build-aux/prohibit-duplicate-header.pl diff --git a/build-aux/prohibit-duplicate-header.pl b/build-aux/prohibit-duplicate-header.pl new file mode 100644 index 0000000..f9ab3f5 --- /dev/null +++ b/build-aux/prohibit-duplicate-header.pl @@ -0,0 +1,22 @@ +#!/usr/bin/perl + +use strict; + +my $file = " "; +my $ret = 0; +my %includes = ( ); + +while (<>) { + if (not $file eq $ARGV) { + %includes = ( ); + $file = $ARGV; + } + if (/^# *include *[<"]([^>"]*\.h)[">]/) { + $includes{$1}++; + if ($includes{$1} == 2) { + $ret = 1; + print STDERR "$1 included multiple times in $ARGV\n"; + } + } +} +exit $ret; diff --git a/cfg.mk b/cfg.mk index 31da9f9..5d9b554 100644 --- a/cfg.mk +++ b/cfg.mk @@ -814,30 +814,6 @@ sc_prohibit_exit_in_tests: halt='use return, not exit(), in tests' \ $(_sc_search_regexp) -# Don't include duplicate header in the source (either *.c or *.h) -sc_prohibit_duplicate_header: - @fail=0; for i in $$($(VC_LIST_EXCEPT) | grep '\.[chx]$$'); do \ - awk '/# *include.*\.h/ { \ - match($$0, /[<"][^>"]*[">]/); \ - arr[substr($$0, RSTART + 1, RLENGTH - 2)]++; \ - } \ - END { \ - for (key in arr) { \ - if (arr[key] > 1) { \ - fail=1; \ - printf("%d %s are included\n", arr[key], key); \ - } \ - } \ - if (fail == 1) { \ - printf("duplicate header(s) in " FILENAME "\n"); \ - exit 1; \ - } \ - }' $$i || fail=1; \ - done; \ - if test $$fail -eq 1; then \ - { echo '$(ME): avoid duplicate headers' 1>&2; exit 1; } \ - fi; - # Don't include "libvirt/*.h" in "" form. sc_prohibit_include_public_headers_quote: @prohibit='# *include *"libvirt/.*\.h"' \ @@ -1098,9 +1074,15 @@ _autogen: # regenerate HACKING as part of the syntax-check ifneq ($(_gl-Makefile),) -syntax-check: $(top_srcdir)/HACKING spacing-check test-wrap-argv +syntax-check: $(top_srcdir)/HACKING spacing-check test-wrap-argv \ + prohibit-duplicate-header endif +# Don't include duplicate header in the source (either *.c or *.h) +prohibit-duplicate-header: + $(AM_V_GEN)files=$$($(VC_LIST_EXCEPT) | grep '\.[chx]$$'); \ + $(PERL) -W $(top_srcdir)/build-aux/prohibit-duplicate-header.pl $$files + spacing-check: $(AM_V_GEN)files=`$(VC_LIST) | grep '\.c$$'`; \ $(PERL) $(top_srcdir)/build-aux/check-spacing.pl $$files || \ -- 2.7.3

This way :make syntax-check in ViM will point you at the offending line. --- build-aux/prohibit-duplicate-header.pl | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/build-aux/prohibit-duplicate-header.pl b/build-aux/prohibit-duplicate-header.pl index f9ab3f5..f0539ae 100644 --- a/build-aux/prohibit-duplicate-header.pl +++ b/build-aux/prohibit-duplicate-header.pl @@ -5,17 +5,21 @@ use strict; my $file = " "; my $ret = 0; my %includes = ( ); +my $lineno = 0; while (<>) { if (not $file eq $ARGV) { %includes = ( ); $file = $ARGV; + $lineno = 0; } + $lineno++; if (/^# *include *[<"]([^>"]*\.h)[">]/) { $includes{$1}++; if ($includes{$1} == 2) { $ret = 1; - print STDERR "$1 included multiple times in $ARGV\n"; + print STDERR "$ARGV:$lineno: $_"; + print STDERR "Do not include a header more than once per file\n"; } } } -- 2.7.3

On Thu, Jun 23, 2016 at 06:23:35AM +0200, Ján Tomko wrote:
v2: * use minuses instead of underscores in make target * actually call it during syntax-check * output file name and line for ViM integration
I think there's still some error because it works in Emacs as well. But that can be resolved later. ACK series.
Ján Tomko (2): syntax-check: rewrite prohibit-duplicate-header in perl prohibit-duplicate-header: print file name and line
build-aux/prohibit-duplicate-header.pl | 26 ++++++++++++++++++++++++++ cfg.mk | 32 +++++++------------------------- 2 files changed, 33 insertions(+), 25 deletions(-) create mode 100644 build-aux/prohibit-duplicate-header.pl
-- 2.7.3
-- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
participants (2)
-
Ján Tomko
-
Martin Kletzander