Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(155)

Side by Side Diff: bin/cbuildbot.py

Issue 5689003: Add ability to store the manifest in the manifest directory. (Closed) Base URL: http://git.chromium.org/git/crosutils.git@master
Patch Set: Issues while testing Created 10 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | bin/cbuildbot_unittest.py » ('j') | bin/cbuildbot_unittest.py » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
11 import re 11 import re
12 import optparse 12 import optparse
13 import os 13 import os
14 import shutil 14 import shutil
15 import sys 15 import sys
16 16
17 import cbuildbot_comm 17 import cbuildbot_comm
18 from cbuildbot_config import config 18 from cbuildbot_config import config
19 19
20 sys.path.append(os.path.join(os.path.dirname(__file__), '../lib')) 20 sys.path.append(os.path.join(os.path.dirname(__file__), '../lib'))
21 from cros_build_lib import (Die, Info, ReinterpretPathForChroot, RunCommand, 21 from cros_build_lib import (Die, Info, ReinterpretPathForChroot, RunCommand,
22 Warning) 22 Warning)
23 23
24 _DEFAULT_RETRIES = 3 24 _DEFAULT_RETRIES = 3
25 _PACKAGE_FILE = '%(buildroot)s/src/scripts/cbuildbot_package.list' 25 _PACKAGE_FILE = '%(buildroot)s/src/scripts/cbuildbot_package.list'
26 ARCHIVE_BASE = '/var/www/archive' 26 ARCHIVE_BASE = '/var/www/archive'
27 ARCHIVE_COUNT = 10 27 ARCHIVE_COUNT = 10
28 PUBLIC_OVERLAY = '%(buildroot)s/src/third_party/chromiumos-overlay'
29 PRIVATE_OVERLAY = '%(buildroot)s/src/private-overlays/chromeos-overlay'
28 30
29 # Currently, both the full buildbot and the preflight buildbot store their 31 # Currently, both the full buildbot and the preflight buildbot store their
30 # data in a variable named PORTAGE_BINHOST, but they're in different files. 32 # data in a variable named PORTAGE_BINHOST, but they're in different files.
31 # We're planning on joining the two files soon and renaming the full binhost 33 # We're planning on joining the two files soon and renaming the full binhost
32 # to FULL_BINHOST. 34 # to FULL_BINHOST.
33 _FULL_BINHOST = 'PORTAGE_BINHOST' 35 _FULL_BINHOST = 'PORTAGE_BINHOST'
34 _PREFLIGHT_BINHOST = 'PORTAGE_BINHOST' 36 _PREFLIGHT_BINHOST = 'PORTAGE_BINHOST'
35 37
36 # ======================== Utility functions ================================ 38 # ======================== Utility functions ================================
37 39
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 RunCommand(['repo', '--trace', 'sync'], cwd=buildroot) 71 RunCommand(['repo', '--trace', 'sync'], cwd=buildroot)
70 retries = 0 72 retries = 0
71 except: 73 except:
72 retries -= 1 74 retries -= 1
73 if retries > 0: 75 if retries > 0:
74 Warning('CBUILDBOT -- Repo Sync Failed, retrying') 76 Warning('CBUILDBOT -- Repo Sync Failed, retrying')
75 else: 77 else:
76 Warning('CBUILDBOT -- Retries exhausted') 78 Warning('CBUILDBOT -- Retries exhausted')
77 raise 79 raise
78 80
79 # Output manifest
80 RunCommand(['repo', 'manifest', '-r', '-o', '-'], cwd=buildroot)
81
82 # =========================== Command Helpers ================================= 81 # =========================== Command Helpers =================================
83 82
84 def _GetAllGitRepos(buildroot, debug=False): 83 def _GetAllGitRepos(buildroot, debug=False):
85 """Returns a list of tuples containing [git_repo, src_path].""" 84 """Returns a list of tuples containing [git_repo, src_path]."""
86 manifest_tuples = [] 85 manifest_tuples = []
87 # Gets all the git repos from a full repo manifest. 86 # Gets all the git repos from a full repo manifest.
88 repo_cmd = "repo manifest -o -".split() 87 repo_cmd = "repo manifest -o -".split()
89 output = RunCommand(repo_cmd, cwd=buildroot, redirect_stdout=True, 88 output = RunCommand(repo_cmd, cwd=buildroot, redirect_stdout=True,
90 redirect_stderr=True, print_cmd=debug) 89 redirect_stderr=True, print_cmd=debug)
91 90
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 for mount_pt_str in mount_pts_in_buildroot.splitlines(): 270 for mount_pt_str in mount_pts_in_buildroot.splitlines():
272 mount_pt = mount_pt_str.rpartition(' type ')[0].partition(' on ')[2] 271 mount_pt = mount_pt_str.rpartition(' type ')[0].partition(' on ')[2]
273 RunCommand(['sudo', 'umount', '-l', mount_pt], error_ok=True) 272 RunCommand(['sudo', 'umount', '-l', mount_pt], error_ok=True)
274 273
275 274
276 def _WipeOldOutput(buildroot): 275 def _WipeOldOutput(buildroot):
277 """Wipes out build output directories.""" 276 """Wipes out build output directories."""
278 RunCommand(['rm', '-rf', 'src/build/images'], cwd=buildroot) 277 RunCommand(['rm', '-rf', 'src/build/images'], cwd=buildroot)
279 278
280 279
280 def _GetChromeOSVersion(buildroot):
281 """Returns the tuple version of the Chrome OS version of the buildroot."""
282 cwd = os.path.join(buildroot, 'src', 'scripts')
283 version_cmd = './chromeos_version.sh'
284 output = RunCommand(version_cmd, cwd=cwd, redirect_stdout=True,
285 redirect_stderr=True)
286 version_re = re.compile('\s+CHROMEOS_VERSION_STRING='
287 '(\d+)\.(\d+)\.(\d+)\.(\w+)')
288 for line in output.splitlines():
289 match = version_re.match(line)
290 if match:
291 return match.group(1), match.group(2), match.group(3), match.group(4)
292
293 raise Exception('Chrome OS version not found.')
294
295
296 def _GetManifestPath(buildroot):
297 """Returns the relative path that a manifest should be saved into."""
298 version_tuple = _GetChromeOSVersion(buildroot)
299 (major, minor, branch, patch) = version_tuple
300 relative_path = os.path.join('.'.join([major, minor]),
301 '%s.xml' % '.'.join(version_tuple))
302 return relative_path
303
304
281 # =========================== Main Commands =================================== 305 # =========================== Main Commands ===================================
282 306
283 307
284 def _PreFlightRinse(buildroot, board, tracking_branch, overlays): 308 def _PreFlightRinse(buildroot, board, tracking_branch, overlays):
285 """Cleans up any leftover state from previous runs.""" 309 """Cleans up any leftover state from previous runs."""
286 _GitCleanup(buildroot, board, tracking_branch, overlays) 310 _GitCleanup(buildroot, board, tracking_branch, overlays)
287 _CleanUpMountPoints(buildroot) 311 _CleanUpMountPoints(buildroot)
288 RunCommand(['sudo', 'killall', 'kvm'], error_ok=True) 312 RunCommand(['sudo', 'killall', 'kvm'], error_ok=True)
289 313
290 314
291 def _FullCheckout(buildroot, tracking_branch, 315 def _FullCheckout(buildroot, tracking_branch,
292 retries=_DEFAULT_RETRIES, 316 retries=_DEFAULT_RETRIES,
293 url='http://git.chromium.org/git/manifest'): 317 url='http://git.chromium.org/git/manifest'):
294 """Performs a full checkout and clobbers any previous checkouts.""" 318 """Performs a full checkout and clobbers any previous checkouts."""
295 RunCommand(['sudo', 'rm', '-rf', buildroot]) 319 RunCommand(['sudo', 'rm', '-rf', buildroot])
296 MakeDir(buildroot, parents=True) 320 MakeDir(buildroot, parents=True)
297 branch = tracking_branch.split('/'); 321 branch = tracking_branch.split('/');
298 RunCommand(['repo', 'init', '-u', 322 RunCommand(['repo', 'init', '-u',
299 url, '-b', 323 url, '-b',
300 '%s' % branch[-1]], cwd=buildroot, input='\n\ny\n') 324 '%s' % branch[-1]], cwd=buildroot, input='\n\ny\n')
301 RepoSync(buildroot, retries) 325 RepoSync(buildroot, retries)
302 326
303 327
304 def _IncrementalCheckout(buildroot, retries=_DEFAULT_RETRIES): 328 def _IncrementalCheckout(buildroot, retries=_DEFAULT_RETRIES):
305 """Performs a checkout without clobbering previous checkout.""" 329 """Performs a checkout without clobbering previous checkout."""
306 RepoSync(buildroot, retries) 330 RepoSync(buildroot, retries)
307 331
308 332
333 def _DumpManifest(buildroot, url):
334 """Stores the manifest in the public | private overlay depending on url."""
335 public_overlay = PUBLIC_OVERLAY % {'buildroot': buildroot}
scottz 2010/12/11 00:01:53 since you use {'buildroot': buildroot] in so many
sosa 2010/12/13 18:46:39 Rather not since buildroot would have to be define
336 private_overlay = PRIVATE_OVERLAY % {'buildroot': buildroot}
337 if url.endswith('manifest-internal'):
338 overlay = PRIVATE_OVERLAY % {'buildroot': buildroot}
339 else:
340 overlay = PUBLIC_OVERLAY % {'buildroot': buildroot}
341
342 # Generate paths for manifests.
343 relative_path = _GetManifestPath(buildroot)
344 manifest_path = os.path.join(overlay, 'manifests', relative_path)
345 symlink_path = os.path.join(overlay, 'manifests', 'LATEST')
346 if not os.path.isdir(os.path.dirname(manifest_path)):
347 os.makedirs(os.path.dirname(manifest_path))
348
349 # Dump the manifest and create a symlink to it.
350 RunCommand(['repo', 'manifest', '-r', '-o', manifest_path], cwd=buildroot)
351 if os.path.exists(symlink_path):
352 os.unlink(symlink_path)
353
354 os.symlink(relative_path, symlink_path)
355
356 # Add it to git and print it to stderr.
357 RunCommand(['git', 'add', os.path.join('manifests', relative_path)],
358 cwd=overlay)
359 RunCommand(['git', 'add', os.path.join('manifests', 'LATEST')], cwd=overlay)
360 shutil.copy(manifest_path, '/dev/stderr')
scottz 2010/12/11 00:01:53 Why are we doing this?
sosa 2010/12/13 18:46:39 Moved out to a function that does standard open, r
361
362
309 def _MakeChroot(buildroot): 363 def _MakeChroot(buildroot):
310 """Wrapper around make_chroot.""" 364 """Wrapper around make_chroot."""
311 cwd = os.path.join(buildroot, 'src', 'scripts') 365 cwd = os.path.join(buildroot, 'src', 'scripts')
312 RunCommand(['./make_chroot', '--fast'], cwd=cwd) 366 RunCommand(['./make_chroot', '--fast'], cwd=cwd)
313 367
314 368
315 def _GetPortageEnvVar(buildroot, board, envvar): 369 def _GetPortageEnvVar(buildroot, board, envvar):
316 """Get a portage environment variable for the specified board, if any. 370 """Get a portage environment variable for the specified board, if any.
317 371
318 buildroot: The root directory where the build occurs. Must be an absolute 372 buildroot: The root directory where the build occurs. Must be an absolute
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
520 """Return the list of overlays to use for a given buildbot. 574 """Return the list of overlays to use for a given buildbot.
521 575
522 Args: 576 Args:
523 buildroot: The root directory where the build occurs. Must be an absolute 577 buildroot: The root directory where the build occurs. Must be an absolute
524 path. 578 path.
525 overlays: A string describing which overlays you want. 579 overlays: A string describing which overlays you want.
526 'private': Just the private overlay. 580 'private': Just the private overlay.
527 'public': Just the public overlay. 581 'public': Just the public overlay.
528 'both': Both the public and private overlays. 582 'both': Both the public and private overlays.
529 """ 583 """
530 public_overlay = '%s/src/third_party/chromiumos-overlay' % buildroot 584 public_overlay = PUBLIC_OVERLAY % {'buildroot': buildroot}
531 private_overlay = '%s/src/private-overlays/chromeos-overlay' % buildroot 585 private_overlay = PRIVATE_OVERLAY % {'buildroot': buildroot}
532 if overlays == 'private': 586 if overlays == 'private':
533 paths = [private_overlay] 587 paths = [private_overlay]
534 elif overlays == 'public': 588 elif overlays == 'public':
535 paths = [public_overlay] 589 paths = [public_overlay]
536 elif overlays == 'both': 590 elif overlays == 'both':
537 paths = [public_overlay, private_overlay] 591 paths = [public_overlay, private_overlay]
538 else: 592 else:
539 Info('No overlays found.') 593 Info('No overlays found.')
540 paths = [] 594 paths = []
541 return paths 595 return paths
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
650 _IncrementalCheckout(buildroot) 704 _IncrementalCheckout(buildroot)
651 705
652 new_binhost = _GetPortageEnvVar(buildroot, board, _FULL_BINHOST) 706 new_binhost = _GetPortageEnvVar(buildroot, board, _FULL_BINHOST)
653 emptytree = (old_binhost and old_binhost != new_binhost) 707 emptytree = (old_binhost and old_binhost != new_binhost)
654 708
655 # Check that all overlays can be found. 709 # Check that all overlays can be found.
656 for path in rev_overlays: 710 for path in rev_overlays:
657 if not os.path.isdir(path): 711 if not os.path.isdir(path):
658 Die('Missing overlay: %s' % path) 712 Die('Missing overlay: %s' % path)
659 713
714 _DumpManifest(buildroot, options.url)
715
660 if not os.path.isdir(chroot_path): 716 if not os.path.isdir(chroot_path):
661 _MakeChroot(buildroot) 717 _MakeChroot(buildroot)
662 718
663 if not os.path.isdir(boardpath): 719 if not os.path.isdir(boardpath):
664 _SetupBoard(buildroot, board=buildconfig['board']) 720 _SetupBoard(buildroot, board=buildconfig['board'])
665 721
666 # Perform uprev. If chrome_uprev is set, rev Chrome ebuilds. 722 # Perform uprev. If chrome_uprev is set, rev Chrome ebuilds.
667 if options.chrome_rev: 723 if options.chrome_rev:
668 chrome_atom_to_build = _MarkChromeAsStable(buildroot, tracking_branch, 724 chrome_atom_to_build = _MarkChromeAsStable(buildroot, tracking_branch,
669 options.chrome_rev) 725 options.chrome_rev)
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
720 except: 776 except:
721 # Send failure to master bot. 777 # Send failure to master bot.
722 if not buildconfig['master'] and buildconfig['important']: 778 if not buildconfig['master'] and buildconfig['important']:
723 cbuildbot_comm.PublishStatus(cbuildbot_comm.STATUS_BUILD_FAILED) 779 cbuildbot_comm.PublishStatus(cbuildbot_comm.STATUS_BUILD_FAILED)
724 780
725 raise 781 raise
726 782
727 783
728 if __name__ == '__main__': 784 if __name__ == '__main__':
729 main() 785 main()
OLDNEW
« no previous file with comments | « no previous file | bin/cbuildbot_unittest.py » ('j') | bin/cbuildbot_unittest.py » ('J')

Powered by Google App Engine
This is Rietveld 408576698