[PATCH v4 1/2] Makefile: add check-headers target

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxx>
Helped-by: Junio C Hamano <gitster@xxxxxxxxx>
Helped-by: Matthieu Moy <Matthieu.Moy@xxxxxxxxxxxxxxx>
Signed-off-by: David Aguilar <davvid@xxxxxxxxx>
---
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

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]