Merge pull request #6590 from 0xc0170/dev_astyle_only_changed

AStyle addition to travis
pull/6805/head
Cruz Monrreal 2018-04-30 11:59:22 -05:00 committed by GitHub
commit a1307d423a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 90 additions and 0 deletions

17
.astyleignore Normal file
View File

@ -0,0 +1,17 @@
BUILD
cmsis
features/mbedtls
features/FEATURE_LWIP/lwip
rtos/TARGET_CORTEX/rtx4
features/filesystem/littlefs/littlefs
features/filesystem/fat/ChaN
features/frameworks
features/FEATURE_BLE/targets
features/FEATURE_LWIP/lwip-interface/lwip
features/unsupported/
features/FEATURE_COMMON_PAL/
FEATURE_NANOSTACK/coap-service
FEATURE_NANOSTACK/sal-stack-nanostack
rtos/TARGET_CORTEX/rtx5
targets
tools

34
.astylerc Normal file
View File

@ -0,0 +1,34 @@
# Mbed OS code style definition file for astyle
# Don't create backup files, let git handle it
suffix=none
# K&R style
style=kr
# 1 TBS addition to k&r, add braces to one liners
# Use -j as it was changed in astyle from brackets to braces, this way it is compatible with older astyle versions
-j
# 4 spaces, convert tabs to spaces
indent=spaces=4
convert-tabs
# Indent switches and cases
indent-switches
indent-cases
# Remove spaces in and around parentheses
unpad-paren
# Insert a space after if, while, for, and around operators
pad-header
pad-oper
# Pointer/reference operators go next to the name (on the right)
align-pointer=name
align-reference=name
# Attach { for classes and namespaces
attach-namespaces
attach-classes

View File

@ -94,6 +94,45 @@ matrix:
# Report success since we have overridden default behaviour
- bash -c "$STATUS" success "Local $NAME testing has passed"
- env:
- NAME=astyle
install:
- wget https://downloads.sourceforge.net/project/astyle/astyle/astyle%203.1/astyle_3.1_linux.tar.gz;
mkdir -p BUILD && tar xf astyle_3.1_linux.tar.gz -C BUILD;
pushd BUILD/astyle/build/gcc;
make;
export PATH=$PWD/bin:$PATH;
popd;
- astyle --version
script:
# only changed files this time
- git diff --name-only $TRAVIS_BRANCH | grep '.*\.\(h\|c\|hpp\|cpp\)' | fgrep -v -f .astyleignore | xargs -n 100 -I {} bash -c "astyle -n --options=.astylerc \"{}\"" > astyle-files-changed.out;
if [ $(cat astyle-files-changed.out | grep Formatted | wc -l) -ne 0 ]; then
git --no-pager diff;
echo "Please fix style issues as shown above";
else
echo "Coding style check OK";
fi
after_success:
# run astyle for all files on the branch
- git checkout -- .
- find -regex '.*\.\(h\|c\|hpp\|cpp\)' -type f | fgrep -v -f .astyleignore | xargs -n 100 -I {} bash -c "astyle -n --options=.astylerc \"{}\"" > astyle-branch.out;
# update status if we succeeded, compare with master if possible
- |
CURR=$(cat astyle-branch.out | grep Formatted | wc -l)
PREV=$(curl https://api.github.com/repos/$TRAVIS_REPO_SLUG/status/master \
| jq -re "select(.sha != \"$TRAVIS_COMMIT\")
| .statuses[] | select(.context == \"travis-ci/$NAME\").description
| capture(\", (?<warnings>[0-9]+) warnings\").warnings" \
|| echo 0)
STATUSM="Passed, ${CURR} warnings"
if [ "$PREV" -ne 0 ]
then
STATUSM="$STATUSM ($(python -c "print '%+d' % ($CURR-$PREV)") warnings)"
fi
- bash -c "$STATUS" success "$STATUSM"
- env:
- NAME=events
- EVENTS=events