Merge branch 'master' into dbus
[sxemacs] / contrib / report-build-failure.sh
1 #!/bin/sh
2 #
3 # Send email to sxemacs-builds list about build failure.
4 # NOTE: At the time of last change, you HAVE to be a subscriber for
5 # your email to actually be delivered to the list
6 #
7 # (C) 2008 Nelson Ferreira
8 #
9 # This program is free software; you can redistribute it and/or modify it
10 # under a BSD-like licence.
11 #
12 # Redistribution and use in source and binary forms, with or without
13 # modification, are permitted provided that the following conditions are met:
14 # Redistributions of source code must retain the above copyright notice, this
15 # list of conditions and the following disclaimer.
16 # Redistributions in binary form must reproduce the above copyright notice,
17 # this list of conditions and the following disclaimer in the documentation
18 # and/or other materials provided with the distribution.
19 # Neither the name of the Technical University of Berlin nor the names of its
20 # contributors may be used to endorse or promote products derived from this
21 # software without specific prior written permission.
22 #
23 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
27 # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 # POSSIBILITY OF SUCH DAMAGE.
34 #
35 echo "Complain bitterly to njsf@sxemacs.org that he has still NOT updated this script to use git"
36 exit 1
37 if [ -z "$1"  ]; then
38     echo "Usage: $0 <from address>"
39     echo "Example: $0 superhacker@sxemacs.org"
40     exit 1
41 else
42     FROM=$1
43 fi
44 if [ -z "$REPORT_DEST" ]; then
45     REPORT_DEST=sxemacs-builds@sxemacs.org
46 fi
47 type sendmail >/dev/null 2>&1 && SENDMAIL=sendmail
48 type tla >/dev/null 2>&1 && TLA=tla
49 type egrep >/dev/null 2>&1 && GREP=egrep
50 type tail >/dev/null 2>&1 && TAIL=tail
51 type tar >/dev/null 2>&1 && TAR=tar
52 type cat >/dev/null 2>&1 && CAT=cat
53 type base64 >/dev/null 2>&1 && BASE64=base64
54 type sed >/dev/null 2>&1 && SED=sed
55 EXT=gz
56 type gzip >/dev/null 2>&1 && COMPRESS=gzip
57 if [ -z "$COMPRESS" ]; then
58     type compress >/dev/null 2>&1 && COMPRESS=compress
59     EXT=Z
60 fi
61 FILTER=cat
62 ENCODING=base64
63 attachment="build-failure-$FROM.tar.${EXT}"
64 if [ -z "${BASE64}" ]; then
65     type uuencode >/dev/null 2>&1 && BASE64=uuencode
66     if [ -n "${BASE64}" ]; then
67         if [ -z "${SED}" ]; then
68             echo "sed was not found and is required when base64 is replaced by uuencode"
69             exit 1
70         fi
71         # Test if this uuencode can actually base64 encode like
72         # in BSD's and MacOS
73         FILTER="${SED} -e s/^begin.*644.*\$// -e s/^end\$// -e s/^====\$// -e /^\$/d "
74         if [ -n "$(echo test | ${BASE64} -m test 2>/dev/null )" ]; then
75             BASE64="${BASE64} -m ${attachment}"
76         else
77             ENCODING=uuencode
78             BASE64="${BASE64} ${attachment}"
79         fi
80     fi
81 fi
82 if [ -n "$2" ]; then
83     REPORT_DEST=$2
84 fi
85 if [ -z "${SENDMAIL}" ]; then
86     if [ -x /usr/lib/sendmail ]; then
87         SENDMAIL=/usr/lib/sendmail
88     elif [ -x /usr/sbin/sendmail ]; then
89         SENDMAIL=/usr/sbin/sendmail
90     elif [ -x /sw/sbin/sendmail ]; then
91         SENDMAIL=/sw/sbin/sendmail
92     else
93         echo "Cannot find sendmail."
94         exit 1
95     fi
96 fi
97 if [ -z "${TLA}" ]; then
98     echo "Cannot find tla."
99     exit 1
100 fi
101 if [ -z "${BASE64}" -o -z "${TAR}" -o -z "${SENDMAIL}" -o -z "${GREP}" -o -z "${CAT}" -o -z "${COMPRESS}" ]; then
102     echo "Could not find one or more of grep (${GREP}), sendmail (${SENDMAIL}),"
103     echo "\t tar (${TAR}), base64 (${BASE64}), cat (${CAT})"
104     exit 1
105 fi
106 if [ ! -f ./config.log -o -z "$(${GREP} -i sxemacs ./config.log)" ]; then
107     echo "Please run this script from the top of the sxemacs build directory.\n"
108     exit 1
109 fi
110 VERSION=$(${GREP} "^#define SXEMACS_ARCH_VERSION" ./config.log | awk '{ print $3 }')
111 if [ -z "$VERSION" ]; then
112     VERSION="Unknown. Possible early configure failure"
113 else
114     attachment="build-failure-$VERSION-$FROM.tar.${EXT}"
115 fi
116 MAIN_VERSION=$(${GREP} "^#define SXEMACS_MAIN_ARCH_VERSION" ./config.log | awk '{ print $3 }')
117 SYNC=""
118 if [ -n "$MAIN_VERSION" -a "$MAIN_VERSION" != "$VERSION" ]; then
119     SYNC="(Last sync with main branch: $MAIN_VERSION)"
120 fi
121 CONFGUESS=$(${GREP} "^host=" ./config.log | awk -F= '{ print $2 }' )
122 if [ -z "$CONFGUESS" ]; then
123     CONFGUESS="Unknown. Possible early configure failure"
124 fi
125 SRCDIR=$(${GREP} "^sxe_srcdir=" ./config.log | awk -F= '{ print $2 }' | sed -e "s/^'//" -e "s/'$//" )
126 BLDDIR=$(${GREP} "^sxe_blddir=" ./config.log | awk -F= '{ print $2 }' | sed -e "s/^'//" -e "s/'$//" )
127 COMPILER=$(${GREP} "^CC=" ./config.log | awk -F= '{ print $2 }' )
128 CONFIG_OPTS=$(${GREP} "^#define EMACS_CONFIG_OPTIONS " ./config.log | sed -e 's/^#define EMACS_CONFIG_OPTIONS //g')
129 if [ -z "$MACHTYPE"  ]; then
130     MACHTYPE=$(uname -a)
131 fi
132 for f in config.log Installation sxemacs_version.m4 ,,beta.out ,,vars.out ,,make-check.out src/config.h ; do
133     if [ -f $f ]; then
134         FILES="$FILES $f"
135     fi
136 done
137 STATUS=$3
138 if [ -z "${STATUS}" ]; then
139     STATUS="BUILD FAILURE"
140 fi
141 SUBJECT="[${STATUS}] Version $VERSION on $CONFGUESS [$MACHTYPE] [@$(pwd)]"
142 MIME="application/x-gzip"
143 boundary="--sxemacs--failure--$$--"
144 KEEP=( \
145     [0]="^(cd|n?make)[:blank:]" \
146     [1]="errors?" \
147     [2]="warnings?" \
148     [3]="pure.*(space|size)" \
149     [4]="hides\>" \
150     [5]="strange" \
151     [6]="shadowings" \
152     [7]="^Compil(ing[:blank:]+in|ation)" \
153     [8]="^Using" \
154     [9]="not[:blank:]+found" \
155     [10]="^While[:blank:]+compiling.*(\n[:blank:]+.+)*" \
156     [11]="^Note:" \
157     [12]="Installing" \
158     [13]="[Ff]ile(s) copied" \
159     [14]="^[A-Za-z_]+=" \
160     [15]="[:blank:]+tests[:blank:]+" \
161     [16]="^(real|user|sys)[:blank:]+[0-9]+m" \
162     )
163 REMOVE=( \
164     [0]="confl.*with.*auto-inlining" \
165     [1]="^Formatting:" \
166     [2]="\(100%\) tests successful" \
167     [3]="errors that should" \
168     [4]="wrong-error" \
169     )
170 KREGEXP=""
171 for r in ${KEEP[*]}; do
172     if [ -z "$KREGEXP" ]; then
173         KREGEXP="$r"
174     else
175         KREGEXP="${KREGEXP}|${r}"
176     fi
177 done
178 RREGEXP=""
179 for r in ${REMOVE[*]}; do
180     if [ -z "$RREGEXP" ]; then
181         RREGEXP="$r"
182     else
183         RREGEXP="${RREGEXP}|${r}"
184     fi
185 done
186 (cat <<EOF
187 From: $FROM
188 To: $REPORT_DEST
189 Subject: $SUBJECT
190 Date: $(date +"%a, %e %Y %T %z")
191 Mime-Version: 1.0
192 Content-Type: multipart/mixed; boundary="$boundary"
193 Content-Disposition: inline
194
195 --$boundary
196 Content-Type: text/plain; charset=us-ascii
197 Content-Disposition: inline
198
199 $STATUS while building $VERSION on $CONFGUESS ($MACHTYPE)
200
201 EOF
202 MSRCDIR="${SRCDIR}"
203 if [ -z "${MSRCDIR}" ]; then
204     MSRCDIR="."
205 fi
206 if [ -n "${MSRCDIR}" -a -d "${MSRCDIR}/{arch}" -a -n "${TLA}"  -a -n "${GREP}"  -a -n "${TAIL}"  ]; then
207     CURDIR=$(pwd)
208     cd "${MSRCDIR}"
209     TREE="$(${TLA} tree-version)"
210     PATCH="$(${TLA} revisions | ${TAIL} -1)"
211     echo "Tree : ${TREE}"
212     echo "Patch: ${PATCH}"
213     echo ""
214     LAST_MAIN="$(${TLA} log-versions | ${GREP} -- '--main--' | ${TAIL} -1)"
215     LAST_MAIN_PATCH="$(${TLA} revisions $LAST_MAIN | ${TAIL} -1)"
216     if [ "${TREE}" != "${LAST_MAIN}" -o "${PATCH}" != "${LAST_MAIN_PATCH}" ]; then
217         echo "Main : $LAST_MAIN"
218         echo "Patch: $LAST_MAIN_PATCH"
219         echo ""
220     fi
221     DIFF_NAME=/tmp/tla-changes-${USER}-$$-${attachment}.log
222     ${TLA} changes -q --diffs > $DIFF_NAME
223     if [ -s $DIFF_NAME ]; then
224         echo "Changes:"
225         echo ""
226         cat $DIFF_NAME
227         echo ""
228         echo "End of Changes"
229     fi
230     /bin/rm $DIFF_NAME
231     cd "${CURDIR}"
232 else
233     echo $SYNC
234 fi
235
236 echo ""
237 if [ -n "${SRCDIR}" ]; then
238     echo " Source in ${SRCDIR}"
239 fi
240 if [ -n "${BLDDIR}" -a "${SRCDIR}" != "${BLDDIR}" ]; then
241     echo " Build  in ${BLDDIR}"
242 fi
243
244 if [ -f ./Installation ]; then
245     echo ""
246     ${CAT} ./Installation
247 else
248     if [ -n "${COMPILER}" ]; then
249         echo " Using compiler ${COMPILER}"
250     fi
251     if [ -n "${CONFIG_OPTS}" ]; then
252         echo " Configured with options: ${CONFIG_OPTS}"
253     fi
254     echo ""
255 fi
256
257 for f in beta make-all make-check-temacs make-check make-install; do
258     if [ -f "./,,${f}.out" ]; then
259         echo "> Contents of $(pwd)/,,${f}.out"
260         echo ""
261         ${GREP} "$KREGEXP" ./,,${f}.out | ${GREP} -v "$RREGEXP"
262     fi
263 done
264
265
266 FIND_NAME=/tmp/find-ldd-${USER}-$$-${attachment}.log
267 find src -type f -a -perm +111  -a -name \*emacs\* -exec file {} \; -exec ldd {} \; > $FIND_NAME 2>&1
268 if [ -s $FIND_NAME ]; then
269     echo " Shared library dependencies "
270     echo ""
271     cat $FIND_NAME
272     echo ""
273     echo ""
274 fi
275 /bin/rm $FIND_NAME
276
277 ${CAT} <<EOF
278
279 --$boundary
280 Content-Type: $MIME;name="$attachment"
281 Content-Disposition: attachment;filename="$attachment"
282 Content-Transfer-Encoding: $ENCODING
283
284 EOF
285 ${TAR} cf - $FILES | ${COMPRESS} -c - | ${BASE64} | ${FILTER}
286 echo ""
287 echo "--$boundary--" ) | $SENDMAIL -t