[PATCH 3/3] buildtools/chkincs: add checks for missing C++ guards
Bruce Richardson
bruce.richardson at intel.com
Tue Feb 15 18:30:29 CET 2022
Simply compiling a C header with a C++ compiler is not enough to flag
missing 'extern "C"' guards. To catch missing guards, we can just use a
simple grep for the 'extern "C"' part, and error out if any files have a
miss.
Signed-off-by: Bruce Richardson <bruce.richardson at intel.com>
---
Depends-on: series-21685 ("add missing C++ guards")
---
buildtools/chkincs/meson.build | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/buildtools/chkincs/meson.build b/buildtools/chkincs/meson.build
index 9442235200..77ef59fb13 100644
--- a/buildtools/chkincs/meson.build
+++ b/buildtools/chkincs/meson.build
@@ -37,6 +37,16 @@ if not add_languages('cpp', required: false)
subdir_done()
endif
+# check for extern C in files, since this is not detected as an error by the compiler
+grep = find_program('grep', required: false)
+if grep.found()
+ errlist = run_command([grep, '--files-without-match', '^extern "C"', dpdk_chkinc_headers],
+ check: false, capture: true).stdout().split()
+ if errlist != []
+ error('Files missing C++ \'extern "C"\' guards:\n- ' + '\n- '.join(errlist))
+ endif
+endif
+
gen_cpp_files = generator(gen_c_file_for_header,
output: '@BASENAME at .cpp',
arguments: ['@INPUT@', '@OUTPUT@'])
--
2.32.0
More information about the dev
mailing list