Skip to content
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

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

Merged
merged 2 commits into from
Dec 10, 2024
Merged
Changes from all commits
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
28 changes: 10 additions & 18 deletions clang_format/run_clang_format.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,20 @@
set -ue

format_all() {
CLANG_FORMAT_CONFIG=$(realpath $1)
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
cd "$BUILD_WORKSPACE_DIRECTORY"
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"
}

format_diff() {
CLANG_FORMAT_CONFIG=$(realpath $1)
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
cd "$BUILD_WORKSPACE_DIRECTORY"
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 -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 --style=file:"$CLANG_FORMAT_CONFIG"
}

check_file() {
Expand All @@ -36,14 +28,14 @@ check_file() {

# .clang-format config file has to be placed in the current working directory
if [ ! -f ".clang-format" ]; then
ln -s $CONFIG .clang-format
ln -s "$CONFIG" .clang-format
fi

$CLANG_FORMAT_BIN $INPUT --dry-run -Werror > $OUTPUT
$CLANG_FORMAT_BIN "$INPUT" --dry-run -Werror > "$OUTPUT"
}

ARG=$1
CLANG_FORMAT_BIN=$(realpath $2)
CLANG_FORMAT_BIN=$(realpath "$2")
shift 2

if [ "$ARG" == "format_diff" ]; then
Expand Down
Loading