From 0daec91683098b7293e27b78063d0e7dcfd34a49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antonio=20Ni=C3=B1o=20D=C3=ADaz?= Date: Mon, 2 Apr 2018 23:40:19 +0100 Subject: [PATCH] Check code style as part of the CI tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If checkpatch.pl detects any ERROR in the new patches, the Travis CI build will fail. Signed-off-by: Antonio Niño Díaz --- .travis-checkpatch.sh | 48 +++++++++++++++++++++++++++++++++++++++++++ .travis.yml | 1 + 2 files changed, 49 insertions(+) create mode 100755 .travis-checkpatch.sh diff --git a/.travis-checkpatch.sh b/.travis-checkpatch.sh new file mode 100755 index 00000000..95f35a79 --- /dev/null +++ b/.travis-checkpatch.sh @@ -0,0 +1,48 @@ +#!/bin/bash + +echo "Checking code style..." + +# Return failure as soon as a command fails to execute + +set -e + +# Download checkpatch.pl and related files + +echo "Getting checkpatch.pl..." + +mkdir checkpatchdir + +wget https://raw.githubusercontent.com/torvalds/linux/master/scripts/checkpatch.pl +mv checkpatch.pl checkpatchdir/checkpatch.pl +chmod +x checkpatchdir/checkpatch.pl + +touch checkpatchdir/const_structs.checkpatch +touch checkpatchdir/spelling.txt + +# Run checkpatch.pl on the new commits + +echo "Running checkpatch.pl..." + +fname=$(mktemp) +rc=0 + +git remote set-branches --add origin develop +git fetch + +make CHECKPATCH=checkpatchdir/checkpatch.pl checkpatch > $fname + +cat $fname + +if grep "ERROR" $fname; then + # At least one error found + echo "Code style errors have been found!" + rc=1 +else + echo "No code style errors found, your patches are ready!" +fi + +# Cleanup + +rm -rf checkpatchdir + +exit $rc diff --git a/.travis.yml b/.travis.yml index 1add5370..d2ce4535 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,5 +10,6 @@ compiler: - clang - gcc script: + - ./.travis-checkpatch.sh - cd test - ./run-tests.sh