diff --git a/.clang-tidy b/.clang-tidy new file mode 100644 index 0000000000..f7009c4666 --- /dev/null +++ b/.clang-tidy @@ -0,0 +1,191 @@ +--- +Checks: "-*, + bugprone-argument-comment + " +# bugprone-assert-side-effect, +# bugprone-bad-signal-to-kill-thread, +# bugprone-bool-pointer-implicit-conversion, +# bugprone-casting-through-void, +# bugprone-chained-comparison, +# bugprone-compare-pointer-to-member-virtual-function, +# bugprone-copy-constructor-init, +# bugprone-crtp-constructor-accessibility, +# bugprone-dangling-handle, +# bugprone-dynamic-static-initializers, +# bugprone-empty-catch, +# bugprone-fold-init-type, +# bugprone-forward-declaration-namespace, +# bugprone-inaccurate-erase, +# bugprone-inc-dec-in-conditions, +# bugprone-incorrect-enable-if, +# bugprone-incorrect-roundings, +# bugprone-infinite-loop, +# bugprone-integer-division, +# bugprone-lambda-function-name, +# bugprone-macro-parentheses, +# bugprone-macro-repeated-side-effects, +# bugprone-misplaced-operator-in-strlen-in-alloc, +# bugprone-misplaced-pointer-arithmetic-in-alloc, +# bugprone-misplaced-widening-cast, +# bugprone-move-forwarding-reference, +# bugprone-multi-level-implicit-pointer-conversion, +# bugprone-multiple-new-in-one-expression, +# bugprone-multiple-statement-macro, +# bugprone-no-escape, +# bugprone-non-zero-enum-to-bool-conversion, +# bugprone-optional-value-conversion, +# bugprone-parent-virtual-call, +# bugprone-pointer-arithmetic-on-polymorphic-object, +# bugprone-posix-return, +# bugprone-redundant-branch-condition, +# bugprone-reserved-identifier, +# bugprone-return-const-ref-from-parameter, +# bugprone-shared-ptr-array-mismatch, +# bugprone-signal-handler, +# bugprone-signed-char-misuse, +# bugprone-sizeof-container, +# bugprone-sizeof-expression, +# bugprone-spuriously-wake-up-functions, +# bugprone-standalone-empty, +# bugprone-string-constructor, +# bugprone-string-integer-assignment, +# bugprone-string-literal-with-embedded-nul, +# bugprone-stringview-nullptr, +# bugprone-suspicious-enum-usage, +# bugprone-suspicious-include, +# bugprone-suspicious-memory-comparison, +# bugprone-suspicious-memset-usage, +# bugprone-suspicious-missing-comma, +# bugprone-suspicious-realloc-usage, +# bugprone-suspicious-semicolon, +# bugprone-suspicious-string-compare, +# bugprone-suspicious-stringview-data-usage, +# bugprone-swapped-arguments, +# bugprone-switch-missing-default-case, +# bugprone-terminating-continue, +# bugprone-throw-keyword-missing, +# bugprone-too-small-loop-variable, +# bugprone-undefined-memory-manipulation, +# bugprone-undelegated-constructor, +# bugprone-unhandled-exception-at-new, +# bugprone-unhandled-self-assignment, +# bugprone-unique-ptr-array-mismatch, +# bugprone-unsafe-functions, +# bugprone-unused-local-non-trivial-variable, +# bugprone-unused-raii, +# bugprone-unused-return-value, +# bugprone-use-after-move, +# bugprone-virtual-near-miss, +# cppcoreguidelines-init-variables, +# cppcoreguidelines-misleading-capture-default-by-value, +# cppcoreguidelines-no-suspend-with-lock, +# cppcoreguidelines-pro-type-member-init, +# cppcoreguidelines-pro-type-static-cast-downcast, +# cppcoreguidelines-rvalue-reference-param-not-moved, +# cppcoreguidelines-use-default-member-init, +# cppcoreguidelines-virtual-class-destructor, +# hicpp-ignored-remove-result, +# llvm-namespace-comment, +# misc-const-correctness, +# misc-definitions-in-headers, +# misc-header-include-cycle, +# misc-include-cleaner, +# misc-misplaced-const, +# misc-redundant-expression, +# misc-static-assert, +# misc-throw-by-value-catch-by-reference, +# 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, +# modernize-type-traits, +# modernize-use-designated-initializers, +# modernize-use-emplace, +# modernize-use-equals-default, +# modernize-use-equals-delete, +# modernize-use-override, +# modernize-use-ranges, +# modernize-use-starts-ends-with, +# modernize-use-std-numbers, +# modernize-use-using, +# performance-faster-string-find, +# performance-for-range-copy, +# performance-implicit-conversion-in-loop, +# performance-inefficient-vector-operation, +# performance-move-const-arg, +# performance-move-constructor-init, +# performance-no-automatic-move, +# performance-trivially-destructible, +# readability-avoid-nested-conditional-operator, +# readability-avoid-return-with-void-value, +# readability-braces-around-statements, +# readability-const-return-type, +# readability-container-contains, +# readability-container-size-empty, +# readability-convert-member-functions-to-static, +# readability-duplicate-include, +# readability-else-after-return, +# readability-enum-initial-value, +# readability-implicit-bool-conversion, +# readability-inconsistent-declaration-parameter-name, +# readability-identifier-naming, +# readability-make-member-function-const, +# readability-math-missing-parentheses, +# readability-misleading-indentation, +# readability-non-const-parameter, +# readability-redundant-casting, +# readability-redundant-declaration, +# readability-redundant-inline-specifier, +# readability-redundant-member-init, +# readability-redundant-string-init, +# readability-reference-to-constructed-temporary, +# readability-simplify-boolean-expr, +# readability-static-accessed-through-instance, +# readability-static-definition-in-anonymous-namespace, +# readability-suspicious-call-argument, +# readability-use-std-min-max +# +# CheckOptions: +# readability-braces-around-statements.ShortStatementLines: 2 +# readability-identifier-naming.MacroDefinitionCase: UPPER_CASE +# readability-identifier-naming.ClassCase: CamelCase +# readability-identifier-naming.StructCase: CamelCase +# readability-identifier-naming.UnionCase: CamelCase +# readability-identifier-naming.EnumCase: CamelCase +# readability-identifier-naming.EnumConstantCase: CamelCase +# readability-identifier-naming.ScopedEnumConstantCase: CamelCase +# readability-identifier-naming.GlobalConstantCase: UPPER_CASE +# readability-identifier-naming.GlobalConstantPrefix: "k" +# readability-identifier-naming.GlobalVariableCase: CamelCase +# readability-identifier-naming.GlobalVariablePrefix: "g" +# readability-identifier-naming.ConstexprFunctionCase: camelBack +# readability-identifier-naming.ConstexprMethodCase: camelBack +# readability-identifier-naming.ClassMethodCase: camelBack +# readability-identifier-naming.ClassMemberCase: camelBack +# readability-identifier-naming.ClassConstantCase: UPPER_CASE +# readability-identifier-naming.ClassConstantPrefix: "k" +# readability-identifier-naming.StaticConstantCase: UPPER_CASE +# readability-identifier-naming.StaticConstantPrefix: "k" +# readability-identifier-naming.StaticVariableCase: UPPER_CASE +# readability-identifier-naming.StaticVariablePrefix: "k" +# readability-identifier-naming.ConstexprVariableCase: UPPER_CASE +# readability-identifier-naming.ConstexprVariablePrefix: "k" +# readability-identifier-naming.LocalConstantCase: camelBack +# readability-identifier-naming.LocalVariableCase: camelBack +# readability-identifier-naming.TemplateParameterCase: CamelCase +# readability-identifier-naming.ParameterCase: camelBack +# readability-identifier-naming.FunctionCase: camelBack +# readability-identifier-naming.MemberCase: camelBack +# readability-identifier-naming.PrivateMemberSuffix: _ +# readability-identifier-naming.ProtectedMemberSuffix: _ +# readability-identifier-naming.PublicMemberSuffix: "" +# readability-identifier-naming.FunctionIgnoredRegexp: ".*tag_invoke.*" +# bugprone-unsafe-functions.ReportMoreUnsafeFunctions: true +# bugprone-unused-return-value.CheckedReturnTypes: ::std::error_code;::std::error_condition;::std::errc +# misc-include-cleaner.IgnoreHeaders: '.*/(detail|impl)/.*;.*(expected|unexpected).*;.*ranges_lower_bound\.h;time.h;stdlib.h;__chrono/.*;fmt/chrono.h;boost/uuid/uuid_hash.hpp' +# +# HeaderFilterRegex: '^.*/(src|tests)/.*\.(h|hpp)$' +WarningsAsErrors: "*" diff --git a/.cmake-format.yaml b/.cmake-format.yaml index 1a3337fe8c..40c1101208 100644 --- a/.cmake-format.yaml +++ b/.cmake-format.yaml @@ -29,7 +29,7 @@ format: disable: false _help_line_width: - How wide to allow formatted cmake files - line_width: 120 + line_width: 100 _help_tab_size: - How many spaces to tab for indent tab_size: 4 diff --git a/.github/workflows/on-pr.yml b/.github/workflows/on-pr.yml index 46f6b7500a..b0710303a0 100644 --- a/.github/workflows/on-pr.yml +++ b/.github/workflows/on-pr.yml @@ -65,9 +65,12 @@ jobs: .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 + .clang-tidy .codecov.yml cmake/** conan/** @@ -107,6 +110,17 @@ jobs: if: ${{ needs.should-run.outputs.go == 'true' }} uses: ./.github/workflows/reusable-check-rename.yml + clang-tidy: + needs: should-run + if: ${{ needs.should-run.outputs.go == 'true' }} + uses: ./.github/workflows/reusable-clang-tidy.yml + permissions: + issues: write + contents: read + with: + check_only_changed: true + create_issue_on_failure: false + build-test: needs: should-run if: ${{ needs.should-run.outputs.go == 'true' }} @@ -156,6 +170,7 @@ jobs: needs: - check-levelization - check-rename + - clang-tidy - build-test - upload-recipe - notify-clio diff --git a/.github/workflows/on-trigger.yml b/.github/workflows/on-trigger.yml index 210670f5a1..c7e0e8c3aa 100644 --- a/.github/workflows/on-trigger.yml +++ b/.github/workflows/on-trigger.yml @@ -22,9 +22,12 @@ on: - ".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" + - ".clang-tidy" - ".codecov.yml" - "cmake/**" - "conan/**" @@ -60,6 +63,15 @@ defaults: shell: bash jobs: + clang-tidy: + uses: ./.github/workflows/reusable-clang-tidy.yml + permissions: + issues: write + contents: read + with: + check_only_changed: false + create_issue_on_failure: ${{ github.event_name == 'schedule' }} + build-test: uses: ./.github/workflows/reusable-build-test.yml strategy: diff --git a/.github/workflows/reusable-clang-tidy-files.yml b/.github/workflows/reusable-clang-tidy-files.yml new file mode 100644 index 0000000000..c410a2e55d --- /dev/null +++ b/.github/workflows/reusable-clang-tidy-files.yml @@ -0,0 +1,162 @@ +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: Release + +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@08eba0b27e820071cde6df949e0beb9ba4906955 # v4.3.0 + + - name: Prepare runner + uses: XRPLF/actions/prepare-runner@2cbf481018d930656e9276fcc20dc0e3a0be5b6d + with: + enable_ccache: false + + - name: Print build environment + uses: ./.github/actions/print-env + + - 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: + FILES: ${{ inputs.files }} + run: | + run-clang-tidy -j ${{ steps.nproc.outputs.nproc }} -p "$BUILD_DIR" $FILES 2>&1 | tee clang-tidy-output.txt + + - name: Upload clang-tidy output + if: steps.run_clang_tidy.outcome != 'success' + uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 + with: + name: clang-tidy-results + path: clang-tidy-output.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 new file mode 100644 index 0000000000..f2f1aeee78 --- /dev/null +++ b/.github/workflows/reusable-clang-tidy.yml @@ -0,0 +1,47 @@ +name: Clang-tidy check + +on: + workflow_call: + inputs: + check_only_changed: + description: "Check only changed files in PR. If false, checks all files in the repository." + type: boolean + default: false + create_issue_on_failure: + description: "Whether to create an issue if the check failed" + type: boolean + default: false + +defaults: + run: + shell: bash + +jobs: + determine-files: + name: Determine files to check + if: ${{ inputs.check_only_changed }} + runs-on: ubuntu-latest + outputs: + any_changed: ${{ steps.changed_files.outputs.any_changed }} + all_changed_files: ${{ steps.changed_files.outputs.all_changed_files }} + steps: + - name: Checkout repository + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 + + - name: Get changed C++ files + id: changed_files + uses: tj-actions/changed-files@ed68ef82c095e0d48ec87eccea555d944a631a4c # v46.0.5 + with: + files: | + **/*.cpp + **/*.h + **/*.ipp + separator: " " + + run-clang-tidy: + needs: [determine-files] + if: ${{ always() && !cancelled() && (!inputs.check_only_changed || needs.determine-files.outputs.any_changed == 'true') }} + uses: ./.github/workflows/reusable-clang-tidy-files.yml + with: + files: ${{ inputs.check_only_changed && needs.determine-files.outputs.all_changed_files || '' }} + create_issue_on_failure: ${{ inputs.create_issue_on_failure }} diff --git a/CMakeLists.txt b/CMakeLists.txt index 3c434506f7..764e917498 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,6 +17,7 @@ project(xrpl) set(CMAKE_CXX_EXTENSIONS OFF) set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) include(CompilationEnv) @@ -38,16 +39,16 @@ include(Ccache) # make GIT_COMMIT_HASH define available to all sources find_package(Git) if (Git_FOUND) - execute_process(COMMAND ${GIT_EXECUTABLE} --git-dir=${CMAKE_CURRENT_SOURCE_DIR}/.git rev-parse HEAD - OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_VARIABLE gch) + execute_process(COMMAND ${GIT_EXECUTABLE} --git-dir=${CMAKE_CURRENT_SOURCE_DIR}/.git rev-parse + HEAD OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_VARIABLE gch) if (gch) set(GIT_COMMIT_HASH "${gch}") message(STATUS gch: ${GIT_COMMIT_HASH}) add_definitions(-DGIT_COMMIT_HASH="${GIT_COMMIT_HASH}") endif () - execute_process(COMMAND ${GIT_EXECUTABLE} --git-dir=${CMAKE_CURRENT_SOURCE_DIR}/.git rev-parse --abbrev-ref HEAD - OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_VARIABLE gb) + execute_process(COMMAND ${GIT_EXECUTABLE} --git-dir=${CMAKE_CURRENT_SOURCE_DIR}/.git rev-parse + --abbrev-ref HEAD OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_VARIABLE gb) if (gb) set(GIT_BRANCH "${gb}") message(STATUS gb: ${GIT_BRANCH}) @@ -67,7 +68,8 @@ include(FetchContent) include(ExternalProject) include(CMakeFuncs) # must come *after* ExternalProject b/c it overrides one function in EP if (target) - message(FATAL_ERROR "The target option has been removed - use native cmake options to control build") + message(FATAL_ERROR "The target option has been removed - use native cmake options to control build" + ) endif () include(XrplSanity) @@ -76,7 +78,8 @@ include(XrplSettings) # this check has to remain in the top-level cmake because of the early return statement if (packages_only) if (NOT TARGET rpm) - message(FATAL_ERROR "packages_only requested, but targets were not created - is docker installed?") + message(FATAL_ERROR "packages_only requested, but targets were not created - is docker installed?" + ) endif () return() endif () @@ -118,7 +121,8 @@ target_link_libraries( option(rocksdb "Enable RocksDB" ON) if (rocksdb) find_package(RocksDB REQUIRED) - set_target_properties(RocksDB::rocksdb PROPERTIES INTERFACE_COMPILE_DEFINITIONS XRPL_ROCKSDB_AVAILABLE=1) + set_target_properties(RocksDB::rocksdb PROPERTIES INTERFACE_COMPILE_DEFINITIONS + XRPL_ROCKSDB_AVAILABLE=1) target_link_libraries(xrpl_libs INTERFACE RocksDB::rocksdb) endif () diff --git a/cmake/Ccache.cmake b/cmake/Ccache.cmake index 000883cf6a..e34627ad8a 100644 --- a/cmake/Ccache.cmake +++ b/cmake/Ccache.cmake @@ -43,7 +43,8 @@ set(CMAKE_VS_GLOBALS "CLToolExe=cl.exe" "CLToolPath=${CMAKE_BINARY_DIR}" "TrackF # By default Visual Studio generators will use /Zi to capture debug information, which is not compatible with ccache, so # tell it to use /Z7 instead. if (MSVC) - foreach (var_ CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE) + foreach (var_ CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE CMAKE_CXX_FLAGS_DEBUG + CMAKE_CXX_FLAGS_RELEASE) string(REPLACE "/Zi" "/Z7" ${var_} "${${var_}}") endforeach () endif () diff --git a/cmake/CodeCoverage.cmake b/cmake/CodeCoverage.cmake index fcc4d44133..74796718c1 100644 --- a/cmake/CodeCoverage.cmake +++ b/cmake/CodeCoverage.cmake @@ -180,7 +180,8 @@ elseif (DEFINED ENV{CODE_COVERAGE_GCOV_TOOL}) set(GCOV_TOOL "$ENV{CODE_COVERAGE_GCOV_TOOL}") elseif ("${CMAKE_CXX_COMPILER_ID}" MATCHES "(Apple)?[Cc]lang") if (APPLE) - execute_process(COMMAND xcrun -f llvm-cov OUTPUT_VARIABLE LLVMCOV_PATH OUTPUT_STRIP_TRAILING_WHITESPACE) + execute_process(COMMAND xcrun -f llvm-cov OUTPUT_VARIABLE LLVMCOV_PATH + OUTPUT_STRIP_TRAILING_WHITESPACE) else () find_program(LLVMCOV_PATH llvm-cov) endif () @@ -199,8 +200,8 @@ foreach (LANG ${LANGUAGES}) if ("${CMAKE_${LANG}_COMPILER_VERSION}" VERSION_LESS 3) message(FATAL_ERROR "Clang version must be 3.0.0 or greater! Aborting...") endif () - elseif (NOT "${CMAKE_${LANG}_COMPILER_ID}" MATCHES "GNU" AND NOT "${CMAKE_${LANG}_COMPILER_ID}" MATCHES - "(LLVM)?[Ff]lang") + elseif (NOT "${CMAKE_${LANG}_COMPILER_ID}" MATCHES "GNU" AND NOT "${CMAKE_${LANG}_COMPILER_ID}" + MATCHES "(LLVM)?[Ff]lang") message(FATAL_ERROR "Compiler is not GNU or Flang! Aborting...") endif () endforeach () @@ -321,14 +322,16 @@ function (setup_target_for_coverage_gcovr) endif () if ("--output" IN_LIST GCOVR_ADDITIONAL_ARGS) - message(FATAL_ERROR "Unsupported --output option detected in GCOVR_ADDITIONAL_ARGS! Aborting...") + message(FATAL_ERROR "Unsupported --output option detected in GCOVR_ADDITIONAL_ARGS! Aborting..." + ) else () if ((Coverage_FORMAT STREQUAL "html-details") OR (Coverage_FORMAT STREQUAL "html-nested")) set(GCOVR_OUTPUT_FILE ${PROJECT_BINARY_DIR}/${Coverage_NAME}/index.html) set(GCOVR_CREATE_FOLDER ${PROJECT_BINARY_DIR}/${Coverage_NAME}) elseif (Coverage_FORMAT STREQUAL "html-single") set(GCOVR_OUTPUT_FILE ${Coverage_NAME}.html) - elseif ((Coverage_FORMAT STREQUAL "json-summary") OR (Coverage_FORMAT STREQUAL "json-details") + elseif ((Coverage_FORMAT STREQUAL "json-summary") OR (Coverage_FORMAT STREQUAL + "json-details") OR (Coverage_FORMAT STREQUAL "coveralls")) set(GCOVR_OUTPUT_FILE ${Coverage_NAME}.json) elseif (Coverage_FORMAT STREQUAL "txt") @@ -452,8 +455,10 @@ function (setup_target_for_coverage_gcovr) COMMENT "Running gcovr to produce code coverage report.") # Show info where to find the report - add_custom_command(TARGET ${Coverage_NAME} POST_BUILD COMMAND echo - COMMENT "Code coverage report saved in ${GCOVR_OUTPUT_FILE} formatted as ${Coverage_FORMAT}") + add_custom_command( + TARGET ${Coverage_NAME} POST_BUILD COMMAND echo + COMMENT "Code coverage report saved in ${GCOVR_OUTPUT_FILE} formatted as ${Coverage_FORMAT}" + ) endfunction () # setup_target_for_coverage_gcovr function (add_code_coverage_to_target name scope) @@ -463,8 +468,9 @@ function (add_code_coverage_to_target name scope) separate_arguments(COVERAGE_C_LINKER_FLAGS NATIVE_COMMAND "${COVERAGE_C_LINKER_FLAGS}") # Add compiler options to the target - target_compile_options(${name} ${scope} $<$:${COVERAGE_CXX_COMPILER_FLAGS}> - $<$:${COVERAGE_C_COMPILER_FLAGS}>) + target_compile_options( + ${name} ${scope} $<$:${COVERAGE_CXX_COMPILER_FLAGS}> + $<$:${COVERAGE_C_COMPILER_FLAGS}>) target_link_libraries(${name} ${scope} $<$:${COVERAGE_CXX_LINKER_FLAGS}> $<$:${COVERAGE_C_LINKER_FLAGS}>) diff --git a/cmake/XrplCompiler.cmake b/cmake/XrplCompiler.cmake index f7ac8c2b71..8093004b2e 100644 --- a/cmake/XrplCompiler.cmake +++ b/cmake/XrplCompiler.cmake @@ -17,7 +17,8 @@ link_libraries(Xrpl::common) if (NOT DEFINED CMAKE_POSITION_INDEPENDENT_CODE) set(CMAKE_POSITION_INDEPENDENT_CODE ON) endif () -set_target_properties(common PROPERTIES INTERFACE_POSITION_INDEPENDENT_CODE ${CMAKE_POSITION_INDEPENDENT_CODE}) +set_target_properties(common PROPERTIES INTERFACE_POSITION_INDEPENDENT_CODE + ${CMAKE_POSITION_INDEPENDENT_CODE}) set(CMAKE_CXX_EXTENSIONS OFF) target_compile_definitions( common @@ -37,7 +38,8 @@ if (MSVC) # remove existing exception flag since we set it to -EHa string(REGEX REPLACE "[-/]EH[a-z]+" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") - foreach (var_ CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE) + foreach (var_ CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE CMAKE_CXX_FLAGS_DEBUG + CMAKE_CXX_FLAGS_RELEASE) # also remove dynamic runtime string(REGEX REPLACE "[-/]MD[d]*" " " ${var_} "${${var_}}") @@ -143,20 +145,23 @@ if (voidstar) elseif (NOT is_linux) message(FATAL_ERROR "Antithesis instrumentation requires Linux, aborting...") elseif (NOT (is_clang AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 16.0)) - message(FATAL_ERROR "Antithesis instrumentation requires Clang version 16 or later, aborting...") + message(FATAL_ERROR "Antithesis instrumentation requires Clang version 16 or later, aborting..." + ) endif () endif () if (use_mold) # use mold linker if available - execute_process(COMMAND ${CMAKE_CXX_COMPILER} -fuse-ld=mold -Wl,--version ERROR_QUIET OUTPUT_VARIABLE LD_VERSION) + execute_process(COMMAND ${CMAKE_CXX_COMPILER} -fuse-ld=mold -Wl,--version ERROR_QUIET + OUTPUT_VARIABLE LD_VERSION) if ("${LD_VERSION}" MATCHES "mold") target_link_libraries(common INTERFACE -fuse-ld=mold) endif () unset(LD_VERSION) elseif (use_gold AND is_gcc) # use gold linker if available - execute_process(COMMAND ${CMAKE_CXX_COMPILER} -fuse-ld=gold -Wl,--version ERROR_QUIET OUTPUT_VARIABLE LD_VERSION) + execute_process(COMMAND ${CMAKE_CXX_COMPILER} -fuse-ld=gold -Wl,--version ERROR_QUIET + OUTPUT_VARIABLE LD_VERSION) #[=========================================================[ NOTE: THE gold linker inserts -rpath as DT_RUNPATH by default instead of DT_RPATH, so you might have slightly @@ -186,7 +191,8 @@ elseif (use_gold AND is_gcc) unset(LD_VERSION) elseif (use_lld) # use lld linker if available - execute_process(COMMAND ${CMAKE_CXX_COMPILER} -fuse-ld=lld -Wl,--version ERROR_QUIET OUTPUT_VARIABLE LD_VERSION) + execute_process(COMMAND ${CMAKE_CXX_COMPILER} -fuse-ld=lld -Wl,--version ERROR_QUIET + OUTPUT_VARIABLE LD_VERSION) if ("${LD_VERSION}" MATCHES "LLD") target_link_libraries(common INTERFACE -fuse-ld=lld) endif () diff --git a/cmake/XrplCore.cmake b/cmake/XrplCore.cmake index 9a847bfcb9..e54dd09953 100644 --- a/cmake/XrplCore.cmake +++ b/cmake/XrplCore.cmake @@ -14,7 +14,8 @@ target_protobuf_sources(xrpl.libpb xrpl/proto LANGUAGE cpp IMPORT_DIRS include/x PROTOS include/xrpl/proto/xrpl.proto) file(GLOB_RECURSE protos "include/xrpl/proto/org/*.proto") -target_protobuf_sources(xrpl.libpb xrpl/proto LANGUAGE cpp IMPORT_DIRS include/xrpl/proto PROTOS "${protos}") +target_protobuf_sources(xrpl.libpb xrpl/proto LANGUAGE cpp IMPORT_DIRS include/xrpl/proto + PROTOS "${protos}") target_protobuf_sources( xrpl.libpb xrpl/proto LANGUAGE grpc @@ -24,8 +25,9 @@ target_protobuf_sources( GENERATE_EXTENSIONS .grpc.pb.h .grpc.pb.cc) target_compile_options( - xrpl.libpb PUBLIC $<$:-wd4996> $<$: --system-header-prefix="google/protobuf" - -Wno-deprecated-dynamic-exception-spec > + xrpl.libpb + PUBLIC $<$:-wd4996> $<$: + --system-header-prefix="google/protobuf" -Wno-deprecated-dynamic-exception-spec > PRIVATE $<$:-wd4065> $<$>:-Wno-deprecated-declarations>) target_link_libraries(xrpl.libpb PUBLIC protobuf::libprotobuf gRPC::grpc++) @@ -73,7 +75,8 @@ target_link_libraries(xrpl.libxrpl.protocol PUBLIC xrpl.libxrpl.crypto xrpl.libx # Level 05 add_module(xrpl core) -target_link_libraries(xrpl.libxrpl.core PUBLIC xrpl.libxrpl.basics xrpl.libxrpl.json xrpl.libxrpl.protocol) +target_link_libraries(xrpl.libxrpl.core PUBLIC xrpl.libxrpl.basics xrpl.libxrpl.json + xrpl.libxrpl.protocol) # Level 06 add_module(xrpl resource) @@ -81,22 +84,23 @@ target_link_libraries(xrpl.libxrpl.resource PUBLIC xrpl.libxrpl.protocol) # Level 07 add_module(xrpl net) -target_link_libraries(xrpl.libxrpl.net PUBLIC xrpl.libxrpl.basics xrpl.libxrpl.json xrpl.libxrpl.protocol - xrpl.libxrpl.resource) +target_link_libraries(xrpl.libxrpl.net PUBLIC xrpl.libxrpl.basics xrpl.libxrpl.json + xrpl.libxrpl.protocol xrpl.libxrpl.resource) add_module(xrpl nodestore) -target_link_libraries(xrpl.libxrpl.nodestore PUBLIC xrpl.libxrpl.basics xrpl.libxrpl.json xrpl.libxrpl.protocol) +target_link_libraries(xrpl.libxrpl.nodestore PUBLIC xrpl.libxrpl.basics xrpl.libxrpl.json + xrpl.libxrpl.protocol) add_module(xrpl shamap) -target_link_libraries(xrpl.libxrpl.shamap PUBLIC xrpl.libxrpl.basics xrpl.libxrpl.crypto xrpl.libxrpl.protocol - xrpl.libxrpl.nodestore) +target_link_libraries(xrpl.libxrpl.shamap PUBLIC xrpl.libxrpl.basics xrpl.libxrpl.crypto + xrpl.libxrpl.protocol xrpl.libxrpl.nodestore) add_module(xrpl rdb) target_link_libraries(xrpl.libxrpl.rdb PUBLIC xrpl.libxrpl.basics xrpl.libxrpl.core) add_module(xrpl server) -target_link_libraries(xrpl.libxrpl.server PUBLIC xrpl.libxrpl.protocol xrpl.libxrpl.core xrpl.libxrpl.rdb - xrpl.libxrpl.resource) +target_link_libraries(xrpl.libxrpl.server PUBLIC xrpl.libxrpl.protocol xrpl.libxrpl.core + xrpl.libxrpl.rdb xrpl.libxrpl.resource) add_module(xrpl conditions) target_link_libraries(xrpl.libxrpl.conditions PUBLIC xrpl.libxrpl.server) diff --git a/cmake/XrplDocs.cmake b/cmake/XrplDocs.cmake index 69581a99c7..4892e390ce 100644 --- a/cmake/XrplDocs.cmake +++ b/cmake/XrplDocs.cmake @@ -65,8 +65,8 @@ add_custom_command( OUTPUT "${doxygen_index_file}" COMMAND "${CMAKE_COMMAND}" -E env "DOXYGEN_OUTPUT_DIRECTORY=${doxygen_output_directory}" "DOXYGEN_INCLUDE_PATH=${doxygen_include_path}" "DOXYGEN_TAGFILES=${doxygen_tagfiles}" - "DOXYGEN_PLANTUML_JAR_PATH=${doxygen_plantuml_jar_path}" "DOXYGEN_DOT_PATH=${doxygen_dot_path}" - "${DOXYGEN_EXECUTABLE}" "${doxyfile}" + "DOXYGEN_PLANTUML_JAR_PATH=${doxygen_plantuml_jar_path}" + "DOXYGEN_DOT_PATH=${doxygen_dot_path}" "${DOXYGEN_EXECUTABLE}" "${doxyfile}" WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" DEPENDS "${dependencies}" "${tagfile}") add_custom_target(docs DEPENDS "${doxygen_index_file}" SOURCES "${dependencies}") diff --git a/cmake/XrplInstall.cmake b/cmake/XrplInstall.cmake index b8cf4fd32f..4cbf381f87 100644 --- a/cmake/XrplInstall.cmake +++ b/cmake/XrplInstall.cmake @@ -41,11 +41,13 @@ install(TARGETS common INCLUDES DESTINATION include) -install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/include/xrpl" DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}") +install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/include/xrpl" + DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}") install(EXPORT XrplExports FILE XrplTargets.cmake NAMESPACE Xrpl:: DESTINATION lib/cmake/xrpl) include(CMakePackageConfigHelpers) -write_basic_package_version_file(XrplConfigVersion.cmake VERSION ${xrpld_version} COMPATIBILITY SameMajorVersion) +write_basic_package_version_file(XrplConfigVersion.cmake VERSION ${xrpld_version} + COMPATIBILITY SameMajorVersion) if (is_root_project AND TARGET xrpld) install(TARGETS xrpld RUNTIME DESTINATION bin) @@ -72,5 +74,5 @@ if (is_root_project AND TARGET xrpld) ") endif () -install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/cmake/XrplConfig.cmake ${CMAKE_CURRENT_BINARY_DIR}/XrplConfigVersion.cmake - DESTINATION lib/cmake/xrpl) +install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/cmake/XrplConfig.cmake + ${CMAKE_CURRENT_BINARY_DIR}/XrplConfigVersion.cmake DESTINATION lib/cmake/xrpl) diff --git a/cmake/XrplInterface.cmake b/cmake/XrplInterface.cmake index f471b37dd7..dbf907c7b4 100644 --- a/cmake/XrplInterface.cmake +++ b/cmake/XrplInterface.cmake @@ -33,10 +33,13 @@ target_compile_definitions( target_compile_options( opts INTERFACE $<$,$>:-Wsuggest-override> - $<$:-Wno-maybe-uninitialized> $<$:-fno-omit-frame-pointer> - $<$:-pg> $<$,$>:-p>) + $<$:-Wno-maybe-uninitialized> + $<$:-fno-omit-frame-pointer> + $<$:-pg> + $<$,$>:-p>) -target_link_libraries(opts INTERFACE $<$:-pg> $<$,$>:-p>) +target_link_libraries(opts INTERFACE $<$:-pg> + $<$,$>:-p>) if (jemalloc) find_package(jemalloc REQUIRED) diff --git a/cmake/XrplSanity.cmake b/cmake/XrplSanity.cmake index 5055414abd..489ad026e1 100644 --- a/cmake/XrplSanity.cmake +++ b/cmake/XrplSanity.cmake @@ -19,7 +19,8 @@ if (NOT is_multiconfig) endif () if (is_clang) # both Clang and AppleClang - if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 16.0) + if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS + 16.0) message(FATAL_ERROR "This project requires clang 16 or later") endif () elseif (is_gcc) @@ -32,7 +33,8 @@ endif () if ("${CMAKE_CURRENT_SOURCE_DIR}" STREQUAL "${CMAKE_BINARY_DIR}") message(FATAL_ERROR "Builds (in-source) are not allowed in " "${CMAKE_CURRENT_SOURCE_DIR}. Please remove CMakeCache.txt and the CMakeFiles " - "directory from ${CMAKE_CURRENT_SOURCE_DIR} and try building in a separate directory.") + "directory from ${CMAKE_CURRENT_SOURCE_DIR} and try building in a separate directory." + ) endif () if (MSVC AND CMAKE_GENERATOR_PLATFORM STREQUAL "Win32") diff --git a/cmake/XrplSettings.cmake b/cmake/XrplSettings.cmake index 6d332be19d..5c753fdcda 100644 --- a/cmake/XrplSettings.cmake +++ b/cmake/XrplSettings.cmake @@ -70,7 +70,8 @@ if (is_linux AND NOT SANITIZER) else () set(TRUNCATED_LOGS_DEFAULT OFF) endif () - option(TRUNCATED_THREAD_NAME_LOGS "Show warnings about truncated thread names on Linux." ${TRUNCATED_LOGS_DEFAULT}) + option(TRUNCATED_THREAD_NAME_LOGS "Show warnings about truncated thread names on Linux." + ${TRUNCATED_LOGS_DEFAULT}) if (TRUNCATED_THREAD_NAME_LOGS) add_compile_definitions(TRUNCATED_THREAD_NAME_LOGS) endif () @@ -92,11 +93,13 @@ endif () option(jemalloc "Enables jemalloc for heap profiling" OFF) option(werr "treat warnings as errors" OFF) -option(local_protobuf "Force a local build of protobuf instead of looking for an installed version." OFF) +option(local_protobuf + "Force a local build of protobuf instead of looking for an installed version." OFF) option(local_grpc "Force a local build of gRPC instead of looking for an installed version." OFF) # the remaining options are obscure and rarely used -option(beast_no_unit_test_inline "Prevents unit test definitions from being inserted into global table" OFF) +option(beast_no_unit_test_inline + "Prevents unit test definitions from being inserted into global table" OFF) option(single_io_service_thread "Restricts the number of threads calling io_context::run to one. \ This can be useful when debugging." OFF) option(boost_show_deprecated "Allow boost to fail on deprecated usage. Only useful if you're trying\ diff --git a/cmake/XrplValidatorKeys.cmake b/cmake/XrplValidatorKeys.cmake index 5fa7e14886..58672aada5 100644 --- a/cmake/XrplValidatorKeys.cmake +++ b/cmake/XrplValidatorKeys.cmake @@ -1,4 +1,6 @@ -option(validator_keys "Enables building of validator-keys tool as a separate target (imported via FetchContent)" OFF) +option(validator_keys + "Enables building of validator-keys tool as a separate target (imported via FetchContent)" + OFF) if (validator_keys) git_branch(current_branch) @@ -8,8 +10,9 @@ if (validator_keys) endif () message(STATUS "Tracking ValidatorKeys branch: ${current_branch}") - FetchContent_Declare(validator_keys GIT_REPOSITORY https://github.com/ripple/validator-keys-tool.git - GIT_TAG "${current_branch}") + FetchContent_Declare( + validator_keys GIT_REPOSITORY https://github.com/ripple/validator-keys-tool.git + GIT_TAG "${current_branch}") FetchContent_MakeAvailable(validator_keys) set_target_properties(validator-keys PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}") install(TARGETS validator-keys RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) diff --git a/cmake/add_module.cmake b/cmake/add_module.cmake index a3cb247fd2..73618e8be3 100644 --- a/cmake/add_module.cmake +++ b/cmake/add_module.cmake @@ -15,11 +15,12 @@ include(isolate_headers) function (add_module parent name) set(target ${PROJECT_NAME}.lib${parent}.${name}) add_library(${target} OBJECT) - file(GLOB_RECURSE sources CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/src/lib${parent}/${name}/*.cpp") + file(GLOB_RECURSE sources CONFIGURE_DEPENDS + "${CMAKE_CURRENT_SOURCE_DIR}/src/lib${parent}/${name}/*.cpp") target_sources(${target} PRIVATE ${sources}) target_include_directories(${target} PUBLIC "$") isolate_headers(${target} "${CMAKE_CURRENT_SOURCE_DIR}/include" "${CMAKE_CURRENT_SOURCE_DIR}/include/${parent}/${name}" PUBLIC) - isolate_headers(${target} "${CMAKE_CURRENT_SOURCE_DIR}/src" "${CMAKE_CURRENT_SOURCE_DIR}/src/lib${parent}/${name}" - PRIVATE) + isolate_headers(${target} "${CMAKE_CURRENT_SOURCE_DIR}/src" + "${CMAKE_CURRENT_SOURCE_DIR}/src/lib${parent}/${name}" PRIVATE) endfunction () diff --git a/cmake/deps/Boost.cmake b/cmake/deps/Boost.cmake index fe62fcb79c..a7b145364d 100644 --- a/cmake/deps/Boost.cmake +++ b/cmake/deps/Boost.cmake @@ -39,6 +39,7 @@ if (SANITIZERS_ENABLED AND is_clang) endif () message(STATUS "Adding [${Boost_INCLUDE_DIRS}] to sanitizer blacklist") file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/san_bl.txt "src:${Boost_INCLUDE_DIRS}/*") - target_compile_options(opts INTERFACE # ignore boost headers for sanitizing - -fsanitize-blacklist=${CMAKE_CURRENT_BINARY_DIR}/san_bl.txt) + target_compile_options( + opts INTERFACE # ignore boost headers for sanitizing + -fsanitize-blacklist=${CMAKE_CURRENT_BINARY_DIR}/san_bl.txt) endif () diff --git a/cspell.config.yaml b/cspell.config.yaml index b2f4a33769..87258758c4 100644 --- a/cspell.config.yaml +++ b/cspell.config.yaml @@ -6,6 +6,7 @@ ignorePaths: - docs/**/*.puml - cmake/** - LICENSE.md + - .clang-tidy language: en allowCompoundWords: true # TODO (#6334) ignoreRandomStrings: true diff --git a/src/libxrpl/ledger/View.cpp b/src/libxrpl/ledger/View.cpp index 72df44ec4a..f4e6e1080b 100644 --- a/src/libxrpl/ledger/View.cpp +++ b/src/libxrpl/ledger/View.cpp @@ -1289,14 +1289,14 @@ addEmptyHolding( dstId, index.key, sleDst, - /*auth=*/false, - /*noRipple=*/true, - /*freeze=*/false, + /*bAuth=*/false, + /*bNoRipple=*/true, + /*bFreeze=*/false, /*deepFreeze*/ false, - /*balance=*/STAmount{Issue{currency, noAccount()}}, - /*limit=*/STAmount{Issue{currency, dstId}}, - /*qualityIn=*/0, - /*qualityOut=*/0, + /*saBalance=*/STAmount{Issue{currency, noAccount()}}, + /*saLimit=*/STAmount{Issue{currency, dstId}}, + /*uSrcQualityIn=*/0, + /*uSrcQualityOut=*/0, journal); }