[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20250402124656.629226-2-jani.nikula@intel.com>
Date: Wed, 2 Apr 2025 15:46:53 +0300
From: Jani Nikula <jani.nikula@...el.com>
To: Linus Torvalds <torvalds@...ux-foundation.org>,
linux-kernel@...r.kernel.org
Cc: jani.nikula@...el.com,
Jason Gunthorpe <jgg@...dia.com>,
Masahiro Yamada <masahiroy@...nel.org>,
David Airlie <airlied@...il.com>,
Simona Vetter <simona.vetter@...ll.ch>,
linux-kbuild@...r.kernel.org,
dri-devel@...ts.freedesktop.org,
intel-xe@...ts.freedesktop.org,
intel-gfx@...ts.freedesktop.org
Subject: [PATCH v2 1/4] kbuild: add generic header check facility
Resurrect a generic header check facility. Check that the headers are
self-contained, have header guards, and (if enabled separately) pass
kernel-doc. Run header checks on .h files listed in header-check-y or
header-check-m, relative to $(src).
Hide header check artifacts under a .header-check subdirectory at the
top level of the build output directory.
Add the facility behind CONFIG_HEADER_CHECK_DISABLE, reversed to keep
the feature disabled for allmodconfig and allyesconfig builds. Also add
a proxy CONFIG_HEADER_CHECK option to simplify dependencies on the
facility. The kernel-doc check requires CONFIG_HEADER_CHECK_KERNEL_DOC.
Cc: Linus Torvalds <torvalds@...ux-foundation.org>
Cc: Masahiro Yamada <masahiroy@...nel.org>
Cc: David Airlie <airlied@...il.com>
Cc: Simona Vetter <simona.vetter@...ll.ch>
Signed-off-by: Jani Nikula <jani.nikula@...el.com>
---
Cc: linux-kbuild@...r.kernel.org
Cc: dri-devel@...ts.freedesktop.org
Cc: intel-xe@...ts.freedesktop.org
Cc: intel-gfx@...ts.freedesktop.org
---
init/Kconfig | 25 +++++++++++++++++++++++++
scripts/Makefile.build | 13 +++++++++++++
scripts/Makefile.lib | 7 +++++++
3 files changed, 45 insertions(+)
diff --git a/init/Kconfig b/init/Kconfig
index 681f38ee68db..2678a5ba7b93 100644
--- a/init/Kconfig
+++ b/init/Kconfig
@@ -217,6 +217,31 @@ config UAPI_HEADER_TEST
If you are a developer or tester and want to ensure the exported
headers are self-contained, say Y here. Otherwise, choose N.
+# Reversed option to disable on allyesconfig/allmodconfig builds
+config HEADER_CHECK_DISABLE
+ bool "Disable extra build-time header checks"
+ default y
+ help
+ Disable extra build-time header checks. The checks may be
+ overzealous. They may slow down or fail the build altogether. They may
+ create excessive dependency files in the tree. They should not be
+ enabled for regular builds, and thus they are disabled by default.
+
+# Proxy config to allow simple "depends on HEADER_CHECK"
+config HEADER_CHECK
+ bool
+ depends on EXPERT && HEADER_CHECK_DISABLE=n
+ default !HEADER_CHECK_DISABLE
+
+config HEADER_CHECK_KERNEL_DOC
+ bool "Run kernel-doc as part of header checks"
+ depends on HEADER_CHECK
+ default n
+ help
+ Run kernel-doc as part of header checks. In addition to compiling,
+ also check kernel-doc comments. With CONFIG_WERROR=y, kernel-doc
+ warnings are treated as errors.
+
config LOCALVERSION
string "Local version - append to kernel release"
help
diff --git a/scripts/Makefile.build b/scripts/Makefile.build
index 56be83024851..f963b2356b0e 100644
--- a/scripts/Makefile.build
+++ b/scripts/Makefile.build
@@ -223,6 +223,19 @@ quiet_cmd_cc_lst_c = MKLST $@
$(obj)/%.lst: $(obj)/%.c FORCE
$(call if_changed_dep,cc_lst_c)
+# Compile C headers (.h) for header check
+# ---------------------------------------------------------------------------
+
+# Include the header twice to detect missing include guard.
+quiet_cmd_header_check = HDRCHK $(patsubst $(srctree)/%,%,$<)
+ cmd_header_check = \
+ $(CC) $(c_flags) -fsyntax-only -x c /dev/null -include $< -include $<; \
+ $(if $(CONFIG_HEADER_CHECK_KERNEL_DOC),$(srctree)/scripts/kernel-doc -none $(if $(CONFIG_WERROR),-Werror) $<,true); \
+ touch $@
+
+.header-check/$(obj)/%.header-check: $(src)/%.h FORCE
+ $(call if_changed_dep,header_check)
+
# Compile Rust sources (.rs)
# ---------------------------------------------------------------------------
diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib
index 57620b439a1f..272a1b42292e 100644
--- a/scripts/Makefile.lib
+++ b/scripts/Makefile.lib
@@ -89,6 +89,13 @@ multi-obj-m := $(addprefix $(obj)/, $(multi-obj-m))
subdir-ym := $(addprefix $(obj)/,$(subdir-ym))
endif
+# Header checks
+# header-check-y/m contain .h files to be checked, relative to $(src)
+
+header-check-y := $(addprefix .header-check/$(obj)/,$(patsubst %.h,%.header-check,$(header-check-y) $(header-check-m)))
+
+always-$(CONFIG_HEADER_CHECK) += $(header-check-y)
+
# Finds the multi-part object the current object will be linked into.
# If the object belongs to two or more multi-part objects, list them all.
modname-multi = $(sort $(foreach m,$(multi-obj-ym),\
--
2.39.5
Powered by blists - more mailing lists