mirror of
https://github.com/esp8266/Arduino.git
synced 2025-04-19 23:22:16 +03:00
ci: check examples code style
Use code style defined in Arduino project to check code style of the examples. The check is done by formatting all files with astyle and checking whether any changes have been introduced.
This commit is contained in:
parent
af74a10d27
commit
e226251b27
20
.travis.yml
20
.travis.yml
@ -3,6 +3,10 @@ language: bash
|
||||
os: linux
|
||||
dist: trusty
|
||||
|
||||
cache:
|
||||
directories:
|
||||
- $HOME/astyle
|
||||
|
||||
matrix:
|
||||
include:
|
||||
- env:
|
||||
@ -15,9 +19,23 @@ matrix:
|
||||
- BUILD_TYPE=package
|
||||
- env:
|
||||
- BUILD_TYPE=host_tests
|
||||
- env:
|
||||
- BUILD_TYPE=style_check
|
||||
|
||||
install:
|
||||
- pip install --user -r doc/requirements.txt
|
||||
- >
|
||||
[ "$BUILD_TYPE" = "docs" ] && {
|
||||
pip install --user -r doc/requirements.txt;
|
||||
} || true
|
||||
- >
|
||||
[ "$BUILD_TYPE" = "style_check" ] && {
|
||||
[ -f $HOME/astyle/build/gcc/bin/astyle ] || {
|
||||
wget -O astyle_3.1_linux.tar.gz https://sourceforge.net/projects/astyle/files/astyle/astyle%203.1/astyle_3.1_linux.tar.gz/download;
|
||||
tar -xf astyle_3.1_linux.tar.gz -C $HOME;
|
||||
make -C $HOME/astyle/build/gcc;
|
||||
}
|
||||
make -C $HOME/astyle/build/gcc prefix=$HOME install;
|
||||
} || true
|
||||
|
||||
script:
|
||||
- $TRAVIS_BUILD_DIR/tests/common.sh
|
||||
|
@ -213,8 +213,30 @@ function build_sketches_with_arduino()
|
||||
echo -e "travis_fold:end:size_report"
|
||||
}
|
||||
|
||||
function check_examples_style()
|
||||
{
|
||||
echo -e "travis_fold:start:check_examples_style"
|
||||
|
||||
find $TRAVIS_BUILD_DIR/libraries -name '*.ino' -exec \
|
||||
astyle \
|
||||
--suffix=none \
|
||||
--options=$TRAVIS_BUILD_DIR/tests/examples_style.conf {} \;
|
||||
|
||||
git diff --exit-code -- $TRAVIS_BUILD_DIR/libraries
|
||||
|
||||
echo -e "travis_fold:end:check_examples_style"
|
||||
}
|
||||
|
||||
set -e
|
||||
|
||||
if [ -z "$TRAVIS_BUILD_DIR" ]; then
|
||||
echo "TRAVIS_BUILD_DIR is not set, trying to guess:"
|
||||
pushd $(dirname $0)/../ > /dev/null
|
||||
TRAVIS_BUILD_DIR=$PWD
|
||||
popd > /dev/null
|
||||
echo "TRAVIS_BUILD_DIR=$TRAVIS_BUILD_DIR"
|
||||
fi
|
||||
|
||||
if [ "$BUILD_TYPE" = "build" ]; then
|
||||
install_arduino
|
||||
build_sketches_with_arduino
|
||||
@ -236,5 +258,11 @@ elif [ "$BUILD_TYPE" = "host_tests" ]; then
|
||||
# Run host side tests
|
||||
cd $TRAVIS_BUILD_DIR/tests
|
||||
run_host_tests
|
||||
elif [ "$BUILD_TYPE" = "style_check" ]; then
|
||||
# Check code style
|
||||
check_examples_style
|
||||
else
|
||||
echo "BUILD_TYPE not set"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
44
tests/examples_style.conf
Normal file
44
tests/examples_style.conf
Normal file
@ -0,0 +1,44 @@
|
||||
# Code formatting rules for Arduino examples, taken from:
|
||||
#
|
||||
# https://github.com/arduino/Arduino/blob/master/build/shared/examples_formatter.conf
|
||||
#
|
||||
|
||||
mode=c
|
||||
lineend=linux
|
||||
|
||||
# 2 spaces indentation
|
||||
indent=spaces=2
|
||||
|
||||
# also indent macros
|
||||
indent-preprocessor
|
||||
|
||||
# indent classes, switches (and cases), comments starting at column 1
|
||||
indent-classes
|
||||
indent-switches
|
||||
indent-cases
|
||||
indent-col1-comments
|
||||
|
||||
# put a space around operators
|
||||
pad-oper
|
||||
|
||||
# put a space after if/for/while
|
||||
pad-header
|
||||
|
||||
# if you like one-liners, keep them
|
||||
keep-one-line-statements
|
||||
add-braces
|
||||
|
||||
style=java
|
||||
attach-namespaces
|
||||
attach-classes
|
||||
attach-inlines
|
||||
attach-extern-c
|
||||
indent-modifiers
|
||||
indent-namespaces
|
||||
indent-labels
|
||||
indent-preproc-block
|
||||
indent-preproc-define
|
||||
indent-preproc-cond
|
||||
unpad-paren
|
||||
add-braces
|
||||
remove-comment-prefix
|
Loading…
x
Reference in New Issue
Block a user