Skip to content

Commit

Permalink
Merge pull request #2095 from hzeller/20240203-formatting
Browse files Browse the repository at this point in the history
Choose latest clang-{tidy,format} on nix; provide buildifier formatting if available
  • Loading branch information
hzeller authored Feb 3, 2024
2 parents c922063 + e2f936c commit 23d683d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
7 changes: 7 additions & 0 deletions .github/bin/run-clang-format.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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}

Expand Down
16 changes: 15 additions & 1 deletion shell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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
'';
}

0 comments on commit 23d683d

Please sign in to comment.