git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
David Aguilar <davvid@gmail.com>
Date
Sep 14, 2014, 01:00 UTC
Message-ID
<1410656450-96087-1-git-send-email-davvid@gmail.com>

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
Next: David Aguilar
Message 1 of 2 in “Makefile: add check-headers target”
  1. 1/2 Makefile: add check-headers targetDavid Aguilar, Sep 14, 2014
  2. 2/2 headers: include dependent headersDavid Aguilar, Sep 14, 2014

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.