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

Improve clang-format detection & enforcement #3462

Merged
merged 3 commits into from
Sep 22, 2021
Merged
Show file tree
Hide file tree
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
1 change: 0 additions & 1 deletion .clang-format.base → .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ BraceWrapping:
AfterClass: true
BeforeCatch: true
BeforeElse: true
BeforeLambdaBody: true
SplitEmptyRecord: true
SplitEmptyNamespace: true
SortIncludes: true
Expand Down
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,3 @@ Testing

# Autogenerated Build Prep artifacts
util/build_prep/*/prep.sh

# Autogenerated Tooling
.clang-format
22 changes: 12 additions & 10 deletions ci/check-commit-format.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,21 @@

set -e

source "$(dirname "$BASH_SOURCE")/detect-clang-format.sh"
if [[ ! -z $(git status --untracked-files=no --porcelain) ]]; then
echo "Unable to run script: working directory not clean (see git status)"
exit 1
fi

source "$(dirname "$BASH_SOURCE")/common.sh"

"$REPO_ROOT/ci/update-clang-format"
"$REPO_ROOT/ci/clang-format-all.sh"

clang_format_result=$(python "$REPO_ROOT/ci/git-clang-format.py" --diff --extensions "hpp,cpp")
if [[ $clang_format_result != "no modified files to format" ]] &&
[[ $clang_format_result != "clang-format did not modify any files" ]]; then
python "$REPO_ROOT/ci/git-clang-format.py" --diff --extensions "hpp,cpp"
echo
if [[ ! -z $(git status --untracked-files=no --porcelain) ]]; then
echo "Code formatting differs from expected - please run ci/clang-format-all.sh"
git diff
git reset --hard HEAD > /dev/null
exit 1
else
echo "clang-format passed"
exit 0
fi

echo "clang-format passed"
exit 0
8 changes: 3 additions & 5 deletions ci/clang-format-all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

set -e

source $(dirname $BASH_SOURCE)/detect-clang-format.sh
source $(dirname $BASH_SOURCE)/common.sh
source "$(dirname "$BASH_SOURCE")/detect-clang-format.sh"
source "$(dirname "$BASH_SOURCE")/common.sh"

cd "$REPO_ROOT"
./ci/update-clang-format
find nano -iname '*.h' -o -iname '*.hpp' -o -iname '*.cpp' | xargs "$CLANG_FORMAT" -i
find "$REPO_ROOT/nano" -iname '*.h' -o -iname '*.hpp' -o -iname '*.cpp' | xargs "$CLANG_FORMAT" -i -style=file
2 changes: 2 additions & 0 deletions ci/detect-clang-format.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,5 @@ if [[ -z $CLANG_FORMAT ]]; then
echo "No 'clang-format' of version '$CLANG_FORMAT_VERSION' could be detected in your PATH."
exit 1
fi

echo "Using '$CLANG_FORMAT' version '$CLANG_FORMAT_VERSION'"
Loading