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