[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 3/4] maint.mk: speed up require_config_h_first
From: |
Ján Tomko |
Subject: |
[PATCH 3/4] maint.mk: speed up require_config_h_first |
Date: |
Tue, 26 Jul 2016 16:28:16 +0200 |
Instead of spawning three processes per file, rewrite the check
in perl and run it once for all the files.
---
Alternatively, grep --max-count 1 could help with getting rid of
the per-file commands and extra sed, but I don't know if it's
portable enough.
ChangeLog | 7 +++++++
top/maint.mk | 25 ++++++++++++++++++-------
2 files changed, 25 insertions(+), 7 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index b698a6c..64e2026 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
2016-07-26 Ján Tomko <address@hidden>
+ maint.mk: speed up require_config_h_first
+
+ Instead of spawning three processes per file, rewrite the check
+ in perl and run it once for all the files.
+
+2016-07-26 Ján Tomko <address@hidden>
+
maint.mk: expand the prohibit_doubled_word regex
This check has a static list of words that are checked for
diff --git a/top/maint.mk b/top/maint.mk
index b074609..3cd79bc 100644
--- a/top/maint.mk
+++ b/top/maint.mk
@@ -437,17 +437,28 @@ sc_require_config_h:
halt='the above files do not include <config.h>' \
$(_sc_search_regexp)
+# Print all filenames where the first include does not match
+# $(config_h_header)
+#
+# Like grep -m 1, this only looks at the first match.
+perl_config_h_first_ = \
+ -e 'BEGIN {$$ret = 0}' \
+ -e 'if (/^\# *include\b/) {' \
+ -e ' if (not m{^\# *include $(config_h_header)}) {' \
+ -e ' print "$$ARGV\n";' \
+ -e ' $$ret = 1;'
\
+ -e ' }' \
+ -e ' \# Move on to next file after first include' \
+ -e ' close ARGV;' \
+ -e '}' \
+ -e 'END {exit $$ret}'
+
# You must include <config.h> before including any other header file.
# This can possibly be via a package-specific header, if given by cfg.mk.
sc_require_config_h_first:
@if $(VC_LIST_EXCEPT) | grep '\.c$$' > /dev/null; then \
- fail=0; \
- for i in $$($(VC_LIST_EXCEPT) | grep '\.c$$'); do \
- grep '^# *include\>' $$i | $(SED) 1q \
- | grep -E '^# *include $(config_h_header)' > /dev/null \
- || { echo $$i; fail=1; }; \
- done; \
- test $$fail = 1 && \
+ files=$$($(VC_LIST_EXCEPT) | grep '\.c$$') && \
+ perl -n $(perl_config_h_first_) $$files || \
{ echo '$(ME): the above files include some other header' \
'before <config.h>' 1>&2; exit 1; } || :; \
else :; \
--
2.7.3