| 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 """CBuildbot is wrapper around the build process used by the pre-flight queue""" | 7 """CBuildbot is wrapper around the build process used by the pre-flight queue""" |
| 8 | 8 |
| 9 import errno | 9 import errno |
| 10 import heapq | 10 import heapq |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 RunCommand(['repo', '--trace', 'sync'], cwd=buildroot) | 80 RunCommand(['repo', '--trace', 'sync'], cwd=buildroot) |
| 81 retries = 0 | 81 retries = 0 |
| 82 except: | 82 except: |
| 83 retries -= 1 | 83 retries -= 1 |
| 84 if retries > 0: | 84 if retries > 0: |
| 85 Warning('CBUILDBOT -- Repo Sync Failed, retrying') | 85 Warning('CBUILDBOT -- Repo Sync Failed, retrying') |
| 86 else: | 86 else: |
| 87 Warning('CBUILDBOT -- Retries exhausted') | 87 Warning('CBUILDBOT -- Retries exhausted') |
| 88 raise | 88 raise |
| 89 | 89 |
| 90 RunCommand(['repo', 'manifest', '-r', '-o', '/dev/stderr'], cwd=buildroot) |
| 91 |
| 90 # =========================== Command Helpers ================================= | 92 # =========================== Command Helpers ================================= |
| 91 | 93 |
| 92 def _GetAllGitRepos(buildroot, debug=False): | 94 def _GetAllGitRepos(buildroot, debug=False): |
| 93 """Returns a list of tuples containing [git_repo, src_path].""" | 95 """Returns a list of tuples containing [git_repo, src_path].""" |
| 94 manifest_tuples = [] | 96 manifest_tuples = [] |
| 95 # Gets all the git repos from a full repo manifest. | 97 # Gets all the git repos from a full repo manifest. |
| 96 repo_cmd = "repo manifest -o -".split() | 98 repo_cmd = "repo manifest -o -".split() |
| 97 output = RunCommand(repo_cmd, cwd=buildroot, redirect_stdout=True, | 99 output = RunCommand(repo_cmd, cwd=buildroot, redirect_stdout=True, |
| 98 redirect_stderr=True, print_cmd=debug) | 100 redirect_stderr=True, print_cmd=debug) |
| 99 | 101 |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 284 for mount_pt_str in mount_pts_in_buildroot.splitlines(): | 286 for mount_pt_str in mount_pts_in_buildroot.splitlines(): |
| 285 mount_pt = mount_pt_str.rpartition(' type ')[0].partition(' on ')[2] | 287 mount_pt = mount_pt_str.rpartition(' type ')[0].partition(' on ')[2] |
| 286 RunCommand(['sudo', 'umount', '-l', mount_pt], error_ok=True) | 288 RunCommand(['sudo', 'umount', '-l', mount_pt], error_ok=True) |
| 287 | 289 |
| 288 | 290 |
| 289 def _WipeOldOutput(buildroot): | 291 def _WipeOldOutput(buildroot): |
| 290 """Wipes out build output directories.""" | 292 """Wipes out build output directories.""" |
| 291 RunCommand(['rm', '-rf', 'src/build/images'], cwd=buildroot) | 293 RunCommand(['rm', '-rf', 'src/build/images'], cwd=buildroot) |
| 292 | 294 |
| 293 | 295 |
| 294 def _GetChromeOSVersion(buildroot): | |
| 295 """Returns the tuple version of the Chrome OS version of the buildroot.""" | |
| 296 cwd = os.path.join(buildroot, 'src', 'third_party', 'chromiumos-overlay', | |
| 297 'chromeos', 'config') | |
| 298 version_cmd = './chromeos_version.sh' | |
| 299 output = RunCommand(version_cmd, cwd=cwd, redirect_stdout=True, | |
| 300 redirect_stderr=True) | |
| 301 version_re = re.compile('\s+CHROMEOS_VERSION_STRING=' | |
| 302 '(\d+)\.(\d+)\.(\d+)\.(\w+)') | |
| 303 for line in output.splitlines(): | |
| 304 match = version_re.match(line) | |
| 305 if match: | |
| 306 return match.group(1), match.group(2), match.group(3), match.group(4) | |
| 307 | |
| 308 raise Exception('Chrome OS version not found.') | |
| 309 | |
| 310 | |
| 311 def _GetManifestPath(buildroot): | |
| 312 """Returns the relative path that a manifest should be saved into.""" | |
| 313 version_tuple = _GetChromeOSVersion(buildroot) | |
| 314 (major, minor, branch, patch) = version_tuple | |
| 315 relative_path = os.path.join('.'.join([major, minor]), | |
| 316 '%s.xml' % '.'.join(version_tuple)) | |
| 317 return relative_path | |
| 318 | |
| 319 | |
| 320 # =========================== Main Commands =================================== | 296 # =========================== Main Commands =================================== |
| 321 | 297 |
| 322 | 298 |
| 323 def _PreFlightRinse(buildroot, board, tracking_branch, overlays): | 299 def _PreFlightRinse(buildroot, board, tracking_branch, overlays): |
| 324 """Cleans up any leftover state from previous runs.""" | 300 """Cleans up any leftover state from previous runs.""" |
| 325 _GitCleanup(buildroot, board, tracking_branch, overlays) | 301 _GitCleanup(buildroot, board, tracking_branch, overlays) |
| 326 _CleanUpMountPoints(buildroot) | 302 _CleanUpMountPoints(buildroot) |
| 327 RunCommand(['sudo', 'killall', 'kvm'], error_ok=True) | 303 RunCommand(['sudo', 'killall', 'kvm'], error_ok=True) |
| 328 | 304 |
| 329 | 305 |
| 330 def _FullCheckout(buildroot, tracking_branch, | 306 def _FullCheckout(buildroot, tracking_branch, |
| 331 retries=_DEFAULT_RETRIES, | 307 retries=_DEFAULT_RETRIES, |
| 332 url='http://git.chromium.org/git/manifest'): | 308 url='http://git.chromium.org/git/manifest'): |
| 333 """Performs a full checkout and clobbers any previous checkouts.""" | 309 """Performs a full checkout and clobbers any previous checkouts.""" |
| 334 RunCommand(['sudo', 'rm', '-rf', buildroot]) | 310 RunCommand(['sudo', 'rm', '-rf', buildroot]) |
| 335 MakeDir(buildroot, parents=True) | 311 MakeDir(buildroot, parents=True) |
| 336 branch = tracking_branch.split('/'); | 312 branch = tracking_branch.split('/'); |
| 337 RunCommand(['repo', 'init', '-u', | 313 RunCommand(['repo', 'init', '-u', |
| 338 url, '-b', | 314 url, '-b', |
| 339 '%s' % branch[-1]], cwd=buildroot, input='\n\ny\n') | 315 '%s' % branch[-1]], cwd=buildroot, input='\n\ny\n') |
| 340 RepoSync(buildroot, retries) | 316 RepoSync(buildroot, retries) |
| 341 | 317 |
| 342 | 318 |
| 343 def _IncrementalCheckout(buildroot, retries=_DEFAULT_RETRIES): | 319 def _IncrementalCheckout(buildroot, retries=_DEFAULT_RETRIES): |
| 344 """Performs a checkout without clobbering previous checkout.""" | 320 """Performs a checkout without clobbering previous checkout.""" |
| 345 RepoSync(buildroot, retries) | 321 RepoSync(buildroot, retries) |
| 346 | 322 |
| 347 | 323 |
| 348 def _DumpManifest(buildroot, url): | |
| 349 """Stores the manifest in the public | private overlay depending on url.""" | |
| 350 public_overlay = PUBLIC_OVERLAY % {'buildroot': buildroot} | |
| 351 private_overlay = PRIVATE_OVERLAY % {'buildroot': buildroot} | |
| 352 if url.endswith('manifest-internal'): | |
| 353 overlay = PRIVATE_OVERLAY % {'buildroot': buildroot} | |
| 354 else: | |
| 355 overlay = PUBLIC_OVERLAY % {'buildroot': buildroot} | |
| 356 | |
| 357 # Generate paths for manifests. | |
| 358 relative_path = _GetManifestPath(buildroot) | |
| 359 manifest_path = os.path.join(overlay, 'manifests', relative_path) | |
| 360 symlink_path = os.path.join(overlay, 'manifests', 'LATEST') | |
| 361 if not os.path.isdir(os.path.dirname(manifest_path)): | |
| 362 os.makedirs(os.path.dirname(manifest_path)) | |
| 363 | |
| 364 # Dump the manifest and create a symlink to it. | |
| 365 RunCommand(['repo', 'manifest', '-r', '-o', manifest_path], cwd=buildroot) | |
| 366 if os.path.exists(symlink_path): | |
| 367 os.unlink(symlink_path) | |
| 368 | |
| 369 os.symlink(relative_path, symlink_path) | |
| 370 | |
| 371 # Add it to git and print it to stderr. | |
| 372 RunCommand(['git', 'add', os.path.join('manifests', relative_path)], | |
| 373 cwd=overlay) | |
| 374 RunCommand(['git', 'add', os.path.join('manifests', 'LATEST')], cwd=overlay) | |
| 375 _PrintFile(manifest_path) | |
| 376 | |
| 377 | |
| 378 def _MakeChroot(buildroot): | 324 def _MakeChroot(buildroot): |
| 379 """Wrapper around make_chroot.""" | 325 """Wrapper around make_chroot.""" |
| 380 cwd = os.path.join(buildroot, 'src', 'scripts') | 326 cwd = os.path.join(buildroot, 'src', 'scripts') |
| 381 RunCommand(['./make_chroot', '--fast'], cwd=cwd) | 327 RunCommand(['./make_chroot', '--fast'], cwd=cwd) |
| 382 | 328 |
| 383 | 329 |
| 384 def _GetPortageEnvVar(buildroot, board, envvar): | 330 def _GetPortageEnvVar(buildroot, board, envvar): |
| 385 """Get a portage environment variable for the specified board, if any. | 331 """Get a portage environment variable for the specified board, if any. |
| 386 | 332 |
| 387 buildroot: The root directory where the build occurs. Must be an absolute | 333 buildroot: The root directory where the build occurs. Must be an absolute |
| (...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 722 _IncrementalCheckout(buildroot) | 668 _IncrementalCheckout(buildroot) |
| 723 | 669 |
| 724 new_binhost = _GetPortageEnvVar(buildroot, board, _FULL_BINHOST) | 670 new_binhost = _GetPortageEnvVar(buildroot, board, _FULL_BINHOST) |
| 725 emptytree = (old_binhost and old_binhost != new_binhost) | 671 emptytree = (old_binhost and old_binhost != new_binhost) |
| 726 | 672 |
| 727 # Check that all overlays can be found. | 673 # Check that all overlays can be found. |
| 728 for path in rev_overlays: | 674 for path in rev_overlays: |
| 729 if not os.path.isdir(path): | 675 if not os.path.isdir(path): |
| 730 Die('Missing overlay: %s' % path) | 676 Die('Missing overlay: %s' % path) |
| 731 | 677 |
| 732 if not options.chrome_rev: | |
| 733 _DumpManifest(buildroot, options.url) | |
| 734 | |
| 735 if not os.path.isdir(chroot_path): | 678 if not os.path.isdir(chroot_path): |
| 736 _MakeChroot(buildroot) | 679 _MakeChroot(buildroot) |
| 737 | 680 |
| 738 if not os.path.isdir(boardpath): | 681 if not os.path.isdir(boardpath): |
| 739 _SetupBoard(buildroot, board=buildconfig['board']) | 682 _SetupBoard(buildroot, board=buildconfig['board']) |
| 740 | 683 |
| 741 # Perform uprev. If chrome_uprev is set, rev Chrome ebuilds. | 684 # Perform uprev. If chrome_uprev is set, rev Chrome ebuilds. |
| 742 if options.chrome_rev: | 685 if options.chrome_rev: |
| 743 chrome_atom_to_build = _MarkChromeAsStable(buildroot, tracking_branch, | 686 chrome_atom_to_build = _MarkChromeAsStable(buildroot, tracking_branch, |
| 744 options.chrome_rev, board) | 687 options.chrome_rev, board) |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 799 except: | 742 except: |
| 800 # Send failure to master bot. | 743 # Send failure to master bot. |
| 801 if not buildconfig['master'] and buildconfig['important']: | 744 if not buildconfig['master'] and buildconfig['important']: |
| 802 cbuildbot_comm.PublishStatus(cbuildbot_comm.STATUS_BUILD_FAILED) | 745 cbuildbot_comm.PublishStatus(cbuildbot_comm.STATUS_BUILD_FAILED) |
| 803 | 746 |
| 804 raise | 747 raise |
| 805 | 748 |
| 806 | 749 |
| 807 if __name__ == '__main__': | 750 if __name__ == '__main__': |
| 808 main() | 751 main() |
| OLD | NEW |