From 2a5cc5309f1e6e33f1a5d9d42f314fbc2ed52859 Mon Sep 17 00:00:00 2001 From: Alfi Maulana Date: Tue, 27 Jun 2023 22:43:34 +0700 Subject: [PATCH 1/6] build(error): make `fix-format` target always run --- .github/workflows/build.yml | 8 +++----- error/CMakeLists.txt | 1 + 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ec5b78e..28a1052 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -23,11 +23,6 @@ jobs: -B ${{ matrix.package }}/build \ -D BUILD_TESTING=ON - - name: Check code formatting - run: | - cmake --build ${{ matrix.package }}/build --target fix-format - git diff --exit-code HEAD - - name: Build project run: cmake --build ${{ matrix.package }}/build @@ -43,6 +38,9 @@ jobs: ${{ matrix.package }}/test/* fail-under-line: 100 + - name: Check diff + run: git diff --exit-code HEAD + debug-msvc: runs-on: windows-latest strategy: diff --git a/error/CMakeLists.txt b/error/CMakeLists.txt index 500ddc1..5da870f 100644 --- a/error/CMakeLists.txt +++ b/error/CMakeLists.txt @@ -15,6 +15,7 @@ target_link_libraries(error PUBLIC fmt) if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR) # Import Format.cmake to format source code cpmaddpackage("gh:TheLartians/Format.cmake@1.7.3") + add_dependencies(error fix-format) if(BUILD_TESTING) enable_testing() From d58962d61116e548d9fb098eaa4ec500bf0e662c Mon Sep 17 00:00:00 2001 From: Alfi Maulana Date: Tue, 27 Jun 2023 22:48:21 +0700 Subject: [PATCH 2/6] ci: always try to install cmake-format --- .github/workflows/build.yml | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 28a1052..af33fab 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -50,6 +50,9 @@ jobs: - name: Checkout repository uses: actions/checkout@v3.5.3 + - name: Install cmake-format + run: pip3 install cmake-format + - name: Configure CMake run: | cmake ${{ matrix.package }} ` @@ -72,6 +75,10 @@ jobs: - name: Checkout repository uses: actions/checkout@v3.5.3 + # TODO: remove this later + - name: Install cmake-format + run: pip3 install cmake-format + - name: Configure and build project uses: threeal/cmake-action@v1.1.0 with: @@ -87,6 +94,10 @@ jobs: - name: Checkout repository uses: actions/checkout@v3.5.3 + # TODO: remove this later + - name: Install cmake-format + run: pip3 install cmake-format + - name: Configure and build project uses: threeal/cmake-action@v1.1.0 with: From 1d6fe35f9a789c920346507c010c996410a49ea1 Mon Sep 17 00:00:00 2001 From: Alfi Maulana Date: Wed, 28 Jun 2023 11:07:39 +0700 Subject: [PATCH 3/6] build(error): add option that enable source code formatting check --- .github/workflows/build.yml | 14 ++------------ error/CMakeLists.txt | 8 ++++++-- 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index af33fab..c4263a2 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -21,7 +21,8 @@ jobs: run: | cmake ${{ matrix.package }} \ -B ${{ matrix.package }}/build \ - -D BUILD_TESTING=ON + -D BUILD_TESTING=ON \ + -D CHECK_FORMAT=ON - name: Build project run: cmake --build ${{ matrix.package }}/build @@ -50,9 +51,6 @@ jobs: - name: Checkout repository uses: actions/checkout@v3.5.3 - - name: Install cmake-format - run: pip3 install cmake-format - - name: Configure CMake run: | cmake ${{ matrix.package }} ` @@ -75,10 +73,6 @@ jobs: - name: Checkout repository uses: actions/checkout@v3.5.3 - # TODO: remove this later - - name: Install cmake-format - run: pip3 install cmake-format - - name: Configure and build project uses: threeal/cmake-action@v1.1.0 with: @@ -94,10 +88,6 @@ jobs: - name: Checkout repository uses: actions/checkout@v3.5.3 - # TODO: remove this later - - name: Install cmake-format - run: pip3 install cmake-format - - name: Configure and build project uses: threeal/cmake-action@v1.1.0 with: diff --git a/error/CMakeLists.txt b/error/CMakeLists.txt index 5da870f..ba2616d 100644 --- a/error/CMakeLists.txt +++ b/error/CMakeLists.txt @@ -13,9 +13,13 @@ target_link_libraries(error PUBLIC fmt) # Check if this project is the main project if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR) + option(CHECK_FORMAT "Enable source code formatting check" OFF) + # Import Format.cmake to format source code - cpmaddpackage("gh:TheLartians/Format.cmake@1.7.3") - add_dependencies(error fix-format) + if(CHECK_FORMAT) + cpmaddpackage("gh:TheLartians/Format.cmake@1.7.3") + add_dependencies(error fix-format) + endif() if(BUILD_TESTING) enable_testing() From 434dbadcf9188a44326c8ef9e4cd7c0f2bba7d95 Mon Sep 17 00:00:00 2001 From: Alfi Maulana Date: Wed, 28 Jun 2023 11:13:24 +0700 Subject: [PATCH 4/6] build(error): add option that enable static analysis warning check --- .github/workflows/build.yml | 6 ++++-- error/CMakeLists.txt | 11 +++++++---- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index c4263a2..2ce02e3 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -22,7 +22,8 @@ jobs: cmake ${{ matrix.package }} \ -B ${{ matrix.package }}/build \ -D BUILD_TESTING=ON \ - -D CHECK_FORMAT=ON + -D CHECK_FORMAT=ON \ + -D CHECK_WARNING=ON - name: Build project run: cmake --build ${{ matrix.package }}/build @@ -56,7 +57,8 @@ jobs: cmake ${{ matrix.package }} ` -B ${{ matrix.package }}/build ` -D CMAKE_CXX_COMPILER=cl ` - -D BUILD_TESTING=ON + -D BUILD_TESTING=ON ` + -D CHECK_WARNING=ON - name: Build project run: cmake --build ${{ matrix.package }}/build diff --git a/error/CMakeLists.txt b/error/CMakeLists.txt index ba2616d..1aee0da 100644 --- a/error/CMakeLists.txt +++ b/error/CMakeLists.txt @@ -14,6 +14,7 @@ target_link_libraries(error PUBLIC fmt) # Check if this project is the main project if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR) option(CHECK_FORMAT "Enable source code formatting check" OFF) + option(CHECK_WARNING "Enable static analysis warning check" OFF) # Import Format.cmake to format source code if(CHECK_FORMAT) @@ -42,10 +43,12 @@ if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR) foreach(TARGET IN LISTS TARGETS) # Statically analyze code by checking for warnings - if(MSVC) - target_compile_options(${TARGET} PRIVATE /WX /permissive- /W4 /w14640 /EHsc) - else() - target_compile_options(${TARGET} PRIVATE -Werror -Wall -Wextra -Wnon-virtual-dtor -Wpedantic) + if(CHECK_WARNING) + if(MSVC) + target_compile_options(${TARGET} PRIVATE /WX /permissive- /W4 /w14640 /EHsc) + else() + target_compile_options(${TARGET} PRIVATE -Werror -Wall -Wextra -Wnon-virtual-dtor -Wpedantic) + endif() endif() # Enable support to check for test coverage From 03ffc1a5e8a316c75e97e53adb02d2aaf6a16242 Mon Sep 17 00:00:00 2001 From: Alfi Maulana Date: Wed, 28 Jun 2023 11:16:02 +0700 Subject: [PATCH 5/6] build(error): add option that enable test coverage check --- .github/workflows/build.yml | 3 ++- error/CMakeLists.txt | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 2ce02e3..d75f76d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -23,7 +23,8 @@ jobs: -B ${{ matrix.package }}/build \ -D BUILD_TESTING=ON \ -D CHECK_FORMAT=ON \ - -D CHECK_WARNING=ON + -D CHECK_WARNING=ON \ + -D CHECK_COVERAGE=ON - name: Build project run: cmake --build ${{ matrix.package }}/build diff --git a/error/CMakeLists.txt b/error/CMakeLists.txt index 1aee0da..0f5d541 100644 --- a/error/CMakeLists.txt +++ b/error/CMakeLists.txt @@ -15,6 +15,7 @@ target_link_libraries(error PUBLIC fmt) if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR) option(CHECK_FORMAT "Enable source code formatting check" OFF) option(CHECK_WARNING "Enable static analysis warning check" OFF) + option(CHECK_COVERAGE "Enable test coverage check" OFF) # Import Format.cmake to format source code if(CHECK_FORMAT) @@ -52,7 +53,7 @@ if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR) endif() # Enable support to check for test coverage - if(BUILD_TESTING AND NOT MSVC) + if(BUILD_TESTING AND CHECK_COVERAGE AND NOT MSVC) target_compile_options(${TARGET} PRIVATE --coverage -O0) target_link_options(${TARGET} PRIVATE --coverage) endif() From 4f1eb156abd08fa6bb602147cf37f66f7f44ab5a Mon Sep 17 00:00:00 2001 From: Alfi Maulana Date: Wed, 28 Jun 2023 11:24:27 +0700 Subject: [PATCH 6/6] chore(error): set subgroups hwrap option in `.cmake-format` --- error/.cmake-format | 3 ++- error/CMakeLists.txt | 5 +---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/error/.cmake-format b/error/.cmake-format index ceb0afb..a6b2f16 100644 --- a/error/.cmake-format +++ b/error/.cmake-format @@ -1,3 +1,4 @@ { - "line_width": 120 + "line_width": 120, + "max_subgroups_hwrap": 3 } diff --git a/error/CMakeLists.txt b/error/CMakeLists.txt index 0f5d541..3ed1fc8 100644 --- a/error/CMakeLists.txt +++ b/error/CMakeLists.txt @@ -37,10 +37,7 @@ if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR) endif() # Get all targets in this directory - get_property( - TARGETS - DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} - PROPERTY BUILDSYSTEM_TARGETS) + get_property(TARGETS DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY BUILDSYSTEM_TARGETS) foreach(TARGET IN LISTS TARGETS) # Statically analyze code by checking for warnings