From 3da70c081d3bad0f76e85320d251dfc499a0b88e Mon Sep 17 00:00:00 2001 From: Andreas Stefl Date: Mon, 25 Dec 2023 21:17:22 +0100 Subject: [PATCH 1/2] Use clang-tidy through cmake (#341) --- .github/workflows/build_test.yml | 11 +++-------- .github/workflows/format.yml | 2 -- .github/workflows/tidy.yml | 14 +++----------- CMakeLists.txt | 11 ++++++++--- static_analysis/clang-tidy/CMakeLists.txt | 10 ++++++++++ 5 files changed, 24 insertions(+), 24 deletions(-) create mode 100644 static_analysis/clang-tidy/CMakeLists.txt diff --git a/.github/workflows/build_test.yml b/.github/workflows/build_test.yml index db7f206d..36b4912f 100644 --- a/.github/workflows/build_test.yml +++ b/.github/workflows/build_test.yml @@ -67,14 +67,9 @@ jobs: env: CC: ${{ matrix.config.cc }} CXX: ${{ matrix.config.cxx }} - run: | - mkdir -p build - cd build - cmake -DCMAKE_BUILD_TYPE=Release .. - - name: make - run: | - cd build - cmake --build . --config Release # `config Release` somehow necessary by windows + run: cmake -B build -S . -DCMAKE_BUILD_TYPE=Release + - name: build + run: cmake --build build --config Release # `config Release` somehow necessary by windows - name: upload binaries uses: actions/upload-artifact@v2 diff --git a/.github/workflows/format.yml b/.github/workflows/format.yml index 4ecc4e18..b5744167 100644 --- a/.github/workflows/format.yml +++ b/.github/workflows/format.yml @@ -11,8 +11,6 @@ jobs: runs-on: ubuntu-22.04 steps: - - run: sudo apt install clang-format-15 - - run: clang-format-15 --version - name: checkout diff --git a/.github/workflows/tidy.yml b/.github/workflows/tidy.yml index 631e37d0..b2c1aa66 100644 --- a/.github/workflows/tidy.yml +++ b/.github/workflows/tidy.yml @@ -15,10 +15,7 @@ jobs: runs-on: ubuntu-22.04 steps: - - name: ubuntu install clang-tidy - run: | - sudo apt install clang-tidy-12 - clang-tidy-12 --version + - run: clang-tidy --version - name: set up python 3.8 uses: actions/setup-python@v2 @@ -31,12 +28,7 @@ jobs: uses: actions/checkout@v2 - name: cmake - run: | - mkdir -p build - cd build - cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_EXPORT_COMPILE_COMMANDS=ON .. + run: cmake -B build -S . -DCMAKE_BUILD_TYPE=Release -DODR_CLANG_TIDY=ON - name: clang-tidy - run: | - FILES=$( find . -path ./build -prune -false -o -type f \( -iname \*.cpp \) ) - clang-tidy-12 -p build -header-filter '.*' $FILES + run: cmake --build build diff --git a/CMakeLists.txt b/CMakeLists.txt index ff018569..d173ea38 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,6 +6,7 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) option(ODR_TEST "enable tests" ON) +option(ODR_CLANG_TIDY "Run clang-tidy static analysis" OFF) # TODO defining global compiler flags seems to be bad practice with conan # TODO consider using conan profiles @@ -163,7 +164,7 @@ add_library(odr "src/odr/internal/zip/zip_util.cpp" "src/odr/internal/zip/zip_archive.cpp" - ) +) set_target_properties(odr PROPERTIES OUTPUT_NAME odr) if (EXISTS "${PROJECT_SOURCE_DIR}/.git") add_dependencies(odr check_git) @@ -171,7 +172,7 @@ endif () target_include_directories(odr PUBLIC src - ) +) target_link_libraries(odr PRIVATE pugixml::pugixml @@ -180,7 +181,7 @@ target_link_libraries(odr nlohmann_json::nlohmann_json vincentlaucsb-csv-parser::vincentlaucsb-csv-parser uchardet::uchardet - ) +) add_subdirectory("cli") @@ -188,6 +189,10 @@ if (ODR_TEST) add_subdirectory("test") endif () +if (ODR_CLANG_TIDY) + add_subdirectory("static_analysis/clang-tidy") +endif () + install( TARGETS odr diff --git a/static_analysis/clang-tidy/CMakeLists.txt b/static_analysis/clang-tidy/CMakeLists.txt new file mode 100644 index 00000000..fa90eaf1 --- /dev/null +++ b/static_analysis/clang-tidy/CMakeLists.txt @@ -0,0 +1,10 @@ +find_program(CLANG_TIDY_COMMAND NAMES clang-tidy) + +if (NOT CLANG_TIDY_COMMAND) + message(ERROR "ACTS_RUN_CLANG_TIDY is ON but clang-tidy is not found!") + set(CMAKE_CXX_CLANG_TIDY "" CACHE STRING "" FORCE) +endif () + +message(STATUS "Setting up clang-tidy run") + +set(CMAKE_CXX_CLANG_TIDY "${CLANG_TIDY_COMMAND}") From 08d6aa8d06bd5acd7a6abd467a4d3ecc5d460116 Mon Sep 17 00:00:00 2001 From: Andreas Stefl Date: Mon, 25 Dec 2023 22:05:58 +0100 Subject: [PATCH 2/2] Update to cpp20 and update deps (#339) --- .github/workflows/build_test.yml | 19 +++++++++---------- CMakeLists.txt | 3 +-- conanfile.py | 4 ++-- src/odr/internal/crypto/crypto_util.cpp | 2 ++ 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/.github/workflows/build_test.yml b/.github/workflows/build_test.yml index 36b4912f..6e389a51 100644 --- a/.github/workflows/build_test.yml +++ b/.github/workflows/build_test.yml @@ -22,11 +22,10 @@ jobs: fail-fast: false matrix: config: - - { os: ubuntu-22.04, cc: clang, cxx: clang++ } - - { os: ubuntu-22.04, cc: gcc, cxx: g++ } - - { os: macos-12, cc: clang, cxx: clang++ } - - { os: windows-2022 } - - { os: ubuntu-20.04, cc: clang, cxx: clang++ } # TODO remove; but there is no firefox in 22.04 yet + - { os: ubuntu-22.04, compiler: clang, cc: clang-15, cxx: clang++-15 } + - { os: ubuntu-22.04, compiler: gcc, cc: gcc-13, cxx: g++-13 } + - { os: macos-12, compiler: clang, cc: clang, cxx: clang++ } + - { os: windows-2022, compiler: msvc } steps: - name: ubuntu install ccache @@ -56,9 +55,9 @@ jobs: ~/.conan/data C:/.conan C:/Users/runneradmin/.conan/data - key: ${{ matrix.config.os }}-${{ matrix.config.cxx }}-${{ env.CCACHE_KEY_SUFFIX }} + key: ${{ matrix.config.os }}-${{ matrix.config.compiler }}-${{ env.CCACHE_KEY_SUFFIX }} restore-keys: | - ${{ matrix.config.os }}-${{ matrix.config.cxx }}- + ${{ matrix.config.os }}-${{ matrix.config.compiler }}- - name: checkout uses: actions/checkout@v2 @@ -74,7 +73,7 @@ jobs: - name: upload binaries uses: actions/upload-artifact@v2 with: - name: bin-${{ matrix.config.os }}-${{ matrix.config.cxx }} + name: bin-${{ matrix.config.os }}-${{ matrix.config.compiler }} path: | build/test/odr_test @@ -85,8 +84,8 @@ jobs: fail-fast: true matrix: config: - - { os: ubuntu-20.04, bin: bin-ubuntu-20.04-clang++ } - - { os: macos-12, bin: bin-macos-12-clang++ } + - { os: ubuntu-22.04, bin: bin-ubuntu-22.04-clang } + - { os: macos-12, bin: bin-macos-12-clang } steps: - name: ubuntu install tidy diff --git a/CMakeLists.txt b/CMakeLists.txt index d173ea38..b1eba431 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,7 @@ cmake_minimum_required(VERSION 3.12.4) project(odr LANGUAGES C CXX) -set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) @@ -39,7 +39,6 @@ if (NOT DEFINED CONAN_EXPORTED) conan_cmake_install(PATH_OR_REFERENCE ".." BUILD missing SETTINGS ${settings} - SETTINGS compiler.cppstd=${CMAKE_CXX_STANDARD} ENV CC=${CMAKE_C_COMPILER} ENV CXX=${CMAKE_CXX_COMPILER}) #include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) diff --git a/conanfile.py b/conanfile.py index 86a14e7d..f3b4c476 100644 --- a/conanfile.py +++ b/conanfile.py @@ -21,9 +21,9 @@ class OpenDocumentCoreConan(ConanFile): exports_sources = ["cli/*", "cmake/*", "src/*", "CMakeLists.txt"] - requires = ["pugixml/1.11", "cryptopp/8.5.0", "miniz/2.1.0", "nlohmann_json/3.10.4", + requires = ["pugixml/1.14", "cryptopp/8.8.0", "miniz/2.1.0", "nlohmann_json/3.11.3", "vincentlaucsb-csv-parser/2.1.3", "uchardet/0.0.7"] - build_requires = ["gtest/1.11.0"] + build_requires = ["gtest/1.14.0"] generators = "cmake_paths", "cmake_find_package" _cmake = None diff --git a/src/odr/internal/crypto/crypto_util.cpp b/src/odr/internal/crypto/crypto_util.cpp index 1e31bba8..736776b9 100644 --- a/src/odr/internal/crypto/crypto_util.cpp +++ b/src/odr/internal/crypto/crypto_util.cpp @@ -1,5 +1,7 @@ #include +#include + #include #include #include