]> git.droids-corp.org - dpdk.git/commitdiff
buildtools/chkincs: check missing C++ guards
authorBruce Richardson <bruce.richardson@intel.com>
Tue, 15 Feb 2022 17:30:29 +0000 (17:30 +0000)
committerThomas Monjalon <thomas@monjalon.net>
Tue, 22 Feb 2022 14:26:15 +0000 (15:26 +0100)
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@intel.com>
Acked-by: Tyler Retzlaff <roretzla@linux.microsoft.com>
buildtools/chkincs/meson.build

index 9bb19c9ba3be4139cfc196e46b89a6e47bdbf9ba..378c2f19ef11f7f582d7366fc6242d23d74467a8 100644 (file)
@@ -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@.cpp',
         arguments: ['@INPUT@', '@OUTPUT@'])