diff --git a/.astyleignore b/.astyleignore new file mode 100644 index 0000000000..bac5af58f0 --- /dev/null +++ b/.astyleignore @@ -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 diff --git a/.astylerc b/.astylerc new file mode 100644 index 0000000000..b208b767a7 --- /dev/null +++ b/.astylerc @@ -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 diff --git a/.travis.yml b/.travis.yml index 8288d507be..0051ebf4a2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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(\", (?[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