diff --git a/.github/bin/run-clang-format.sh b/.github/bin/run-clang-format.sh index c81c6d323..e5558d84e 100755 --- a/.github/bin/run-clang-format.sh +++ b/.github/bin/run-clang-format.sh @@ -19,6 +19,7 @@ set -e # error out on error. FORMAT_OUT=${TMPDIR:-/tmp}/clang-format-diff.out CLANG_FORMAT_BINARY=${CLANG_FORMAT_BINARY:-clang-format} +BUILDIFIER_BINARY=${BUILDIFIER_BINARY:-buildifier} ${CLANG_FORMAT_BINARY} --version @@ -33,6 +34,12 @@ find . -name "*.h" -o -name "*.cc" \ | egrep -v 'third_party/|external_libs/|.github/' \ | xargs -P2 ${CLANG_FORMAT_BINARY} --style="Google" -i +# If we have buildifier installed, use that on BUILD files +if command -v ${BUILDIFIER_BINARY} >/dev/null; then + echo "Run $(buildifier --version)" + ${BUILDIFIER_BINARY} $(find . -name BUILD -o -name "*.bzl") +fi + # Check if we got any diff git diff > ${FORMAT_OUT} diff --git a/shell.nix b/shell.nix index 3b68bbba6..f2a851fc0 100644 --- a/shell.nix +++ b/shell.nix @@ -46,7 +46,21 @@ verible_used_stdenv.mkDerivation { # Ease development lcov # coverage html generation. - clang-tools_15 # clang-format, clang-tidy bazel-buildtools # buildifier + + # TODO: would it be possible to define two variables here + # clang_for_formatting, clang_for_tidy so that we don't have + # to re-type the version below in the shell hook ? + clang-tools_15 # For clang-format (see below) + clang-tools_17 # For clang-tidy (see below) ]; + shellHook = '' + # We choose the last clang-format that produces the same result + # as the one used on the github CI (newer ones arrange some things + # slightly differently, so would result in a conflict). + export CLANG_FORMAT=${pkgs.clang-tools_15}/bin/clang-tidy + + # Use latest clang-tidy we can get for most detailed + export CLANG_TIDY=${pkgs.clang-tools_17}/bin/clang-tidy + ''; }