From 5871e9297fc8286f0003b599116c670ca93aeda4 Mon Sep 17 00:00:00 2001 From: Marc Alff Date: Mon, 3 Oct 2022 16:45:02 +0200 Subject: [PATCH] Fixes #1648 Add a MAINTAINER_MODE in CMake. Build with gcc and clang in maintainer mode in github CI. --- .github/workflows/ci.yml | 32 +++++++++++++++++++++++++++ CMakeLists.txt | 48 ++++++++++++++++++++++++++++++++++++++++ ci/README.md | 1 + ci/do_ci.sh | 16 ++++++++++++++ 4 files changed, 97 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3a1c419334..6fa272b195 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -23,6 +23,38 @@ jobs: sudo ./ci/setup_thrift.sh ./ci/do_ci.sh cmake.test + cmake_gcc_maintainer_test: + name: CMake gcc (maintainer mode) + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + with: + submodules: 'recursive' + - name: setup + run: | + sudo ./ci/setup_cmake.sh + sudo ./ci/setup_ci_environment.sh + - name: run cmake gcc (maintainer mode) + run: | + sudo ./ci/setup_thrift.sh + ./ci/do_ci.sh cmake.maintainer.test + + cmake_clang_maintainer_test: + name: CMake clang (maintainer mode) + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + with: + submodules: 'recursive' + - name: setup + run: | + sudo ./ci/setup_cmake.sh + sudo ./ci/setup_ci_environment.sh + - name: run cmake clang (maintainer mode) + run: | + sudo ./ci/setup_thrift.sh + CC=/usr/bin/clang CXX=/usr/bin/clang++ ./ci/do_ci.sh cmake.maintainer.test + cmake_deprecated_metrics_test: name: CMake test (without otlp-exporter and with deprecated metrics) runs-on: ubuntu-latest diff --git a/CMakeLists.txt b/CMakeLists.txt index a1b6934003..cf5337db0a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -163,6 +163,54 @@ option(BUILD_TESTING "Whether to enable tests" ON) option(BUILD_W3CTRACECONTEXT_TEST "Whether to build w3c trace context" OFF) +option(MAINTAINER_MODE "Build in maintainer mode (-Wall -Werror)" OFF) + +if(MAINTAINER_MODE) + + add_compile_options(-Wall) + add_compile_options(-Werror) + add_compile_options(-Wextra) + + if(CMAKE_CXX_COMPILER_ID MATCHES "GNU") + + # Tested with GCC 9.4, + # compiling options most likely are available + # on older compilers as well. + if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 9.4) + # Relaxed warnings + + # Enforced warnings + endif() + + endif() + + if(CMAKE_CXX_COMPILER_ID MATCHES "Clang") + + # Tested with CLang 12.0.1, + # compiling options most likely are available + # on older compilers as well. + # FIXME: figure out which version is used in github ci. + if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 1.0) + # Relaxed warnings + add_compile_options(-Wno-error=unused-private-field) + + # Relaxed warning, for GRPC generated code. + add_compile_options(-Wno-error=shadow-field) + + # Enforced warnings + add_compile_options(-Wconditional-uninitialized) + add_compile_options(-Wextra-semi) + add_compile_options(-Wheader-hygiene) + add_compile_options(-Wnon-virtual-dtor) + add_compile_options(-Wundefined-reinterpret-cast) + add_compile_options(-Wrange-loop-analysis) + add_compile_options(-Winconsistent-missing-destructor-override) + add_compile_options(-Winconsistent-missing-override) + add_compile_options(-Wnewline-eof) + endif() + endif() +endif(MAINTAINER_MODE) + if(WIN32) if(BUILD_TESTING) if(MSVC) diff --git a/ci/README.md b/ci/README.md index 14a6107eb8..65bea032d7 100644 --- a/ci/README.md +++ b/ci/README.md @@ -4,6 +4,7 @@ CI tests can be run on docker by invoking the script `./ci/run_docker.sh ./ci/do_ci.sh {TARGET}` where the targets are: * `cmake.test`: build cmake targets and run tests. +* `cmake.maintainer.test`: build with cmake and test, in maintainer mode. * `cmake.legacy.test`: build cmake targets with gcc 4.8 and run tests. * `cmake.c++20.test`: build cmake targets with the C++20 standard and run tests. * `cmake.test_example_plugin`: build and test an example OpenTelemetry plugin. diff --git a/ci/do_ci.sh b/ci/do_ci.sh index bf775fa564..8c4e483237 100755 --- a/ci/do_ci.sh +++ b/ci/do_ci.sh @@ -89,6 +89,22 @@ if [[ "$1" == "cmake.test" ]]; then make make test exit 0 +elif [[ "$1" == "cmake.maintainer.test" ]]; then + cd "${BUILD_DIR}" + rm -rf * + cmake -DCMAKE_BUILD_TYPE=Debug \ + -DWITH_PROMETHEUS=ON \ + -DWITH_ZIPKIN=ON \ + -DWITH_JAEGER=ON \ + -DWITH_ELASTICSEARCH=ON \ + -DWITH_LOGS_PREVIEW=ON \ + -DWITH_METRICS_PREVIEW=OFF \ + -DWITH_ASYNC_EXPORT_PREVIEW=ON \ + -DMAINTAINER_MODE=ON \ + "${SRC_DIR}" + make + make test + exit 0 elif [[ "$1" == "cmake.with_async_export.test" ]]; then cd "${BUILD_DIR}" rm -rf *