Improve uncrustify Jenkins builds
authorTeemu Murtola <teemu.murtola@gmail.com>
Fri, 5 Jun 2015 19:25:13 +0000 (22:25 +0300)
committerTeemu Murtola <teemu.murtola@gmail.com>
Fri, 12 Jun 2015 08:38:27 +0000 (10:38 +0200)
Add a script to wrap uncrustify.sh for Jenkins, and make it produce
additional text files that can more easily be used for further
processing in Jenkins.

Change-Id: I3c25760eec4c37a07a7889f471eb5b61f9932a9c

admin/run-uncrustify.sh [new file with mode: 0755]
admin/uncrustify.sh
docs/dev-manual/jenkins.rst

diff --git a/admin/run-uncrustify.sh b/admin/run-uncrustify.sh
new file mode 100755 (executable)
index 0000000..e06bf4c
--- /dev/null
@@ -0,0 +1,86 @@
+#!/bin/bash
+#
+# This file is part of the GROMACS molecular simulation package.
+#
+# Copyright (c) 2015, by the GROMACS development team, led by
+# Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
+# and including many others, as listed in the AUTHORS file in the
+# top-level source directory and at http://www.gromacs.org.
+#
+# GROMACS is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public License
+# as published by the Free Software Foundation; either version 2.1
+# of the License, or (at your option) any later version.
+#
+# GROMACS is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with GROMACS; if not, see
+# http://www.gnu.org/licenses, or write to the Free Software Foundation,
+# Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
+#
+# If you want to redistribute modifications to GROMACS, please
+# consider that scientific software is very special. Version
+# control is crucial - bugs must be traceable. We will be happy to
+# consider code for inclusion in the official distribution, but
+# derived work must not be called official GROMACS. Details are found
+# in the README & COPYING files - if they are missing, get the
+# official version at http://www.gromacs.org.
+#
+# To help us fund GROMACS development, we humbly ask that you cite
+# the research papers on the package. Check out http://www.gromacs.org.
+
+# This script is used by Gerrit to run uncrustify in the uncrustify_* jobs.
+# The main purpose of this script is to isolate Jenkins from the details of
+# the uncrustify.sh script, and to provide a facade that can keep the interface
+# to Jenkins the same even if uncrustify.sh changes.
+# It also provides some logic to produce better messages for Jenkins.
+#
+# Interface from Jenkins to this script is:
+#  * location of the script
+#  * UNCRUSTIFY environment variable to specify the location of uncrustify
+#
+# Communication back to Jenkins is through
+#  * return value of this script (non-zero marks the build failed).
+#  * stdout (any instance of "FAILED" marks the build unstable),
+#  * unsuccessful-reason.log contains a short description of what failed
+#    or was unstable
+#  * uncrustify.log contains messages about what files needed changes
+
+srcdir=`git rev-parse --show-toplevel`
+cd $srcdir
+if [ ! -f "admin/run-uncrustify.sh" ] ; then
+    echo "Failed to find root of the source tree"
+    exit 1
+fi
+
+warning_log=uncrustify.log
+unsuccessful_log=unsuccessful-reason.log
+
+admin/uncrustify.sh check --rev=HEAD^ --warnings=$warning_log
+stat=$?
+if [ $stat -eq 1 ] ; then
+    echo "FAILED: uncrustify.sh found issues"
+    warning_count=`wc -l <$warning_log`
+    if [ $warning_count -lt 5 ] ; then
+        cp -f $warning_log $unsuccessful_log
+    else
+        rm -f $unsuccessful_log
+        uncrustify_count=`grep "needs uncrustify" $warning_log | wc -l`
+        cpyear_count=`grep "copyright year" $warning_log | wc -l`
+        cpheader_count=`grep "copyright header" $warning_log | wc -l`
+        [ $uncrustify_count -gt 0 ] && echo "formatting issues in" $uncrustify_count "file(s)" >> $unsuccessful_log
+        [ $cpyear_count -gt 0 ] && echo "copyright year missing in" $cpyear_count "file(s)" >> $unsuccessful_log
+        [ $cpheader_count -gt 0 ] && echo "copyright header issues in" $cpheader_count "file(s)" >> $unsuccessful_log
+        cat $unsuccessful_log
+    fi
+    exit 0
+elif [ $stat -ne 0 ] ; then
+    echo "FAILED: uncrustify.sh failed to run"
+    echo "uncrustify.sh failed to run" > $unsuccessful_log
+    exit 1
+fi
+exit 0
index c1e3f81c135a8df06dfb800212fa5175fb8e7c06..da28285613f3a603577293df089b9567aee7d6b3 100755 (executable)
@@ -42,7 +42,8 @@
 # Parse command-line arguments
 function usage() {
     echo "usage: uncrustify.sh [-f|--force] [--rev=REV]"
-    echo "           [--uncrustify=(off|check)] [--copyright=<cmode>] [<action>]"
+    echo "           [--uncrustify=(off|check)] [--copyright=<cmode>]"
+    echo "           [--warnings=<file>] [<action>]"
     echo "<action>: (check*|diff|update)[-(index|workdir*)] (*=default)"
     echo "<cmode>:  off|add|update*|replace|full"
 }
@@ -53,6 +54,7 @@ baserev="HEAD"
 force=
 uncrustify_mode=check
 copyright_mode=update
+warning_file=
 for arg in "$@" ; do
     if [[ "$arg" == "check-index" || "$arg" == "check-workdir" || \
           "$arg" == "diff-index" || "$arg" == "diff-workdir" || \
@@ -77,6 +79,8 @@ for arg in "$@" ; do
         force=1
     elif [[ "$arg" == --rev=* ]] ; then
         baserev=${arg#--rev=}
+    elif [[ "$arg" == --warnings=* ]] ; then
+        warning_file=${arg#--warnings=}
     elif [[ "$arg" == "-h" || "$arg" == "--help" ]] ; then
         usage
         exit 0
@@ -272,7 +276,7 @@ elif [[ $action == update-workdir ]] ; then
 fi
 
 # Report what was done
-sort $tmpdir/messages
+sort $tmpdir/messages | tee $srcdir/$warning_file
 
 rm -rf $tmpdir
 exit $changes
index 13d0cc94e41198fc84f5190e9deffcdda17ee90a..696b0b7f4acb4d718c098065d06947a394a0781d 100644 (file)
@@ -65,15 +65,14 @@ This build checks the source code for formatting such as consistent indentation
 and use of braces, as well as for copyright headers.  See :doc:`formatting` for
 the guidelines that are enforced.
 
-Technically, the build simply runs :file:`admin/uncrustify.sh` as ::
-
-  admin/uncrustify.sh check --rev=HEAD^
-
-to check the formatting in the changes for the commit.
-If the return value is non-zero (i.e., any changes would be required), the
-build is marked unstable.
-Currently, only the console log of the build shows what actually was the issue.
-See :doc:`uncrustify` for more details on the script and uncrustify.
+Technically, the build simply runs :file:`admin/run-uncrustify.sh` to check the
+formatting in the changes for the commit.
+If the any changes are required, the build is marked unstable.
+If the script completely fails (should be rare), the build fails.
+A file with issues found by the script is archived as an artifact in the build,
+and a summary is reported back to Gerrit (or the actual issues if there are
+only a few).
+See :doc:`uncrustify` for more details on uncrustify and on scripts to run it.
 
 .. TODO: Provide links to the build system page, once there are on the git
    commit chain...