From: David Aguilar <davvid@gmail.com>
To: Junio C Hamano <gitster@pobox.com>
Cc: git@vger.kernel.org, "Jeff King" <peff@peff.net>,
"Jonathan Nieder" <jrnieder@gmail.com>,
"René Scharfe" <l.s.r@web.de>,
"Matthieu Moy" <Matthieu.Moy@grenoble-inp.fr>
Subject: [PATCH 1/2] check-headers: add header usage checks for .c files
Date: Sun, 14 Sep 2014 00:40:44 -0700 [thread overview]
Message-ID: <1410680445-84593-1-git-send-email-davvid@gmail.com> (raw)
Teach check-header.sh to ensure that the first included header in .c
files is either git-compat-util.h, builtin.h, or cache.h.
Ensure that common-cmds.h is only included by help.c.
Move the logic into functions so that we can skip parts of the check.
Signed-off-by: David Aguilar <davvid@gmail.com>
---
This depends on my previous patch that adds check-header.sh.
| 66 +++++++++++++++++++++++++++++++++++++++++++++++++++-----
1 file changed, 61 insertions(+), 5 deletions(-)
--git a/check-headers.sh b/check-headers.sh
index ef06f56..7f25e7a 100755
--- a/check-headers.sh
+++ b/check-headers.sh
@@ -1,5 +1,9 @@
#!/bin/sh
+# This script is run via make.
+# "make check-headers SKIP_HEADER_CHECK=1" skips the header dependency check.
+# "make check-headers SKIP_USAGE_CHECK=1" skips the header usage check.
+
exit_code=0
maybe_exit () {
@@ -14,11 +18,11 @@ maybe_exit () {
fi
}
-for header in *.h ewah/*.h vcs-svn/*.h xdiff/*.h
-do
+check_header () {
+ header="$1"
case "$header" in
common-cmds.h)
- # should only be included by help.c
+ # should only be included by help.c, not checked
;;
*)
subdir=$(dirname "$header") &&
@@ -29,6 +33,58 @@ do
maybe_exit $?
;;
esac
-done
+}
+
+check_headers () {
+ for header in *.h ewah/*.h vcs-svn/*.h xdiff/*.h
+ do
+ check_header "$header"
+ done
+}
+
+check_header_usage () {
+ first=$(grep '^#include' "$1" |
+ head -n1 |
+ sed -e 's,#include ",,' -e 's,"$,,')
+
+ case "$first" in
+ cache.h|builtin.h|git-compat-util.h)
+ # happy
+ ;;
+ *)
+ echo "error: $1 must #include \"git-compat-util.h\" before $first"
+ maybe_exit 1
+ ;;
+ esac
+
+ if grep common-cmds.h "$1" >/dev/null && test "$1" != help.c
+ then
+ echo "error: $1 must not include common-cmds.h"
+ maybe_exit 1
+ fi
+}
+
+check_usage () {
+ # Implementation files should #include git-compat-util.h, cache.h,
+ # or builtin.h before any others.
+ for impl in *.c builtin/*.c
+ do
+ check_header_usage "$impl"
+ done
+}
+
+main () {
+ if test -z "$SKIP_HEADER_CHECK"
+ then
+ check_headers "$@"
+ fi
+
+ if test -z "$SKIP_USAGE_CHECK"
+ then
+ check_usage
+ fi
+
+ exit $exit_code
+}
-exit $exit_code
+main "$@"
--
2.1.0.241.ga16d620
next reply other threads:[~2014-09-14 7:41 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-09-14 7:40 David Aguilar [this message]
2014-09-14 7:40 ` [PATCH 2/2] cleanups: ensure that git-compat-util.h is included first David Aguilar
2014-09-15 19:14 ` [PATCH 1/2] check-headers: add header usage checks for .c files Junio C Hamano
2014-09-15 19:16 ` Junio C Hamano
2014-09-15 19:19 ` Junio C Hamano
2014-09-15 19:49 ` David Aguilar
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1410680445-84593-1-git-send-email-davvid@gmail.com \
--to=davvid@gmail.com \
--cc=Matthieu.Moy@grenoble-inp.fr \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=jrnieder@gmail.com \
--cc=l.s.r@web.de \
--cc=peff@peff.net \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.