script/autobuild.py: remove explicit --with-perl-*-install-dir options
[sfrench/samba-autobuild/.git] / script / autobuild.py
1 #!/usr/bin/env python
2 # run tests on all Samba subprojects and push to a git tree on success
3 # Copyright Andrew Tridgell 2010
4 # released under GNU GPL v3 or later
5
6 from subprocess import call, check_call,Popen, PIPE
7 import os, tarfile, sys, time
8 from optparse import OptionParser
9 import smtplib
10 from email.mime.text import MIMEText
11 from distutils.sysconfig import get_python_lib
12
13 # This speeds up testing remarkably.
14 os.environ['TDB_NO_FSYNC'] = '1'
15
16 cleanup_list = []
17
18 builddirs = {
19     "ctdb"    : "ctdb",
20     "samba"  : ".",
21     "samba-ctdb" : ".",
22     "samba-libs"  : ".",
23     "ldb"     : "lib/ldb",
24     "tdb"     : "lib/tdb",
25     "ntdb"    : "lib/ntdb",
26     "talloc"  : "lib/talloc",
27     "replace" : "lib/replace",
28     "tevent"  : "lib/tevent",
29     "pidl"    : "pidl",
30     "pass"    : ".",
31     "fail"    : ".",
32     "retry"   : "."
33     }
34
35 defaulttasks = [ "ctdb", "samba", "samba-ctdb", "samba-libs", "ldb", "tdb", "ntdb", "talloc", "replace", "tevent", "pidl" ]
36
37 tasks = {
38     "ctdb" : [ ("random-sleep", "../script/random-sleep.sh 60 600", "text/plain"),
39                ("configure", "./configure ${PREFIX}", "text/plain"),
40                ("make", "make all", "text/plain"),
41                ("install", "make install", "text/plain"),
42                ("test", "make autotest", "text/plain"),
43                ("check-clean-tree", "../script/clean-source-tree.sh", "text/plain"),
44                ("clean", "make clean", "text/plain") ],
45
46     # We have 'test' before 'install' because, 'test' should work without 'install'
47     "samba" : [ ("configure", "./configure.developer ${PREFIX} --with-selftest-prefix=./bin/ab", "text/plain"),
48                 ("make", "make -j", "text/plain"),
49                 ("test", "make test FAIL_IMMEDIATELY=1", "text/plain"),
50                 ("install", "make install", "text/plain"),
51                 ("check-clean-tree", "script/clean-source-tree.sh", "text/plain"),
52                 ("clean", "make clean", "text/plain") ],
53
54     "samba-ctdb" : [ ("random-sleep", "script/random-sleep.sh 60 600", "text/plain"),
55
56                      # make sure we have tdb around:
57                      ("tdb-configure", "cd lib/tdb && PYTHONPATH=${PYTHON_PREFIX}/site-packages:$PYTHONPATH PKG_CONFIG_PATH=$PKG_CONFIG_PATH:${PREFIX_DIR}/lib/pkgconfig ./configure --bundled-libraries=NONE --abi-check --enable-debug -C ${PREFIX}", "text/plain"),
58                      ("tdb-make", "cd lib/tdb && make", "text/plain"),
59                      ("tdb-install", "cd lib/tdb && make install", "text/plain"),
60
61                      # build and install ctdb:
62                      ("ctdb-configure", "cd ./ctdb && PKG_CONFIG_PATH=${PREFIX_DIR}/lib/pkgconfig:${PKG_CONFIG_PATH} ./configure ${PREFIX} --bundled-libraries=!tdb", "text/plain"),
63                      ("ctdb-make", "cd ./ctdb && make all", "text/plain"),
64                      ("ctdb-install", "cd ./ctdb && make install", "text/plain"),
65                      ("ctdb-header-ls", "ls ${PREFIX_DIR}/include/ctdb.h", "text/plain"),
66
67                      # build samba with cluster support against this ctdb:
68                      ("samba-configure", "PYTHONPATH=${PYTHON_PREFIX}/site-packages:$PYTHONPATH PKG_CONFIG_PATH=${PREFIX_DIR}/lib/pkgconfig:${PKG_CONFIG_PATH} ./configure.developer ${PREFIX} --with-selftest-prefix=./bin/ab --with-cluster-support --with-ctdb-dir=${PREFIX_DIR} --bundled-libraries=!tdb", "text/plain"),
69                      ("samba-make", "make", "text/plain"),
70                      ("samba-check", "./bin/smbd -b | grep CLUSTER_SUPPORT", "text/plain"),
71                      ("samba-install", "make install", "text/plain"),
72
73                      # clean up:
74                      ("check-clean-tree", "script/clean-source-tree.sh", "text/plain"),
75                      ("clean", "make clean", "text/plain"),
76                      ("ctdb-clean", "cd ./ctdb && make clean", "text/plain") ],
77
78     "samba-libs" : [
79                       ("random-sleep", "script/random-sleep.sh 60 600", "text/plain"),
80                       ("talloc-configure", "cd lib/talloc && PYTHONPATH=${PYTHON_PREFIX}/site-packages:$PYTHONPATH PKG_CONFIG_PATH=$PKG_CONFIG_PATH:${PREFIX_DIR}/lib/pkgconfig ./configure --bundled-libraries=NONE --abi-check --enable-debug -C ${PREFIX}", "text/plain"),
81                       ("talloc-make", "cd lib/talloc && make", "text/plain"),
82                       ("talloc-install", "cd lib/talloc && make install", "text/plain"),
83
84                       ("tdb-configure", "cd lib/tdb && PYTHONPATH=${PYTHON_PREFIX}/site-packages:$PYTHONPATH PKG_CONFIG_PATH=$PKG_CONFIG_PATH:${PREFIX_DIR}/lib/pkgconfig ./configure --bundled-libraries=NONE --abi-check --enable-debug -C ${PREFIX}", "text/plain"),
85                       ("tdb-make", "cd lib/tdb && make", "text/plain"),
86                       ("tdb-install", "cd lib/tdb && make install", "text/plain"),
87
88                       ("ntdb-configure", "cd lib/ntdb && PYTHONPATH=${PYTHON_PREFIX}/site-packages:$PYTHONPATH PKG_CONFIG_PATH=$PKG_CONFIG_PATH:${PREFIX_DIR}/lib/pkgconfig ./configure --bundled-libraries=NONE --abi-check --enable-debug -C ${PREFIX}", "text/plain"),
89                       ("ntdb-make", "cd lib/ntdb && make", "text/plain"),
90                       ("ntdb-install", "cd lib/ntdb && make install", "text/plain"),
91
92                       ("tevent-configure", "cd lib/tevent && PYTHONPATH=${PYTHON_PREFIX}/site-packages:$PYTHONPATH PKG_CONFIG_PATH=$PKG_CONFIG_PATH:${PREFIX_DIR}/lib/pkgconfig ./configure --bundled-libraries=NONE --abi-check --enable-debug -C ${PREFIX}", "text/plain"),
93                       ("tevent-make", "cd lib/tevent && make", "text/plain"),
94                       ("tevent-install", "cd lib/tevent && make install", "text/plain"),
95
96                       ("ldb-configure", "cd lib/ldb && PYTHONPATH=${PYTHON_PREFIX}/site-packages:$PYTHONPATH PKG_CONFIG_PATH=$PKG_CONFIG_PATH:${PREFIX_DIR}/lib/pkgconfig ./configure --bundled-libraries=NONE --abi-check --enable-debug -C ${PREFIX}", "text/plain"),
97                       ("ldb-make", "cd lib/ldb && make", "text/plain"),
98                       ("ldb-install", "cd lib/ldb && make install", "text/plain"),
99
100                       ("configure", "PYTHONPATH=${PYTHON_PREFIX}/site-packages:$PYTHONPATH PKG_CONFIG_PATH=$PKG_CONFIG_PATH:${PREFIX_DIR}/lib/pkgconfig ./configure --bundled-libraries=!talloc,!tdb,!pytdb,!ntdb,!pyntdb,!ldb,!pyldb,!tevent,!pytevent --abi-check --enable-debug -C ${PREFIX}", "text/plain"),
101                       ("make", "make", "text/plain"),
102                       ("install", "make install", "text/plain"),
103                       ("dist", "make dist", "text/plain")],
104
105     "ldb" : [
106               ("random-sleep", "../../script/random-sleep.sh 60 600", "text/plain"),
107               ("configure", "./configure --enable-developer -C ${PREFIX}", "text/plain"),
108               ("make", "make", "text/plain"),
109               ("install", "make install", "text/plain"),
110               ("test", "make test", "text/plain"),
111               ("check-clean-tree", "../../script/clean-source-tree.sh", "text/plain"),
112               ("distcheck", "make distcheck", "text/plain"),
113               ("clean", "make clean", "text/plain") ],
114
115     "tdb" : [
116               ("random-sleep", "../../script/random-sleep.sh 60 600", "text/plain"),
117               ("configure", "./configure --enable-developer -C ${PREFIX}", "text/plain"),
118               ("make", "make", "text/plain"),
119               ("install", "make install", "text/plain"),
120               ("test", "make test", "text/plain"),
121               ("check-clean-tree", "../../script/clean-source-tree.sh", "text/plain"),
122               ("distcheck", "make distcheck", "text/plain"),
123               ("clean", "make clean", "text/plain") ],
124
125     "ntdb" : [
126                ("random-sleep", "../../script/random-sleep.sh 60 600", "text/plain"),
127                ("configure", "./configure --enable-developer -C ${PREFIX}", "text/plain"),
128                ("make", "make", "text/plain"),
129                ("install", "make install", "text/plain"),
130                ("test", "make test", "text/plain"),
131                ("check-clean-tree", "../../script/clean-source-tree.sh", "text/plain"),
132                ("distcheck", "make distcheck", "text/plain"),
133                ("clean", "make clean", "text/plain") ],
134
135     "talloc" : [
136                  ("random-sleep", "../../script/random-sleep.sh 60 600", "text/plain"),
137                  ("configure", "./configure --enable-developer -C ${PREFIX}", "text/plain"),
138                  ("make", "make", "text/plain"),
139                  ("install", "make install", "text/plain"),
140                  ("test", "make test", "text/plain"),
141                  ("check-clean-tree", "../../script/clean-source-tree.sh", "text/plain"),
142                  ("distcheck", "make distcheck", "text/plain"),
143                  ("clean", "make clean", "text/plain") ],
144
145     "replace" : [
146                   ("random-sleep", "../../script/random-sleep.sh 60 600", "text/plain"),
147                   ("configure", "./configure --enable-developer -C ${PREFIX}", "text/plain"),
148                   ("make", "make", "text/plain"),
149                   ("install", "make install", "text/plain"),
150                   ("test", "make test", "text/plain"),
151                   ("check-clean-tree", "../../script/clean-source-tree.sh", "text/plain"),
152                   ("distcheck", "make distcheck", "text/plain"),
153                   ("clean", "make clean", "text/plain") ],
154
155     "tevent" : [
156                  ("random-sleep", "../../script/random-sleep.sh 60 600", "text/plain"),
157                  ("configure", "./configure --enable-developer -C ${PREFIX}", "text/plain"),
158                  ("make", "make", "text/plain"),
159                  ("install", "make install", "text/plain"),
160                  ("test", "make test", "text/plain"),
161                  ("check-clean-tree", "../../script/clean-source-tree.sh", "text/plain"),
162                  ("distcheck", "make distcheck", "text/plain"),
163                  ("clean", "make clean", "text/plain") ],
164
165     "pidl" : [
166                ("random-sleep", "../script/random-sleep.sh 60 600", "text/plain"),
167                ("configure", "perl Makefile.PL PREFIX=${PREFIX_DIR}", "text/plain"),
168                ("touch", "touch *.yp", "text/plain"),
169                ("make", "make", "text/plain"),
170                ("test", "make test", "text/plain"),
171                ("install", "make install", "text/plain"),
172                ("check-clean-tree", "../script/clean-source-tree.sh", "text/plain"),
173                ("clean", "make clean", "text/plain") ],
174
175     # these are useful for debugging autobuild
176     'pass' : [ ("pass", 'echo passing && /bin/true', "text/plain") ],
177     'fail' : [ ("fail", 'echo failing && /bin/false', "text/plain") ]
178 }
179
180 def run_cmd(cmd, dir=".", show=None, output=False, checkfail=True):
181     if show is None:
182         show = options.verbose
183     if show:
184         print("Running: '%s' in '%s'" % (cmd, dir))
185     if output:
186         return Popen([cmd], shell=True, stdout=PIPE, cwd=dir).communicate()[0]
187     elif checkfail:
188         return check_call(cmd, shell=True, cwd=dir)
189     else:
190         return call(cmd, shell=True, cwd=dir)
191
192
193 class builder(object):
194     '''handle build of one directory'''
195
196     def __init__(self, name, sequence):
197         self.name = name
198         self.dir = builddirs[name]
199
200         self.tag = self.name.replace('/', '_')
201         self.sequence = sequence
202         self.next = 0
203         self.stdout_path = "%s/%s.stdout" % (gitroot, self.tag)
204         self.stderr_path = "%s/%s.stderr" % (gitroot, self.tag)
205         if options.verbose:
206             print("stdout for %s in %s" % (self.name, self.stdout_path))
207             print("stderr for %s in %s" % (self.name, self.stderr_path))
208         run_cmd("rm -f %s %s" % (self.stdout_path, self.stderr_path))
209         self.stdout = open(self.stdout_path, 'w')
210         self.stderr = open(self.stderr_path, 'w')
211         self.stdin  = open("/dev/null", 'r')
212         self.sdir = "%s/%s" % (testbase, self.tag)
213         self.prefix = "%s/prefix/%s" % (testbase, self.tag)
214         run_cmd("rm -rf %s" % self.sdir)
215         cleanup_list.append(self.sdir)
216         cleanup_list.append(self.prefix)
217         os.makedirs(self.sdir)
218         run_cmd("rm -rf %s" % self.sdir)
219         run_cmd("git clone --shared %s %s" % (test_master, self.sdir), dir=test_master, show=True)
220         self.start_next()
221
222     def start_next(self):
223         if self.next == len(self.sequence):
224             print '%s: Completed OK' % self.name
225             self.done = True
226             return
227         (self.stage, self.cmd, self.output_mime_type) = self.sequence[self.next]
228         self.cmd = self.cmd.replace("${PYTHON_PREFIX}", get_python_lib(standard_lib=1, prefix=self.prefix))
229         self.cmd = self.cmd.replace("${PREFIX}", "--prefix=%s" % self.prefix)
230         self.cmd = self.cmd.replace("${PREFIX_DIR}", "%s" % self.prefix)
231 #        if self.output_mime_type == "text/x-subunit":
232 #            self.cmd += " | %s --immediate" % (os.path.join(os.path.dirname(__file__), "selftest/format-subunit"))
233         print '%s: [%s] Running %s' % (self.name, self.stage, self.cmd)
234         cwd = os.getcwd()
235         os.chdir("%s/%s" % (self.sdir, self.dir))
236         self.proc = Popen(self.cmd, shell=True,
237                           stdout=self.stdout, stderr=self.stderr, stdin=self.stdin)
238         os.chdir(cwd)
239         self.next += 1
240
241
242 class buildlist(object):
243     '''handle build of multiple directories'''
244
245     def __init__(self, tasklist, tasknames, rebase_url, rebase_branch="master"):
246         global tasks
247         self.tlist = []
248         self.tail_proc = None
249         self.retry = None
250         if tasknames == []:
251             tasknames = defaulttasks
252         for n in tasknames:
253             b = builder(n, tasks[n])
254             self.tlist.append(b)
255         if options.retry:
256             rebase_remote = "rebaseon"
257             retry_task = [ ("retry",
258                             '''set -e
259                             git remote add -t %s %s %s
260                             git fetch %s
261                             while :; do
262                               sleep 60
263                               git describe %s/%s > old_remote_branch.desc
264                               git fetch %s
265                               git describe %s/%s > remote_branch.desc
266                               diff old_remote_branch.desc remote_branch.desc
267                             done
268                            ''' % (
269                                rebase_branch, rebase_remote, rebase_url,
270                                rebase_remote,
271                                rebase_remote, rebase_branch,
272                                rebase_remote,
273                                rebase_remote, rebase_branch
274                            ),
275                            "test/plain" ) ]
276
277             self.retry = builder('retry', retry_task)
278             self.need_retry = False
279
280     def kill_kids(self):
281         if self.tail_proc is not None:
282             self.tail_proc.terminate()
283             self.tail_proc.wait()
284             self.tail_proc = None
285         if self.retry is not None:
286             self.retry.proc.terminate()
287             self.retry.proc.wait()
288             self.retry = None
289         for b in self.tlist:
290             if b.proc is not None:
291                 run_cmd("killbysubdir %s > /dev/null 2>&1" % b.sdir, checkfail=False)
292                 b.proc.terminate()
293                 b.proc.wait()
294                 b.proc = None
295
296     def wait_one(self):
297         while True:
298             none_running = True
299             for b in self.tlist:
300                 if b.proc is None:
301                     continue
302                 none_running = False
303                 b.status = b.proc.poll()
304                 if b.status is None:
305                     continue
306                 b.proc = None
307                 return b
308             if options.retry:
309                 ret = self.retry.proc.poll()
310                 if ret is not None:
311                     self.need_retry = True
312                     self.retry = None
313                     return None
314             if none_running:
315                 return None
316             time.sleep(0.1)
317
318     def run(self):
319         while True:
320             b = self.wait_one()
321             if options.retry and self.need_retry:
322                 self.kill_kids()
323                 print("retry needed")
324                 return (0, None, None, None, "retry")
325             if b is None:
326                 break
327             if os.WIFSIGNALED(b.status) or os.WEXITSTATUS(b.status) != 0:
328                 self.kill_kids()
329                 return (b.status, b.name, b.stage, b.tag, "%s: [%s] failed '%s' with status %d" % (b.name, b.stage, b.cmd, b.status))
330             b.start_next()
331         self.kill_kids()
332         return (0, None, None, None, "All OK")
333
334     def tarlogs(self, fname):
335         tar = tarfile.open(fname, "w:gz")
336         for b in self.tlist:
337             tar.add(b.stdout_path, arcname="%s.stdout" % b.tag)
338             tar.add(b.stderr_path, arcname="%s.stderr" % b.tag)
339         if os.path.exists("autobuild.log"):
340             tar.add("autobuild.log")
341         tar.close()
342
343     def remove_logs(self):
344         for b in self.tlist:
345             os.unlink(b.stdout_path)
346             os.unlink(b.stderr_path)
347
348     def start_tail(self):
349         cwd = os.getcwd()
350         cmd = "tail -f *.stdout *.stderr"
351         os.chdir(gitroot)
352         self.tail_proc = Popen(cmd, shell=True)
353         os.chdir(cwd)
354
355
356 def cleanup():
357     if options.nocleanup:
358         return
359     print("Cleaning up ....")
360     for d in cleanup_list:
361         run_cmd("rm -rf %s" % d)
362
363
364 def find_git_root():
365     '''get to the top of the git repo'''
366     p=os.getcwd()
367     while p != '/':
368         if os.path.isdir(os.path.join(p, ".git")):
369             return p
370         p = os.path.abspath(os.path.join(p, '..'))
371     return None
372
373
374 def daemonize(logfile):
375     pid = os.fork()
376     if pid == 0: # Parent
377         os.setsid()
378         pid = os.fork()
379         if pid != 0: # Actual daemon
380             os._exit(0)
381     else: # Grandparent
382         os._exit(0)
383
384     import resource      # Resource usage information.
385     maxfd = resource.getrlimit(resource.RLIMIT_NOFILE)[1]
386     if maxfd == resource.RLIM_INFINITY:
387         maxfd = 1024 # Rough guess at maximum number of open file descriptors.
388     for fd in range(0, maxfd):
389         try:
390             os.close(fd)
391         except OSError:
392             pass
393     os.open(logfile, os.O_RDWR | os.O_CREAT)
394     os.dup2(0, 1)
395     os.dup2(0, 2)
396
397 def write_pidfile(fname):
398     '''write a pid file, cleanup on exit'''
399     f = open(fname, mode='w')
400     f.write("%u\n" % os.getpid())
401     f.close()
402
403
404 def rebase_tree(rebase_url, rebase_branch = "master"):
405     rebase_remote = "rebaseon"
406     print("Rebasing on %s" % rebase_url)
407     run_cmd("git describe HEAD", show=True, dir=test_master)
408     run_cmd("git remote add -t %s %s %s" %
409             (rebase_branch, rebase_remote, rebase_url),
410             show=True, dir=test_master)
411     run_cmd("git fetch %s" % rebase_remote, show=True, dir=test_master)
412     if options.fix_whitespace:
413         run_cmd("git rebase --force-rebase --whitespace=fix %s/%s" %
414                 (rebase_remote, rebase_branch),
415                 show=True, dir=test_master)
416     else:
417         run_cmd("git rebase --force-rebase %s/%s" %
418                 (rebase_remote, rebase_branch),
419                 show=True, dir=test_master)
420     diff = run_cmd("git --no-pager diff HEAD %s/%s" %
421                    (rebase_remote, rebase_branch),
422                    dir=test_master, output=True)
423     if diff == '':
424         print("No differences between HEAD and %s/%s - exiting" %
425               (rebase_remote, rebase_branch))
426         sys.exit(0)
427     run_cmd("git describe %s/%s" %
428             (rebase_remote, rebase_branch),
429             show=True, dir=test_master)
430     run_cmd("git describe HEAD", show=True, dir=test_master)
431     run_cmd("git --no-pager diff --stat HEAD %s/%s" %
432             (rebase_remote, rebase_branch),
433             show=True, dir=test_master)
434
435 def push_to(push_url, push_branch = "master"):
436     push_remote = "pushto"
437     print("Pushing to %s" % push_url)
438     if options.mark:
439         run_cmd("git config --replace-all core.editor script/commit_mark.sh", dir=test_master)
440         run_cmd("git commit --amend -c HEAD", dir=test_master)
441         # the notes method doesn't work yet, as metze hasn't allowed refs/notes/* in master
442         # run_cmd("EDITOR=script/commit_mark.sh git notes edit HEAD", dir=test_master)
443     run_cmd("git remote add -t %s %s %s" %
444             (push_branch, push_remote, push_url),
445             show=True, dir=test_master)
446     run_cmd("git push %s +HEAD:%s" %
447             (push_remote, push_branch),
448             show=True, dir=test_master)
449
450 def_testbase = os.getenv("AUTOBUILD_TESTBASE", "/memdisk/%s" % os.getenv('USER'))
451
452 gitroot = find_git_root()
453 if gitroot is None:
454     raise Exception("Failed to find git root")
455
456 parser = OptionParser()
457 parser.add_option("", "--tail", help="show output while running", default=False, action="store_true")
458 parser.add_option("", "--keeplogs", help="keep logs", default=False, action="store_true")
459 parser.add_option("", "--nocleanup", help="don't remove test tree", default=False, action="store_true")
460 parser.add_option("", "--testbase", help="base directory to run tests in (default %s)" % def_testbase,
461                   default=def_testbase)
462 parser.add_option("", "--passcmd", help="command to run on success", default=None)
463 parser.add_option("", "--verbose", help="show all commands as they are run",
464                   default=False, action="store_true")
465 parser.add_option("", "--rebase", help="rebase on the given tree before testing",
466                   default=None, type='str')
467 parser.add_option("", "--pushto", help="push to a git url on success",
468                   default=None, type='str')
469 parser.add_option("", "--mark", help="add a Tested-By signoff before pushing",
470                   default=False, action="store_true")
471 parser.add_option("", "--fix-whitespace", help="fix whitespace on rebase",
472                   default=False, action="store_true")
473 parser.add_option("", "--retry", help="automatically retry if master changes",
474                   default=False, action="store_true")
475 parser.add_option("", "--email", help="send email to the given address on failure",
476                   type='str', default=None)
477 parser.add_option("", "--always-email", help="always send email, even on success",
478                   action="store_true")
479 parser.add_option("", "--daemon", help="daemonize after initial setup",
480                   action="store_true")
481 parser.add_option("", "--branch", help="the branch to work on (default=master)",
482                   default="master", type='str')
483 parser.add_option("", "--log-base", help="location where the logs can be found (default=cwd)",
484                   default=gitroot, type='str')
485
486 def email_failure(status, failed_task, failed_stage, failed_tag, errstr, log_base=None):
487     '''send an email to options.email about the failure'''
488     user = os.getenv("USER")
489     if log_base is None:
490         log_base = gitroot
491     text = '''
492 Dear Developer,
493
494 Your autobuild failed when trying to test %s with the following error:
495    %s
496
497 the autobuild has been abandoned. Please fix the error and resubmit.
498
499 A summary of the autobuild process is here:
500
501   %s/autobuild.log
502 ''' % (failed_task, errstr, log_base)
503     
504     if failed_task != 'rebase':
505         text += '''
506 You can see logs of the failed task here:
507
508   %s/%s.stdout
509   %s/%s.stderr
510
511 or you can get full logs of all tasks in this job here:
512
513   %s/logs.tar.gz
514
515 The top commit for the tree that was built was:
516
517 %s
518
519 ''' % (log_base, failed_tag, log_base, failed_tag, log_base, top_commit_msg)
520     msg = MIMEText(text)
521     msg['Subject'] = 'autobuild failure for task %s during %s' % (failed_task, failed_stage)
522     msg['From'] = 'autobuild@samba.org'
523     msg['To'] = options.email
524
525     s = smtplib.SMTP()
526     s.connect()
527     s.sendmail(msg['From'], [msg['To']], msg.as_string())
528     s.quit()
529
530 def email_success(log_base=None):
531     '''send an email to options.email about a successful build'''
532     user = os.getenv("USER")
533     if log_base is None:
534         log_base = gitroot
535     text = '''
536 Dear Developer,
537
538 Your autobuild has succeeded.
539
540 '''
541
542     if options.keeplogs:
543         text += '''
544
545 you can get full logs of all tasks in this job here:
546
547   %s/logs.tar.gz
548
549 ''' % log_base
550
551     text += '''
552 The top commit for the tree that was built was:
553
554 %s
555 ''' % top_commit_msg
556
557     msg = MIMEText(text)
558     msg['Subject'] = 'autobuild success'
559     msg['From'] = 'autobuild@samba.org'
560     msg['To'] = options.email
561
562     s = smtplib.SMTP()
563     s.connect()
564     s.sendmail(msg['From'], [msg['To']], msg.as_string())
565     s.quit()
566
567
568 (options, args) = parser.parse_args()
569
570 if options.retry:
571     if options.rebase is None:
572         raise Exception('You can only use --retry if you also rebase')
573
574 testbase = "%s/b%u" % (options.testbase, os.getpid())
575 test_master = "%s/master" % testbase
576
577 # get the top commit message, for emails
578 top_commit_msg = run_cmd("git log -1", dir=gitroot, output=True)
579
580 try:
581     os.makedirs(testbase)
582 except Exception, reason:
583     raise Exception("Unable to create %s : %s" % (testbase, reason))
584 cleanup_list.append(testbase)
585
586 if options.daemon:
587     logfile = os.path.join(testbase, "log")
588     print "Forking into the background, writing progress to %s" % logfile
589     daemonize(logfile)
590
591 write_pidfile(gitroot + "/autobuild.pid")
592
593 while True:
594     try:
595         run_cmd("rm -rf %s" % test_master)
596         cleanup_list.append(test_master)
597         run_cmd("git clone --shared %s %s" % (gitroot, test_master), show=True, dir=gitroot)
598     except Exception:
599         cleanup()
600         raise
601
602     try:
603         try:
604             if options.rebase is not None:
605                 rebase_tree(options.rebase, rebase_branch=options.branch)
606         except Exception:
607             cleanup_list.append(gitroot + "/autobuild.pid")
608             cleanup()
609             email_failure(-1, 'rebase', 'rebase', 'rebase',
610                           'rebase on %s failed' % options.branch,
611                           log_base=options.log_base)
612             sys.exit(1)
613         blist = buildlist(tasks, args, options.rebase, rebase_branch=options.branch)
614         if options.tail:
615             blist.start_tail()
616         (status, failed_task, failed_stage, failed_tag, errstr) = blist.run()
617         if status != 0 or errstr != "retry":
618             break
619         cleanup()
620     except Exception:
621         cleanup()
622         raise
623
624 cleanup_list.append(gitroot + "/autobuild.pid")
625
626 blist.kill_kids()
627 if options.tail:
628     print("waiting for tail to flush")
629     time.sleep(1)
630
631 if status == 0:
632     print errstr
633     if options.passcmd is not None:
634         print("Running passcmd: %s" % options.passcmd)
635         run_cmd(options.passcmd, dir=test_master)
636     if options.pushto is not None:
637         push_to(options.pushto, push_branch=options.branch)
638     if options.keeplogs:
639         blist.tarlogs("logs.tar.gz")
640         print("Logs in logs.tar.gz")
641     if options.always_email:
642         email_success(log_base=options.log_base)
643     blist.remove_logs()
644     cleanup()
645     print(errstr)
646     sys.exit(0)
647
648 # something failed, gather a tar of the logs
649 blist.tarlogs("logs.tar.gz")
650
651 if options.email is not None:
652     email_failure(status, failed_task, failed_stage, failed_tag, errstr, log_base=options.log_base)
653
654 cleanup()
655 print(errstr)
656 print("Logs in logs.tar.gz")
657 sys.exit(status)