From 62fab61417c11eca130d5b0c5eef12f69ec27d5e Mon Sep 17 00:00:00 2001 From: Jonathan Hui Date: Tue, 21 Jun 2016 08:58:00 -0700 Subject: [PATCH] Wrap astyle to return a non-zero error code when style checking fails. (#189) --- .astyle-opts => .astyle/astyle-opts | 0 .astyle/astyle-wrap.sh | 44 +++++++++++++++++++++++++++++ .travis/script.sh | 2 +- Makefile.am | 3 +- configure.ac | 6 ++-- 5 files changed, 50 insertions(+), 5 deletions(-) rename .astyle-opts => .astyle/astyle-opts (100%) create mode 100755 .astyle/astyle-wrap.sh diff --git a/.astyle-opts b/.astyle/astyle-opts similarity index 100% rename from .astyle-opts rename to .astyle/astyle-opts diff --git a/.astyle/astyle-wrap.sh b/.astyle/astyle-wrap.sh new file mode 100755 index 000000000..d86713422 --- /dev/null +++ b/.astyle/astyle-wrap.sh @@ -0,0 +1,44 @@ +#!/bin/sh +# +# Copyright (c) 2016, Nest Labs, Inc. +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# 3. Neither the name of the copyright holder nor the +# names of its contributors may be used to endorse or promote products +# derived from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# + +# +# astye does not return a non-zero exit code. This wrapper exists with a +# non-zero exit code if there is any output from astyle. +# + +die() { + echo " *** ERROR: " $* + exit 1 +} + +set -x + +[ -z `$@` ] || { + [ $@ =~ .*dry-run.* ] || die +} diff --git a/.travis/script.sh b/.travis/script.sh index e58e512a7..b14a781d1 100755 --- a/.travis/script.sh +++ b/.travis/script.sh @@ -39,7 +39,7 @@ set -x [ $BUILD_TARGET != pretty-check ] || { export PATH=/tmp/astyle/build/gcc/bin:$PATH || die ./configure || die - make pretty || die + make pretty-check || die } [ $BUILD_TARGET != posix ] || { diff --git a/Makefile.am b/Makefile.am index 5261d17a5..d2466d9e3 100644 --- a/Makefile.am +++ b/Makefile.am @@ -47,7 +47,8 @@ SUBDIRS = \ $(NULL) EXTRA_DIST = \ - .astyle-opts \ + .astyle/astyle-opts \ + .astyle/astyle-wrap.sh \ .default-version \ bootstrap \ bootstrap-configure \ diff --git a/configure.ac b/configure.ac index aeb715ac5..5747606b8 100644 --- a/configure.ac +++ b/configure.ac @@ -268,9 +268,9 @@ AM_CONDITIONAL([OPENTHREAD_BUILD_OPTIMIZED], [test "${nl_cv_build_optimized}" = # Code style # -AC_CHECK_TOOL(ASTYLE, astyle) -AC_SUBST(ASTYLE_PRETTY_ARGS, ["--options=\${abs_top_builddir}/.astyle-opts"]) -AC_SUBST(ASTYLE_PRETTY_CHECK_ARGS, ["--options=\${abs_top_builddir}/.astyle-opts --dry-run"]) +AC_SUBST(ASTYLE, ["\${abs_top_srcdir}/.astyle/astyle-wrap.sh"]) +AC_SUBST(ASTYLE_PRETTY_ARGS, ["astyle --options=\${abs_top_builddir}/.astyle/astyle-opts"]) +AC_SUBST(ASTYLE_PRETTY_CHECK_ARGS, ["astyle --options=\${abs_top_builddir}/.astyle/astyle-opts --dry-run"]) # # Tests