diff --git a/.clang-tidy b/.clang-tidy index fb461aa..d8aaf10 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -3,6 +3,7 @@ Checks: > -llvmlibc-restrict-system-libc-headers, -llvmlibc-implementation-in-namespace, -llvmlibc-callee-namespace, + -llvmlibc-inline-function-decl, -llvm-header-guard, -fuchsia-overloaded-operator, -modernize-use-trailing-return-type, diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index ffd28b0..b74fbbf 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -11,8 +11,8 @@ "twxs.cmake", "fredericbonnet.cmake-test-adapter", "ms-vscode.cmake-tools", - "notskm.clang-tidy", - "ryanluker.vscode-coverage-gutters", + "AndreasNonslidHvardsen.clang-tidy-on-active-file", + "ryanluker.vscode-coverage-gutters" ] } }, diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index c0d0120..bdceda6 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -24,6 +24,7 @@ jobs: enable_tests: "ON", enable_coverage: "OFF", enable_asan: "OFF", + code_quality: false, } - { name: "Ubuntu 22.04 GCC (Debug)", @@ -32,6 +33,7 @@ jobs: enable_tests: "ON", enable_coverage: "ON", enable_asan: "ON", + code_quality: true, } - { name: "macOS Latest Clang (Release)", @@ -40,6 +42,7 @@ jobs: enable_tests: "ON", enable_coverage: "OFF", enable_asan: "OFF", + code_quality: false, } - { name: "Windows Latest (Release)", @@ -48,16 +51,20 @@ jobs: enable_tests: "ON", enable_coverage: "OFF", enable_asan: "OFF", + code_quality: false, } steps: - uses: actions/checkout@v4 + with: + fetch-depth: 0 - name: Set up Cache uses: actions/cache@v3 with: path: | build/ + build-code-quality/ key: ${{ matrix.config.name }}-cmake-${{ hashFiles('CMakeLists.txt', 'cmake/*.cmake') }} - name: Create Build Environment @@ -65,6 +72,12 @@ jobs: # We'll use this as our working directory for all subsequent commands run: cmake -E make_directory ${{github.workspace}}/build + - name: Code Quality + run: | + ./code-quality.sh ${{ github.event.repository.default_branch }} ${{ github.event_name }} ${{github.workspace}} \ + ${{github.workspace}}/build-code-quality ${{ matrix.config.build_type }} tests + if: matrix.config.code_quality == true + - name: Configure CMake # Use a bash shell so we can use the same syntax for environment variable # access regardless of the host operating system diff --git a/.gitignore b/.gitignore index 42afabf..0ec9e7f 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1 @@ -/build \ No newline at end of file +/build* diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json index 25425b8..8254c4e 100644 --- a/.vscode/c_cpp_properties.json +++ b/.vscode/c_cpp_properties.json @@ -1,23 +1,23 @@ { "configurations": [ { - "name": "clang", + "name": "gcc", "includePath": [ "${workspaceFolder}/**" ], "defines": [], - "compilerPath": "/usr/bin/clang-14", + "compilerPath": "/usr/bin/gcc-9", "cStandard": "c17", "intelliSenseMode": "linux-clang-x64", "configurationProvider": "ms-vscode.cmake-tools" }, { - "name": "gcc", + "name": "clang", "includePath": [ "${workspaceFolder}/**" ], "defines": [], - "compilerPath": "/usr/bin/gcc-9", + "compilerPath": "/usr/bin/clang-10", "cStandard": "c17", "intelliSenseMode": "linux-clang-x64", "configurationProvider": "ms-vscode.cmake-tools" diff --git a/.vscode/settings.json b/.vscode/settings.json index ef3f263..761de49 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -8,6 +8,7 @@ "cmake.configureOnOpen": true, "cmake.sourceDirectory": "${workspaceFolder}", "cmake.buildDirectory": "${workspaceFolder}/build", + "cmake.options.statusBarVisibility": "visible", "editor.codeActionsOnSave": { "source.fixAll": "explicit" }, @@ -26,6 +27,8 @@ "jacoco.xml", "coverage.cobertura.xml" ], + "clang-tidy-on-active-file.autoRunOnSave": true, + "clang-tidy-on-active-file.configPath": "/workspace/.clang-tidy", "C_Cpp.default.configurationProvider": "ms-vscode.cmake-tools", "C_Cpp.codeAnalysis.clangTidy.enabled": true, "C_Cpp.codeAnalysis.clangTidy.useBuildPath": true, diff --git a/code-quality.sh b/code-quality.sh new file mode 100755 index 0000000..efc6204 --- /dev/null +++ b/code-quality.sh @@ -0,0 +1,63 @@ +#!/bin/bash + +set -e + +default_branch=$1 # master +event=$2 # pull_request|push +workspace=$3 # .. +build_path=$4 # build-dir +build_type=$5 # Debug +build_target=$6 # tests + +echo default_branch=$default_branch +echo event=$event +echo workspace=$workspace +echo build_path=$build_path +echo build_type=$build_type +echo build_target=$build_target + +if [ -z ${default_branch} ]; then + echo "Default branch is missing" + exit 1 +fi + +cwd=$PWD + +# Build with clang for compilation database used by clang-tidy +mkdir -p ${build_path} +cd ${build_path} + +cmake ${workspace} \ + -DCMAKE_EXPORT_COMPILE_COMMANDS=ON \ + -DCMAKE_C_COMPILER=clang \ + -DCMAKE_CXX_COMPILER=clang++ \ + -DCMAKE_BUILD_TYPE=${build_type} \ + -DENABLE_TESTS=ON +cmake --build . --config ${build_type} --target ${build_target} + +cd ${cwd} + +# Find files +files=$(if [ $event == "pull_request" ]; then + git diff --name-only origin/$default_branch...HEAD +else + git ls-files +fi | grep '\.*pp$') + +# Run tools +echo + +if [ ! -z "${files}" ]; then + file_count=$(echo "${files}" | wc -w) + + echo "Format ${file_count} file(s)" + clang-format -i $files + + git diff --exit-code + echo + + echo "Tidy ${file_count} file(s)" + clang-tidy -p ${build_path} $files +else + echo "No files changed" +fi diff --git a/include/msd/zip.hpp b/include/msd/zip.hpp index fa0b91f..0e23a05 100644 --- a/include/msd/zip.hpp +++ b/include/msd/zip.hpp @@ -6,6 +6,7 @@ #include #include #include +#include #include namespace msd {