forked from OSGeo/gdal
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
RFC69: C++ code formatting - config, scripts and workflows
- Loading branch information
Showing
4 changed files
with
122 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
|
||
name: clang-format Check | ||
|
||
on: [push, pull_request] | ||
|
||
jobs: | ||
|
||
formatting-check: | ||
|
||
name: Formatting Check | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout GDAL | ||
uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 100 | ||
|
||
- name: Set up Python | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: 3.7 | ||
|
||
- name: Install Run clang-format style check for C/C++ programs. | ||
run: pip install clang-format==15.0.4 | ||
|
||
- name: Check new code with clang-format | ||
run: ./scripts/clang-format.sh | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
#!/bin/sh | ||
set -eu | ||
|
||
if ! (clang-format --version >/dev/null); then | ||
echo "clang-format not available. Install it with 'pre-commit'" | ||
exit 1 | ||
fi | ||
|
||
# GNU prefix command for mac os support (gsed) | ||
GP= | ||
# shellcheck disable=SC2039 | ||
case "${OSTYPE:-}" in | ||
darwin*) | ||
GP=g | ||
;; | ||
esac | ||
|
||
# determine changed files | ||
FILES=$(git diff --diff-filter=AM --name-only HEAD~1| tr '\n' ' ' | sort -u) | ||
|
||
if [ -z "$FILES" ]; then | ||
echo "nothing was modified" | ||
exit 0 | ||
fi | ||
|
||
STYLEDIFF=/tmp/clang-format.diff | ||
true > $STYLEDIFF | ||
|
||
for f in $FILES; do | ||
if ! [ -f "$f" ]; then | ||
echo "$f was removed." >>/tmp/ctest-important.log | ||
continue | ||
fi | ||
|
||
# echo "Checking $f" | ||
case "$f" in | ||
*.cpp|*.c|*.h|*.cxx|*.hxx|*.c++|*.h++|*.cc|*.hh|*.C|*.H) | ||
;; | ||
|
||
*) | ||
continue | ||
;; | ||
esac | ||
|
||
m="$f.prepare" | ||
cp "$f" "$m" | ||
clang-format -i "$f" | ||
if diff -u "$m" "$f" >>$STYLEDIFF; then | ||
rm "$m" | ||
else | ||
echo "File $f is not styled properly." | ||
fi | ||
done | ||
|
||
if [ -s "$STYLEDIFF" ]; then | ||
echo | ||
echo "Required code formatting updates:" | ||
cat "$STYLEDIFF" | ||
|
||
cat <<EOF | ||
Tips to prevent and resolve: | ||
* Run pre-commit to install clang-format for C++ code style | ||
EOF | ||
exit 1 | ||
fi |