diff --git a/.github/workflows/CI-cygwin.yml b/.github/workflows/CI-cygwin.yml deleted file mode 100644 index 445c0953eb5..00000000000 --- a/.github/workflows/CI-cygwin.yml +++ /dev/null @@ -1,61 +0,0 @@ -# Syntax reference https://help.github.com/en/actions/reference/workflow-syntax-for-github-actions -# Environment reference https://help.github.com/en/actions/reference/virtual-environments-for-github-hosted-runners -name: CI-cygwin - -on: - push: - branches: - - 'main' - - 'releases/**' - - '2.*' - tags: - - '2.*' - pull_request: - -permissions: - contents: read - -defaults: - run: - shell: cmd - -jobs: - # TODO: add CMake build - build_cygwin: - strategy: - matrix: - # only use the latest windows-* as the installed toolchain is identical - os: [windows-2025] - platform: [x86_64] - include: - - platform: 'x86_64' - packages: | - gcc-g++ - python3 - fail-fast: false - - runs-on: ${{ matrix.os }} - - steps: - - uses: actions/checkout@v4 - with: - persist-credentials: false - - - name: Set up Cygwin - uses: cygwin/cygwin-install-action@master - with: - platform: ${{ matrix.platform }} - packages: ${{ matrix.packages }} - - # Cygwin will always link the binaries even if they already exist. The linking is also extremely slow. So just run the "check" target which includes all the binaries. - - name: Build all and run test - run: | - C:\cygwin\bin\bash.exe -l -c cd %GITHUB_WORKSPACE% && make VERBOSE=1 -j%NUMBER_OF_PROCESSORS% CXXOPTS="-Werror" test - - - name: Extra test for misra - run: | - cd %GITHUB_WORKSPACE%\addons\test - ..\..\cppcheck.exe --dump -DDUMMY --suppress=uninitvar --inline-suppr misra\misra-test.c --std=c89 --platform=unix64 - python3 ..\misra.py -verify misra\misra-test.c.dump - ..\..\cppcheck.exe --addon=misra --enable=style --inline-suppr --enable=information --error-exitcode=1 misra\misra-ctu-1-test.c misra\misra-ctu-2-test.c - diff --git a/.github/workflows/CI-mingw.yml b/.github/workflows/CI-mingw.yml deleted file mode 100644 index 1b0cf3e5672..00000000000 --- a/.github/workflows/CI-mingw.yml +++ /dev/null @@ -1,75 +0,0 @@ -# Syntax reference https://help.github.com/en/actions/reference/workflow-syntax-for-github-actions -# Environment reference https://help.github.com/en/actions/reference/virtual-environments-for-github-hosted-runners -name: CI-mingw - -on: - push: - branches: - - 'main' - - 'releases/**' - - '2.*' - tags: - - '2.*' - pull_request: - -permissions: - contents: read - -defaults: - run: - shell: msys2 {0} - -jobs: - # TODO: add CMake build - build_mingw: - strategy: - matrix: - # only use the latest windows-* as the installed toolchain is identical - os: [windows-2025] - fail-fast: false - - runs-on: ${{ matrix.os }} - - timeout-minutes: 19 # max + 3*std of the last 7K runs - - steps: - - uses: actions/checkout@v4 - with: - persist-credentials: false - - - name: Set up MSYS2 - uses: msys2/setup-msys2@v2 - with: - release: false # use pre-installed - # TODO: install mingw-w64-x86_64-make and use mingw32.make instead - currently fails with "Windows Subsystem for Linux has no installed distributions." - install: >- - mingw-w64-x86_64-lld - mingw-w64-x86_64-ccache - make - mingw-w64-x86_64-gcc - - - name: ccache - uses: hendrikmuhs/ccache-action@v1.2 - with: - key: ${{ github.workflow }}-${{ github.job }}-${{ matrix.os }} - - - name: Build cppcheck - run: | - export PATH="/mingw64/lib/ccache/bin:$PATH" - # set RDYNAMIC to work around broken MinGW detection - # use lld for faster linking - make VERBOSE=1 RDYNAMIC=-lshlwapi LDOPTS=-fuse-ld=lld -j$(nproc) CXXOPTS="-Werror" cppcheck - - - name: Build test - run: | - export PATH="/mingw64/lib/ccache/bin:$PATH" - # set RDYNAMIC to work around broken MinGW detection - # use lld for faster linking - make VERBOSE=1 RDYNAMIC=-lshlwapi LDOPTS=-fuse-ld=lld -j$(nproc) CXXOPTS="-Werror" testrunner - - - name: Run test - run: | - export PATH="/mingw64/lib/ccache/bin:$PATH" - # set RDYNAMIC to work around broken MinGW detection - # use lld for faster linking - make VERBOSE=1 RDYNAMIC=-lshlwapi LDOPTS=-fuse-ld=lld -j$(nproc) CXXOPTS="-Werror" test diff --git a/.github/workflows/CI-unixish-docker.yml b/.github/workflows/CI-unixish-docker.yml deleted file mode 100644 index 4df9b4e9340..00000000000 --- a/.github/workflows/CI-unixish-docker.yml +++ /dev/null @@ -1,138 +0,0 @@ -# Syntax reference https://help.github.com/en/actions/reference/workflow-syntax-for-github-actions -# Environment reference https://help.github.com/en/actions/reference/virtual-environments-for-github-hosted-runners -name: CI-unixish-docker - -on: - push: - branches: - - 'main' - - 'releases/**' - - '2.*' - tags: - - '2.*' - pull_request: - -permissions: - contents: read - -jobs: - build_cmake: - - strategy: - matrix: - image: ["ubuntu:24.04"] - include: - - build_gui: false - - image: "ubuntu:24.04" - build_gui: true - fail-fast: false # Prefer quick result - - runs-on: ubuntu-22.04 - - # TODO: is this actually applied to the guest? - env: - # TODO: figure out why there are cache misses with PCH enabled - CCACHE_SLOPPINESS: pch_defines,time_macros - - container: - image: ${{ matrix.image }} - - steps: - - uses: actions/checkout@v4 - with: - persist-credentials: false - - - name: Install missing software on ubuntu - if: contains(matrix.image, 'ubuntu') - run: | - apt-get update - apt-get install -y cmake g++ make libxml2-utils libpcre3-dev - - - name: Install missing software (gui) on latest ubuntu - if: matrix.build_gui - run: | - apt-get install -y qt6-base-dev qt6-charts-dev qt6-tools-dev - - # needs to be called after the package installation since - # - it doesn't call "apt-get update" - - name: ccache - uses: hendrikmuhs/ccache-action@v1.2 - with: - key: ${{ github.workflow }}-${{ matrix.image }} - - - name: CMake build - if: ${{ !matrix.build_gui }} - run: | - mkdir cmake.output - cd cmake.output - cmake -G "Unix Makefiles" -DHAVE_RULES=On -DBUILD_TESTS=On -DCMAKE_DISABLE_PRECOMPILE_HEADERS=On -DCMAKE_COMPILE_WARNING_AS_ERROR=On -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache .. - cmake --build . -- -j$(nproc) - - - name: CMake build (with GUI) - if: matrix.build_gui - run: | - cmake -S . -B cmake.output -G "Unix Makefiles" -DHAVE_RULES=On -DBUILD_TESTS=On -DBUILD_GUI=On -DWITH_QCHART=On -DBUILD_TRIAGE=On -DCMAKE_COMPILE_WARNING_AS_ERROR=On -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache - cmake --build cmake.output -- -j$(nproc) - - - name: Run CMake test - run: | - cmake --build cmake.output --target check -- -j$(nproc) - - build_make: - - strategy: - matrix: - image: ["ubuntu:24.04"] - fail-fast: false # Prefer quick result - - runs-on: ubuntu-22.04 - - container: - image: ${{ matrix.image }} - - steps: - - uses: actions/checkout@v4 - with: - persist-credentials: false - - - name: Install missing software on ubuntu - if: contains(matrix.image, 'ubuntu') - run: | - apt-get update - apt-get install -y g++ make python3 libxml2-utils libpcre3-dev - - # needs to be called after the package installation since - # - it doesn't call "apt-get update" - - name: ccache - uses: hendrikmuhs/ccache-action@v1.2 - with: - key: ${{ github.workflow }}-${{ matrix.image }} - - - name: Build cppcheck - run: | - export PATH="/usr/lib/ccache:/usr/local/opt/ccache/libexec:$PATH" - make -j$(nproc) HAVE_RULES=yes CXXOPTS="-Werror" - - - name: Build test - run: | - export PATH="/usr/lib/ccache:/usr/local/opt/ccache/libexec:$PATH" - make -j$(nproc) HAVE_RULES=yes CXXOPTS="-Werror" testrunner - - - name: Run test - run: | - make -j$(nproc) HAVE_RULES=yes test - - # requires python3 - - name: Run extra tests - run: | - test/scripts/generate_and_run_more_tests.sh - - # requires which - - name: Validate - run: | - make -j$(nproc) checkCWEEntries validateXML - - - name: Test addons - run: | - ./cppcheck --addon=threadsafety addons/test/threadsafety - ./cppcheck --addon=threadsafety --std=c++03 addons/test/threadsafety diff --git a/.github/workflows/CI-unixish.yml b/.github/workflows/CI-unixish.yml index 14682a41a56..a423a77c0a7 100644 --- a/.github/workflows/CI-unixish.yml +++ b/.github/workflows/CI-unixish.yml @@ -16,397 +16,6 @@ permissions: contents: read jobs: - build_cmake_tinyxml2: - - strategy: - matrix: - os: [ubuntu-22.04, macos-15] - fail-fast: false # Prefer quick result - - runs-on: ${{ matrix.os }} - - env: - # TODO: figure out why there are cache misses with PCH enabled - CCACHE_SLOPPINESS: pch_defines,time_macros - - steps: - - uses: actions/checkout@v4 - with: - persist-credentials: false - - - name: ccache - uses: hendrikmuhs/ccache-action@v1.2 - with: - key: ${{ github.workflow }}-${{ github.job }}-${{ matrix.os }} - - - name: Install missing software on ubuntu - if: contains(matrix.os, 'ubuntu') - run: | - sudo apt-get update - sudo apt-get install libxml2-utils libtinyxml2-dev - # qt6-tools-dev-tools for lprodump - # qt6-l10n-tools for lupdate - sudo apt-get install qt6-base-dev libqt6charts6-dev qt6-tools-dev qt6-tools-dev-tools qt6-l10n-tools libglx-dev libgl1-mesa-dev - - # coreutils contains "nproc" - - name: Install missing software on macos - if: contains(matrix.os, 'macos') - run: | - # pcre was removed from runner images in November 2022 - brew install coreutils qt@6 tinyxml2 pcre - - - name: CMake build on ubuntu (with GUI / system tinyxml2) - if: contains(matrix.os, 'ubuntu') - run: | - cmake -S . -B cmake.output.tinyxml2 -G "Unix Makefiles" -DHAVE_RULES=On -DBUILD_TESTS=On -DBUILD_GUI=On -DWITH_QCHART=On -DBUILD_TRIAGE=On -DUSE_BUNDLED_TINYXML2=Off -DCMAKE_DISABLE_PRECOMPILE_HEADERS=On -DCMAKE_COMPILE_WARNING_AS_ERROR=On -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache - cmake --build cmake.output.tinyxml2 -- -j$(nproc) - - - name: CMake build on macos (with GUI / system tinyxml2) - if: contains(matrix.os, 'macos') - run: | - cmake -S . -B cmake.output.tinyxml2 -G "Unix Makefiles" -DHAVE_RULES=On -DBUILD_TESTS=On -DBUILD_GUI=On -DWITH_QCHART=On -DBUILD_TRIAGE=On -DUSE_BUNDLED_TINYXML2=Off -DCMAKE_DISABLE_PRECOMPILE_HEADERS=On -DCMAKE_COMPILE_WARNING_AS_ERROR=On -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -DQt6_DIR=$(brew --prefix qt@6)/lib/cmake/Qt6 - cmake --build cmake.output.tinyxml2 -- -j$(nproc) - - - name: Run CMake test (system tinyxml2) - run: | - cmake --build cmake.output.tinyxml2 --target check -- -j$(nproc) - - build_cmake: - - strategy: - matrix: - os: [ubuntu-22.04, macos-15] - fail-fast: false # Prefer quick result - - runs-on: ${{ matrix.os }} - - env: - # TODO: figure out why there are cache misses with PCH enabled - CCACHE_SLOPPINESS: pch_defines,time_macros - - steps: - - uses: actions/checkout@v4 - with: - persist-credentials: false - - - name: ccache - uses: hendrikmuhs/ccache-action@v1.2 - with: - key: ${{ github.workflow }}-${{ github.job }}-${{ matrix.os }} - - # TODO: move latest compiler to separate step - # TODO: bail out on warnings with latest GCC - - name: Set up GCC - uses: egor-tensin/setup-gcc@v1 - if: false # matrix.os == 'ubuntu-22.04' - with: - version: 13 - platform: x64 - - - name: Select compiler - if: false # matrix.os == 'ubuntu-22.04' - run: | - echo "CXX=g++-13" >> $GITHUB_ENV - - - name: Install missing software on ubuntu - if: contains(matrix.os, 'ubuntu') - run: | - sudo apt-get update - sudo apt-get install libxml2-utils - # qt6-tools-dev-tools for lprodump - # qt6-l10n-tools for lupdate - sudo apt-get install qt6-base-dev libqt6charts6-dev qt6-tools-dev qt6-tools-dev-tools qt6-l10n-tools libglx-dev libgl1-mesa-dev - - # coreutils contains "nproc" - - name: Install missing software on macos - if: contains(matrix.os, 'macos') - run: | - # pcre was removed from runner images in November 2022 - brew install coreutils qt@6 pcre - - - name: Run CMake on ubuntu (with GUI) - if: contains(matrix.os, 'ubuntu') - run: | - cmake -S . -B cmake.output -G "Unix Makefiles" -DHAVE_RULES=On -DBUILD_TESTS=On -DBUILD_GUI=On -DWITH_QCHART=On -DBUILD_TRIAGE=On -DCMAKE_DISABLE_PRECOMPILE_HEADERS=On -DCMAKE_COMPILE_WARNING_AS_ERROR=On -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -DCMAKE_INSTALL_PREFIX=cppcheck-cmake-install - - - name: Run CMake on macos (with GUI) - if: contains(matrix.os, 'macos') - run: | - cmake -S . -B cmake.output -G "Unix Makefiles" -DHAVE_RULES=On -DBUILD_TESTS=On -DBUILD_GUI=On -DWITH_QCHART=On -DBUILD_TRIAGE=On -DCMAKE_DISABLE_PRECOMPILE_HEADERS=On -DCMAKE_COMPILE_WARNING_AS_ERROR=On -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -DCMAKE_INSTALL_PREFIX=cppcheck-cmake-install -DQt6_DIR=$(brew --prefix qt@6)/lib/cmake/Qt6 - - - name: Run CMake build - run: | - cmake --build cmake.output -- -j$(nproc) - - - name: Run CMake test - run: | - cmake --build cmake.output --target check -- -j$(nproc) - - - name: Run CTest - run: | - pushd cmake.output - ctest --output-on-failure -j$(nproc) - - - name: Run CMake install - run: | - cmake --build cmake.output --target install - - - name: Run CMake on ubuntu (no CLI) - if: matrix.os == 'ubuntu-22.04' - run: | - cmake -S . -B cmake.output_nocli -G "Unix Makefiles" -DBUILD_CLI=Off - - - name: Run CMake on ubuntu (no CLI / with tests) - if: matrix.os == 'ubuntu-22.04' - run: | - # the test and CLI code are too intertwined so for now we need to reject that - if cmake -S . -B cmake.output_nocli_tests -G "Unix Makefiles" -DBUILD_TESTS=On -DBUILD_CLI=Off; then - exit 1 - else - exit 0 - fi - - - name: Run CMake on ubuntu (no CLI / with GUI) - if: matrix.os == 'ubuntu-22.04' - run: | - cmake -S . -B cmake.output_nocli_gui -G "Unix Makefiles" -DBUILD_CLI=Off -DBUILD_GUI=On - - - name: Run CMake on ubuntu (no GUI) - if: matrix.os == 'ubuntu-22.04' - run: | - cmake -S . -B cmake.output_nogui -G "Unix Makefiles" -DBUILD_GUI=Off - - - name: Run CMake on ubuntu (no GUI / with triage) - if: matrix.os == 'ubuntu-22.04' - run: | - # cannot build triage without GUI - if cmake -S . -B cmake.output_nogui_triage -G "Unix Makefiles" -DBUILD_GUI=Off -DBUILD_TRIAGE=On; then - exit 1 - else - exit 0 - fi - - - name: Run CMake on ubuntu (no CLI / no GUI) - if: matrix.os == 'ubuntu-22.04' - run: | - cmake -S . -B cmake.output_nocli_nogui -G "Unix Makefiles" -DBUILD_GUI=Off - - build_cmake_cxxstd: - - strategy: - matrix: - os: [ubuntu-22.04, macos-15] - cxxstd: [14, 17, 20] - # FIXME: macos-15 fails to compile with C++20 - # - # /Users/runner/work/cppcheck/cppcheck/cmake.output/gui/test/projectfile/moc_testprojectfile.cpp:84:1: error: 'constinit' specifier is incompatible with C++ standards before C++20 [-Werror,-Wc++20-compat] - # 84 | Q_CONSTINIT const QMetaObject TestProjectFile::staticMetaObject = { { - # | ^ - # /opt/homebrew/opt/qt/lib/QtCore.framework/Headers/qcompilerdetection.h:1409:23: note: expanded from macro 'Q_CONSTINIT' - exclude: - - os: macos-15 - cxxstd: 20 - fail-fast: false # Prefer quick result - - runs-on: ${{ matrix.os }} - - env: - # TODO: figure out why there are cache misses with PCH enabled - CCACHE_SLOPPINESS: pch_defines,time_macros - - steps: - - uses: actions/checkout@v4 - with: - persist-credentials: false - - - name: ccache - uses: hendrikmuhs/ccache-action@v1.2 - with: - key: ${{ github.workflow }}-${{ github.job }}-${{ matrix.os }}-${{ matrix.cxxstd }} - - - name: Install missing software on ubuntu - if: contains(matrix.os, 'ubuntu') - run: | - sudo apt-get update - sudo apt-get install libxml2-utils - # qt6-tools-dev-tools for lprodump - # qt6-l10n-tools for lupdate - sudo apt-get install qt6-base-dev libqt6charts6-dev qt6-tools-dev qt6-tools-dev-tools qt6-l10n-tools libglx-dev libgl1-mesa-dev - - # coreutils contains "nproc" - - name: Install missing software on macos - if: contains(matrix.os, 'macos') - run: | - # pcre was removed from runner images in November 2022 - brew install coreutils qt@6 pcre - - - name: Run CMake on ubuntu (with GUI) - if: contains(matrix.os, 'ubuntu') - run: | - cmake -S . -B cmake.output -G "Unix Makefiles" -DCMAKE_CXX_STANDARD=${{ matrix.cxxstd }} -DHAVE_RULES=On -DBUILD_TESTS=On -DBUILD_GUI=On -DWITH_QCHART=On -DBUILD_TRIAGE=On -DCMAKE_DISABLE_PRECOMPILE_HEADERS=On -DCMAKE_COMPILE_WARNING_AS_ERROR=On -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache - - - name: Run CMake on macos (with GUI) - if: contains(matrix.os, 'macos') - run: | - cmake -S . -B cmake.output -G "Unix Makefiles" -DCMAKE_CXX_STANDARD=${{ matrix.cxxstd }} -DHAVE_RULES=On -DBUILD_TESTS=On -DBUILD_GUI=On -DWITH_QCHART=On -DBUILD_TRIAGE=On -DCMAKE_DISABLE_PRECOMPILE_HEADERS=On -DCMAKE_COMPILE_WARNING_AS_ERROR=On -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -DQt6_DIR=$(brew --prefix qt@6)/lib/cmake/Qt6 - - - name: Run CMake build - run: | - cmake --build cmake.output -- -j$(nproc) - - build_uchar: - - strategy: - matrix: - os: [ubuntu-22.04, macos-15] - fail-fast: false # Prefer quick result - - runs-on: ${{ matrix.os }} - - steps: - - uses: actions/checkout@v4 - with: - persist-credentials: false - - - name: ccache - uses: hendrikmuhs/ccache-action@v1.2 - with: - key: ${{ github.workflow }}-${{ github.job }}-${{ matrix.os }} - - # coreutils contains "nproc" - - name: Install missing software on macos - if: contains(matrix.os, 'macos') - run: | - brew install coreutils - - - name: Build with Unsigned char - run: | - export PATH="/usr/lib/ccache:/usr/local/opt/ccache/libexec:$PATH" - make -j$(nproc) CXXOPTS="-Werror -funsigned-char" testrunner - - - name: Test with Unsigned char - run: | - ./testrunner - - build_mathlib: - - strategy: - matrix: - os: [ubuntu-22.04, macos-15] - fail-fast: false # Prefer quick result - - runs-on: ${{ matrix.os }} - - steps: - - uses: actions/checkout@v4 - with: - persist-credentials: false - - - name: ccache - uses: hendrikmuhs/ccache-action@v1.2 - with: - key: ${{ github.workflow }}-${{ github.job }}-${{ matrix.os }} - - # coreutils contains "nproc" - - name: Install missing software on macos - if: contains(matrix.os, 'macos') - run: | - brew install coreutils - - - name: Build with TEST_MATHLIB_VALUE - run: | - export PATH="/usr/lib/ccache:/usr/local/opt/ccache/libexec:$PATH" - make -j$(nproc) CXXOPTS="-Werror" CPPOPTS=-DTEST_MATHLIB_VALUE all - - - name: Test with TEST_MATHLIB_VALUE - run: | - make -j$(nproc) test - - check_nonneg: - - strategy: - matrix: - os: [ubuntu-22.04, macos-15] - fail-fast: false # Prefer quick result - - runs-on: ${{ matrix.os }} - - steps: - - uses: actions/checkout@v4 - with: - persist-credentials: false - - # coreutils contains "g++" (default is "c++") and "nproc" - - name: Install missing software on macos - if: contains(matrix.os, 'macos') - run: | - brew install coreutils - - - name: Check syntax with NONNEG - run: | - make check-nonneg CXXOPTS="-Werror" - - build_cmake_boost: - - strategy: - matrix: - os: [macos-15] # non-macos platforms are already built with Boost in other contexts - fail-fast: false # Prefer quick result - - runs-on: ${{ matrix.os }} - - env: - # TODO: figure out why there are cache misses with PCH enabled - CCACHE_SLOPPINESS: pch_defines,time_macros - - steps: - - uses: actions/checkout@v4 - with: - persist-credentials: false - - - name: ccache - uses: hendrikmuhs/ccache-action@v1.2 - with: - key: ${{ github.workflow }}-${{ github.job }}-${{ matrix.os }} - - - name: Run CMake on macOS (force Boost) - run: | - # make sure we fail when Boost is requested and not available. - # will fail because no package configuration is available. - if cmake -S . -B cmake.output.boost-force-noavail -G "Unix Makefiles" -DUSE_BOOST=On; then - exit 1 - else - exit 0 - fi - - # coreutils contains "nproc" - - name: Install missing software on macOS - run: | - brew install coreutils boost - - - name: Run CMake on macOS (force Boost) - run: | - cmake -S . -B cmake.output.boost-force -G "Unix Makefiles" -DUSE_BOOST=On - - - name: Run CMake on macOS (no Boost) - run: | - # make sure Boost is not used when disabled even though it is available - cmake -S . -B cmake.output.boost-no -G "Unix Makefiles" -DUSE_BOOST=Off - if grep -q '\-DHAVE_BOOST' ./cmake.output.boost-no/compile_commands.json; then - exit 1 - else - exit 0 - fi - - - name: Run CMake on macOS (with Boost) - run: | - cmake -S . -B cmake.output.boost -G "Unix Makefiles" -DBUILD_TESTS=On -DCMAKE_DISABLE_PRECOMPILE_HEADERS=On -DCMAKE_COMPILE_WARNING_AS_ERROR=On -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache - grep -q '\-DHAVE_BOOST' ./cmake.output.boost/compile_commands.json - - - name: Build with CMake on macOS (with Boost) - run: | - cmake --build cmake.output.boost -- -j$(nproc) - build: strategy: @@ -633,93 +242,3 @@ jobs: run: | warnings="-pedantic -Wall -Wextra -Wcast-qual -Wno-deprecated-declarations -Wfloat-equal -Wmissing-declarations -Wmissing-format-attribute -Wno-long-long -Wpacked -Wredundant-decls -Wundef -Wno-shadow -Wno-missing-field-initializers -Wno-missing-braces -Wno-sign-compare -Wno-multichar" g++ $warnings -c -Ilib -Iexternals/tinyxml2 democlient/democlient.cpp - - - name: Test disabled executors - if: matrix.os == 'ubuntu-22.04' - run: | - g++ -Ilib -c cli/threadexecutor.cpp -DDISALLOW_THREAD_EXECUTOR - test -z "$(nm threadexecutor.o)" - g++ -Ilib -c cli/processexecutor.cpp -DDISALLOW_PROCESS_EXECUTOR - test -z "$(nm processexecutor.o)" - # TODO: test NO_* defines - - - name: Show all ignored files - if: false # TODO: currently lists all the contents of ignored folders - we only need what actually matched - run: | - git ls-files --others --ignored --exclude-standard - - - name: Check for changed and unversioned files - run: | - # TODO: how to do this with a single command? - git status --ignored=no - git status --ignored=no | grep -q 'working tree clean' - - selfcheck: - needs: build # wait for all tests to be successful first - - runs-on: ubuntu-22.04 # run on the latest image only - - steps: - - uses: actions/checkout@v4 - with: - persist-credentials: false - - - name: ccache - uses: hendrikmuhs/ccache-action@v1.2 - with: - key: ${{ github.workflow }}-${{ github.job }}-${{ matrix.os }} - - - name: Install missing software on ubuntu - run: | - sudo apt-get update - # qt6-tools-dev-tools for lprodump - # qt6-l10n-tools for lupdate - sudo apt-get install qt6-base-dev libqt6charts6-dev qt6-tools-dev qt6-tools-dev-tools qt6-l10n-tools libglx-dev libgl1-mesa-dev - sudo apt-get install libboost-container-dev - - - name: Self check (build) - run: | - export PATH="/usr/lib/ccache:/usr/local/opt/ccache/libexec:$PATH" - # compile with verification and ast matchers - make -j$(nproc) CXXOPTS="-Werror -g -O2" CPPOPTS="-DCHECK_INTERNAL -DHAVE_BOOST" MATCHCOMPILER=yes VERIFY=1 - - - name: CMake - run: | - cmake -S . -B cmake.output -DHAVE_RULES=On -DBUILD_TESTS=On -DBUILD_GUI=On -DWITH_QCHART=On -DBUILD_TRIAGE=On -DUSE_MATCHCOMPILER=Verify -DENABLE_CHECK_INTERNAL=On -DCPPCHK_GLIBCXX_DEBUG=Off -DCMAKE_DISABLE_PRECOMPILE_HEADERS=On -DCMAKE_GLOBAL_AUTOGEN_TARGET=On -DDISABLE_DMAKE=On - - - name: Generate dependencies - run: | - # make sure auto-generated GUI files exist - make -C cmake.output autogen - make -C cmake.output gui-build-deps triage-build-ui-deps - - - name: Self check - run: | - selfcheck_options="-q -j$(nproc) --std=c++11 --template=selfcheck --showtime=file-total -D__GNUC__ --error-exitcode=1 --inline-suppr --suppressions-list=.selfcheck_suppressions --library=gnu --inconclusive --enable=style,performance,portability,warning,missingInclude,information --exception-handling --debug-warnings --check-level=exhaustive" - cppcheck_options="-D__CPPCHECK__ -DCHECK_INTERNAL -DHAVE_RULES --library=cppcheck-lib -Ilib -Iexternals/simplecpp/ -Iexternals/tinyxml2" - gui_options="-DQT_VERSION=0x060000 -DQ_MOC_OUTPUT_REVISION=68 -DQT_CHARTS_LIB -DQT_MOC_HAS_STRINGDATA --library=qt" - ec=0 - - # TODO: add --check-config - - # early exit - if [ $ec -eq 1 ]; then - exit $ec - fi - - # self check externals - ./cppcheck $selfcheck_options externals || ec=1 - # self check lib/cli - mkdir b1 - ./cppcheck $selfcheck_options $cppcheck_options --cppcheck-build-dir=b1 --addon=naming.json frontend || ec=1 - ./cppcheck $selfcheck_options $cppcheck_options --cppcheck-build-dir=b1 --addon=naming.json -Ifrontend cli || ec=1 - ./cppcheck $selfcheck_options $cppcheck_options --cppcheck-build-dir=b1 --addon=naming.json --enable=internal lib || ec=1 - # check gui with qt settings - mkdir b2 - ./cppcheck $selfcheck_options $cppcheck_options $gui_options --cppcheck-build-dir=b2 --addon=naming.json -Icmake.output/gui -Ifrontend -Igui gui/*.cpp cmake.output/gui || ec=1 - # self check test and tools - ./cppcheck $selfcheck_options $cppcheck_options -Ifrontend -Icli test/*.cpp || ec=1 - ./cppcheck $selfcheck_options $cppcheck_options -Icli tools/dmake/*.cpp || ec=1 - # triage - ./cppcheck $selfcheck_options $cppcheck_options $gui_options -Icmake.output/tools/triage -Igui tools/triage/*.cpp cmake.output/tools/triage || ec=1 - exit $ec diff --git a/.github/workflows/CI-windows.yml b/.github/workflows/CI-windows.yml index 2b08f18bbf5..c2e7900c51b 100644 --- a/.github/workflows/CI-windows.yml +++ b/.github/workflows/CI-windows.yml @@ -21,83 +21,6 @@ defaults: jobs: - build_qt: - strategy: - matrix: - os: [windows-2022, windows-2025] - qt_ver: [6.10.0] - fail-fast: false - - runs-on: ${{ matrix.os }} - - steps: - - uses: actions/checkout@v4 - with: - persist-credentials: false - - - name: Set up Visual Studio environment - uses: ilammy/msvc-dev-cmd@v1 - with: - arch: x64 - - - name: Install Qt ${{ matrix.qt_ver }} - uses: jurplel/install-qt-action@v4 - with: - version: ${{ matrix.qt_ver }} - modules: 'qtcharts' - setup-python: 'false' - cache: true - aqtversion: '==3.1.*' # TODO: remove when aqtinstall 3.2.2 is available - - - name: Run CMake - run: | - rem TODO: enable rules? - rem specify Release build so matchcompiler is used - cmake -S . -B build -DCMAKE_BUILD_TYPE=Release -DCMAKE_COMPILE_WARNING_AS_ERROR=On -DBUILD_GUI=On -DWITH_QCHART=On -DBUILD_TRIAGE=On -DBUILD_ONLINE_HELP=On -DCMAKE_INSTALL_PREFIX=cppcheck-cmake-install -DCMAKE_COMPILE_WARNING_AS_ERROR=On || exit /b !errorlevel! - - - name: Build GUI release - run: | - cmake --build build --target cppcheck-gui --config Release || exit /b !errorlevel! - - - name: Deploy GUI - run: | - windeployqt build\bin\Release || exit /b !errorlevel! - del build\bin\Release\cppcheck-gui.ilk || exit /b !errorlevel! - del build\bin\Release\cppcheck-gui.pdb || exit /b !errorlevel! - - # TODO: run GUI tests - - - name: Run CMake install - run: | - cmake --build build --target install - - build_cmake_cxxstd: - strategy: - matrix: - os: [windows-2022, windows-2025] - cxxstd: [14, 17, 20] - fail-fast: false - - runs-on: ${{ matrix.os }} - - steps: - - uses: actions/checkout@v4 - with: - persist-credentials: false - - - name: Set up Visual Studio environment - uses: ilammy/msvc-dev-cmd@v1 - with: - arch: x64 - - - name: Run CMake - run: | - cmake -S . -B build.cxxstd -G "Visual Studio 17 2022" -A x64 -DCMAKE_CXX_STANDARD=${{ matrix.cxxstd }} -DCMAKE_BUILD_TYPE=Debug -DCMAKE_COMPILE_WARNING_AS_ERROR=On -DCMAKE_COMPILE_WARNING_AS_ERROR=On || exit /b !errorlevel! - - - name: Build - run: | - cmake --build build.cxxstd --config Debug || exit /b !errorlevel! - build: strategy: matrix: diff --git a/.github/workflows/buildman.yml b/.github/workflows/buildman.yml deleted file mode 100644 index b0b399dd851..00000000000 --- a/.github/workflows/buildman.yml +++ /dev/null @@ -1,65 +0,0 @@ -# Syntax reference https://help.github.com/en/actions/reference/workflow-syntax-for-github-actions -# Environment reference https://help.github.com/en/actions/reference/virtual-environments-for-github-hosted-runners -name: Build manual - -on: - push: - branches: - - 'main' - - 'releases/**' - - '2.*' - tags: - - '2.*' - pull_request: - -permissions: - contents: read - -jobs: - convert_via_pandoc: - runs-on: ubuntu-24.04 - steps: - - uses: actions/checkout@v4 - with: - persist-credentials: false - - - run: | - mkdir output - - - uses: docker://pandoc/latex:3.6.3 - with: - args: --output=output/manual.html man/manual.md - - - uses: docker://pandoc/latex:3.6.3 - with: - args: --output=output/manual.pdf man/manual.md - - - uses: docker://pandoc/latex:3.6.3 - with: - args: --output=output/manual-premium.pdf man/manual-premium.md - - - uses: actions/upload-artifact@v4 - with: - name: output - path: output - - manpage: - runs-on: ubuntu-22.04 - steps: - - uses: actions/checkout@v4 - with: - persist-credentials: false - - - name: Install missing software on ubuntu - run: | - sudo apt-get update - sudo apt-get install -y xsltproc docbook-xsl - - - name: build manpage - run: | - make man - - - uses: actions/upload-artifact@v4 - with: - name: cppcheck.1 - path: cppcheck.1 diff --git a/.github/workflows/cifuzz.yml b/.github/workflows/cifuzz.yml deleted file mode 100644 index 7b462c688f0..00000000000 --- a/.github/workflows/cifuzz.yml +++ /dev/null @@ -1,34 +0,0 @@ -# Syntax reference https://help.github.com/en/actions/reference/workflow-syntax-for-github-actions -# Environment reference https://help.github.com/en/actions/reference/virtual-environments-for-github-hosted-runners -name: CIFuzz - -on: [pull_request] - -permissions: - contents: read - -jobs: - Fuzzing: - runs-on: ubuntu-latest - if: ${{ github.repository_owner == 'danmar' }} - steps: - - name: Build Fuzzers - id: build - uses: google/oss-fuzz/infra/cifuzz/actions/build_fuzzers@master - with: - oss-fuzz-project-name: 'cppcheck' - dry-run: false - language: c++ - - name: Run Fuzzers - uses: google/oss-fuzz/infra/cifuzz/actions/run_fuzzers@master - with: - oss-fuzz-project-name: 'cppcheck' - fuzz-seconds: 300 - dry-run: false - language: c++ - - name: Upload Crash - uses: actions/upload-artifact@v4 - if: failure() && steps.build.outcome == 'success' - with: - name: artifacts - path: ./out/artifacts diff --git a/.github/workflows/clang-tidy.yml b/.github/workflows/clang-tidy.yml deleted file mode 100644 index 5d7445f34b5..00000000000 --- a/.github/workflows/clang-tidy.yml +++ /dev/null @@ -1,93 +0,0 @@ -# Syntax reference https://help.github.com/en/actions/reference/workflow-syntax-for-github-actions -# Environment reference https://help.github.com/en/actions/reference/virtual-environments-for-github-hosted-runners -name: clang-tidy - -on: - push: - branches: - - 'main' - - 'releases/**' - - '2.*' - tags: - - '2.*' - pull_request: - schedule: - - cron: '0 0 * * 0' - workflow_dispatch: - -permissions: - contents: read - -jobs: - build: - - runs-on: ubuntu-22.04 - - env: - QT_VERSION: 6.10.0 - - steps: - - uses: actions/checkout@v4 - with: - persist-credentials: false - - - name: Install missing software - run: | - sudo apt-get update - sudo apt-get install -y cmake make - sudo apt-get install -y libpcre3-dev - sudo apt-get install -y libgl-dev # fixes missing dependency for Qt in CMake - - - name: Install clang - run: | - sudo apt-get purge --auto-remove llvm python3-lldb-14 llvm-14 - wget https://apt.llvm.org/llvm.sh - chmod +x llvm.sh - sudo ./llvm.sh 22 - sudo apt-get install -y clang-tidy-22 - - - name: Install Qt ${{ env.QT_VERSION }} - uses: jurplel/install-qt-action@v4 - with: - version: ${{ env.QT_VERSION }} - modules: 'qtcharts' - setup-python: 'false' - install-deps: false - cache: true - - - name: Verify clang-tidy configuration - run: | - clang-tidy-22 --verify-config - - - name: Prepare CMake - run: | - cmake -S . -B cmake.output -G "Unix Makefiles" -DHAVE_RULES=On -DBUILD_TESTS=On -DBUILD_GUI=On -DWITH_QCHART=On -DBUILD_TRIAGE=On -DENABLE_CHECK_INTERNAL=On -DCMAKE_GLOBAL_AUTOGEN_TARGET=On -DDISABLE_DMAKE=On -DCPPCHK_GLIBCXX_DEBUG=Off -DWARNINGS_ARE_ERRORS=On - env: - CC: clang-22 - CXX: clang++-22 - - - name: Prepare CMake dependencies - run: | - # make sure the auto-generated GUI sources exist - make -C cmake.output autogen - # make sure the precompiled headers exist - make -C cmake.output/cli cmake_pch.hxx.pch - make -C cmake.output/gui cmake_pch.hxx.pch - make -C cmake.output/lib cmake_pch.hxx.pch - make -C cmake.output/test cmake_pch.hxx.pch - - - name: Clang-Tidy - if: ${{ github.event.schedule == '' && github.event_name != 'workflow_dispatch' }} - run: | - cmake --build cmake.output --target run-clang-tidy 2> /dev/null - - - name: Clang Static Analyzer - if: ${{ github.event.schedule != '' || github.event_name == 'workflow_dispatch' }} - run: | - cmake --build cmake.output --target run-clang-tidy-csa 2> /dev/null - - - uses: actions/upload-artifact@v4 - if: success() || failure() - with: - name: Compilation Database - path: ./cmake.output/compile_commands.json diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml deleted file mode 100644 index 12e758d2c9e..00000000000 --- a/.github/workflows/codeql-analysis.yml +++ /dev/null @@ -1,52 +0,0 @@ -# Syntax reference https://help.github.com/en/actions/reference/workflow-syntax-for-github-actions -# Environment reference https://help.github.com/en/actions/reference/virtual-environments-for-github-hosted-runners -name: "CodeQL" - -on: - push: - branches: - - 'main' - - 'releases/**' - - '2.*' - tags: - - '2.*' - pull_request: - -permissions: - contents: read - -jobs: - analyze: - name: Analyze - runs-on: ubuntu-22.04 - permissions: - security-events: write - - strategy: - fail-fast: false - matrix: - # Override automatic language detection by changing the below list - # Supported options are ['csharp', 'cpp', 'go', 'java', 'javascript', 'python'] - language: ['cpp', 'python'] - # Learn more... - # https://docs.github.com/en/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#overriding-automatic-language-detection - - steps: - - name: Checkout repository - uses: actions/checkout@v4 - with: - persist-credentials: false - - # Initializes the CodeQL tools for scanning. - - name: Initialize CodeQL - uses: github/codeql-action/init@v3 - with: - languages: ${{ matrix.language }} - - - name: Build cppcheck - if: matrix.language == 'cpp' - run: | - make -j$(nproc) CXXOPTS="-Werror" HAVE_RULES=yes CPPCHK_GLIBCXX_DEBUG= cppcheck - - - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v3 diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml deleted file mode 100644 index 13f56172a80..00000000000 --- a/.github/workflows/coverage.yml +++ /dev/null @@ -1,71 +0,0 @@ -# Syntax reference https://help.github.com/en/actions/reference/workflow-syntax-for-github-actions -# Environment reference https://help.github.com/en/actions/reference/virtual-environments-for-github-hosted-runners -name: Coverage - -on: - push: - branches: - - 'main' - - 'releases/**' - - '2.*' - tags: - - '2.*' - pull_request: - -permissions: - contents: read - -jobs: - build: - - runs-on: ubuntu-22.04 - - steps: - - uses: actions/checkout@v4 - with: - persist-credentials: false - - - name: ccache - uses: hendrikmuhs/ccache-action@v1.2 - with: - key: ${{ github.workflow }}-${{ runner.os }} - - - name: Install missing software on ubuntu - run: | - sudo apt-get update - sudo apt-get install libxml2-utils lcov - - - name: Install missing Python packages on ubuntu - run: | - python -m pip install pip --upgrade - python -m pip install lcov_cobertura - - - name: Compile instrumented - run: | - export PATH="/usr/lib/ccache:/usr/local/opt/ccache/libexec:$PATH" - make -j$(nproc) CXXOPTS="-Werror -g -fprofile-arcs -ftest-coverage" HAVE_RULES=yes CPPCHK_GLIBCXX_DEBUG= all - - - name: Run instrumented tests - run: | - ./testrunner - test/cfg/runtests.sh - - - name: Generate coverage report - run: | - gcov lib/*.cpp -o lib/ - lcov --directory ./ --capture --output-file lcov_tmp.info -b ./ - lcov --extract lcov_tmp.info "$(pwd)/*" --output-file lcov.info - genhtml lcov.info -o coverage_report --frame --legend --demangle-cpp - - - uses: actions/upload-artifact@v4 - with: - name: Coverage results - path: coverage_report - - - uses: codecov/codecov-action@v4 - with: - token: ${{ secrets.CODECOV_TOKEN }} - # file: ./coverage.xml # optional - flags: unittests # optional - name: ${{ github.repository }} # optional - fail_ci_if_error: true # optional (default = false): diff --git a/.github/workflows/coverity.yml b/.github/workflows/coverity.yml deleted file mode 100644 index 3c07b61d7c7..00000000000 --- a/.github/workflows/coverity.yml +++ /dev/null @@ -1,41 +0,0 @@ -# Syntax reference https://help.github.com/en/actions/reference/workflow-syntax-for-github-actions -# Environment reference https://help.github.com/en/actions/reference/virtual-environments-for-github-hosted-runners -name: Coverity - -on: - schedule: - - cron: "0 0 * * *" - -permissions: - contents: read - -jobs: - scan: - runs-on: ubuntu-latest - if: ${{ github.repository_owner == 'danmar' }} - steps: - - uses: actions/checkout@v4 - with: - persist-credentials: false - - name: Install missing software on ubuntu - run: | - sudo apt-get update - sudo apt-get install qtbase5-dev qttools5-dev libqt5charts5-dev libboost-container-dev - - name: Download Coverity build tool - run: | - wget -c -N https://scan.coverity.com/download/linux64 --post-data "token=${{ secrets.COVERITY_SCAN_TOKEN }}&project=cppcheck" -O coverity_tool.tar.gz - mkdir coverity_tool - tar xzf coverity_tool.tar.gz --strip 1 -C coverity_tool - - name: Build with Coverity build tool - run: | - export PATH=`pwd`/coverity_tool/bin:$PATH - cov-build --dir cov-int make CPPCHK_GLIBCXX_DEBUG= - - name: Submit build result to Coverity Scan - run: | - tar czvf cov.tar.gz cov-int - curl --form token=${{ secrets.COVERITY_SCAN_TOKEN }} \ - --form email=daniel.marjamaki@gmail.com \ - --form file=@cov.tar.gz \ - --form version="Commit $GITHUB_SHA" \ - --form description="Development" \ - https://scan.coverity.com/builds?project=cppcheck diff --git a/.github/workflows/cppcheck-premium.yml b/.github/workflows/cppcheck-premium.yml deleted file mode 100644 index 5cb63ca4d5e..00000000000 --- a/.github/workflows/cppcheck-premium.yml +++ /dev/null @@ -1,72 +0,0 @@ -# Syntax reference https://help.github.com/en/actions/reference/workflow-syntax-for-github-actions -# Environment reference https://help.github.com/en/actions/reference/virtual-environments-for-github-hosted-runners -name: cppcheck-premium - -on: - push: - branches: - - 'main' - - 'releases/**' - - '2.*' - tags: - - '2.*' - pull_request: - workflow_dispatch: - inputs: - premium_version: - description: 'Cppcheck Premium version' - -permissions: - contents: read - security-events: write - -jobs: - - build: - runs-on: ubuntu-24.04 # run on the latest image only - steps: - - uses: actions/checkout@v4 - with: - persist-credentials: false - - - name: Download cppcheckpremium release - run: | - premium_version=${{ inputs.premium_version }} - if [ -z $premium_version ]; then - premium_version=25.8.3 - #wget https://files.cppchecksolutions.com/devdrop/cppcheckpremium-$premium_version-amd64.tar.gz -O cppcheckpremium.tar.gz - wget https://files.cppchecksolutions.com/$premium_version/ubuntu-24.04/cppcheckpremium-$premium_version-amd64.tar.gz -O cppcheckpremium.tar.gz - else - wget https://files.cppchecksolutions.com/$premium_version/ubuntu-24.04/cppcheckpremium-$premium_version-amd64.tar.gz -O cppcheckpremium.tar.gz - fi - tar xzf cppcheckpremium.tar.gz - mv cppcheckpremium-$premium_version cppcheckpremium - - - name: Generate a license file - run: | - echo cppcheck > cppcheck.lic - echo 261231 >> cppcheck.lic - echo 80000 >> cppcheck.lic - echo 4b64673f03fb6230 >> cppcheck.lic - echo path:lib >> cppcheck.lic - - - name: Check - run: | - cppcheckpremium/premiumaddon --check-loc-license cppcheck.lic > cppcheck-premium-loc - cppcheckpremium/cppcheck --premium=safety-off -j$(nproc) -D__GNUC__ -D__CPPCHECK__ --suppressions-list=cppcheckpremium-suppressions --platform=unix64 --enable=style --premium=misra-c++-2023 --premium=cert-c++-2016 --inline-suppr lib --error-exitcode=0 --output-format=sarif 2> results.sarif - - - name: Cat results - run: | - #sed -i 's|"security-severity":.*||' results.sarif - cat results.sarif - - - uses: actions/upload-artifact@v4 - with: - name: results - path: results.sarif - - - name: Upload report - uses: github/codeql-action/upload-sarif@v3 - with: - sarif_file: results.sarif - category: cppcheckpremium diff --git a/.github/workflows/format.yml b/.github/workflows/format.yml deleted file mode 100644 index fd491c0ec0e..00000000000 --- a/.github/workflows/format.yml +++ /dev/null @@ -1,55 +0,0 @@ -# Syntax reference https://help.github.com/en/actions/reference/workflow-syntax-for-github-actions -# Environment reference https://help.github.com/en/actions/reference/virtual-environments-for-github-hosted-runners -name: format - -on: - push: - branches: - - 'main' - - 'releases/**' - - '2.*' - tags: - - '2.*' - pull_request: - -permissions: - contents: read - -jobs: - build: - - runs-on: ubuntu-22.04 - - env: - UNCRUSTIFY_VERSION: 0.80.1 - - steps: - - uses: actions/checkout@v4 - with: - persist-credentials: false - - - name: Cache uncrustify - uses: actions/cache@v4 - id: cache-uncrustify - with: - path: | - ~/uncrustify - key: ${{ runner.os }}-uncrustify-${{ env.UNCRUSTIFY_VERSION }} - - - name: build uncrustify - if: steps.cache-uncrustify.outputs.cache-hit != 'true' - run: | - set -x - wget https://github.com/uncrustify/uncrustify/archive/refs/tags/uncrustify-${{ env.UNCRUSTIFY_VERSION }}.tar.gz - tar xzvf uncrustify-${{ env.UNCRUSTIFY_VERSION }}.tar.gz - cd uncrustify-uncrustify-${{ env.UNCRUSTIFY_VERSION }} - cmake -S . -B build -DCMAKE_BUILD_TYPE=Release - cmake --build build -- -j$(nproc) -s - mkdir ~/uncrustify - cp build/uncrustify ~/uncrustify/ - - - name: Uncrustify check - run: | - UNCRUSTIFY=~/uncrustify/uncrustify ./runformat - git diff - git diff | diff - /dev/null &> /dev/null diff --git a/.github/workflows/iwyu.yml b/.github/workflows/iwyu.yml deleted file mode 100644 index 772a0da320c..00000000000 --- a/.github/workflows/iwyu.yml +++ /dev/null @@ -1,268 +0,0 @@ -# Syntax reference https://help.github.com/en/actions/reference/workflow-syntax-for-github-actions -# Environment reference https://help.github.com/en/actions/reference/virtual-environments-for-github-hosted-runners -name: include-what-you-use - -on: - schedule: - - cron: '0 0 * * 0' - workflow_dispatch: - -permissions: - contents: read - -jobs: - iwyu: - - strategy: - matrix: - # "opensuse/tumbleweed:latest" / "fedora:latest" / "debian:unstable" / "archlinux:latest" - include: - - os: ubuntu-22.04 - image: "fedora:latest" - stdlib: libstdc++ - clang_inc: '-isystem/usr/lib/clang/20/include' - # TODO: disable because it currently fails with "error: tried including but didn't find libc++'s header." - #- os: ubuntu-22.04 - # image: "fedora:latest" - # stdlib: libc++ - # clang_inc: '-isystem/usr/lib/clang/20/include' - - os: macos-13 - image: "" - stdlib: libc++ # no libstdc++ on macOS - mapping_file_opt: '-Xiwyu --mapping_file=$(realpath ./macos.imp)' - fail-fast: false - - runs-on: ${{ matrix.os }} - if: ${{ github.repository_owner == 'danmar' }} - - container: - image: ${{ matrix.image }} - - env: - QT_VERSION: 6.10.0 - - steps: - - uses: actions/checkout@v4 - with: - persist-credentials: false - - - name: Install missing software on debian/ubuntu - if: contains(matrix.image, 'debian') - run: | - apt-get update - apt-get install -y cmake clang make libpcre3-dev - apt-get install -y libgl-dev # fixes missing dependency for Qt in CMake - apt-get install -y iwyu - - - name: Install missing software on archlinux - if: contains(matrix.image, 'archlinux') - run: | - set -x - pacman -Sy - pacman -S cmake make clang pcre --noconfirm - pacman -S libglvnd --noconfirm # fixes missing dependency for Qt in CMake - pacman-key --init - pacman-key --recv-key 3056513887B78AEB --keyserver keyserver.ubuntu.com - pacman-key --lsign-key 3056513887B78AEB - pacman -U 'https://cdn-mirror.chaotic.cx/chaotic-aur/chaotic-keyring.pkg.tar.zst' 'https://cdn-mirror.chaotic.cx/chaotic-aur/chaotic-mirrorlist.pkg.tar.zst' --noconfirm - echo "[chaotic-aur]" >> /etc/pacman.conf - echo "Include = /etc/pacman.d/chaotic-mirrorlist" >> /etc/pacman.conf - pacman -Sy - pacman -S include-what-you-use --noconfirm - ln -s iwyu-tool /usr/sbin/iwyu_tool - - - name: Install missing software on Fedora - if: contains(matrix.image, 'fedora') - run: | - dnf install -y cmake clang pcre-devel - dnf install -y libglvnd-devel # fixes missing dependency for Qt in CMake - dnf install -y p7zip-plugins # required as fallback for py7zr in Qt installation - dnf install -y python3-pip # fixes missing pip module in jurplel/install-qt-action - dnf install -y python3-devel # fixes building of wheels for jurplel/install-qt-action - dnf install -y cairo-devel gtk3-devel libcurl-devel lua-devel openssl-devel python3-devel sqlite-devel boost-devel cppunit-devel libsigc++20-devel # for strict cfg checks - dnf install -y iwyu - ln -s iwyu_tool.py /usr/bin/iwyu_tool - - - name: Install missing software on Fedora (libc++) - if: contains(matrix.image, 'fedora') && matrix.stdlib == 'libc++' - run: | - dnf install -y libcxx-devel - - - name: Install missing software on OpenSUSE - if: contains(matrix.image, 'opensuse') - run: | - zypper install -y cmake clang pcre-devel - zypper install -y include-what-you-use-tools - ln -s iwyu_tool.py /usr/bin/iwyu_tool - - # coreutils contains "nproc" - - name: Install missing software on macOS - if: contains(matrix.os, 'macos') - run: | - brew install include-what-you-use pcre coreutils - ln -s iwyu_tool.py /usr/local/bin/iwyu_tool - - # Fails on OpenSUSE: - # Warning: Failed to restore: Tar failed with error: Unable to locate executable file: tar. Please verify either the file path exists or the file can be found within a directory specified by the PATH environment variable. Also check the file mode to verify the file is executable. - # Also the shell is broken afterwards: - # OCI runtime exec failed: exec failed: unable to start container process: exec: "sh": executable file not found in $PATH: unknown - - name: Install Qt ${{ env.QT_VERSION }} - uses: jurplel/install-qt-action@v4 - with: - version: ${{ env.QT_VERSION }} - modules: 'qtcharts' - setup-python: 'false' - install-deps: false - cache: true - - - name: Generate macOS mappings - if: contains(matrix.os, 'macos') - run: | - set -x - - wget https://raw.githubusercontent.com/include-what-you-use/include-what-you-use/master/mapgen/iwyu-mapgen-apple-libc.py - python3 iwyu-mapgen-apple-libc.py $(xcrun --show-sdk-path)/usr/include > macos.imp - - - name: Prepare CMake - run: | - cmake -S . -B cmake.output -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release -DHAVE_RULES=On -DBUILD_TESTS=On -DBUILD_GUI=On -DWITH_QCHART=On -DBUILD_TRIAGE=On -DENABLE_CHECK_INTERNAL=On -DCMAKE_GLOBAL_AUTOGEN_TARGET=On -DDISABLE_DMAKE=On -DCMAKE_DISABLE_PRECOMPILE_HEADERS=On -DCPPCHK_GLIBCXX_DEBUG=Off -DUSE_MATCHCOMPILER=Off -DEXTERNALS_AS_SYSTEM=On -DUSE_LIBCXX=${{ matrix.stdlib == 'libc++' }} - env: - CC: clang - CXX: clang++ - - # Fails on Debian: - # /__w/cppcheck/Qt/6.7.0/gcc_64/libexec/rcc: error while loading shared libraries: libglib-2.0.so.0: cannot open shared object file: No such file or directory - - name: Prepare CMake dependencies - run: | - # make sure the auto-generated GUI sources exist - make -C cmake.output autogen - # make sure the precompiled headers exist - #make -C cmake.output/cli cmake_pch.hxx.pch - #make -C cmake.output/gui cmake_pch.hxx.pch - #make -C cmake.output/lib cmake_pch.hxx.pch - #make -C cmake.output/test cmake_pch.hxx.pch - # make sure the auto-generated GUI dependencies exist - make -C cmake.output gui-build-deps - make -C cmake.output triage-build-ui-deps - - - name: iwyu_tool - run: | - # TODO: remove -stdlib= - it should have been taken from the compilation database - iwyu_tool -p cmake.output -j $(nproc) -- -w -Xiwyu --max_line_length=1024 -Xiwyu --comment_style=long -Xiwyu --quoted_includes_first -Xiwyu --update_comments -stdlib=${{ matrix.stdlib }} ${{ matrix.mapping_file_opt }} ${{ matrix.clang_inc }} > iwyu.log - - # TODO: run with all configurations - - name: test/cfg - if: matrix.stdlib == 'libstdc++' - run: | - # TODO: redirect to log - ./test/cfg/runtests.sh - env: - IWYU: include-what-you-use - IWYU_CLANG_INC: ${{ matrix.clang_inc }} - - - uses: actions/upload-artifact@v4 - if: success() || failure() - with: - name: Compilation Database (include-what-you-use - ${{ matrix.os }} ${{ matrix.stdlib }}) - path: ./cmake.output/compile_commands.json - - - uses: actions/upload-artifact@v4 - if: ${{ contains(matrix.os, 'macos') && (success() || failure()) }} - with: - name: macOS Mappings - path: | - ./iwyu-mapgen-apple-libc.py - ./macos.imp - - - uses: actions/upload-artifact@v4 - if: success() || failure() - with: - name: Logs (include-what-you-use - ${{ matrix.os }} ${{ matrix.stdlib }}) - path: ./*.log - - clang-include-cleaner: - - strategy: - matrix: - stdlib: [libstdc++, libc++] - include: - - stdlib: libstdc++ - use_libcxx: Off - - stdlib: libc++ - use_libcxx: On - fail-fast: false - - runs-on: ubuntu-22.04 - if: ${{ github.repository_owner == 'danmar' }} - - env: - QT_VERSION: 6.10.0 - - steps: - - uses: actions/checkout@v4 - with: - persist-credentials: false - - - name: Install missing software - run: | - sudo apt-get update - sudo apt-get install -y cmake make libpcre3-dev - sudo apt-get install -y libgl-dev # missing dependency for using Qt in CMake - - - name: Install clang - run: | - sudo apt-get purge --auto-remove llvm python3-lldb-14 llvm-14 - wget https://apt.llvm.org/llvm.sh - chmod +x llvm.sh - sudo ./llvm.sh 22 - sudo apt-get install -y clang-tools-22 - - - name: Install libc++ - if: matrix.stdlib == 'libc++' - run: | - sudo apt-get install -y libc++-22-dev - - - name: Install Qt ${{ env.QT_VERSION }} - uses: jurplel/install-qt-action@v4 - with: - version: ${{ env.QT_VERSION }} - modules: 'qtcharts' - setup-python: 'false' - install-deps: false - cache: true - - - name: Prepare CMake - run: | - cmake -S . -B cmake.output -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release -DHAVE_RULES=On -DBUILD_TESTS=On -DBUILD_GUI=On -DWITH_QCHART=On -DBUILD_TRIAGE=On -DENABLE_CHECK_INTERNAL=On -DCMAKE_GLOBAL_AUTOGEN_TARGET=On -DDISABLE_DMAKE=On -DCMAKE_DISABLE_PRECOMPILE_HEADERS=On -DCPPCHK_GLIBCXX_DEBUG=Off -DUSE_MATCHCOMPILER=Off -DEXTERNALS_AS_SYSTEM=On -DUSE_LIBCXX=${{ matrix.use_libcxx }} - env: - CC: clang-22 - CXX: clang++-22 - - - name: Prepare CMake dependencies - run: | - # make sure the auto-generated GUI sources exist - make -C cmake.output autogen - # make sure the precompiled headers exist - #make -C cmake.output/cli cmake_pch.hxx.pch - #make -C cmake.output/gui cmake_pch.hxx.pch - #make -C cmake.output/lib cmake_pch.hxx.pch - #make -C cmake.output/test cmake_pch.hxx.pch - # make sure the auto-generated GUI dependencies exist - make -C cmake.output gui-build-deps - - - name: clang-include-cleaner - run: | - # TODO: run multi-threaded - find $PWD/cli $PWD/lib $PWD/test $PWD/gui -maxdepth 1 -name "*.cpp" | xargs -t -n 1 clang-include-cleaner-22 --print=changes --extra-arg=-w --extra-arg=-stdlib=${{ matrix.stdlib }} -p cmake.output > clang-include-cleaner.log 2>&1 - - - uses: actions/upload-artifact@v4 - if: success() || failure() - with: - name: Compilation Database (clang-include-cleaner - ${{ matrix.stdlib }}) - path: ./cmake.output/compile_commands.json - - - uses: actions/upload-artifact@v4 - if: success() || failure() - with: - name: Logs (clang-include-cleaner - ${{ matrix.stdlib }}) - path: ./*.log diff --git a/.github/workflows/release-windows-mingw.yml b/.github/workflows/release-windows-mingw.yml deleted file mode 100644 index 3b9b836347f..00000000000 --- a/.github/workflows/release-windows-mingw.yml +++ /dev/null @@ -1,69 +0,0 @@ -# Syntax reference https://help.github.com/en/actions/reference/workflow-syntax-for-github-actions -# Environment reference https://help.github.com/en/actions/reference/virtual-environments-for-github-hosted-runners -name: release-windows-mingw - -on: - push: - branches: - - 'main' - - 'releases/**' - - '2.*' - tags: - - '2.*' - pull_request: - -permissions: - contents: read - -defaults: - run: - shell: msys2 {0} - -jobs: - # TODO: add CMake build - build_mingw: - strategy: - matrix: - # only use the latest windows-* as the installed toolchain is identical - os: [windows-2025] - fail-fast: false - - runs-on: ${{ matrix.os }} - - timeout-minutes: 19 # max + 3*std of the last 7K runs - - steps: - - uses: actions/checkout@v4 - with: - persist-credentials: false - - - name: Set up MSYS2 - uses: msys2/setup-msys2@v2 - with: - release: false # use pre-installed - # TODO: install mingw-w64-x86_64-make and use mingw32.make instead - currently fails with "Windows Subsystem for Linux has no installed distributions." - install: >- - mingw-w64-x86_64-lld - make - mingw-w64-x86_64-gcc - python - - - name: Build cppcheck - run: | - export PATH="/mingw64/lib/ccache/bin:$PATH" - # set RDYNAMIC to work around broken MinGW detection - make VERBOSE=1 RDYNAMIC=-lshlwapi -j$(nproc) CXXFLAGS=-O2 MATCHCOMPILER=yes cppcheck - - - name: Package - run: | - mkdir cppcheck-mingw - cp cppcheck.exe cppcheck-mingw/ - cp -R cfg platforms cppcheck-mingw/ - cp /mingw64/bin/libgcc_s_seh-1.dll cppcheck-mingw/ - cp /mingw64/bin/libstdc*.dll cppcheck-mingw/ - cp /mingw64/bin/libwinpthread-1.dll cppcheck-mingw/ - - - uses: actions/upload-artifact@v4 - with: - name: cppcheck-mingw - path: cppcheck-mingw diff --git a/.github/workflows/release-windows.yml b/.github/workflows/release-windows.yml deleted file mode 100644 index 2836000acc5..00000000000 --- a/.github/workflows/release-windows.yml +++ /dev/null @@ -1,209 +0,0 @@ -# Syntax reference https://help.github.com/en/actions/reference/workflow-syntax-for-github-actions -# Environment reference https://help.github.com/en/actions/reference/virtual-environments-for-github-hosted-runners -name: release-windows - -on: - push: - tags: - - '2.*' - schedule: - - cron: '0 0 * * *' - workflow_dispatch: - -permissions: - contents: read - -defaults: - run: - shell: cmd - -jobs: - - build: - - runs-on: windows-2025 - if: ${{ github.repository_owner == 'danmar' }} - - env: - # see https://www.pcre.org/original/changelog.txt - PCRE_VERSION: 8.45 - QT_VERSION: 6.10.0 - BOOST_MINOR_VERSION: 89 - - steps: - - uses: actions/checkout@v4 - with: - persist-credentials: false - - - name: Set up Visual Studio environment - uses: ilammy/msvc-dev-cmd@v1 - - - name: Download PCRE - run: | - curl -fsSL https://github.com/pfultz2/pcre/archive/refs/tags/%PCRE_VERSION%.zip -o pcre-%PCRE_VERSION%.zip || exit /b !errorlevel! - - - name: Install PCRE - run: | - @echo on - 7z x pcre-%PCRE_VERSION%.zip || exit /b !errorlevel! - cd pcre-%PCRE_VERSION% || exit /b !errorlevel! - git apply --ignore-space-change ..\externals\pcre.patch || exit /b !errorlevel! - cmake . -G "Visual Studio 17 2022" -A x64 -DPCRE_BUILD_PCRECPP=OFF -DPCRE_BUILD_PCREGREP=OFF -DPCRE_BUILD_TESTS=OFF -DCMAKE_POLICY_VERSION_MINIMUM=3.5 -DCMAKE_COMPILE_WARNING_AS_ERROR=On || exit /b !errorlevel! - msbuild -m PCRE.sln -p:Configuration=Release -p:Platform=x64 || exit /b !errorlevel! - copy pcre.h ..\externals || exit /b !errorlevel! - copy Release\pcre.lib ..\externals\pcre64.lib || exit /b !errorlevel! - - - name: Download Boost - run: | - curl -fsSL https://archives.boost.io/release/1.%BOOST_MINOR_VERSION%.0/source/boost_1_%BOOST_MINOR_VERSION%_0.7z -o boost.zip || exit /b !errorlevel! - - - name: Install Boost - run: | - @echo on - 7z x boost.zip boost_1_%BOOST_MINOR_VERSION%_0/boost || exit /b !errorlevel! - ren boost_1_%BOOST_MINOR_VERSION%_0 boost || exit /b !errorlevel! - - # available modules: https://github.com/miurahr/aqtinstall/blob/master/docs/getting_started.rst#installing-modules - # available tools: https://github.com/miurahr/aqtinstall/blob/master/docs/getting_started.rst#installing-tools - - name: Install Qt ${{ env.QT_VERSION }} - uses: jurplel/install-qt-action@v4 - with: - version: ${{ env.QT_VERSION }} - modules: 'qtcharts' - setup-python: 'false' - tools: 'tools_opensslv3_x64' - aqtversion: '==3.1.*' # TODO: remove when aqtinstall 3.2.2 is available - - # TODO: build with multiple threads - - name: Build x64 release GUI - run: | - :: TODO: enable rules? - :: specify Release build so matchcompiler is used - cmake -S . -B build -DCMAKE_BUILD_TYPE=Release -DBUILD_GUI=On -DWITH_QCHART=On -DBUILD_ONLINE_HELP=On -DUSE_BOOST=ON -DBOOST_INCLUDEDIR=%GITHUB_WORKSPACE%\boost -DCMAKE_COMPILE_WARNING_AS_ERROR=On || exit /b !errorlevel! - cmake --build build --target cppcheck-gui --config Release || exit /b !errorlevel! - - # TODO: package PDBs - - name: Deploy app - run: | - windeployqt build\bin\Release || exit /b !errorlevel! - del build\bin\Release\cppcheck-gui.ilk || exit /b !errorlevel! - del build\bin\Release\cppcheck-gui.pdb || exit /b !errorlevel! - - - uses: actions/upload-artifact@v4 - with: - name: deploy - path: build\bin\Release - - - name: Matchcompiler - run: python tools\matchcompiler.py --write-dir lib || exit /b !errorlevel! - - # TODO: build with multiple threads - - name: Build CLI x64 release configuration using MSBuild - run: msbuild -m cppcheck.sln -t:cli -p:Configuration=Release-PCRE -p:Platform=x64 -p:HaveBoost=HAVE_BOOST -p:BoostInclude=%GITHUB_WORKSPACE%\boost || exit /b !errorlevel! - env: - _CL_: /WX - - - uses: actions/upload-artifact@v4 - with: - name: bin - path: bin - - - name: Install missing Python packages - run: | - pip install -U pyinstaller || exit /b !errorlevel! - - # TODO: include in installer? - - name: Compile misra.py executable - run: | - cd addons || exit /b !errorlevel! - pyinstaller --hidden-import xml --hidden-import xml.etree --hidden-import xml.etree.ElementTree misra.py || exit /b !errorlevel! - del *.spec || exit /b !errorlevel! - - # TODO: include in installer? - - name: Compile cppcheck-htmlreport executable - run: | - cd htmlreport || exit /b !errorlevel! - pyinstaller cppcheck-htmlreport || exit /b !errorlevel! - del *.spec || exit /b !errorlevel! - - # TODO: test the compiled Python files - - - name: Collect files - run: | - @echo on - move build\bin\Release win_installer\files || exit /b !errorlevel! - copy AUTHORS win_installer\files\authors.txt || exit /b !errorlevel! - copy win_installer\GPLv3.txt win_installer\files\ || exit /b !errorlevel! - copy externals\picojson\LICENSE win_installer\files\picojson-license.txt || exit /b !errorlevel! - copy externals\simplecpp\LICENSE win_installer\files\simplecpp-license.txt || exit /b !errorlevel! - copy externals\tinyxml2\LICENSE win_installer\files\tinyxml2-license.txt || exit /b !errorlevel! - copy addons\dist\misra\*.* win_installer\files\addons || exit /b !errorlevel! - copy bin\cppcheck.exe win_installer\files || exit /b !errorlevel! - copy bin\cppcheck-core.dll win_installer\files || exit /b !errorlevel! - :: mkdir win_installer\files\help || exit /b !errorlevel! - xcopy /s gui\help win_installer\files\help || exit /b !errorlevel! - copy gui\help\online-help.qhc win_installer\files\ || exit /b !errorlevel! - copy gui\help\online-help.qch win_installer\files\ || exit /b !errorlevel! - del win_installer\files\cfg\*.rng || exit /b !errorlevel! - del win_installer\files\platforms\*.rng || exit /b !errorlevel! - del win_installer\files\translations\*.qm || exit /b !errorlevel! - move build\gui\*.qm win_installer\files\translations || exit /b !errorlevel! - copy htmlreport\dist\cppcheck-htmlreport\*.* win_installer\files || exit /b !errorlevel! - :: copy libcrypto-3-x64.dll and libssl-3-x64.dll - copy %RUNNER_WORKSPACE%\Qt\Tools\OpenSSLv3\Win_x64\bin\lib*.dll win_installer\files || exit /b !errorlevel! - - - uses: actions/upload-artifact@v4 - with: - name: collect - path: win_installer\files - - - name: Build Installer - run: | - cd win_installer || exit /b !errorlevel! - :: Read ProductVersion - for /f "tokens=4 delims= " %%a in ('find "ProductVersion" productInfo.wxi') do set PRODUCTVER=%%a - :: Remove double quotes - set PRODUCTVER=%PRODUCTVER:"=% - @echo ProductVersion="%PRODUCTVER%" || exit /b !errorlevel! - msbuild -m cppcheck.wixproj -p:Platform=x64,ProductVersion=%PRODUCTVER%.${{ github.run_number }} || exit /b !errorlevel! - - - uses: actions/upload-artifact@v4 - with: - name: installer - path: win_installer/Build/ - - - name: Clean up deploy - run: | - @echo on - :: del win_installer\files\addons\*.dll || exit /b !errorlevel! - del win_installer\files\addons\*.doxyfile || exit /b !errorlevel! - del win_installer\files\addons\*.md || exit /b !errorlevel! - :: del win_installer\files\addons\*.pyd || exit /b !errorlevel! - :: del win_installer\files\addons\base_library.zip || exit /b !errorlevel! - rmdir /s /q win_installer\files\addons\test || exit /b !errorlevel! - rmdir /s /q win_installer\files\addons\doc || exit /b !errorlevel! - :: rmdir /s /q win_installer\files\bearer || exit /b !errorlevel! - rmdir /s /q win_installer\files\generic || exit /b !errorlevel! - rmdir /s /q win_installer\files\help || exit /b !errorlevel! - rmdir /s /q win_installer\files\iconengines || exit /b !errorlevel! - rmdir /s /q win_installer\files\imageformats || exit /b !errorlevel! - rmdir /s /q win_installer\files\networkinformation || exit /b !errorlevel! - :: rmdir /s /q win_installer\files\printsupport || exit /b !errorlevel! - rmdir /s /q win_installer\files\sqldrivers || exit /b !errorlevel! - rmdir /s /q win_installer\files\tls || exit /b !errorlevel! - ren win_installer\files\translations lang || exit /b !errorlevel! - del win_installer\files\d3dcompiler_47.dll || exit /b !errorlevel! - del win_installer\files\dxcompiler.dll || exit /b !errorlevel! - del win_installer\files\dxil.dll || exit /b !errorlevel! - del win_installer\files\dmake.exe || exit /b !errorlevel! - del win_installer\files\dmake.pdb || exit /b !errorlevel! - :: del win_installer\files\libEGL.dll || exit /b !errorlevel! - :: del win_installer\files\libGLESv2.dll || exit /b !errorlevel! - del win_installer\files\opengl32sw.dll || exit /b !errorlevel! - del win_installer\files\Qt6Svg.dll || exit /b !errorlevel! - del win_installer\files\vc_redist.x64.exe || exit /b !errorlevel! - - - uses: actions/upload-artifact@v4 - with: - name: portable - path: win_installer\files diff --git a/.github/workflows/scriptcheck.yml b/.github/workflows/scriptcheck.yml deleted file mode 100644 index 844b1d5c2f3..00000000000 --- a/.github/workflows/scriptcheck.yml +++ /dev/null @@ -1,222 +0,0 @@ -# Syntax reference https://help.github.com/en/actions/reference/workflow-syntax-for-github-actions -# Environment reference https://help.github.com/en/actions/reference/virtual-environments-for-github-hosted-runners -name: scriptcheck - -on: - push: - branches: - - 'main' - - 'releases/**' - - '2.*' - tags: - - '2.*' - pull_request: - -permissions: - contents: read - -jobs: - build: - - runs-on: ubuntu-22.04 - - steps: - - uses: actions/checkout@v4 - with: - persist-credentials: false - - - name: ccache - uses: hendrikmuhs/ccache-action@v1.2 - with: - key: ${{ github.workflow }}-${{ runner.os }} - - - name: Cache Cppcheck - uses: actions/cache@v4 - with: - path: cppcheck - key: ${{ runner.os }}-scriptcheck-cppcheck-${{ github.sha }} - - - name: build cppcheck - run: | - export PATH="/usr/lib/ccache:/usr/local/opt/ccache/libexec:$PATH" - make -j$(nproc) CXXOPTS="-Werror" - strip -s ./cppcheck - - scriptcheck: - - needs: build - runs-on: ubuntu-22.04 - strategy: - matrix: - python-version: [3.7, 3.8, 3.9, '3.10', '3.11', '3.12', '3.13', '3.14'] - include: - - python-version: '3.14' - python-latest: true - - fail-fast: false - - steps: - - uses: actions/checkout@v4 - with: - persist-credentials: false - - # TODO: bailout on error - - name: Restore Cppcheck - uses: actions/cache@v4 - with: - path: cppcheck - key: ${{ runner.os }}-scriptcheck-cppcheck-${{ github.sha }} - - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v5 - with: - python-version: ${{ matrix.python-version }} - check-latest: true - - - name: Install missing software on ubuntu - run: | - sudo apt-get update - sudo apt-get install tidy libxml2-utils - - - name: Install missing software on ubuntu (Python 3) - run: | - # shellcheck cannot be installed via pip - # ERROR: Could not find a version that satisfies the requirement shellcheck (from versions: none) - # ERROR: No matching distribution found for shellcheck - sudo apt-get install shellcheck - python -m pip install pip --upgrade - python -m pip install natsort - python -m pip install pexpect - python -m pip install 'pylint<4.1.0' - python -m pip install unittest2 - python -m pip install pytest - python -m pip install pytest-xdist - python -m pip install pygments - python -m pip install requests - python -m pip install psutil - python -m pip install setuptools - - - name: run Shellcheck - if: matrix.python-latest - run: | - find . -name "*.sh" | xargs shellcheck --exclude SC2002,SC2013,SC2034,SC2035,SC2043,SC2046,SC2086,SC2089,SC2090,SC2129,SC2211,SC2231 - - - name: run pylint - if: matrix.python-latest - run: | - shopt -s globstar - pylint --jobs $(nproc) --py-version 3.7 addons/**/*.py htmlreport/cppcheck-htmlreport htmlreport/**/*.py test/**/*.py tools/**/*.py - - - name: check .json files - if: matrix.python-latest - run: | - find . -name '*.json' | xargs -n 1 python -m json.tool > /dev/null - - - name: Validate - if: matrix.python-latest - run: | - make -j$(nproc) validateCFG validatePlatforms validateRules - - - name: check python syntax - run: | - shopt -s globstar - python -m py_compile addons/**/*.py - python -m py_compile htmlreport/cppcheck-htmlreport - python -m py_compile htmlreport/**/*.py - python -m py_compile test/**/*.py - python -m py_compile tools/**/*.py - - - name: compile addons - run: | - python -m compileall ./addons - - - name: test matchcompiler - run: | - python test/tools/test_matchcompiler.py - env: - PYTHONPATH: ./tools - - # TODO: run with "-n auto" when misra_test.py can be run in parallel - # we cannot specify -Werror since xml/etree/ElementTree.py in Python 3.9/3.10 contains an unclosed file - - name: test addons - if: matrix.python-version == '3.9' || matrix.python-version == '3.10' - run: | - python -m pytest --strict-markers -vv -n 1 addons/test - env: - PYTHONPATH: ./addons - - # TODO: run with "-n auto" when misra_test.py can be run in parallel - - name: test addons - if: matrix.python-version != '3.9' && matrix.python-version != '3.10' - run: | - python -m pytest -Werror --strict-markers -vv -n 1 addons/test - env: - PYTHONPATH: ./addons - - - name: test htmlreport (standalone) - run: | - test/tools/htmlreport/test_htmlreport.py - test/tools/htmlreport/check.sh - - - name: test htmlreport (pip) - run: | - python -m venv venv - source venv/bin/activate - python -m pip install -U pip - pip install ./htmlreport/ - which cppcheck-htmlreport - PIP_PACKAGE_TEST=1 test/tools/htmlreport/test_htmlreport.py - # TODO: does not test the pip binary - test/tools/htmlreport/check.sh - - - name: test reduce - run: | - python -m pytest -Werror --strict-markers -vv test/tools/reduce_test.py - env: - PYTHONPATH: ./tools - - - name: test donate_cpu_lib - run: | - python -m pytest -Werror --strict-markers -vv test/tools/donate_cpu_lib_test.py - env: - PYTHONPATH: ./tools - - - name: test donate_cpu_server - run: | - python -m pytest -Werror --strict-markers -vv test/tools/donate_cpu_server_test.py - # TODO: why is this file generated? also should be in a temporary folder if possible - rm -f test/tools/donate-cpu-server.log - env: - PYTHONPATH: ./tools - - - name: Show all ignored files - if: false # TODO: currently lists all the contents of ignored folders - we only need what actually matched - run: | - git ls-files --others --ignored --exclude-standard - - - name: Check for changed and unversioned files - run: | - # TODO: how to do this with a single command? - git status --ignored=no - git status --ignored=no | grep -q 'working tree clean' - - dmake: - strategy: - matrix: - os: [ubuntu-22.04, macos-15, windows-2025] - fail-fast: false - - runs-on: ${{ matrix.os }} - - steps: - - uses: actions/checkout@v4 - with: - persist-credentials: false - - - name: run dmake - run: | - make -j3 CXXOPTS="-Werror" run-dmake - - - name: check diff - run: | - git diff --exit-code diff --git a/.github/workflows/selfcheck.yml b/.github/workflows/selfcheck.yml deleted file mode 100644 index 27cd1254dcb..00000000000 --- a/.github/workflows/selfcheck.yml +++ /dev/null @@ -1,204 +0,0 @@ -# Syntax reference https://help.github.com/en/actions/reference/workflow-syntax-for-github-actions -# Environment reference https://help.github.com/en/actions/reference/virtual-environments-for-github-hosted-runners -name: selfcheck - -on: - push: - branches: - - 'main' - - 'releases/**' - - '2.*' - tags: - - '2.*' - pull_request: - -permissions: - contents: read - -jobs: - build: - - runs-on: ubuntu-22.04 - - env: - QT_VERSION: 6.10.0 - - steps: - - uses: actions/checkout@v4 - with: - persist-credentials: false - - - name: ccache - uses: hendrikmuhs/ccache-action@v1.2 - with: - key: ${{ github.workflow }}-${{ runner.os }} - - - name: Install missing software - run: | - sudo apt-get update - sudo apt-get install clang-14 - sudo apt-get install libboost-container-dev - sudo apt-get install valgrind - sudo apt-get install -y libgl-dev # fixes missing dependency for Qt in CMake - - - name: Install Qt ${{ env.QT_VERSION }} - uses: jurplel/install-qt-action@v4 - with: - version: ${{ env.QT_VERSION }} - modules: 'qtcharts' - setup-python: 'false' - install-deps: false - cache: true - - # TODO: cache this - perform same build as for the other self check - - name: Self check (build) - run: | - export PATH="/usr/lib/ccache:/usr/local/opt/ccache/libexec:$PATH" - # valgrind cannot handle DWARF 5 yet so force version 4 - # work around performance regression with -inline-deferral - make -j$(nproc) CXXOPTS="-Werror -O2 -gdwarf-4" CPPOPTS="-DHAVE_BOOST -mllvm -inline-deferral" MATCHCOMPILER=yes CPPCHK_GLIBCXX_DEBUG= - env: - CC: clang-14 - CXX: clang++-14 - - # unusedFunction - start - - name: CMake - run: | - cmake -S . -B cmake.output -G "Unix Makefiles" -DHAVE_RULES=On -DBUILD_TESTS=On -DBUILD_GUI=ON -DWITH_QCHART=ON -DBUILD_TRIAGE=On -DENABLE_CHECK_INTERNAL=On -DCMAKE_GLOBAL_AUTOGEN_TARGET=On -DDISABLE_DMAKE=On -DCPPCHK_GLIBCXX_DEBUG=Off - - - name: Generate dependencies - run: | - # make sure auto-generated GUI files exist - make -C cmake.output autogen - # make sure the precompiled headers exist - make -C cmake.output lib/CMakeFiles/cppcheck-core.dir/cmake_pch.hxx.cxx - make -C cmake.output test/CMakeFiles/testrunner.dir/cmake_pch.hxx.cxx - # make sure the auto-generated GUI dependencies exist - make -C cmake.output gui-build-deps - - - name: Self check (unusedFunction) - if: false # TODO: fails with preprocessorErrorDirective - see #10667 - run: | - ./cppcheck -q --template=selfcheck --error-exitcode=1 --library=cppcheck-lib --library=qt -D__CPPCHECK__ -D__GNUC__ -DQT_VERSION=0x060000 -DQ_MOC_OUTPUT_REVISION=69 -DQT_CHARTS_LIB -DQT_MOC_HAS_STRINGDATA --enable=unusedFunction,information --exception-handling -rp=. --project=cmake.output/compile_commands.json --suppressions-list=.selfcheck_unused_suppressions --inline-suppr - env: - DISABLE_VALUEFLOW: 1 - UNUSEDFUNCTION_ONLY: 1 - # unusedFunction - end - - # the following steps are duplicated from above since setting up the build node in a parallel step takes longer than the actual steps - - # unusedFunction notest - start - - name: CMake (no test) - run: | - cmake -S . -B cmake.output.notest -G "Unix Makefiles" -DHAVE_RULES=On -DBUILD_TESTS=Off -DBUILD_GUI=ON -DBUILD_TRIAGE=On -DWITH_QCHART=ON -DENABLE_CHECK_INTERNAL=On -DCMAKE_GLOBAL_AUTOGEN_TARGET=On -DDISABLE_DMAKE=On -DCPPCHK_GLIBCXX_DEBUG=Off - - - name: Generate dependencies (no test) - run: | - # make sure auto-generated GUI files exist - make -C cmake.output.notest autogen - # make sure the precompiled headers exist - make -C cmake.output.notest lib/CMakeFiles/cppcheck-core.dir/cmake_pch.hxx.cxx - # make sure the auto-generated GUI dependencies exist - make -C cmake.output.notest gui-build-deps - - - name: Self check (unusedFunction / no test) - run: | - ./cppcheck -q --template=selfcheck --error-exitcode=1 --library=cppcheck-lib --library=qt -D__CPPCHECK__ -D__GNUC__ -DQT_VERSION=0x060000 -DQ_MOC_OUTPUT_REVISION=69 -DQT_CHARTS_LIB -DQT_MOC_HAS_STRINGDATA --enable=unusedFunction,information --exception-handling -rp=. --project=cmake.output.notest/compile_commands.json --suppressions-list=.selfcheck_unused_suppressions --inline-suppr - env: - DISABLE_VALUEFLOW: 1 - UNUSEDFUNCTION_ONLY: 1 - # unusedFunction notest - end - - # unusedFunction notest nogui - start - - name: CMake (no test / no gui) - run: | - cmake -S . -B cmake.output.notest_nogui -G "Unix Makefiles" -DHAVE_RULES=On -DBUILD_TESTS=Off -DENABLE_CHECK_INTERNAL=On -DCPPCHK_GLIBCXX_DEBUG=Off - - - name: Generate dependencies (no test / no gui) - run: | - # make sure the precompiled headers exist - make -C cmake.output.notest_nogui lib/CMakeFiles/cppcheck-core.dir/cmake_pch.hxx.cxx - - - name: Self check (unusedFunction / no test / no gui) - run: | - supprs="--suppress=unusedFunction:lib/errorlogger.h:196 --suppress=unusedFunction:lib/importproject.cpp:1530 --suppress=unusedFunction:lib/importproject.cpp:1554" - ./cppcheck -q --template=selfcheck --error-exitcode=1 --library=cppcheck-lib -D__CPPCHECK__ -D__GNUC__ --enable=unusedFunction,information --exception-handling -rp=. --project=cmake.output.notest_nogui/compile_commands.json --suppressions-list=.selfcheck_unused_suppressions --inline-suppr $supprs - env: - DISABLE_VALUEFLOW: 1 - UNUSEDFUNCTION_ONLY: 1 - # unusedFunction notest nogui - end - - # unusedFunction notest nocli - start - - name: CMake (no test / no cli) - run: | - cmake -S . -B cmake.output.notest_nocli -G "Unix Makefiles" -DHAVE_RULES=On -DBUILD_TESTS=Off -DBUILD_CLI=Off -DBUILD_GUI=ON -DWITH_QCHART=ON -DBUILD_TRIAGE=On -DENABLE_CHECK_INTERNAL=On -DCMAKE_GLOBAL_AUTOGEN_TARGET=On -DDISABLE_DMAKE=On -DCPPCHK_GLIBCXX_DEBUG=Off - - - name: Generate dependencies (no test / no cli) - run: | - # make sure auto-generated GUI files exist - make -C cmake.output.notest_nocli autogen - # make sure the precompiled headers exist - make -C cmake.output.notest_nocli lib/CMakeFiles/cppcheck-core.dir/cmake_pch.hxx.cxx - # make sure the auto-generated GUI dependencies exist - make -C cmake.output.notest_nocli gui-build-deps - - - name: Self check (unusedFunction / no test / no cli) - if: false # TODO: the findings are currently too intrusive - run: | - ./cppcheck -q --template=selfcheck --error-exitcode=1 --library=cppcheck-lib --library=qt -D__CPPCHECK__ -D__GNUC__ -DQT_VERSION=0x060000 -DQ_MOC_OUTPUT_REVISION=69 -DQT_CHARTS_LIB -DQT_MOC_HAS_STRINGDATA --enable=unusedFunction,information --exception-handling -rp=. --project=cmake.output.notest_nocli/compile_commands.json --suppressions-list=.selfcheck_unused_suppressions --inline-suppr - env: - DISABLE_VALUEFLOW: 1 - UNUSEDFUNCTION_ONLY: 1 - # unusedFunction notest nocli - end - - # unusedFunction notest nocli nogui - start - - name: CMake (no test / no cli / no gui) - run: | - cmake -S . -B cmake.output.notest_nocli_nogui -G "Unix Makefiles" -DHAVE_RULES=On -DBUILD_TESTS=Off -DBUILD_CLI=Off -DBUILD_GUI=Off -DENABLE_CHECK_INTERNAL=On -DCPPCHK_GLIBCXX_DEBUG=Off - - - name: Generate dependencies (no test / no cli / no gui) - run: | - # make sure the precompiled headers exist - make -C cmake.output.notest_nocli_nogui lib/CMakeFiles/cppcheck-core.dir/cmake_pch.hxx.cxx - - - name: Self check (unusedFunction / no test / no cli / no gui) - if: false # TODO: the findings are currently too intrusive - run: | - ./cppcheck -q --template=selfcheck --error-exitcode=1 --library=cppcheck-lib --library=qt -D__CPPCHECK__ -D__GNUC__ --enable=unusedFunction,information --exception-handling -rp=. --project=cmake.output.notest_nocli_nogui/compile_commands.json --suppressions-list=.selfcheck_unused_suppressions --inline-suppr - env: - DISABLE_VALUEFLOW: 1 - UNUSEDFUNCTION_ONLY: 1 - # unusedFunction notest nocli nogui - end - - - name: Fetch corpus - run: | - wget https://github.com/danmar/cppcheck/archive/refs/tags/2.8.tar.gz - tar xvf 2.8.tar.gz - - - name: CMake (corpus / no test) - run: | - cmake -S cppcheck-2.8 -B cmake.output.corpus -G "Unix Makefiles" -DHAVE_RULES=On -DBUILD_TESTS=Off -DBUILD_GUI=ON -DUSE_QT6=On -DWITH_QCHART=ON -DENABLE_CHECK_INTERNAL=On -DCMAKE_GLOBAL_AUTOGEN_TARGET=On -DDISABLE_DMAKE=On -DCPPCHK_GLIBCXX_DEBUG=Off -DCMAKE_POLICY_VERSION_MINIMUM=3.5 - - - name: Generate dependencies (corpus) - run: | - # make sure auto-generated GUI files exist - make -C cmake.output.corpus autogen - # make sure the precompiled headers exist - make -C cmake.output.corpus lib/CMakeFiles/lib_objs.dir/cmake_pch.hxx.cxx - # make sure the auto-generated GUI dependencies exist - make -C cmake.output.corpus gui-build-deps - - - name: Self check (unusedFunction / corpus / no test / callgrind) - run: | - # TODO: fix -rp so the suppressions actually work - valgrind --tool=callgrind ./cppcheck --template=selfcheck --error-exitcode=0 --library=cppcheck-lib --library=qt -D__GNUC__ -DQT_VERSION=0x060000 -DQ_MOC_OUTPUT_REVISION=69 -DQT_CHARTS_LIB -DQT_MOC_HAS_STRINGDATA --enable=unusedFunction,information --exception-handling -rp=. --project=cmake.output.corpus/compile_commands.json --suppressions-list=.selfcheck_unused_suppressions --inline-suppr 2>callgrind.log || (cat callgrind.log && false) - cat callgrind.log - callgrind_annotate --auto=no > callgrind.annotated.log - head -50 callgrind.annotated.log - env: - DISABLE_VALUEFLOW: 1 - - - uses: actions/upload-artifact@v4 - with: - name: Callgrind Output - path: ./callgrind.* diff --git a/.github/workflows/valgrind.yml b/.github/workflows/valgrind.yml deleted file mode 100644 index 9a6026aa25b..00000000000 --- a/.github/workflows/valgrind.yml +++ /dev/null @@ -1,65 +0,0 @@ -# Syntax reference https://help.github.com/en/actions/reference/workflow-syntax-for-github-actions -# Environment reference https://help.github.com/en/actions/reference/virtual-environments-for-github-hosted-runners -name: valgrind - -on: - push: - branches: - - 'main' - - 'releases/**' - - '2.*' - tags: - - '2.*' - pull_request: - -permissions: - contents: read - -jobs: - build: - - runs-on: ubuntu-22.04 - - steps: - - uses: actions/checkout@v4 - with: - persist-credentials: false - - - name: ccache - uses: hendrikmuhs/ccache-action@v1.2 - with: - key: ${{ github.workflow }}-${{ runner.os }} - - - name: Install missing software - run: | - sudo apt-get update - sudo apt-get install libxml2-utils - sudo apt-get install valgrind - sudo apt-get install libboost-container-dev - sudo apt-get install debuginfod - - - name: Build cppcheck - run: | - export PATH="/usr/lib/ccache:/usr/local/opt/ccache/libexec:$PATH" - make -j$(nproc) CXXOPTS="-Werror -O1 -g" CPPOPTS="-DHAVE_BOOST" HAVE_RULES=yes MATCHCOMPILER=yes CPPCHK_GLIBCXX_DEBUG= - - - name: Build test - run: | - export PATH="/usr/lib/ccache:/usr/local/opt/ccache/libexec:$PATH" - make -j$(nproc) CXXOPTS="-Werror -O1 -g" CPPOPTS="-DHAVE_BOOST" HAVE_RULES=yes MATCHCOMPILER=yes CPPCHK_GLIBCXX_DEBUG= testrunner - - - name: Run valgrind - run: | - ec=0 - valgrind --error-limit=yes --leak-check=full --num-callers=50 --show-reachable=yes --track-origins=yes --suppressions=valgrind/testrunner.supp --gen-suppressions=all --log-fd=9 --error-exitcode=42 ./testrunner TestGarbage TestOther TestSimplifyTemplate 9>memcheck.log || ec=1 - cat memcheck.log - exit $ec - # TODO: debuginfod.ubuntu.com is currently not responding to any requests causing it to run into a 40(!) minute timeout - #env: - # DEBUGINFOD_URLS: https://debuginfod.ubuntu.com - - - uses: actions/upload-artifact@v4 - if: success() || failure() - with: - name: Logs - path: ./*.log diff --git a/cli/cmdlineparser.cpp b/cli/cmdlineparser.cpp index 92f4c6cef3b..f183b5c646e 100644 --- a/cli/cmdlineparser.cpp +++ b/cli/cmdlineparser.cpp @@ -621,6 +621,9 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a mSettings.cppHeaderProbe = true; } + else if (std::strcmp(argv[i], "--debug-analyzerinfo") == 0) + mSettings.debugainfo = true; + else if (std::strcmp(argv[i], "--debug-ast") == 0) mSettings.debugast = true; diff --git a/cli/cppcheckexecutor.cpp b/cli/cppcheckexecutor.cpp index a16f76183c0..ef47920a5d9 100644 --- a/cli/cppcheckexecutor.cpp +++ b/cli/cppcheckexecutor.cpp @@ -299,9 +299,10 @@ int CppCheckExecutor::check_wrapper(const Settings& settings, Suppressions& supp * @param unmatched list of unmatched suppressions (from Settings::Suppressions::getUnmatched(Local|Global)Suppressions) * @return true is returned if errors are reported */ -static bool reportUnmatchedSuppressions(const std::list &unmatched, ErrorLogger &errorLogger, const std::vector& filters) +static std::vector<::ErrorMessage> reportUnmatchedSuppressions(const std::list &unmatched, const std::vector& filters) { - bool err = false; + std::vector<::ErrorMessage> errors; + // Report unmatched suppressions for (const SuppressionList::Suppression &s : unmatched) { // check if this unmatched suppression is suppressed @@ -329,10 +330,11 @@ static bool reportUnmatchedSuppressions(const std::list &files, const std::list& fileSettings, ErrorLogger& errorLogger) { @@ -358,21 +360,55 @@ bool CppCheckExecutor::reportUnmatchedSuppressions(const Settings &settings, con supprlist.addSuppression(std::move(s)); } + const auto reportErrorsFn = [&](const std::string& sourcefile, std::size_t fsFileId, const std::vector<::ErrorMessage>& errors) -> bool { + if (errors.empty()) + return false; + + // TODO: what if sourcefile is empty? + + AnalyzerInformation analyzerInfo; + // FIXME: this is a horrible hack + // we need to "re-open" the file so we can add the unmatchedSuppression findings. + // we cannot keep it open conditionally because the whole program analysis read the XML. + // re-ordering is also not an option because the unmatched suppression reporting needs to be run after all other checks. + analyzerInfo.reopen(settings.buildDir, sourcefile, /*cfgname*/"", fsFileId); + + for (const auto& errmsg : errors) { + analyzerInfo.reportErr(errmsg); + errorLogger.reportErr(errmsg); + } + return true; + }; + bool err = false; for (auto i = files.cbegin(); i != files.cend(); ++i) { - err |= ::reportUnmatchedSuppressions(supprlist.getUnmatchedLocalSuppressions(*i), errorLogger, settings.unmatchedSuppressionFilters); + const std::vector errors = ::reportUnmatchedSuppressions(supprlist.getUnmatchedLocalSuppressions(*i), settings.unmatchedSuppressionFilters); + err |= reportErrorsFn(i->spath(), 0, errors); } for (auto i = fileSettings.cbegin(); i != fileSettings.cend(); ++i) { - err |= ::reportUnmatchedSuppressions(supprlist.getUnmatchedLocalSuppressions(i->file), errorLogger, settings.unmatchedSuppressionFilters); + const std::vector errors = ::reportUnmatchedSuppressions(supprlist.getUnmatchedLocalSuppressions(i->file), settings.unmatchedSuppressionFilters); + err |= reportErrorsFn(i->file.spath(), i->fileIndex, errors); } if (settings.inlineSuppressions) { - err |= ::reportUnmatchedSuppressions(supprlist.getUnmatchedInlineSuppressions(), errorLogger, settings.unmatchedSuppressionFilters); + const std::vector errors = ::reportUnmatchedSuppressions(supprlist.getUnmatchedInlineSuppressions(), settings.unmatchedSuppressionFilters); + for (const auto& errmsg : errors) { + std::string sourcefile; + if (!errmsg.callStack.empty()) + sourcefile = errmsg.callStack.cbegin()->getfile(); + err |= reportErrorsFn(sourcefile, 0, {errmsg}); + } } - err |= ::reportUnmatchedSuppressions(supprlist.getUnmatchedGlobalSuppressions(), errorLogger, settings.unmatchedSuppressionFilters); + const std::vector errors = ::reportUnmatchedSuppressions(supprlist.getUnmatchedGlobalSuppressions(), settings.unmatchedSuppressionFilters); + for (const auto& errmsg : errors) { + std::string sourcefile; + if (!errmsg.callStack.empty()) + sourcefile = errmsg.callStack.cbegin()->getfile(); + err |= reportErrorsFn(sourcefile, 0, {errmsg}); + } return err; } @@ -425,9 +461,10 @@ int CppCheckExecutor::check_internal(const Settings& settings, Suppressions& sup #endif } + // TODO: is this run again instead of using previously cached results? returnValue |= cppcheck.analyseWholeProgram(settings.buildDir, mFiles, mFileSettings, stdLogger.getCtuInfo()); - if (settings.severity.isEnabled(Severity::information) || settings.checkConfiguration) { + if ((settings.severity.isEnabled(Severity::information) || settings.checkConfiguration) && !supprs.nomsg.getSuppressions().empty()) { const bool err = reportUnmatchedSuppressions(settings, supprs.nomsg, mFiles, mFileSettings, stdLogger); if (err && returnValue == 0) returnValue = settings.exitCode; diff --git a/lib/analyzerinfo.cpp b/lib/analyzerinfo.cpp index c7045252f3d..b7237341c60 100644 --- a/lib/analyzerinfo.cpp +++ b/lib/analyzerinfo.cpp @@ -25,6 +25,7 @@ #include #include +#include #include #include #include @@ -84,29 +85,55 @@ void AnalyzerInformation::close() } } -bool AnalyzerInformation::skipAnalysis(const tinyxml2::XMLDocument &analyzerInfoDoc, std::size_t hash, std::list &errors) +bool AnalyzerInformation::skipAnalysis(const tinyxml2::XMLDocument &analyzerInfoDoc, std::size_t hash, std::list &errors, bool debug) { const tinyxml2::XMLElement * const rootNode = analyzerInfoDoc.FirstChildElement(); - if (rootNode == nullptr) + if (rootNode == nullptr) { + if (debug) + std::cout << "discarding cached result - no root node found" << std::endl; return false; + } - const char *attr = rootNode->Attribute("hash"); - if (!attr || attr != std::to_string(hash)) + if (strcmp(rootNode->Name(), "analyzerinfo") != 0) { + if (debug) + std::cout << "discarding cached result - unexpected root node" << std::endl; return false; + } - // Check for invalid license error or internal error, in which case we should retry analysis - for (const tinyxml2::XMLElement *e = rootNode->FirstChildElement(); e; e = e->NextSiblingElement()) { - if (std::strcmp(e->Name(), "error") == 0 && - (e->Attribute("id", "premium-invalidLicense") || - e->Attribute("id", "premium-internalError") || - e->Attribute("id", "internalError") - )) - return false; + const char * const attr = rootNode->Attribute("hash"); + if (!attr) { + if (debug) + std::cout << "discarding cached result - no 'hash' attribute found" << std::endl; + return false; + } + if (attr != std::to_string(hash)) { + if (debug) + std::cout << "discarding cached result - hash mismatch" << std::endl; + return false; } for (const tinyxml2::XMLElement *e = rootNode->FirstChildElement(); e; e = e->NextSiblingElement()) { - if (std::strcmp(e->Name(), "error") == 0) - errors.emplace_back(e); + if (std::strcmp(e->Name(), "error") != 0) + continue; + + // TODO: discarding results on internalError doesn't make sense since that won't fix itself + // Check for invalid license error or internal error, in which case we should retry analysis + static std::array s_ids{ + "premium-invalidLicense", + "premium-internalError", + "internalError" + }; + for (const auto* id : s_ids) + { + if (e->Attribute("id", id)) { + if (debug) + std::cout << "discarding cached result - '" << id << "' encountered" << std::endl; + errors.clear(); + return false; + } + } + + errors.emplace_back(e); } return true; @@ -114,15 +141,13 @@ bool AnalyzerInformation::skipAnalysis(const tinyxml2::XMLDocument &analyzerInfo std::string AnalyzerInformation::getAnalyzerInfoFileFromFilesTxt(std::istream& filesTxt, const std::string &sourcefile, const std::string &cfg, int fileIndex) { - const std::string id = (fileIndex > 0) ? std::to_string(fileIndex) : ""; std::string line; - const std::string end(sep + cfg + sep + id + sep + Path::simplifyPath(sourcefile)); while (std::getline(filesTxt,line)) { - if (line.size() <= end.size() + 2U) - continue; - if (!endsWith(line, end.c_str(), end.size())) - continue; - return line.substr(0,line.find(sep)); + AnalyzerInformation::Info filesTxtInfo; + if (!filesTxtInfo.parse(line)) + continue; // TODO: report error? + if (endsWith(sourcefile, filesTxtInfo.sourceFile) && filesTxtInfo.cfg == cfg && filesTxtInfo.fileIndex == fileIndex) + return filesTxtInfo.afile; } return ""; } @@ -145,24 +170,39 @@ std::string AnalyzerInformation::getAnalyzerInfoFile(const std::string &buildDir return Path::join(buildDir, std::move(filename)) + ".analyzerinfo"; } -bool AnalyzerInformation::analyzeFile(const std::string &buildDir, const std::string &sourcefile, const std::string &cfg, int fileIndex, std::size_t hash, std::list &errors) +bool AnalyzerInformation::analyzeFile(const std::string &buildDir, const std::string &sourcefile, const std::string &cfg, int fileIndex, std::size_t hash, std::list &errors, bool debug) { + if (mOutputStream.is_open()) + throw std::runtime_error("analyzer information file is already open"); + if (buildDir.empty() || sourcefile.empty()) return true; - close(); const std::string analyzerInfoFile = AnalyzerInformation::getAnalyzerInfoFile(buildDir,sourcefile,cfg,fileIndex); - tinyxml2::XMLDocument analyzerInfoDoc; - const tinyxml2::XMLError xmlError = analyzerInfoDoc.LoadFile(analyzerInfoFile.c_str()); - if (xmlError == tinyxml2::XML_SUCCESS && skipAnalysis(analyzerInfoDoc, hash, errors)) - return false; + { + tinyxml2::XMLDocument analyzerInfoDoc; + const tinyxml2::XMLError xmlError = analyzerInfoDoc.LoadFile(analyzerInfoFile.c_str()); + if (xmlError == tinyxml2::XML_SUCCESS) { + if (skipAnalysis(analyzerInfoDoc, hash, errors, debug)) { + if (debug) + std::cout << "skipping analysis - loaded " << errors.size() << " cached finding(s) from '" << analyzerInfoFile << "'" << std::endl; + return false; + } + } + else if (xmlError != tinyxml2::XML_ERROR_FILE_NOT_FOUND) { + if (debug) + std::cout << "discarding cached result - failed to load '" << analyzerInfoFile << "' (" << tinyxml2::XMLDocument::ErrorIDToName(xmlError) << ")" << std::endl; + } + else if (debug) + std::cout << "no cached result '" << analyzerInfoFile << "' found" << std::endl; + } mOutputStream.open(analyzerInfoFile); - if (mOutputStream.is_open()) { - mOutputStream << "\n"; - mOutputStream << "\n"; - } + if (!mOutputStream.is_open()) + throw std::runtime_error("failed to open '" + analyzerInfoFile + "'"); + mOutputStream << "\n"; + mOutputStream << "\n"; return true; } @@ -179,6 +219,7 @@ void AnalyzerInformation::setFileInfo(const std::string &check, const std::strin mOutputStream << " \n" << fileInfo << " \n"; } +// TODO: report detailed errors? bool AnalyzerInformation::Info::parse(const std::string& filesTxtLine) { const std::string::size_type sep1 = filesTxtLine.find(sep); if (sep1 == std::string::npos) @@ -206,37 +247,70 @@ bool AnalyzerInformation::Info::parse(const std::string& filesTxtLine) { return true; } -// TODO: bail out on unexpected data -void AnalyzerInformation::processFilesTxt(const std::string& buildDir, const std::function& handler) +std::string AnalyzerInformation::processFilesTxt(const std::string& buildDir, const std::function& handler, bool debug) { const std::string filesTxt(buildDir + "/files.txt"); std::ifstream fin(filesTxt.c_str()); std::string filesTxtLine; while (std::getline(fin, filesTxtLine)) { AnalyzerInformation::Info filesTxtInfo; - if (!filesTxtInfo.parse(filesTxtLine)) { - return; - } + if (!filesTxtInfo.parse(filesTxtLine)) + return "failed to parse '" + filesTxtLine + "' from '" + filesTxt + "'"; + + if (filesTxtInfo.afile.empty()) + return "empty afile from '" + filesTxt + "'"; const std::string xmlfile = buildDir + '/' + filesTxtInfo.afile; tinyxml2::XMLDocument doc; const tinyxml2::XMLError error = doc.LoadFile(xmlfile.c_str()); + if (error == tinyxml2::XML_ERROR_FILE_NOT_FOUND) + return "'" + xmlfile + "' from '" + filesTxt + "' not found"; + if (error != tinyxml2::XML_SUCCESS) - return; + return "failed to load '" + xmlfile + "' from '" + filesTxt + "'"; const tinyxml2::XMLElement * const rootNode = doc.FirstChildElement(); if (rootNode == nullptr) - return; + return "no root node found in '" + xmlfile + "' from '" + filesTxt + "'"; + + if (strcmp(rootNode->Name(), "analyzerinfo") != 0) + return "unexpected root node in '" + xmlfile + "' from '" + filesTxt + "'"; for (const tinyxml2::XMLElement *e = rootNode->FirstChildElement(); e; e = e->NextSiblingElement()) { if (std::strcmp(e->Name(), "FileInfo") != 0) continue; const char *checkattr = e->Attribute("check"); - if (checkattr == nullptr) + if (checkattr == nullptr) { + if (debug) + std::cout << "'check' attribute missing in 'FileInfo' in '" << xmlfile << "' from '" << filesTxt + "'"; continue; + } handler(checkattr, e, filesTxtInfo); } } + + // TODO: error on empty file? + return ""; } +void AnalyzerInformation::reopen(const std::string &buildDir, const std::string &sourcefile, const std::string &cfg, int fileIndex) +{ + if (buildDir.empty() || sourcefile.empty()) + return; + + const std::string analyzerInfoFile = AnalyzerInformation::getAnalyzerInfoFile(buildDir,sourcefile,cfg,fileIndex); + std::ifstream ifs(analyzerInfoFile); + if (!ifs.is_open()) + return; + + std::ostringstream iss; + iss << ifs.rdbuf(); + ifs.close(); + + std::string content = iss.str(); + content = content.substr(0, content.find("")); + + mOutputStream.open(analyzerInfoFile, std::ios::trunc); + mOutputStream << content; +} diff --git a/lib/analyzerinfo.h b/lib/analyzerinfo.h index 881076c09f4..c6db1997148 100644 --- a/lib/analyzerinfo.h +++ b/lib/analyzerinfo.h @@ -61,11 +61,16 @@ class CPPCHECKLIB AnalyzerInformation { /** Close current TU.analyzerinfo file */ void close(); - bool analyzeFile(const std::string &buildDir, const std::string &sourcefile, const std::string &cfg, int fileIndex, std::size_t hash, std::list &errors); + /** + * @throws std::runtime_error thrown if the output file is already open or the output file cannot be opened + */ + bool analyzeFile(const std::string &buildDir, const std::string &sourcefile, const std::string &cfg, int fileIndex, std::size_t hash, std::list &errors, bool debug = false); void reportErr(const ErrorMessage &msg); void setFileInfo(const std::string &check, const std::string &fileInfo); static std::string getAnalyzerInfoFile(const std::string &buildDir, const std::string &sourcefile, const std::string &cfg, int fileIndex); + void reopen(const std::string &buildDir, const std::string &sourcefile, const std::string &cfg, int fileIndex); + static const char sep = ':'; class CPPCHECKLIB Info { @@ -77,14 +82,14 @@ class CPPCHECKLIB AnalyzerInformation { std::string sourceFile; }; - static void processFilesTxt(const std::string& buildDir, const std::function& handler); + static std::string processFilesTxt(const std::string& buildDir, const std::function& handler, bool debug = false); protected: static std::string getFilesTxt(const std::list &sourcefiles, const std::string &userDefines, const std::list &fileSettings); static std::string getAnalyzerInfoFileFromFilesTxt(std::istream& filesTxt, const std::string &sourcefile, const std::string &cfg, int fileIndex); - static bool skipAnalysis(const tinyxml2::XMLDocument &analyzerInfoDoc, std::size_t hash, std::list &errors); + static bool skipAnalysis(const tinyxml2::XMLDocument &analyzerInfoDoc, std::size_t hash, std::list &errors, bool debug = false); private: std::ofstream mOutputStream; diff --git a/lib/checkunusedfunctions.cpp b/lib/checkunusedfunctions.cpp index 7edaff6c241..eb06a4691f1 100644 --- a/lib/checkunusedfunctions.cpp +++ b/lib/checkunusedfunctions.cpp @@ -482,7 +482,12 @@ void CheckUnusedFunctions::analyseWholeProgram(const Settings &settings, ErrorLo } }; - AnalyzerInformation::processFilesTxt(buildDir, handler); + const std::string err = AnalyzerInformation::processFilesTxt(buildDir, handler, settings.debugainfo); + if (!err.empty()) { + const ErrorMessage errmsg({}, "", Severity::error, err, "internalError", Certainty::normal); + errorLogger.reportErr(errmsg); + return; + } for (auto decl = decls.cbegin(); decl != decls.cend(); ++decl) { const std::string &functionName = stripTemplateParameters(decl->first); diff --git a/lib/cppcheck.cpp b/lib/cppcheck.cpp index 399eb6d3d6e..407b956bb88 100644 --- a/lib/cppcheck.cpp +++ b/lib/cppcheck.cpp @@ -974,7 +974,7 @@ unsigned int CppCheck::checkInternal(const FileWithDetails& file, const std::str mLogger->setAnalyzerInfo(nullptr); std::list errors; - analyzerInformation->analyzeFile(mSettings.buildDir, file.spath(), cfgname, fileIndex, hash, errors); + analyzerInformation->analyzeFile(mSettings.buildDir, file.spath(), cfgname, fileIndex, hash, errors, mSettings.debugainfo); analyzerInformation->setFileInfo("CheckUnusedFunctions", mUnusedFunctionsCheck->analyzerInfo(tokenizer)); analyzerInformation->close(); } @@ -1020,7 +1020,7 @@ unsigned int CppCheck::checkInternal(const FileWithDetails& file, const std::str // Calculate hash so it can be compared with old hash / future hashes const std::size_t hash = calculateHash(preprocessor, file.spath()); std::list errors; - if (!analyzerInformation->analyzeFile(mSettings.buildDir, file.spath(), cfgname, fileIndex, hash, errors)) { + if (!analyzerInformation->analyzeFile(mSettings.buildDir, file.spath(), cfgname, fileIndex, hash, errors, mSettings.debugainfo)) { while (!errors.empty()) { mErrorLogger.reportErr(errors.front()); errors.pop_front(); @@ -1861,12 +1861,17 @@ unsigned int CppCheck::analyseWholeProgram(const std::string &buildDir, const st } }; - AnalyzerInformation::processFilesTxt(buildDir, handler); - - // Analyse the tokens - // cppcheck-suppress shadowFunction - TODO: fix this - for (Check *check : Check::instances()) - check->analyseWholeProgram(ctuFileInfo, fileInfoList, mSettings, mErrorLogger); + const std::string err = AnalyzerInformation::processFilesTxt(buildDir, handler, mSettings.debugainfo); + if (!err.empty()) { + const ErrorMessage errmsg({}, "", Severity::error, err, "internalError", Certainty::normal); + mErrorLogger.reportErr(errmsg); + } + else { + // Analyse the tokens + // cppcheck-suppress shadowFunction - TODO: fix this + for (Check *check : Check::instances()) + check->analyseWholeProgram(ctuFileInfo, fileInfoList, mSettings, mErrorLogger); + } for (Check::FileInfo *fi : fileInfoList) delete fi; diff --git a/lib/errorlogger.cpp b/lib/errorlogger.cpp index e62ed6b806d..13f66c13d1a 100644 --- a/lib/errorlogger.cpp +++ b/lib/errorlogger.cpp @@ -162,6 +162,7 @@ ErrorMessage::ErrorMessage(ErrorPath errorPath, const TokenList *tokenList, Seve // hash = calculateWarningHash(tokenList, hashWarning.str()); } +// TODO: improve errorhandling? ErrorMessage::ErrorMessage(const tinyxml2::XMLElement * const errmsg) : severity(Severity::none), cwe(0U), diff --git a/lib/settings.h b/lib/settings.h index 04541cda08c..6521ba4581d 100644 --- a/lib/settings.h +++ b/lib/settings.h @@ -189,6 +189,9 @@ class CPPCHECKLIB WARN_UNUSED Settings { /** @brief Are we running from DACA script? */ bool daca{}; + /** @brief Is --debug-analyzerinfo given? */ + bool debugainfo{}; + /** @brief Is --debug-ast given? */ bool debugast{}; diff --git a/lib/utils.h b/lib/utils.h index c59e4d3a32c..c84c72236c1 100644 --- a/lib/utils.h +++ b/lib/utils.h @@ -124,6 +124,11 @@ bool endsWith(const std::string& str, const char (&end)[N]) return endsWith(str, end, N - 1); } +inline bool endsWith(const std::string& str, const std::string& end) +{ + return endsWith(str, end.c_str(), end.length()); +} + inline static bool isPrefixStringCharLiteral(const std::string &str, char q, const std::string& p) { // str must be at least the prefix plus the start and end quote diff --git a/test/cli/clang-import_test.py b/test/cli/clang-import_test.py index e4ec19a5ada..23be48c91ca 100644 --- a/test/cli/clang-import_test.py +++ b/test/cli/clang-import_test.py @@ -217,6 +217,7 @@ def test_cmd_std_c(tmp_path): # #13129 # TODO: remove when we inject the build-dir into all tests +@pytest.mark.xfail(strict=True) # TODO: no analyzer information generated with --clang - see #14456 def test_cmd_std_c_builddir(tmp_path): # #13129 build_dir = tmp_path / 'b1' os.makedirs(build_dir) diff --git a/test/cli/other_test.py b/test/cli/other_test.py index c4ae2fab5cf..20485a08359 100644 --- a/test/cli/other_test.py +++ b/test/cli/other_test.py @@ -2353,12 +2353,12 @@ def test_inline_suppr_builddir(tmp_path): __test_inline_suppr(tmp_path, ['--cppcheck-build-dir={}'.format(build_dir), '-j1']) -# TODO: the suppressions are generated outside of the scope which captures the analysis information -@pytest.mark.xfail(strict=True) def test_inline_suppr_builddir_cached(tmp_path): build_dir = tmp_path / 'b1' os.mkdir(build_dir) __test_inline_suppr(tmp_path, ['--cppcheck-build-dir={}'.format(build_dir), '-j1']) + with open(build_dir / 'test.a1' , 'r') as f: + print(f.readlines()) __test_inline_suppr(tmp_path, ['--cppcheck-build-dir={}'.format(build_dir), '-j1']) @@ -2368,8 +2368,6 @@ def test_inline_suppr_builddir_j(tmp_path): __test_inline_suppr(tmp_path, ['--cppcheck-build-dir={}'.format(build_dir), '-j2']) -# TODO: the suppressions are generated outside of the scope which captures the analysis information -@pytest.mark.xfail(strict=True) def test_inline_suppr_builddir_j_cached(tmp_path): build_dir = tmp_path / 'b1' os.mkdir(build_dir) @@ -4119,3 +4117,101 @@ def test_active_unusedfunction_only_misra_builddir(tmp_path): 'CheckUnusedFunctions::check' ] __test_active_checkers(tmp_path, 1, 1175, use_unusedfunction_only=True, use_misra=True, checkers_exp=checkers_exp) + + +def test_analyzerinfo(tmp_path): + test_file = tmp_path / 'test.c' + with open(test_file, "w") as f: + f.write( +"""void f() +{ + (void)(*((int*)0)); +} +""") + + build_dir = tmp_path / 'b1' + os.makedirs(build_dir) + + test_a1_file = build_dir / 'test.a1' + + args = [ + '-q', + '--debug-analyzerinfo', + '--template=simple', + '--cppcheck-build-dir={}'.format(build_dir), + '--enable=all', + str(test_file) + ] + + stderr_exp = [ + '{}:3:14: error: Null pointer dereference: (int*)0 [nullPointer]'.format(test_file), + "{}:1:6: style: The function 'f' is never used. [unusedFunction]".format(test_file) + ] + + def run_and_assert_cppcheck(stdout_exp): + exitcode, stdout, stderr = cppcheck(args) + assert exitcode == 0, stdout + assert stdout.splitlines() == stdout_exp + assert stderr.splitlines() == stderr_exp + + # no cached results + run_and_assert_cppcheck([ + "no cached result '{}' found".format(test_a1_file) + ]) + + # cached results + run_and_assert_cppcheck([ + "skipping analysis - loaded 1 cached finding(s) from '{}'".format(test_a1_file) + ]) + + # modified file + with open(test_file, 'a') as f: + f.write('\n#define DEF') + + run_and_assert_cppcheck([ + "discarding cached result - hash mismatch" # TODO: add filename + ]) + + # invalid XML + with open(test_a1_file, 'a') as f: + f.write('.') + + run_and_assert_cppcheck([ + "discarding cached result - failed to load '{}' (XML_ERROR_PARSING_TEXT)".format(test_a1_file) + ]) + + # missing root node + with open(test_a1_file, 'w') as f: + f.write('') + + run_and_assert_cppcheck([ + "discarding cached result - no root node found" # TODO: add filename + ]) + + # mismatched root node + with open(test_a1_file, 'w') as f: + f.write('') + + run_and_assert_cppcheck([ + "discarding cached result - unexpected root node" # TODO: add filename + ]) + + # missing 'hash' attribute + with open(test_a1_file, 'w') as f: + f.write('') + + run_and_assert_cppcheck([ + "discarding cached result - no 'hash' attribute found" # TODO: add filename + ]) + + # invalid 'hash' attribute + with open(test_a1_file, 'w') as f: + f.write('') + + run_and_assert_cppcheck([ + "discarding cached result - hash mismatch" # TODO: add filename + ]) + + # TODO: + # - invalid error + # - internalError diff --git a/test/cli/testutils.py b/test/cli/testutils.py index f352af49f15..4fff02e8737 100644 --- a/test/cli/testutils.py +++ b/test/cli/testutils.py @@ -5,6 +5,7 @@ import subprocess import time import tempfile +import pathlib # Create Cppcheck project file import sys @@ -205,29 +206,88 @@ def cppcheck_ex(args, env=None, remove_checkers_report=True, cwd=None, cppcheck_ logging.info(exe + ' ' + ' '.join(args)) - run_subprocess = __run_subprocess_tty if tty else __run_subprocess - return_code, stdout, stderr = run_subprocess([exe] + args, env=env, cwd=cwd, timeout=timeout) + def run_cppcheck(): + run_subprocess = __run_subprocess_tty if tty else __run_subprocess + rc, out, err = run_subprocess([exe] + args, env=env, cwd=cwd, timeout=timeout) - stdout = stdout.decode(encoding='utf-8', errors='ignore').replace('\r\n', '\n') - stderr = stderr.decode(encoding='utf-8', errors='ignore').replace('\r\n', '\n') + out = out.decode(encoding='utf-8', errors='ignore').replace('\r\n', '\n') + err = err.decode(encoding='utf-8', errors='ignore').replace('\r\n', '\n') - if builddir_tmp: - builddir_tmp.cleanup() + return rc, out, err - if remove_checkers_report: - if stderr.find('[checkersReport]\n') > 0: - start_id = stderr.find('[checkersReport]\n') - start_line = stderr.rfind('\n', 0, start_id) + return_code, stdout, stderr = run_cppcheck() + + def remove_checkers_msg(msgs): + if msgs.find('[checkersReport]\n') > 0: + start_id = msgs.find('[checkersReport]\n') + start_line = msgs.rfind('\n', 0, start_id) if start_line <= 0: - stderr = '' + msgs = '' else: - stderr = stderr[:start_line + 1] - elif stderr.find(': (information) Active checkers: ') >= 0: - pos = stderr.find(': (information) Active checkers: ') + msgs = msgs[:start_line + 1] + elif msgs.find(': (information) Active checkers: ') >= 0: + pos = msgs.find(': (information) Active checkers: ') if pos == 0: - stderr = '' - elif stderr[pos - 1] == '\n': - stderr = stderr[:pos] + msgs = '' + elif msgs[pos - 1] == '\n': + msgs = msgs[:pos] + return msgs + + if builddir_tmp: + # run it again with the generated cache and make sure the output is identical + + def get_cache_contents(): + content = {} + for dirpath, dirnames, filenames in os.walk(builddir_tmp.name): + for fn in filenames: + content[os.path.join(dirpath, fn)] = (pathlib.Path(builddir_tmp.name) / dirpath / fn).read_text() + for dn in dirnames: + content[os.path.join(dirpath, dn)] = None + return content + + cache_content = get_cache_contents() + + # TODO: check that the cached results were actually used - run with --debug-analyzerinfo, check timestamps, etc. + return_code_1, stdout_1, stderr_1 = run_cppcheck() + + # TODO: the following asserts do not show a diff when the test fails + # this can apparently by fixed by using register_assert_rewrite() but I have no idea how + + assert return_code == return_code_1 + + stdout_lines = stdout.splitlines() + stdout_1_lines = stdout_1.splitlines() + print('stdout - expected') + print(stdout_lines) + print('stdout - actual') + print(stdout_1_lines) + # strip some common output only seen during analysis + stdout_lines = [entry for entry in stdout_lines if not entry.startswith('Processing rule: ')] + stdout_lines = [entry for entry in stdout_lines if not entry.startswith('progress: ')] + # TODO: no messages for checked configurations when using cached data + #assert stdout_lines == stdout_1_lines + + stderr_lines = stderr.splitlines() + stderr_1_lines = stderr_1.splitlines() + print('stderr - expected') + print(stderr_lines) + print('stderr - actual') + print(stderr_1_lines) + # TODO: filter out checkersReport because it different amount of active checkers for cached runs + #stderr_lines = remove_checkers_msg(stderr).splitlines() + #stderr_1_lines = remove_checkers_msg(stderr_1).splitlines() + assert stderr_lines == stderr_1_lines + + cache_content_1 = get_cache_contents() + + assert cache_content == cache_content_1 + + if builddir_tmp: + builddir_tmp.cleanup() + + if remove_checkers_report: + stderr = remove_checkers_msg(stderr) + return return_code, stdout, stderr, exe diff --git a/test/testcmdlineparser.cpp b/test/testcmdlineparser.cpp index 3b343cbc92e..b6690f8d5c7 100644 --- a/test/testcmdlineparser.cpp +++ b/test/testcmdlineparser.cpp @@ -493,6 +493,7 @@ class TestCmdlineParser : public TestFixture { TEST_CASE(safetyOverride); TEST_CASE(noSafety); TEST_CASE(noSafetyOverride); + TEST_CASE(debugAnalyzerinfo); TEST_CASE(ignorepaths1); TEST_CASE(ignorepaths2); @@ -3424,6 +3425,13 @@ class TestCmdlineParser : public TestFixture { ASSERT_EQUALS(false, settings->safety); } + void debugAnalyzerinfo() { + REDIRECT; + const char * const argv[] = {"cppcheck", "--debug-analyzerinfo", "file.cpp"}; + ASSERT_EQUALS_ENUM(CmdLineParser::Result::Success, parseFromArgs(argv)); + ASSERT_EQUALS(true, settings->debugainfo); + } + void ignorepaths1() { REDIRECT; const char * const argv[] = {"cppcheck", "-isrc", "file.cpp"};