git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: David Aguilar <davvid@gmail.com>
To: Junio C Hamano <gitster@pobox.com>
Cc: git@vger.kernel.org, "Jeff King" <peff@peff.net>,
	"René Scharfe" <l.s.r@web.de>,
	"Jonathan Nieder" <jrnieder@gmail.com>,
	"Matthieu Moy" <Matthieu.Moy@grenoble-inp.fr>
Subject: [PATCH v4 1/2] Makefile: add check-headers target
Date: Sat, 13 Sep 2014 18:00:49 -0700	[thread overview]
Message-ID: <1410656450-96087-1-git-send-email-davvid@gmail.com> (raw)

This allows us to ensure that each header can be included
individually without needing to include other headers first.

Implicitly include git-compat-util.h during the check since
the implementation files will have already included it.

Helped-by: Jonathan Nieder <jrnieder@gmail.com>
Helped-by: Junio C Hamano <gitster@pobox.com>
Helped-by: Matthieu Moy <Matthieu.Moy@grenoble-inp.fr>
Signed-off-by: David Aguilar <davvid@gmail.com>
---
Changes since last time:

We now automatically include git-compat-util.h during the check
per the CodingGuidelines rule to always include it in all .c files.

We now use a case statement to special-case common-cmds.h, which
allows us to replace usage of git ls-files and a pipe with a simpler
for header in ... loop.

 Makefile         |  6 ++++++
 check-headers.sh | 34 ++++++++++++++++++++++++++++++++++
 2 files changed, 40 insertions(+)
 create mode 100755 check-headers.sh

diff --git a/Makefile b/Makefile
index e0f15a3..d7c9225 100644
--- a/Makefile
+++ b/Makefile
@@ -2408,6 +2408,12 @@ check-docs::
 check-builtins::
 	./check-builtins.sh
 
+### Make sure headers include their dependencies
+#
+check-headers::
+	./check-headers.sh $(CC) $(ALL_CFLAGS) $(EXTRA_CPPFLAGS)
+
+
 ### Test suite coverage testing
 #
 .PHONY: coverage coverage-clean coverage-compile coverage-test coverage-report
diff --git a/check-headers.sh b/check-headers.sh
new file mode 100755
index 0000000..ef06f56
--- /dev/null
+++ b/check-headers.sh
@@ -0,0 +1,34 @@
+#!/bin/sh
+
+exit_code=0
+
+maybe_exit () {
+	status="$1"
+	if test "$status" != 0
+	then
+		exit_code="$status"
+		if test -n "$CHECK_HEADERS_STOP"
+		then
+			exit "$status"
+		fi
+	fi
+}
+
+for header in *.h ewah/*.h vcs-svn/*.h xdiff/*.h
+do
+	case "$header" in
+	common-cmds.h)
+		# should only be included by help.c
+		;;
+	*)
+		subdir=$(dirname "$header") &&
+		echo "HEADER $header" &&
+		"$@" -Wno-unused -I"$subdir" -include git-compat-util.h \
+			-c -o "$header".check -x c - <"$header" &&
+		rm "$header".check ||
+		maybe_exit $?
+		;;
+	esac
+done
+
+exit $exit_code
-- 
2.0.4.1.g929bde9

             reply	other threads:[~2014-09-14  1:01 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-09-14  1:00 David Aguilar [this message]
2014-09-14  1:00 ` [PATCH v4 2/2] headers: include dependent headers 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=1410656450-96087-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 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 NNTP newsgroup(s).