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