From 22f49bd8a835039e286c1401a041ef44cc038c6c Mon Sep 17 00:00:00 2001 From: Russel Date: Mon, 26 Jul 2021 08:04:50 -0700 Subject: [PATCH 1/2] update clang-format checks for full history checks for clang-format 10.0.0 --- ci/check-commit-format.sh | 36 ++++++++++++++++++++++++++++++++++-- nano/core_test/telemetry.cpp | 32 ++++++++++++++++---------------- 2 files changed, 50 insertions(+), 18 deletions(-) diff --git a/ci/check-commit-format.sh b/ci/check-commit-format.sh index 4055ac7bd6..c69a18b418 100755 --- a/ci/check-commit-format.sh +++ b/ci/check-commit-format.sh @@ -1,12 +1,44 @@ #!/usr/bin/env bash +FOUND=0 + +# hard requirement of clang-format 10.0.0 +CF_EXECUTABLE=' + clang-format-10.0.0 + clang-format-10.0 + clang-format-10 + clang-format +' + +# check different executable strings +for executable in $CF_EXECUTABLE; do + if type -p "$executable" >/dev/null; then + clang_format="$executable" + FOUND=1 + break + fi +done + +# alert if not installed +if [ $FOUND == 0 ]; then + echo "clang-format not found, please install 10.0.0 first" + exit 1 +fi + +# check if old version is found +if ! "$clang_format" --version | grep '10.0.0' &>/dev/null; then + echo "clang-format version 10.0.0 is required, please update it" + exit 1 +fi + + REPO_ROOT=$(git rev-parse --show-toplevel) "${REPO_ROOT}/ci/update-clang-format" -RESULT=$(python $REPO_ROOT/ci/git-clang-format.py --diff -f --commit HEAD~1 --extensions "hpp,cpp") +RESULT=$(python $REPO_ROOT/ci/git-clang-format.py --diff --extensions "hpp,cpp") if [ "$RESULT" != "no modified files to format" ] && [ "$RESULT" != "clang-format did not modify any files" ]; then - python $REPO_ROOT/ci/git-clang-format.py --diff -f --commit HEAD~1 --extensions "hpp,cpp" + python $REPO_ROOT/ci/git-clang-format.py --diff --extensions "hpp,cpp" echo echo "Code formatting differs from expected - please run ci/clang-format-all.sh" exit 1 diff --git a/nano/core_test/telemetry.cpp b/nano/core_test/telemetry.cpp index 3f1d7a2264..6c841ce5d8 100644 --- a/nano/core_test/telemetry.cpp +++ b/nano/core_test/telemetry.cpp @@ -555,14 +555,14 @@ TEST (telemetry, remove_peer_different_genesis) // Possible TSAN issue in the future if something else uses this, but will only appear in tests. nano::state_block_builder builder; auto junk = builder - .account (nano::dev::genesis_key.pub) - .previous (0) - .representative (nano::dev::genesis_key.pub) - .balance (0) - .link (0) - .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) - .work (0) - .build_shared (); + .account (nano::dev::genesis_key.pub) + .previous (0) + .representative (nano::dev::genesis_key.pub) + .balance (0) + .link (0) + .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) + .work (0) + .build_shared (); node1->network_params.ledger.genesis = junk; node1->start (); system.nodes.push_back (node1); @@ -593,14 +593,14 @@ TEST (telemetry, remove_peer_different_genesis_udp) auto node1 (std::make_shared (system.io_ctx, nano::get_available_port (), nano::unique_path (), system.logging, system.work, node_flags)); nano::state_block_builder builder; auto junk = builder - .account (nano::dev::genesis_key.pub) - .previous (0) - .representative (nano::dev::genesis_key.pub) - .balance (0) - .link (0) - .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) - .work (0) - .build_shared (); + .account (nano::dev::genesis_key.pub) + .previous (0) + .representative (nano::dev::genesis_key.pub) + .balance (0) + .link (0) + .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) + .work (0) + .build_shared (); node1->network_params.ledger.genesis = junk; node1->start (); system.nodes.push_back (node1); From 0931625e5f28d498b01687a817db055ba632c43d Mon Sep 17 00:00:00 2001 From: Russel Date: Mon, 26 Jul 2021 08:16:08 -0700 Subject: [PATCH 2/2] no need to explicitly install as clang-format, installed versions suffice --- .github/workflows/analyzers.yml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.github/workflows/analyzers.yml b/.github/workflows/analyzers.yml index ac4d7d2f1e..f30a0fa356 100644 --- a/.github/workflows/analyzers.yml +++ b/.github/workflows/analyzers.yml @@ -12,10 +12,6 @@ jobs: env: DEBIAN_FRONTEND: noninteractive run: sudo apt-get install clang-format-10 - - name: Setting clang-format 10 as the default - env: - DEBIAN_FRONTEND: noninteractive - run: sudo update-alternatives --install /usr/bin/clang-format clang-format /usr/bin/clang-format-10 1000 - name: Clang Format run: ci/check-commit-format.sh