[v3,7/7] buildtools/chkincs: test headers for C++ compatibility

Message ID 20220210140355.586399-8-bruce.richardson@intel.com (mailing list archive)
State Superseded, archived
Delegated to: Thomas Monjalon
Headers
Series Verify C++ compatibility of public headers |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/github-robot: build fail github build: failed

Commit Message

Bruce Richardson Feb. 10, 2022, 2:03 p.m. UTC
  Add support for checking each of our headers for issues when included in
a C++ file.

Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
---
 .ci/linux-build.sh             |  1 +
 buildtools/chkincs/main.cpp    |  4 ++++
 buildtools/chkincs/meson.build | 20 ++++++++++++++++++++
 3 files changed, 25 insertions(+)
 create mode 100644 buildtools/chkincs/main.cpp
  

Comments

David Marchand Feb. 10, 2022, 2:37 p.m. UTC | #1
On Thu, Feb 10, 2022 at 3:05 PM Bruce Richardson
<bruce.richardson@intel.com> wrote:
>
> Add support for checking each of our headers for issues when included in
> a C++ file.
>
> Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
> ---
>  .ci/linux-build.sh             |  1 +
>  buildtools/chkincs/main.cpp    |  4 ++++
>  buildtools/chkincs/meson.build | 20 ++++++++++++++++++++
>  3 files changed, 25 insertions(+)
>  create mode 100644 buildtools/chkincs/main.cpp
>
> diff --git a/.ci/linux-build.sh b/.ci/linux-build.sh
> index c10c1a8ab5..67d68535e0 100755
> --- a/.ci/linux-build.sh
> +++ b/.ci/linux-build.sh
> @@ -74,6 +74,7 @@ fi
>
>  if [ "$BUILD_32BIT" = "true" ]; then
>      OPTS="$OPTS -Dc_args=-m32 -Dc_link_args=-m32"
> +    OPTS="$OPTS -Dcpp_args=-m32 -Dcpp_link_args=-m32"
>      export PKG_CONFIG_LIBDIR="/usr/lib32/pkgconfig"
>  fi
>

Even though check_includes=true is not forced for 32bits in
test-meson-builds.sh, I sometimes enable more checks for some targets.
Can this change be applied to test-meson-builds.sh too?

https://git.dpdk.org/dpdk/tree/devtools/test-meson-builds.sh#n249
  
Bruce Richardson Feb. 10, 2022, 3:21 p.m. UTC | #2
On Thu, Feb 10, 2022 at 03:37:04PM +0100, David Marchand wrote:
> On Thu, Feb 10, 2022 at 3:05 PM Bruce Richardson
> <bruce.richardson@intel.com> wrote:
> >
> > Add support for checking each of our headers for issues when included in
> > a C++ file.
> >
> > Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
> > ---
> >  .ci/linux-build.sh             |  1 +
> >  buildtools/chkincs/main.cpp    |  4 ++++
> >  buildtools/chkincs/meson.build | 20 ++++++++++++++++++++
> >  3 files changed, 25 insertions(+)
> >  create mode 100644 buildtools/chkincs/main.cpp
> >
> > diff --git a/.ci/linux-build.sh b/.ci/linux-build.sh
> > index c10c1a8ab5..67d68535e0 100755
> > --- a/.ci/linux-build.sh
> > +++ b/.ci/linux-build.sh
> > @@ -74,6 +74,7 @@ fi
> >
> >  if [ "$BUILD_32BIT" = "true" ]; then
> >      OPTS="$OPTS -Dc_args=-m32 -Dc_link_args=-m32"
> > +    OPTS="$OPTS -Dcpp_args=-m32 -Dcpp_link_args=-m32"
> >      export PKG_CONFIG_LIBDIR="/usr/lib32/pkgconfig"
> >  fi
> >
> 
> Even though check_includes=true is not forced for 32bits in
> test-meson-builds.sh, I sometimes enable more checks for some targets.
> Can this change be applied to test-meson-builds.sh too?
> 
> https://git.dpdk.org/dpdk/tree/devtools/test-meson-builds.sh#n249
> 
Yes, will do.
  

Patch

diff --git a/.ci/linux-build.sh b/.ci/linux-build.sh
index c10c1a8ab5..67d68535e0 100755
--- a/.ci/linux-build.sh
+++ b/.ci/linux-build.sh
@@ -74,6 +74,7 @@  fi
 
 if [ "$BUILD_32BIT" = "true" ]; then
     OPTS="$OPTS -Dc_args=-m32 -Dc_link_args=-m32"
+    OPTS="$OPTS -Dcpp_args=-m32 -Dcpp_link_args=-m32"
     export PKG_CONFIG_LIBDIR="/usr/lib32/pkgconfig"
 fi
 
diff --git a/buildtools/chkincs/main.cpp b/buildtools/chkincs/main.cpp
new file mode 100644
index 0000000000..d25bb8852a
--- /dev/null
+++ b/buildtools/chkincs/main.cpp
@@ -0,0 +1,4 @@ 
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2021 Intel Corporation
+ */
+int main(void) { return 0; }
diff --git a/buildtools/chkincs/meson.build b/buildtools/chkincs/meson.build
index 5ffca89761..beabcd55d8 100644
--- a/buildtools/chkincs/meson.build
+++ b/buildtools/chkincs/meson.build
@@ -28,3 +28,23 @@  executable('chkincs', sources,
         dependencies: deps,
         link_whole: dpdk_static_libraries + dpdk_drivers,
         install: false)
+
+# run tests for c++ builds also
+if not add_languages('cpp', required: false)
+    subdir_done()
+endif
+
+gen_cpp_files = generator(gen_c_file_for_header,
+        output: '@BASENAME@.cpp',
+        arguments: ['@INPUT@', '@OUTPUT@'])
+
+cpp_sources = files('main.cpp')
+cpp_sources += gen_cpp_files.process(dpdk_chkinc_headers)
+
+executable('chkincs-cpp', cpp_sources,
+        cpp_args: ['-include', 'rte_config.h', cflags],
+        link_args: dpdk_extra_ldflags,
+        include_directories: includes,
+        dependencies: deps,
+        link_whole: dpdk_static_libraries + dpdk_drivers,
+        install: false)