[Libreoffice-commits] dev-tools.git: cppcheck/cppcheck-report.sh

Maarten Hoes hoes.maarten at gmail.com
Fri Jan 23 12:29:47 PST 2015


 cppcheck/cppcheck-report.sh |   65 +++++++++++++++++++++++++++++++++++++++-----
 1 file changed, 58 insertions(+), 7 deletions(-)

New commits:
commit ec1c1ddcc8eb03b71e8e69c5c2644a4d80947730
Author: Maarten Hoes <hoes.maarten at gmail.com>
Date:   Wed Jan 21 14:13:11 2015 +0100

    redirect output to file, mail it to list on error if mailx is present.
    
    Change-Id: I4e6829cab888376290541adc2a4e03270cabd8ce
    Reviewed-on: https://gerrit.libreoffice.org/14074
    Reviewed-by: Caolán McNamara <caolanm at redhat.com>
    Tested-by: Caolán McNamara <caolanm at redhat.com>

diff --git a/cppcheck/cppcheck-report.sh b/cppcheck/cppcheck-report.sh
index fc9ea32..f018770 100755
--- a/cppcheck/cppcheck-report.sh
+++ b/cppcheck/cppcheck-report.sh
@@ -10,6 +10,13 @@
 
 [ "$DEBUG" ] && set -xv
 
+# save stdout and stderr
+exec 3>&1 4>&2 >/tmp/foo.log 2>&1
+
+# redirect to log file
+exec > /tmp/cppcheck-report.log
+exec 2>&1
+
 #
 # Functions
 #
@@ -18,7 +25,9 @@ die()
 {
     [ "$DEBUG" ] && set -xv
 
-    echo "Error:" "$@" >&2
+    MESSAGE="$@"
+    echo "Error:" "${MESSAGE?}" >&2
+    mail_failure "${MESSAGE?}"
     exit -1;
 }
 
@@ -108,7 +117,6 @@ get_commit_cppcheck()
     popd > /dev/null || die "Failed to change directory out of ${CPPCHECK_DIR?}"
 }
 
-
 upload_report()
 {
     [ "$DEBUG" ] && set -xv
@@ -118,16 +126,57 @@ upload_report()
     scp -r "${HTML_DIR?}"/* upload at dev-builds.libreoffice.org:"${UPLOAD_DIR?}"/ || die "Failed to upload report to ${UPLOAD_DIR?}"
 }
 
+mail_success()
+{
+    [ "$DEBUG" ] && set -xv
 
-#
-# Main
-#
+    which mailx >/dev/null 2>&1
+    if [ "$?" = "0" ] ; then
+
+mailx -s "CppCheck Report update" "${MAILTO?}" <<EOF
+
+A new cppcheck report is available at : http://dev-builds.libreoffice.org/cppcheck_reports/master/
+
+This job was run at `date +%Y-%d-%m_%H:%M:%S` with user `whoami` at host `cat /etc/hostname` as $MY_NAME
+
+EOF
+
+    fi
+}
 
+mail_failure()
+{
+    [ "$DEBUG" ] && set -xv
+    MESSAGE="$@"
+
+    if [ -f /tmp/cppcheck-report.log ] ; then
+        cp -f /tmp/cppcheck-report.log ~/cppcheck-report.log
+        rm -f ~/cppcheck-report.log.gz
+        gzip ~/cppcheck-report.log
+    fi
+
+    which mailx >/dev/null 2>&1
+    if [ "$?" = "0" ] ; then
+
+mailx -s "CppCheck Report: Failure" "${MAILTO?}" <<EOF
+`uuencode /home/buildslave/cppcheck-report.log.gz /home/buildslave/cppcheck-report.log.gz`
+
+The cppcheck job failed with message: "${MESSAGE?}"
+
+This job was run at `date +%Y-%d-%m_%H:%M:%S` with user `whoami` at host `cat /etc/hostname` as $MY_NAME
+
+EOF
+
+    fi
+}
 
 usage()
 {
     [ "$DEBUG" ] && set -xv
 
+    # restore stdout and stderr
+    exec 1>&3 2>&4
+
     echo >&2 "Usage: lcov-report.sh -s [DIRECTORY] -w [DIRECTORY]
         -s    source code directory
         -w    html (www) directory
@@ -150,7 +199,9 @@ DATA_DIR=/tmp
 CPPCHECK_GIT_URL="git://github.com/danmar/cppcheck.git"
 LO_GIT_URL="git://anongit.freedesktop.org/libreoffice/core.git"
 UPLOAD_DIR=/srv/www/dev-builds.libreoffice.org/cppcheck_reports/master
-
+MAILTO=libreoffice at lists.freedesktop.org
+MY_NAME=`dirname $0`
+MESSAGE=
 
 while getopts ":s:w:c:" opt ; do
     case "$opt" in
@@ -177,4 +228,4 @@ get_commit_lo
 build_cppcheck
 run_cppcheck
 upload_report
-
+mail_success


More information about the Libreoffice-commits mailing list