| OLD | NEW |
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 | 2 |
| 3 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 3 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. |
| 4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
| 5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
| 6 | 6 |
| 7 import errno | 7 import errno |
| 8 import optparse | 8 import optparse |
| 9 import os | 9 import os |
| 10 import shutil | 10 import shutil |
| 11 import subprocess | 11 import subprocess |
| 12 import sys | 12 import sys |
| 13 | 13 |
| 14 from cbuildbot_config import config | 14 from cbuildbot_config import config |
| 15 | 15 |
| 16 _DEFAULT_RETRIES=3 |
| 17 |
| 16 # Utility functions | 18 # Utility functions |
| 17 | 19 |
| 18 def RunCommand(cmd, error_ok=False, error_message=None, exit_code=False, | 20 def RunCommand(cmd, error_ok=False, error_message=None, exit_code=False, |
| 19 redirect_stdout=False, redirect_stderr=False, cwd=None, | 21 redirect_stdout=False, redirect_stderr=False, cwd=None, |
| 20 input=None): | 22 input=None): |
| 21 # Print out the command before running. | 23 # Print out the command before running. |
| 22 print >>sys.stderr, "CBUILDBOT -- RunCommand:", ' '.join(cmd) | 24 print >>sys.stderr, "CBUILDBOT -- RunCommand:", ' '.join(cmd) |
| 23 if redirect_stdout: | 25 if redirect_stdout: |
| 24 stdout = subprocess.PIPE | 26 stdout = subprocess.PIPE |
| 25 else: | 27 else: |
| (...skipping 18 matching lines...) Expand all Loading... |
| 44 | 46 |
| 45 def MakeDir(path, parents=False): | 47 def MakeDir(path, parents=False): |
| 46 try: | 48 try: |
| 47 os.makedirs(path) | 49 os.makedirs(path) |
| 48 except OSError,e: | 50 except OSError,e: |
| 49 if e.errno == errno.EEXIST and parents: | 51 if e.errno == errno.EEXIST and parents: |
| 50 pass | 52 pass |
| 51 else: | 53 else: |
| 52 raise | 54 raise |
| 53 | 55 |
| 56 def RepoSync(buildroot, retries=_DEFAULT_RETRIES): |
| 57 while retries > 0: |
| 58 try: |
| 59 RunCommand(['repo', 'sync'], cwd=buildroot) |
| 60 retries = 0 |
| 61 except: |
| 62 retries -= 1 |
| 63 if retries > 0: |
| 64 print >>sys.stderr, 'CBUILDBOT -- Repo Sync Failed, retrying' |
| 65 else: |
| 66 print >>sys.stderr, 'CBUILDBOT -- Retries exhausted' |
| 67 raise |
| 68 |
| 54 # Main functions | 69 # Main functions |
| 55 | 70 |
| 56 def _FullCheckout(buildroot): | 71 def _FullCheckout(buildroot, rw_checkout=True, retries=_DEFAULT_RETRIES): |
| 72 RunCommand(['sudo', 'rm', '-rf', buildroot]) |
| 57 MakeDir(buildroot, parents=True) | 73 MakeDir(buildroot, parents=True) |
| 58 RunCommand(['repo', 'init', '-u', 'http://src.chromium.org/git/manifest'], | 74 RunCommand(['repo', 'init', '-u', 'http://src.chromium.org/git/manifest'], |
| 59 cwd=buildroot, input='\n\ny\n') | 75 cwd=buildroot, input='\n\ny\n') |
| 60 RunCommand(['repo', 'sync'], cwd=buildroot) | 76 RepoSync(buildroot, retries) |
| 61 RunCommand(['repo', 'forall', '-c', 'git', 'config', | 77 if rw_checkout: |
| 62 'url.ssh://git@gitrw.chromium.org:9222.pushinsteadof', | 78 RunCommand(['repo', 'forall', '-c', 'git', 'config', |
| 63 'http://src.chromium.org/git'], cwd=buildroot) | 79 'url.ssh://git@gitrw.chromium.org:9222.pushinsteadof', |
| 80 'http://src.chromium.org/git'], cwd=buildroot) |
| 64 | 81 |
| 65 def _IncrementalCheckout(buildroot): | 82 def _IncrementalCheckout(buildroot, retries=_DEFAULT_RETRIES): |
| 66 RunCommand(['repo', 'sync'], cwd=buildroot) | 83 RepoSync(buildroot, retries) |
| 67 | 84 |
| 68 def _MakeChroot(buildroot): | 85 def _MakeChroot(buildroot): |
| 69 cwd = os.path.join(buildroot, 'src', 'scripts') | 86 cwd = os.path.join(buildroot, 'src', 'scripts') |
| 70 RunCommand(['./make_chroot', '--fast'], cwd=cwd) | 87 RunCommand(['./make_chroot', '--fast'], cwd=cwd) |
| 71 | 88 |
| 72 def _SetupBoard(buildroot, board='x86-generic'): | 89 def _SetupBoard(buildroot, board='x86-generic'): |
| 73 cwd = os.path.join(buildroot, 'src', 'scripts') | 90 cwd = os.path.join(buildroot, 'src', 'scripts') |
| 74 RunCommand(['./setup_board', '--fast', '--default', '--board=%s' % board], | 91 RunCommand(['./setup_board', '--fast', '--default', '--board=%s' % board], |
| 75 cwd=cwd) | 92 cwd=cwd) |
| 76 | 93 |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 if buildconfig['uprev']: | 158 if buildconfig['uprev']: |
| 142 _UprevPush(buildroot) | 159 _UprevPush(buildroot) |
| 143 _UprevCleanup(buildroot) | 160 _UprevCleanup(buildroot) |
| 144 except: | 161 except: |
| 145 # something went wrong, cleanup (being paranoid) for next build | 162 # something went wrong, cleanup (being paranoid) for next build |
| 146 RunCommand(['sudo', 'rm', '-rf', buildroot]) | 163 RunCommand(['sudo', 'rm', '-rf', buildroot]) |
| 147 raise | 164 raise |
| 148 | 165 |
| 149 if __name__ == '__main__': | 166 if __name__ == '__main__': |
| 150 main() | 167 main() |
| OLD | NEW |