Add triggers to action to update contrib scripts
[sxemacs] / contrib / report-build-failure.sh
1 #!/bin/sh
2 #
3 echo "Complain bitterly to njsf@sxemacs.org that he has still NOT updated this script to use git"
4 exit 1
5 if [ -z "$1"  ]; then
6     echo "Usage: $0 <from address>"
7     echo "Example: $0 superhacker@sxemacs.org"
8     exit 1
9 else
10     FROM=$1
11 fi
12 if [ -z "$REPORT_DEST" ]; then
13     REPORT_DEST=sxemacs-builds@sxemacs.org
14 fi
15 type sendmail >/dev/null 2>&1 && SENDMAIL=sendmail
16 type tla >/dev/null 2>&1 && TLA=tla
17 type egrep >/dev/null 2>&1 && GREP=egrep
18 type tail >/dev/null 2>&1 && TAIL=tail
19 type tar >/dev/null 2>&1 && TAR=tar
20 type cat >/dev/null 2>&1 && CAT=cat
21 type base64 >/dev/null 2>&1 && BASE64=base64
22 type sed >/dev/null 2>&1 && SED=sed
23 EXT=gz
24 type gzip >/dev/null 2>&1 && COMPRESS=gzip
25 if [ -z "$COMPRESS" ]; then
26     type compress >/dev/null 2>&1 && COMPRESS=compress
27     EXT=Z
28 fi
29 FILTER=cat
30 ENCODING=base64
31 attachment="build-failure-$FROM.tar.${EXT}"
32 if [ -z "${BASE64}" ]; then
33     type uuencode >/dev/null 2>&1 && BASE64=uuencode
34     if [ -n "${BASE64}" ]; then
35         if [ -z "${SED}" ]; then
36             echo "sed was not found and is required when base64 is replaced by uuencode"
37             exit 1
38         fi
39         # Test if this uuencode can actually base64 encode like
40         # in BSD's and MacOS
41         FILTER="${SED} -e s/^begin.*644.*\$// -e s/^end\$// -e s/^====\$// -e /^\$/d "
42         if [ -n "$(echo test | ${BASE64} -m test 2>/dev/null )" ]; then
43             BASE64="${BASE64} -m ${attachment}"
44         else
45             ENCODING=uuencode
46             BASE64="${BASE64} ${attachment}"
47         fi
48     fi
49 fi
50 if [ -n "$2" ]; then
51     REPORT_DEST=$2
52 fi
53 if [ -z "${SENDMAIL}" ]; then
54     if [ -x /usr/lib/sendmail ]; then
55         SENDMAIL=/usr/lib/sendmail
56     elif [ -x /usr/sbin/sendmail ]; then
57         SENDMAIL=/usr/sbin/sendmail
58     elif [ -x /sw/sbin/sendmail ]; then
59         SENDMAIL=/sw/sbin/sendmail
60     else
61         echo "Cannot find sendmail."
62         exit 1
63     fi
64 fi
65 if [ -z "${TLA}" ]; then
66     echo "Cannot find tla."
67     exit 1
68 fi
69 if [ -z "${BASE64}" -o -z "${TAR}" -o -z "${SENDMAIL}" -o -z "${GREP}" -o -z "${CAT}" -o -z "${COMPRESS}" ]; then
70     echo "Could not find one or more of grep (${GREP}), sendmail (${SENDMAIL}),"
71     echo "\t tar (${TAR}), base64 (${BASE64}), cat (${CAT})"
72     exit 1
73 fi
74 if [ ! -f ./config.log -o -z "$(${GREP} -i sxemacs ./config.log)" ]; then
75     echo "Please run this script from the top of the sxemacs build directory.\n"
76     exit 1
77 fi
78 VERSION=$(${GREP} "^#define SXEMACS_ARCH_VERSION" ./config.log | awk '{ print $3 }')
79 if [ -z "$VERSION" ]; then
80     VERSION="Unknown. Possible early configure failure"
81 else
82     attachment="build-failure-$VERSION-$FROM.tar.${EXT}"
83 fi
84 MAIN_VERSION=$(${GREP} "^#define SXEMACS_MAIN_ARCH_VERSION" ./config.log | awk '{ print $3 }')
85 SYNC=""
86 if [ -n "$MAIN_VERSION" -a "$MAIN_VERSION" != "$VERSION" ]; then
87     SYNC="(Last sync with main branch: $MAIN_VERSION)"
88 fi
89 CONFGUESS=$(${GREP} "^host=" ./config.log | awk -F= '{ print $2 }' )
90 if [ -z "$CONFGUESS" ]; then
91     CONFGUESS="Unknown. Possible early configure failure"
92 fi
93 SRCDIR=$(${GREP} "^sxe_srcdir=" ./config.log | awk -F= '{ print $2 }' | sed -e "s/^'//" -e "s/'$//" )
94 BLDDIR=$(${GREP} "^sxe_blddir=" ./config.log | awk -F= '{ print $2 }' | sed -e "s/^'//" -e "s/'$//" )
95 COMPILER=$(${GREP} "^CC=" ./config.log | awk -F= '{ print $2 }' )
96 CONFIG_OPTS=$(${GREP} "^#define EMACS_CONFIG_OPTIONS " ./config.log | sed -e 's/^#define EMACS_CONFIG_OPTIONS //g')
97 if [ -z "$MACHTYPE"  ]; then
98     MACHTYPE=$(uname -a)
99 fi
100 for f in config.log Installation sxemacs_version.m4 ,,beta.out ,,vars.out ,,make-check.out src/config.h ; do
101     if [ -f $f ]; then
102         FILES="$FILES $f"
103     fi
104 done
105 STATUS=$3
106 if [ -z "${STATUS}" ]; then
107     STATUS="BUILD FAILURE"
108 fi
109 SUBJECT="[${STATUS}] Version $VERSION on $CONFGUESS [$MACHTYPE] [@$(pwd)]"
110 MIME="application/x-gzip"
111 boundary="--sxemacs--failure--$$--"
112 KEEP=( \
113     [0]="^(cd|n?make)[:blank:]" \
114     [1]="errors?" \
115     [2]="warnings?" \
116     [3]="pure.*(space|size)" \
117     [4]="hides\>" \
118     [5]="strange" \
119     [6]="shadowings" \
120     [7]="^Compil(ing[:blank:]+in|ation)" \
121     [8]="^Using" \
122     [9]="not[:blank:]+found" \
123     [10]="^While[:blank:]+compiling.*(\n[:blank:]+.+)*" \
124     [11]="^Note:" \
125     [12]="Installing" \
126     [13]="[Ff]ile(s) copied" \
127     [14]="^[A-Za-z_]+=" \
128     [15]="[:blank:]+tests[:blank:]+" \
129     [16]="^(real|user|sys)[:blank:]+[0-9]+m" \
130     )
131 REMOVE=( \
132     [0]="confl.*with.*auto-inlining" \
133     [1]="^Formatting:" \
134     [2]="\(100%\) tests successful" \
135     [3]="errors that should" \
136     [4]="wrong-error" \
137     )
138 KREGEXP=""
139 for r in ${KEEP[*]}; do
140     if [ -z "$KREGEXP" ]; then
141         KREGEXP="$r"
142     else
143         KREGEXP="${KREGEXP}|${r}"
144     fi
145 done
146 RREGEXP=""
147 for r in ${REMOVE[*]}; do
148     if [ -z "$RREGEXP" ]; then
149         RREGEXP="$r"
150     else
151         RREGEXP="${RREGEXP}|${r}"
152     fi
153 done
154 (cat <<EOF
155 From: $FROM
156 To: $REPORT_DEST
157 Subject: $SUBJECT
158 Date: $(date +"%a, %e %Y %T %z")
159 Mime-Version: 1.0
160 Content-Type: multipart/mixed; boundary="$boundary"
161 Content-Disposition: inline
162
163 --$boundary
164 Content-Type: text/plain; charset=us-ascii
165 Content-Disposition: inline
166
167 $STATUS while building $VERSION on $CONFGUESS ($MACHTYPE)
168
169 EOF
170 MSRCDIR="${SRCDIR}"
171 if [ -z "${MSRCDIR}" ]; then
172     MSRCDIR="."
173 fi
174 if [ -n "${MSRCDIR}" -a -d "${MSRCDIR}/{arch}" -a -n "${TLA}"  -a -n "${GREP}"  -a -n "${TAIL}"  ]; then
175     CURDIR=$(pwd)
176     cd "${MSRCDIR}"
177     TREE="$(${TLA} tree-version)"
178     PATCH="$(${TLA} revisions | ${TAIL} -1)"
179     echo "Tree : ${TREE}" 
180     echo "Patch: ${PATCH}" 
181     echo ""
182     LAST_MAIN="$(${TLA} log-versions | ${GREP} -- '--main--' | ${TAIL} -1)"
183     LAST_MAIN_PATCH="$(${TLA} revisions $LAST_MAIN | ${TAIL} -1)"
184     if [ "${TREE}" != "${LAST_MAIN}" -o "${PATCH}" != "${LAST_MAIN_PATCH}" ]; then
185         echo "Main : $LAST_MAIN" 
186         echo "Patch: $LAST_MAIN_PATCH" 
187         echo ""
188     fi
189     DIFF_NAME=/tmp/tla-changes-${USER}-$$-${attachment}.log
190     ${TLA} changes -q --diffs > $DIFF_NAME
191     if [ -s $DIFF_NAME ]; then
192         echo "Changes:"
193         echo ""
194         cat $DIFF_NAME
195         echo ""
196         echo "End of Changes"
197     fi
198     /bin/rm $DIFF_NAME
199     cd "${CURDIR}"
200 else
201     echo $SYNC
202 fi
203
204 echo ""
205 if [ -n "${SRCDIR}" ]; then
206     echo " Source in ${SRCDIR}"
207 fi
208 if [ -n "${BLDDIR}" -a "${SRCDIR}" != "${BLDDIR}" ]; then 
209     echo " Build  in ${BLDDIR}"
210 fi
211
212 if [ -f ./Installation ]; then
213     echo ""
214     ${CAT} ./Installation
215 else
216     if [ -n "${COMPILER}" ]; then
217         echo " Using compiler ${COMPILER}"
218     fi
219     if [ -n "${CONFIG_OPTS}" ]; then
220         echo " Configured with options: ${CONFIG_OPTS}"
221     fi
222     echo ""
223 fi
224
225 for f in beta make-all make-check-temacs make-check make-install; do
226     if [ -f "./,,${f}.out" ]; then
227         echo "> Contents of $(pwd)/,,${f}.out"
228         echo ""
229         ${GREP} "$KREGEXP" ./,,${f}.out | ${GREP} -v "$RREGEXP" 
230     fi
231 done
232
233
234 FIND_NAME=/tmp/find-ldd-${USER}-$$-${attachment}.log
235 find src -type f -a -perm +111  -a -name \*emacs\* -exec file {} \; -exec ldd {} \; > $FIND_NAME 2>&1
236 if [ -s $FIND_NAME ]; then
237     echo " Shared library dependencies "
238     echo ""
239     cat $FIND_NAME
240     echo ""
241     echo ""
242 fi
243 /bin/rm $FIND_NAME
244
245 ${CAT} <<EOF
246
247 --$boundary
248 Content-Type: $MIME;name="$attachment"
249 Content-Disposition: attachment;filename="$attachment"
250 Content-Transfer-Encoding: $ENCODING
251
252 EOF
253 ${TAR} cf - $FILES | ${COMPRESS} -c - | ${BASE64} | ${FILTER}
254 echo ""
255 echo "--$boundary--" ) | $SENDMAIL -t