Skip to content

clang-format: Use config directly instead of modifying repository [AP-3053] #146

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 10, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 2 additions & 10 deletions clang_format/run_clang_format.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,17 @@ format_all() {
CLANG_FORMAT_CONFIG=$(realpath $1)

cd $BUILD_WORKSPACE_DIRECTORY
if ! test -f .clang-format; then
echo ".clang-format file not found. Bazel will copy the default .clang-format file."
cp $CLANG_FORMAT_CONFIG .
fi
git ls-files '*.[ch]' '*.cpp' '*.cxx' '*.cc' '*.hpp' '*.hxx' \
| xargs -r $CLANG_FORMAT_BIN -i
| xargs -r $CLANG_FORMAT_BIN -i --style=file:$CLANG_FORMAT_CONFIG

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: ShellCheck reports several issues in this script (missing double quotes around all variables, uses of backquotes), which might be worth fixing?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool linter! I've fixed all the smells.

}

format_diff() {
CLANG_FORMAT_CONFIG=$(realpath $1)

cd $BUILD_WORKSPACE_DIRECTORY
if ! test -f .clang-format; then
echo ".clang-format file not found. Bazel will copy the default .clang-format file."
cp $CLANG_FORMAT_CONFIG .
fi
git describe --tags --abbrev=0 --always \
| xargs -rI % git diff --diff-filter=ACMRTUXB --name-only --line-prefix=`git rev-parse --show-toplevel`/ % -- '*.[ch]' '*.cpp' '*.cxx' '*.cc' '*.hpp' '*.hxx' \
| xargs -r $CLANG_FORMAT_BIN -i
| xargs -r $CLANG_FORMAT_BIN -i --style=file:$CLANG_FORMAT_CONFIG
}

check_file() {
Expand Down
Loading