From 5466c5be26ad00207e0c572d08286908d401576a Mon Sep 17 00:00:00 2001 From: Ehsan Saei <71217171+esigo@users.noreply.github.com> Date: Wed, 5 Jul 2023 18:30:43 +0200 Subject: [PATCH] Add Include what you use (#2214) --- ci/do_ci.sh | 22 ++++++++++++++++++---- ci/setup_ci_environment.sh | 3 ++- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/ci/do_ci.sh b/ci/do_ci.sh index e4e4807c82..42bf3df416 100755 --- a/ci/do_ci.sh +++ b/ci/do_ci.sh @@ -59,6 +59,16 @@ mkdir -p "${BUILD_DIR}" [ -z "${PLUGIN_DIR}" ] && export PLUGIN_DIR=$HOME/plugin mkdir -p "${PLUGIN_DIR}" +IWYU="" +MAKE_COMMAND="make -k -j \$(nproc)" +if [[ "${CXX}" == *clang* ]]; then + MAKE_COMMAND="make -k CXX=include-what-you-use CXXFLAGS=\"-Xiwyu --error_always\" -j \$(nproc)" + IWYU="-DCMAKE_CXX_INCLUDE_WHAT_YOU_USE=iwyu" +fi + +echo "make command: ${MAKE_COMMAND}" +echo "IWYU option: ${IWYU}" + BAZEL_OPTIONS_DEFAULT="--copt=-DENABLE_LOGS_PREVIEW --copt=-DENABLE_TEST --copt=-DENABLE_METRICS_EXEMPLAR_PREVIEW" BAZEL_OPTIONS="--cxxopt=-std=c++14 $BAZEL_OPTIONS_DEFAULT" @@ -107,8 +117,9 @@ elif [[ "$1" == "cmake.maintainer.sync.test" ]]; then -DWITH_ASYNC_EXPORT_PREVIEW=OFF \ -DOTELCPP_MAINTAINER_MODE=ON \ -DWITH_NO_DEPRECATED_CODE=ON \ + ${IWYU} \ "${SRC_DIR}" - make -k + eval "$MAKE_COMMAND" make test exit 0 elif [[ "$1" == "cmake.maintainer.async.test" ]]; then @@ -129,8 +140,9 @@ elif [[ "$1" == "cmake.maintainer.async.test" ]]; then -DWITH_ASYNC_EXPORT_PREVIEW=ON \ -DOTELCPP_MAINTAINER_MODE=ON \ -DWITH_NO_DEPRECATED_CODE=ON \ + ${IWYU} \ "${SRC_DIR}" - make -k -j $(nproc) + eval "$MAKE_COMMAND" make test exit 0 elif [[ "$1" == "cmake.maintainer.cpp11.async.test" ]]; then @@ -201,8 +213,9 @@ elif [[ "$1" == "cmake.c++20.test" ]]; then -DCMAKE_CXX_FLAGS="-Werror $CXXFLAGS" \ -DWITH_ASYNC_EXPORT_PREVIEW=ON \ -DCMAKE_CXX_STANDARD=20 \ + ${IWYU} \ "${SRC_DIR}" - make -j $(nproc) + eval "$MAKE_COMMAND" make test exit 0 elif [[ "$1" == "cmake.c++20.stl.test" ]]; then @@ -214,8 +227,9 @@ elif [[ "$1" == "cmake.c++20.stl.test" ]]; then -DCMAKE_CXX_FLAGS="-Werror $CXXFLAGS" \ -DWITH_ASYNC_EXPORT_PREVIEW=ON \ -DWITH_STL=ON \ + ${IWYU} \ "${SRC_DIR}" - make -j $(nproc) + eval "$MAKE_COMMAND" make test exit 0 elif [[ "$1" == "cmake.legacy.test" ]]; then diff --git a/ci/setup_ci_environment.sh b/ci/setup_ci_environment.sh index f995ed75b5..8e93b8d5b5 100755 --- a/ci/setup_ci_environment.sh +++ b/ci/setup_ci_environment.sh @@ -11,4 +11,5 @@ apt-get install --no-install-recommends --no-install-suggests -y \ wget \ git \ valgrind \ - lcov + lcov \ + iwyu