diff --git a/.clang-tidy b/.clang-tidy index daacf4f00e..33569be50a 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -4,8 +4,8 @@ Checks: "-*, bugprone-assert-side-effect, bugprone-bad-signal-to-kill-thread, bugprone-bool-pointer-implicit-conversion, - bugprone-casting-through-void, bugprone-capturing-this-in-member-variable, + bugprone-casting-through-void, bugprone-chained-comparison, bugprone-compare-pointer-to-member-virtual-function, bugprone-copy-constructor-init, @@ -24,10 +24,10 @@ Checks: "-*, bugprone-lambda-function-name, bugprone-macro-parentheses, bugprone-macro-repeated-side-effects, + bugprone-misleading-setter-of-reference, bugprone-misplaced-operator-in-strlen-in-alloc, bugprone-misplaced-pointer-arithmetic-in-alloc, bugprone-misplaced-widening-cast, - bugprone-misleading-setter-of-reference, bugprone-move-forwarding-reference, bugprone-multi-level-implicit-pointer-conversion, bugprone-multiple-new-in-one-expression, @@ -73,10 +73,10 @@ Checks: "-*, bugprone-unhandled-self-assignment, bugprone-unique-ptr-array-mismatch, bugprone-unsafe-functions, - bugprone-use-after-move, + bugprone-unused-local-non-trivial-variable, bugprone-unused-raii, bugprone-unused-return-value, - bugprone-unused-local-non-trivial-variable, + bugprone-use-after-move, bugprone-virtual-near-miss, cppcoreguidelines-init-variables, cppcoreguidelines-misleading-capture-default-by-value, @@ -88,6 +88,7 @@ Checks: "-*, cppcoreguidelines-use-enum-class, cppcoreguidelines-virtual-class-destructor, hicpp-ignored-remove-result, + llvm-namespace-comment, misc-const-correctness, misc-definitions-in-headers, misc-header-include-cycle, @@ -99,6 +100,7 @@ Checks: "-*, misc-unused-alias-decls, misc-unused-using-decls, modernize-concat-nested-namespaces, + modernize-deprecated-headers, modernize-make-shared, modernize-make-unique, modernize-pass-by-value, @@ -114,8 +116,6 @@ Checks: "-*, modernize-use-starts-ends-with, modernize-use-std-numbers, modernize-use-using, - modernize-deprecated-headers, - llvm-namespace-comment, performance-faster-string-find, performance-for-range-copy, performance-implicit-conversion-in-loop, diff --git a/.github/workflows/on-pr.yml b/.github/workflows/on-pr.yml index 28299a1264..d95f3a6c00 100644 --- a/.github/workflows/on-pr.yml +++ b/.github/workflows/on-pr.yml @@ -58,15 +58,12 @@ jobs: # Keep the paths below in sync with those in `on-trigger.yml`. .github/actions/build-deps/** - .github/actions/build-test/** .github/actions/generate-version/** .github/actions/setup-conan/** .github/scripts/strategy-matrix/** - .github/workflows/reusable-build.yml .github/workflows/reusable-build-test-config.yml .github/workflows/reusable-build-test.yml .github/workflows/reusable-clang-tidy.yml - .github/workflows/reusable-clang-tidy-files.yml .github/workflows/reusable-strategy-matrix.yml .github/workflows/reusable-test.yml .github/workflows/reusable-upload-recipe.yml @@ -176,4 +173,4 @@ jobs: runs-on: ubuntu-latest steps: - name: Fail - run: false + run: exit 1 diff --git a/.github/workflows/on-trigger.yml b/.github/workflows/on-trigger.yml index 5856c67bd3..11d98bffb7 100644 --- a/.github/workflows/on-trigger.yml +++ b/.github/workflows/on-trigger.yml @@ -15,15 +15,12 @@ on: # Keep the paths below in sync with those in `on-pr.yml`. - ".github/actions/build-deps/**" - - ".github/actions/build-test/**" - ".github/actions/generate-version/**" - ".github/actions/setup-conan/**" - ".github/scripts/strategy-matrix/**" - - ".github/workflows/reusable-build.yml" - ".github/workflows/reusable-build-test-config.yml" - ".github/workflows/reusable-build-test.yml" - ".github/workflows/reusable-clang-tidy.yml" - - ".github/workflows/reusable-clang-tidy-files.yml" - ".github/workflows/reusable-strategy-matrix.yml" - ".github/workflows/reusable-test.yml" - ".github/workflows/reusable-upload-recipe.yml" diff --git a/.github/workflows/reusable-clang-tidy-files.yml b/.github/workflows/reusable-clang-tidy-files.yml deleted file mode 100644 index 7b35b2d968..0000000000 --- a/.github/workflows/reusable-clang-tidy-files.yml +++ /dev/null @@ -1,175 +0,0 @@ -name: Run clang-tidy on files - -on: - workflow_call: - inputs: - files: - description: "List of files to check (empty means check all files)" - type: string - default: "" - create_issue_on_failure: - description: "Whether to create an issue if the check failed" - type: boolean - default: false - -defaults: - run: - shell: bash - -env: - # Conan installs the generators in the build/generators directory, see the - # layout() method in conanfile.py. We then run CMake from the build directory. - BUILD_DIR: build - BUILD_TYPE: Debug # Debug so that ASSERTS and such participate in clang-tidy check - -jobs: - run-clang-tidy: - name: Run clang tidy - runs-on: ["self-hosted", "Linux", "X64", "heavy"] - container: "ghcr.io/xrplf/ci/debian-trixie:clang-21-sha-53033a2" - permissions: - issues: write - contents: read - steps: - - name: Checkout repository - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 - - - name: Prepare runner - uses: XRPLF/actions/prepare-runner@90f11ee655d1687824fb8793db770477d52afbab - with: - enable_ccache: false - - - name: Print build environment - uses: XRPLF/actions/print-build-env@59dec886e4afb05a1724443af08baccbc045b574 - - - name: Get number of processors - uses: XRPLF/actions/get-nproc@cf0433aa74563aead044a1e395610c96d65a37cf - id: nproc - - - name: Setup Conan - uses: ./.github/actions/setup-conan - - - name: Build dependencies - uses: ./.github/actions/build-deps - with: - build_nproc: ${{ steps.nproc.outputs.nproc }} - build_type: ${{ env.BUILD_TYPE }} - log_verbosity: verbose - - - name: Configure CMake - working-directory: ${{ env.BUILD_DIR }} - run: | - cmake \ - -G 'Ninja' \ - -DCMAKE_TOOLCHAIN_FILE:FILEPATH=build/generators/conan_toolchain.cmake \ - -DCMAKE_BUILD_TYPE="${BUILD_TYPE}" \ - -Dtests=ON \ - -Dwerr=ON \ - -Dxrpld=ON \ - .. - - # clang-tidy needs headers generated from proto files - - name: Build libxrpl.libpb - working-directory: ${{ env.BUILD_DIR }} - run: | - ninja -j ${{ steps.nproc.outputs.nproc }} xrpl.libpb - - - name: Run clang tidy - id: run_clang_tidy - continue-on-error: true - env: - TARGETS: ${{ inputs.files != '' && inputs.files || 'src tests' }} - run: | - run-clang-tidy -j ${{ steps.nproc.outputs.nproc }} -p "${BUILD_DIR}" -quiet -fix -allow-no-checks ${TARGETS} 2>&1 | tee clang-tidy-output.txt - - - name: Upload clang-tidy output - if: ${{ github.event.repository.visibility == 'public' && steps.run_clang_tidy.outcome != 'success' }} - uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 - with: - name: clang-tidy-results - path: clang-tidy-output.txt - retention-days: 30 - - - name: Generate git diff - if: ${{ steps.run_clang_tidy.outcome != 'success' }} - run: | - git diff | tee clang-tidy-git-diff.txt - - - name: Upload clang-tidy diff output - if: ${{ github.event.repository.visibility == 'public' && steps.run_clang_tidy.outcome != 'success' }} - uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 - with: - name: clang-tidy-git-diff - path: clang-tidy-git-diff.txt - retention-days: 30 - - - name: Create an issue - if: ${{ steps.run_clang_tidy.outcome != 'success' && inputs.create_issue_on_failure }} - id: create_issue - shell: bash - env: - GH_TOKEN: ${{ github.token }} - run: | - # Prepare issue body with clang-tidy output - cat > issue.md < filtered-output.txt || true - - # If filtered output is empty, use original (might be a different error format) - if [ ! -s filtered-output.txt ]; then - cp clang-tidy-output.txt filtered-output.txt - fi - - # Truncate if too large - head -c 60000 filtered-output.txt >> issue.md - if [ "$(wc -c < filtered-output.txt)" -gt 60000 ]; then - echo "" >> issue.md - echo "... (output truncated, see artifacts for full output)" >> issue.md - fi - - rm filtered-output.txt - else - echo "No output file found" >> issue.md - fi - - cat >> issue.md < create_issue.log - - created_issue="$(sed 's|.*/||' create_issue.log)" - echo "created_issue=$created_issue" >> $GITHUB_OUTPUT - echo "Created issue #$created_issue" - - rm -f create_issue.log issue.md clang-tidy-output.txt - - - name: Fail the workflow if clang-tidy failed - if: ${{ steps.run_clang_tidy.outcome != 'success' }} - run: | - echo "Clang-tidy check failed!" - exit 1 diff --git a/.github/workflows/reusable-clang-tidy.yml b/.github/workflows/reusable-clang-tidy.yml index 7a8bf6de57..a678fe4c8e 100644 --- a/.github/workflows/reusable-clang-tidy.yml +++ b/.github/workflows/reusable-clang-tidy.yml @@ -1,4 +1,4 @@ -name: Clang-tidy check +name: Run clang-tidy on files on: workflow_call: @@ -16,40 +16,198 @@ defaults: run: shell: bash +env: + BUILD_DIR: build + BUILD_TYPE: Debug # Debug so that ASSERTS and such participate in clang-tidy check + + OUTPUT_FILE: clang-tidy-output.txt + DIFF_FILE: clang-tidy-git-diff.txt + ISSUE_FILE: clang-tidy-issue.md + jobs: determine-files: - name: Determine files to check if: ${{ inputs.check_only_changed }} - runs-on: ubuntu-latest - outputs: - clang_tidy_config_changed: ${{ steps.changed_clang_tidy.outputs.any_changed }} - any_cpp_changed: ${{ steps.changed_files.outputs.any_changed }} - all_changed_files: ${{ steps.changed_files.outputs.all_changed_files }} + permissions: + contents: read + uses: XRPLF/actions/.github/workflows/determine-tidy-files.yml@12f5dbc98a2260259a66970e57fa4d26fb7f285c + + run-clang-tidy: + name: Run clang tidy + needs: [determine-files] + if: ${{ always() && !cancelled() && (!inputs.check_only_changed || needs.determine-files.outputs.cpp_changed_files != '' || needs.determine-files.outputs.clang_tidy_config_changed == 'true') }} + runs-on: ["self-hosted", "Linux", "X64", "heavy"] + container: "ghcr.io/xrplf/ci/debian-trixie:clang-21-sha-53033a2" + permissions: + contents: read steps: - name: Checkout repository uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 - - name: Get changed C++ files - id: changed_files - uses: tj-actions/changed-files@9426d40962ed5378910ee2e21d5f8c6fcbf2dd96 # v47.0.6 + - name: Prepare runner + uses: XRPLF/actions/prepare-runner@90f11ee655d1687824fb8793db770477d52afbab with: - files: | - **/*.cpp - **/*.h - **/*.ipp - separator: " " + enable_ccache: false - - name: Get changed clang-tidy configuration - id: changed_clang_tidy - uses: tj-actions/changed-files@9426d40962ed5378910ee2e21d5f8c6fcbf2dd96 # v47.0.6 + - name: Print build environment + uses: XRPLF/actions/print-build-env@59dec886e4afb05a1724443af08baccbc045b574 + + - name: Get number of processors + uses: XRPLF/actions/get-nproc@cf0433aa74563aead044a1e395610c96d65a37cf + id: nproc + + - name: Setup Conan + uses: ./.github/actions/setup-conan + + - name: Build dependencies + uses: ./.github/actions/build-deps with: - files: | - .clang-tidy + build_nproc: ${{ steps.nproc.outputs.nproc }} + build_type: ${{ env.BUILD_TYPE }} + log_verbosity: verbose - run-clang-tidy: - needs: [determine-files] - if: ${{ always() && !cancelled() && (!inputs.check_only_changed || needs.determine-files.outputs.any_cpp_changed == 'true' || needs.determine-files.outputs.clang_tidy_config_changed == 'true') }} - uses: ./.github/workflows/reusable-clang-tidy-files.yml - with: - files: ${{ (needs.determine-files.outputs.clang_tidy_config_changed != 'true' && inputs.check_only_changed) && needs.determine-files.outputs.all_changed_files || '' }} - create_issue_on_failure: ${{ inputs.create_issue_on_failure }} + - name: Configure CMake + working-directory: ${{ env.BUILD_DIR }} + run: | + cmake \ + -G 'Ninja' \ + -DCMAKE_TOOLCHAIN_FILE:FILEPATH=build/generators/conan_toolchain.cmake \ + -DCMAKE_BUILD_TYPE="${BUILD_TYPE}" \ + -Dtests=ON \ + -Dwerr=ON \ + -Dxrpld=ON \ + .. + + # clang-tidy needs headers generated from proto files + - name: Build libxrpl.libpb + working-directory: ${{ env.BUILD_DIR }} + run: | + ninja -j ${{ steps.nproc.outputs.nproc }} xrpl.libpb + + - name: Run clang tidy + id: run_clang_tidy + continue-on-error: true + env: + TARGETS: ${{ (needs.determine-files.outputs.clang_tidy_config_changed != 'true' && inputs.check_only_changed) && needs.determine-files.outputs.cpp_changed_files || 'src tests' }} + run: | + set -o pipefail + run-clang-tidy -j ${{ steps.nproc.outputs.nproc }} -p "${BUILD_DIR}" -quiet -fix -allow-no-checks ${TARGETS} 2>&1 | tee "${OUTPUT_FILE}" + + - name: Upload clang-tidy output + if: ${{ github.event.repository.visibility == 'public' && steps.run_clang_tidy.outcome != 'success' }} + uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 + with: + path: ${{ env.OUTPUT_FILE }} + archive: false + retention-days: 30 + + - name: Generate git diff + if: ${{ steps.run_clang_tidy.outcome != 'success' }} + run: | + git diff | tee "${DIFF_FILE}" + + - name: Upload clang-tidy diff output + if: ${{ github.event.repository.visibility == 'public' && steps.run_clang_tidy.outcome != 'success' }} + uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 + with: + path: ${{ env.DIFF_FILE }} + archive: false + retention-days: 30 + + - name: Write issue header + if: ${{ steps.run_clang_tidy.outcome != 'success' }} + run: | + # Prepare issue body with clang-tidy output + cat > "${ISSUE_FILE}" < filtered-output.txt || true + + # If filtered output is empty, use original (might be a different error format) + if [ ! -s filtered-output.txt ]; then + cp "${OUTPUT_FILE}" filtered-output.txt + fi + + # Truncate if too large + head -c 60000 filtered-output.txt >> "${ISSUE_FILE}" + if [ "$(wc -c < filtered-output.txt)" -gt 60000 ]; then + echo "" >> "${ISSUE_FILE}" + echo "... (output truncated, see artifacts for full output)" >> "${ISSUE_FILE}" + fi + + rm filtered-output.txt + else + echo "No output file found" >> "${ISSUE_FILE}" + fi + + - name: Append issue footer + if: ${{ steps.run_clang_tidy.outcome != 'success' }} + run: | + cat >> "${ISSUE_FILE}" < create_issue.log + + - name: Output created issue number + run: | + created_issue="$(sed 's|.*/||' create_issue.log)" + echo "created_issue=$created_issue" >> $GITHUB_OUTPUT + echo "Created issue #$created_issue" diff --git a/cspell.config.yaml b/cspell.config.yaml index 028f02191e..5aaeeae5e3 100644 --- a/cspell.config.yaml +++ b/cspell.config.yaml @@ -151,6 +151,7 @@ words: - lseq - lsmf - ltype + - mathbunnyru - mcmodel - MEMORYSTATUSEX - MPTAMM