diff mbox series

[13/15] kbuild: add support for ensuring headers are self-contained

Message ID 20190604101409.2078-14-yamada.masahiro@socionext.com
State New
Headers show
Series kbuild: refactor headers_install and support compile-test of UAPI headers | expand

Commit Message

Masahiro Yamada June 4, 2019, 10:14 a.m. UTC
From: Jani Nikula <jani.nikula@intel.com>


Sometimes it's useful to be able to explicitly ensure certain headers
remain self-contained, i.e. that they are compilable as standalone
units, by including and/or forward declaring everything they depend on.

Add special target header-test-y where individual Makefiles can add
headers to be tested if CONFIG_HEADER_TEST is enabled. This will
generate a dummy C file per header that gets built as part of extra-y.

Cc: Chris Wilson <chris@chris-wilson.co.uk>
Cc: Masahiro Yamada <yamada.masahiro@socionext.com>
Cc: Michal Marek <michal.lkml@markovi.net>
Signed-off-by: Jani Nikula <jani.nikula@intel.com>

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>

---

 Documentation/kbuild/makefiles.txt |  7 +++++++
 init/Kconfig                       |  9 +++++++++
 scripts/Makefile.build             | 10 ++++++++++
 scripts/Makefile.lib               |  3 +++
 4 files changed, 29 insertions(+)

-- 
2.17.1

Comments

Sam Ravnborg June 4, 2019, 5:25 p.m. UTC | #1
On Tue, Jun 04, 2019 at 03:42:48PM +0300, Jani Nikula wrote:
> Sometimes it's useful to be able to explicitly ensure certain headers

> remain self-contained, i.e. that they are compilable as standalone

> units, by including and/or forward declaring everything they depend on.

> 

> Add special target header-test-y where individual Makefiles can add

> headers to be tested if CONFIG_HEADER_TEST is enabled. This will

> generate a dummy C file per header that gets built as part of extra-y.

> 

> Cc: Chris Wilson <chris@chris-wilson.co.uk>

> Cc: Masahiro Yamada <yamada.masahiro@socionext.com>

> Cc: Michal Marek <michal.lkml@markovi.net>

> Cc: Sam Ravnborg <sam@ravnborg.org>

> Signed-off-by: Jani Nikula <jani.nikula@intel.com>


Looks good, thanks.

Reviewed-by: Sam Ravnborg <sam@ravnborg.org>
Masahiro Yamada June 18, 2019, 3:45 p.m. UTC | #2
On Wed, Jun 5, 2019 at 2:26 AM Sam Ravnborg <sam@ravnborg.org> wrote:
>

> On Tue, Jun 04, 2019 at 03:42:48PM +0300, Jani Nikula wrote:

> > Sometimes it's useful to be able to explicitly ensure certain headers

> > remain self-contained, i.e. that they are compilable as standalone

> > units, by including and/or forward declaring everything they depend on.

> >

> > Add special target header-test-y where individual Makefiles can add

> > headers to be tested if CONFIG_HEADER_TEST is enabled. This will

> > generate a dummy C file per header that gets built as part of extra-y.

> >

> > Cc: Chris Wilson <chris@chris-wilson.co.uk>

> > Cc: Masahiro Yamada <yamada.masahiro@socionext.com>

> > Cc: Michal Marek <michal.lkml@markovi.net>

> > Cc: Sam Ravnborg <sam@ravnborg.org>

> > Signed-off-by: Jani Nikula <jani.nikula@intel.com>

>

> Looks good, thanks.

>

> Reviewed-by: Sam Ravnborg <sam@ravnborg.org>

>


Applied to linux-kbuild.
Thanks.


-- 
Best Regards
Masahiro Yamada
diff mbox series

Patch

diff --git a/Documentation/kbuild/makefiles.txt b/Documentation/kbuild/makefiles.txt
index bac301a73a86..ca4b24ec0399 100644
--- a/Documentation/kbuild/makefiles.txt
+++ b/Documentation/kbuild/makefiles.txt
@@ -1018,6 +1018,13 @@  When kbuild executes, the following steps are followed (roughly):
 	In this example, extra-y is used to list object files that
 	shall be built, but shall not be linked as part of built-in.a.
 
+    header-test-y
+
+	header-test-y specifies headers (*.h) in the current directory that
+	should be compile tested to ensure they are self-contained,
+	i.e. compilable as standalone units. If CONFIG_HEADER_TEST is enabled,
+	this autogenerates dummy sources to include the headers, and builds them
+	as part of extra-y.
 
 --- 6.7 Commands useful for building a boot image
 
diff --git a/init/Kconfig b/init/Kconfig
index 36894c9fb420..02d8897b91fb 100644
--- a/init/Kconfig
+++ b/init/Kconfig
@@ -96,6 +96,15 @@  config COMPILE_TEST
 	  here. If you are a user/distributor, say N here to exclude useless
 	  drivers to be distributed.
 
+config HEADER_TEST
+	bool "Compile test headers that should be standalone compilable"
+	help
+	  Compile test headers listed in header-test-y target to ensure they are
+	  self-contained, i.e. compilable as standalone units.
+
+	  If you are a developer or tester and want to ensure the requested
+	  headers are self-contained, say Y here. Otherwise, choose N.
+
 config LOCALVERSION
 	string "Local version - append to kernel release"
 	help
diff --git a/scripts/Makefile.build b/scripts/Makefile.build
index ae9cf740633e..2b4d56483c2e 100644
--- a/scripts/Makefile.build
+++ b/scripts/Makefile.build
@@ -294,6 +294,16 @@  quiet_cmd_cc_lst_c = MKLST   $@
 $(obj)/%.lst: $(src)/%.c FORCE
 	$(call if_changed_dep,cc_lst_c)
 
+# Dummy C sources for header test (header-test-y target)
+# ---------------------------------------------------------------------------
+
+quiet_cmd_header_test = HDRTEST $@
+      cmd_header_test = echo "\#include \"$(<F)\"" > $@
+
+# FIXME: would be nice to be able to limit this implicit rule to header-test-y
+$(obj)/%.header_test.c: $(src)/%.h FORCE
+	$(call if_changed,header_test)
+
 # Compile assembler sources (.S)
 # ---------------------------------------------------------------------------
 
diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib
index f1f38c8cdc74..60a739a22b9c 100644
--- a/scripts/Makefile.lib
+++ b/scripts/Makefile.lib
@@ -66,6 +66,9 @@  extra-y += $(patsubst %.dtb,%.dt.yaml, $(dtb-y))
 extra-$(CONFIG_OF_ALL_DTBS) += $(patsubst %.dtb,%.dt.yaml, $(dtb-))
 endif
 
+# Test self-contained headers
+extra-$(CONFIG_HEADER_TEST) += $(patsubst %.h,%.header_test.o,$(header-test-y))
+
 # Add subdir path
 
 extra-y		:= $(addprefix $(obj)/,$(extra-y))