From d292005da998b4faa925122a1b44a5698072dbaa Mon Sep 17 00:00:00 2001 From: Ehsan Saei <71217171+esigo@users.noreply.github.com> Date: Sat, 1 Jul 2023 12:47:13 +0200 Subject: [PATCH] Add Include what you use --- 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 6020d22a04..60f87e54a9 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" @@ -109,8 +119,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 @@ -132,8 +143,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 @@ -206,8 +218,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 @@ -219,8 +232,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