Skip to content

Commit a1307d4

Browse files
author
Cruz Monrreal
authored
Merge pull request #6590 from 0xc0170/dev_astyle_only_changed
AStyle addition to travis
2 parents 46379d8 + c12ee10 commit a1307d4

File tree

3 files changed

+90
-0
lines changed

3 files changed

+90
-0
lines changed

.astyleignore

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
BUILD
2+
cmsis
3+
features/mbedtls
4+
features/FEATURE_LWIP/lwip
5+
rtos/TARGET_CORTEX/rtx4
6+
features/filesystem/littlefs/littlefs
7+
features/filesystem/fat/ChaN
8+
features/frameworks
9+
features/FEATURE_BLE/targets
10+
features/FEATURE_LWIP/lwip-interface/lwip
11+
features/unsupported/
12+
features/FEATURE_COMMON_PAL/
13+
FEATURE_NANOSTACK/coap-service
14+
FEATURE_NANOSTACK/sal-stack-nanostack
15+
rtos/TARGET_CORTEX/rtx5
16+
targets
17+
tools

.astylerc

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Mbed OS code style definition file for astyle
2+
3+
# Don't create backup files, let git handle it
4+
suffix=none
5+
6+
# K&R style
7+
style=kr
8+
9+
# 1 TBS addition to k&r, add braces to one liners
10+
# Use -j as it was changed in astyle from brackets to braces, this way it is compatible with older astyle versions
11+
-j
12+
13+
# 4 spaces, convert tabs to spaces
14+
indent=spaces=4
15+
convert-tabs
16+
17+
# Indent switches and cases
18+
indent-switches
19+
indent-cases
20+
21+
# Remove spaces in and around parentheses
22+
unpad-paren
23+
24+
# Insert a space after if, while, for, and around operators
25+
pad-header
26+
pad-oper
27+
28+
# Pointer/reference operators go next to the name (on the right)
29+
align-pointer=name
30+
align-reference=name
31+
32+
# Attach { for classes and namespaces
33+
attach-namespaces
34+
attach-classes

.travis.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,45 @@ matrix:
9494
# Report success since we have overridden default behaviour
9595
- bash -c "$STATUS" success "Local $NAME testing has passed"
9696

97+
- env:
98+
- NAME=astyle
99+
install:
100+
- wget https://downloads.sourceforge.net/project/astyle/astyle/astyle%203.1/astyle_3.1_linux.tar.gz;
101+
mkdir -p BUILD && tar xf astyle_3.1_linux.tar.gz -C BUILD;
102+
pushd BUILD/astyle/build/gcc;
103+
make;
104+
export PATH=$PWD/bin:$PATH;
105+
popd;
106+
- astyle --version
107+
script:
108+
# only changed files this time
109+
- 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;
110+
if [ $(cat astyle-files-changed.out | grep Formatted | wc -l) -ne 0 ]; then
111+
git --no-pager diff;
112+
echo "Please fix style issues as shown above";
113+
else
114+
echo "Coding style check OK";
115+
fi
116+
after_success:
117+
# run astyle for all files on the branch
118+
- git checkout -- .
119+
- 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;
120+
# update status if we succeeded, compare with master if possible
121+
- |
122+
CURR=$(cat astyle-branch.out | grep Formatted | wc -l)
123+
PREV=$(curl https://api.github.com/repos/$TRAVIS_REPO_SLUG/status/master \
124+
| jq -re "select(.sha != \"$TRAVIS_COMMIT\")
125+
| .statuses[] | select(.context == \"travis-ci/$NAME\").description
126+
| capture(\", (?<warnings>[0-9]+) warnings\").warnings" \
127+
|| echo 0)
128+
129+
STATUSM="Passed, ${CURR} warnings"
130+
if [ "$PREV" -ne 0 ]
131+
then
132+
STATUSM="$STATUSM ($(python -c "print '%+d' % ($CURR-$PREV)") warnings)"
133+
fi
134+
- bash -c "$STATUS" success "$STATUSM"
135+
97136
- env:
98137
- NAME=events
99138
- EVENTS=events

0 commit comments

Comments
 (0)