911ebfa18f1b824752eb9fbf6201bcbd4ecbe19e
[strace-test.git] / strace-build-test
1 #!/bin/bash
2
3 POINT=HEAD
4 ARCH=$(dpkg-architecture -q DEB_BUILD_ARCH)
5 HOSTNAME=$(hostname)
6 PKG_TEST="https://www.einval.com/debian/strace/package-test"
7
8 while getopts ":p:a:" opt; do
9   case $opt in
10     p)
11       POINT=$OPTARG
12       ;;
13     a)
14       ARCH=$OPTARG
15       set +e
16       chk=`dpkg-architecture -a$ARCH > /dev/null 2>&1 ; echo $?`
17       set -e
18       if [ $chk != 0 ]; then
19           echo "Did not recognise ${ARCH} as a Debian architecture name. Exit."
20           exit 1
21       fi
22       ARCH=${ARCH}
23       ;;
24     \?)
25       echo "Invalid option: -$OPTARG" >&2
26       ;;
27   esac
28 done
29
30 PATH=/usr/local/sbin:/usr/local/bin:$PATH
31 export PATH
32
33 NUMCPUS=$(grep processor /proc/cpuinfo | wc -l)
34 if [ $NUMCPUS -gt 1 ]; then
35     PARALLEL="-j $NUMCPUS"
36 else
37     PARALLEL=""
38 fi
39
40 set -e
41 set -x
42
43 mysid=sid-93sam-strace-$RANDOM
44
45 cleanup () {
46     schroot -e -c $mysid
47 }
48
49 trap cleanup 0
50
51 BASE_CHROOT="sid_$ARCH-dchroot"
52
53 schroot -e -c $mysid || true
54 schroot -b -c $BASE_CHROOT -n $mysid
55 dd-schroot-cmd -y -c $mysid apt-get update
56 dd-schroot-cmd -y -c $mysid apt-get build-dep strace
57 dd-schroot-cmd -y -c $mysid apt-get install git autotools-dev gawk dh-autoreconf wget
58 dd-schroot-cmd -y -c $mysid apt-get install gcc-multilib || true
59
60 DATETIME=$(date -u '+%Y-%m-%d-%H%M%S')
61 BDIR=~/build/strace/build-test-${DATETIME}
62
63 mkdir -p ${BDIR}
64 cd ${BDIR}
65
66 cat > ~/build/strace/inside-schroot-test.sh << EOF
67 #!/bin/sh
68 cd ${BDIR}
69 git clone -q http://git.code.sf.net/p/strace/code strace.git
70 echo "BUILD ENVIRONMENT INFORMATION"
71 echo "============================="
72 echo "Debian architecture"
73 echo "-------------------"
74 dpkg-architecture -q DEB_BUILD_ARCH
75 echo "Hostname"
76 echo "--------"
77 hostname
78 echo "uname -rm"
79 echo "---------"
80 uname -rm
81 echo "Version of kernel headers (linux-libc-dev)"
82 echo "------------------------------------------"
83 dpkg -s linux-libc-dev
84 echo "Version of libc"
85 echo "---------------"
86 dpkg -s libc6-dev
87 echo "Version of gcc"
88 echo "--------------"
89 dpkg -s gcc
90 cd strace.git
91 git checkout $POINT
92 git log | head -1
93 ./bootstrap
94 ./configure
95 make $PARALLEL && make check VERBOSE=1 && echo SUCCESS > ${BDIR}/RESULT
96 EOF
97
98 chmod +x ~/build/strace/inside-schroot-test.sh
99
100 cd ~
101
102 # Run the command, outout to typescript
103 script -c "schroot -r -c $mysid ~/build/strace/inside-schroot-test.sh"
104
105 if [ ! -f ${BDIR}/RESULT ] ; then
106     echo "BUILD FAILED - not doing cleanup"
107     echo "Results in ${BDIR}"
108 fi
109
110 rm -rf ${BDIR}
111 rm -f ~/build/strace/inside-schroot-test.sh
112 mv typescript typescript-$ARCH-$HOSTNAME-${DATETIME}.txt
113 gzip -9 typescript-$ARCH-$HOSTNAME-${DATETIME}.txt
114 FILE="typescript-$ARCH-$HOSTNAME-${DATETIME}.txt.gz"
115 (echo "START $FILE" ; \
116  base64 < $FILE ; \
117  echo "END $FILE") | \
118     mailx -s "strace-build-test $ARCH-$HOSTNAME-${DATETIME} log" \
119           steve-strace@einval.com
120 rm -f $FILE
121
122 # Check to see if we have a package build to test too, run it in a
123 # separate log file but using the same chroot for speed
124 rm -rf ~/build/strace/package-test
125 set +e
126 WGET_OPTS="--ca-certificate=/home/93sam/.CA/ca-certificates.crt"
127 wget $WGET_OPTS -O /dev/null $PKG_TEST/MANIFEST
128 if [ $? -eq 0 ]; then
129     # Time to grab sources
130     mkdir ~/build/strace/package-test
131     cd ~/build/strace/package-test
132     wget $WGET_OPTS $PKG_TEST/MANIFEST
133     for file in $(cat MANIFEST); do
134         wget $PKG_TEST/$file
135     done
136     DSC=$(ls *.dsc)
137
138     cat > ~/build/strace/inside-schroot-test.sh << EOF
139 #!/bin/sh
140 cd ~/build/strace/package-test
141 dpkg-source -x *.dsc
142 cd strace-*
143 debuild
144 EOF
145     chmod +x ~/build/strace/inside-schroot-test.sh
146     set -e
147     cd ~
148     # Run the command, outout to typescript
149     script -c "schroot -r -c $mysid ~/build/strace/inside-schroot-test.sh"
150
151     rm -rf ~/build/strace/package-test
152     rm -f ~/build/strace/inside-schroot-test.sh
153     gzip -9 typescript
154     FILE=typescript.gz
155     (echo "START $FILE" ; \
156      base64 < $FILE ; \
157      echo "END $FILE") | \
158         mailx -s "$DSC package build log: $ARCH on $HOSTNAME " \
159               steve@einval.com
160     rm -f $FILE
161 fi