Fix typo in comment.
[python.git] / Misc / build.sh
bloba5a7d49eaf1dd899a668652b4a647ba13224c1e5
1 #!/bin/sh
3 ## Script to build and test the latest python from svn. It basically
4 ## does this:
5 ## svn up ; ./configure ; make ; make test ; make install ; cd Doc ; make
6 ##
7 ## Logs are kept and rsync'ed to the webhost. If there are test failure(s),
8 ## information about the failure(s) is mailed.
9 ##
10 ## The user must be a member of the webmaster group locally and on webhost.
12 ## This script is run on the PSF's machine as user neal via crontab.
14 ## Yes, this script would probably be easier in python, but then
15 ## there's a bootstrap problem. What if Python doesn't build?
17 ## This script should be fairly clean Bourne shell, ie not too many
18 ## bash-isms. We should try to keep it portable to other Unixes.
19 ## Even though it will probably only run on Linux. I'm sure there are
20 ## several GNU-isms currently (date +%s and readlink).
22 ## Perhaps this script should be broken up into 2 (or more) components.
23 ## Building doc is orthogonal to the rest of the python build/test.
26 ## FIXME: we should detect test hangs (eg, if they take more than 45 minutes)
28 ## FIXME: we should run valgrind
29 ## FIXME: we should run code coverage
31 ## Utilities invoked in this script include:
32 ## basename, date, dirname, expr, grep, readlink, uname
33 ## cksum, make, mutt, rsync, svn
35 ## remember where did we started from
36 DIR=`dirname $0`
37 if [ "$DIR" = "" ]; then
38 DIR="."
41 ## make directory absolute
42 DIR=`readlink -f $DIR`
43 FULLPATHNAME="$DIR/`basename $0`"
44 ## we want Misc/..
45 DIR=`dirname $DIR`
47 ## Configurable options
49 FAILURE_SUBJECT="Python Regression Test Failures"
50 #FAILURE_MAILTO="YOUR_ACCOUNT@gmail.com"
51 FAILURE_MAILTO="python-checkins@python.org"
52 #FAILURE_CC="optional--uncomment and set to desired address"
54 REMOTE_SYSTEM="neal@dinsdale.python.org"
55 REMOTE_DIR="/data/ftp.python.org/pub/docs.python.org/dev/"
56 RESULT_FILE="$DIR/build/index.html"
57 INSTALL_DIR="/tmp/python-test/local"
58 RSYNC_OPTS="-C -e ssh -rlogD"
60 # Always run the installed version of Python.
61 PYTHON=$INSTALL_DIR/bin/python
63 # Python options and regression test program that should always be run.
64 REGRTEST_ARGS="-E -tt $INSTALL_DIR/lib/python2.7/test/regrtest.py"
66 REFLOG="build/reflog.txt.out"
67 # These tests are not stable and falsely report leaks sometimes.
68 # The entire leak report will be mailed if any test not in this list leaks.
69 # Note: test_XXX (none currently) really leak, but are disabled
70 # so we don't send spam. Any test which really leaks should only
71 # be listed here if there are also test cases under Lib/test/leakers.
72 LEAKY_TESTS="test_(asynchat|cmd_line|docxmlrpc|dumbdbm|file|ftplib|httpservers|imaplib|popen2|socket|smtplib|sys|telnetlib|threadedtempfile|threading|threadsignals|xmlrpc)"
74 # Skip these tests altogether when looking for leaks. These tests
75 # do not need to be stored above in LEAKY_TESTS too.
76 # test_compiler almost never finishes with the same number of refs
77 # since it depends on other modules, skip it.
78 # test_logging causes hangs, skip it.
79 # KBK 21Apr09: test_httpservers causes hangs, skip for now.
80 LEAKY_SKIPS="-x test_compiler test_logging test_httpservers"
82 # Change this flag to "yes" for old releases to only update/build the docs.
83 BUILD_DISABLED="no"
85 ## utility functions
86 current_time() {
87 date +%s
90 update_status() {
91 now=`current_time`
92 time=`expr $now - $3`
93 echo "<li><a href=\"$2\">$1</a> <font size=\"-1\">($time seconds)</font></li>" >> $RESULT_FILE
96 place_summary_first() {
97 testf=$1
98 sed -n '/^[0-9][0-9]* tests OK\./,$p' < $testf \
99 | egrep -v '\[[0-9]+ refs\]' > $testf.tmp
100 echo "" >> $testf.tmp
101 cat $testf >> $testf.tmp
102 mv $testf.tmp $testf
105 count_failures () {
106 testf=$1
107 n=`grep -ic " failed:" $testf`
108 if [ $n -eq 1 ] ; then
109 n=`grep " failed:" $testf | sed -e 's/ .*//'`
111 echo $n
114 mail_on_failure() {
115 if [ "$NUM_FAILURES" != "0" ]; then
116 dest=$FAILURE_MAILTO
117 # FAILURE_CC is optional.
118 if [ "$FAILURE_CC" != "" ]; then
119 dest="$dest -c $FAILURE_CC"
121 if [ "x$3" != "x" ] ; then
122 (echo "More important issues:"
123 echo "----------------------"
124 egrep -v "$3" < $2
125 echo ""
126 echo "Less important issues:"
127 echo "----------------------"
128 egrep "$3" < $2)
129 else
130 cat $2
131 fi | mutt -s "$FAILURE_SUBJECT $1 ($NUM_FAILURES)" $dest
135 ## setup
136 cd $DIR
137 make clobber > /dev/null 2>&1
138 cp -p Modules/Setup.dist Modules/Setup
139 # But maybe there was no Makefile - we are only building docs. Clear build:
140 rm -rf build/
141 mkdir -p build
142 rm -rf $INSTALL_DIR
143 ## get the path we are building
144 repo_path=$(grep "url=" .svn/entries | sed -e s/\\W*url=// -e s/\"//g)
146 ## create results file
147 TITLE="Automated Python Build Results"
148 echo "<html>" >> $RESULT_FILE
149 echo " <head>" >> $RESULT_FILE
150 echo " <title>$TITLE</title>" >> $RESULT_FILE
151 echo " <meta http-equiv=\"refresh\" content=\"43200\">" >> $RESULT_FILE
152 echo " </head>" >> $RESULT_FILE
153 echo "<body>" >> $RESULT_FILE
154 echo "<h2>Automated Python Build Results</h2>" >> $RESULT_FILE
155 echo "<table>" >> $RESULT_FILE
156 echo " <tr>" >> $RESULT_FILE
157 echo " <td>Built on:</td><td>`date`</td>" >> $RESULT_FILE
158 echo " </tr><tr>" >> $RESULT_FILE
159 echo " <td>Hostname:</td><td>`uname -n`</td>" >> $RESULT_FILE
160 echo " </tr><tr>" >> $RESULT_FILE
161 echo " <td>Platform:</td><td>`uname -srmpo`</td>" >> $RESULT_FILE
162 echo " </tr><tr>" >> $RESULT_FILE
163 echo " <td>URL:</td><td>$repo_path</td>" >> $RESULT_FILE
164 echo " </tr>" >> $RESULT_FILE
165 echo "</table>" >> $RESULT_FILE
166 echo "<ul>" >> $RESULT_FILE
168 ## update, build, and test
169 ORIG_CHECKSUM=`cksum $FULLPATHNAME`
170 F=svn-update.out
171 start=`current_time`
172 svn update >& build/$F
173 err=$?
174 update_status "Updating" "$F" $start
175 if [ $err = 0 -a "$BUILD_DISABLED" != "yes" ]; then
176 ## FIXME: we should check if this file has changed.
177 ## If it has changed, we should re-run the script to pick up changes.
178 if [ "$ORIG_CHECKSUM" != "$ORIG_CHECKSUM" ]; then
179 exec $FULLPATHNAME $@
182 F=svn-stat.out
183 start=`current_time`
184 svn stat >& build/$F
185 ## ignore some of the diffs
186 NUM_DIFFS=`egrep -vc '^. (@test|db_home|Lib/test/(regrtest\.py|db_home))$' build/$F`
187 update_status "svn stat ($NUM_DIFFS possibly important diffs)" "$F" $start
189 F=configure.out
190 start=`current_time`
191 ./configure --prefix=$INSTALL_DIR --with-pydebug >& build/$F
192 err=$?
193 update_status "Configuring" "$F" $start
194 if [ $err = 0 ]; then
195 F=make.out
196 start=`current_time`
197 make >& build/$F
198 err=$?
199 warnings=`grep warning build/$F | egrep -vc "te?mpnam(_r|)' is dangerous,"`
200 update_status "Building ($warnings warnings)" "$F" $start
201 if [ $err = 0 ]; then
202 ## make install
203 F=make-install.out
204 start=`current_time`
205 make install >& build/$F
206 update_status "Installing" "$F" $start
208 if [ ! -x $PYTHON ]; then
209 ln -s ${PYTHON}2.* $PYTHON
212 ## make and run basic tests
213 F=make-test.out
214 start=`current_time`
215 $PYTHON $REGRTEST_ARGS -u urlfetch >& build/$F
216 NUM_FAILURES=`count_failures build/$F`
217 place_summary_first build/$F
218 update_status "Testing basics ($NUM_FAILURES failures)" "$F" $start
219 mail_on_failure "basics" build/$F
221 F=make-test-opt.out
222 start=`current_time`
223 $PYTHON -O $REGRTEST_ARGS -u urlfetch >& build/$F
224 NUM_FAILURES=`count_failures build/$F`
225 place_summary_first build/$F
226 update_status "Testing opt ($NUM_FAILURES failures)" "$F" $start
227 mail_on_failure "opt" build/$F
229 ## run the tests looking for leaks
230 F=make-test-refleak.out
231 start=`current_time`
232 ## ensure that the reflog exists so the grep doesn't fail
233 touch $REFLOG
234 $PYTHON $REGRTEST_ARGS -R 4:3:$REFLOG -u network $LEAKY_SKIPS >& build/$F
235 LEAK_PAT="($LEAKY_TESTS|sum=0)"
236 NUM_FAILURES=`egrep -vc "$LEAK_PAT" $REFLOG`
237 place_summary_first build/$F
238 update_status "Testing refleaks ($NUM_FAILURES failures)" "$F" $start
239 mail_on_failure "refleak" $REFLOG "$LEAK_PAT"
241 ## now try to run all the tests
242 F=make-testall.out
243 start=`current_time`
244 ## skip curses when running from cron since there's no terminal
245 ## skip sound since it's not setup on the PSF box (/dev/dsp)
246 $PYTHON $REGRTEST_ARGS -uall -x test_curses test_linuxaudiodev test_ossaudiodev >& build/$F
247 NUM_FAILURES=`count_failures build/$F`
248 place_summary_first build/$F
249 update_status "Testing all except curses and sound ($NUM_FAILURES failures)" "$F" $start
250 mail_on_failure "all" build/$F
256 ## make doc
257 cd $DIR/Doc
258 F="make-doc.out"
259 start=`current_time`
260 make clean > ../build/$F 2>&1
261 make checkout html >> ../build/$F 2>&1
262 err=$?
263 update_status "Making doc" "$F" $start
264 if [ $err != 0 ]; then
265 NUM_FAILURES=1
266 mail_on_failure "doc" ../build/$F
269 echo "</ul>" >> $RESULT_FILE
270 echo "</body>" >> $RESULT_FILE
271 echo "</html>" >> $RESULT_FILE
273 ## copy results
274 chgrp -R webmaster build/html
275 chmod -R g+w build/html
276 rsync $RSYNC_OPTS build/html/* $REMOTE_SYSTEM:$REMOTE_DIR
277 cd ../build
278 rsync $RSYNC_OPTS index.html *.out $REMOTE_SYSTEM:$REMOTE_DIR/results/