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 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
174 repo_name = revision_tuple[0].replace('.git', '') | 174 repo_name = revision_tuple[0].replace('.git', '') |
175 # Might not have entry if no matching ebuild. | 175 # Might not have entry if no matching ebuild. |
176 if repo_dictionary.has_key(repo_name): | 176 if repo_dictionary.has_key(repo_name): |
177 # May be many corresponding packages to a given git repo e.g. kernel). | 177 # May be many corresponding packages to a given git repo e.g. kernel). |
178 for package in repo_dictionary[repo_name]: | 178 for package in repo_dictionary[repo_name]: |
179 revisions[package] = revision_tuple[1] | 179 revisions[package] = revision_tuple[1] |
180 | 180 |
181 return revisions.items() | 181 return revisions.items() |
182 | 182 |
183 | 183 |
184 def _UprevFromRevisionList(buildroot, tracking_branch, revision_list, board): | 184 def _UprevFromRevisionList(buildroot, tracking_branch, revision_list, board, |
185 overlays): | |
185 """Uprevs based on revision list.""" | 186 """Uprevs based on revision list.""" |
186 if not revision_list: | 187 if not revision_list: |
187 Info('No packages found to uprev') | 188 Info('No packages found to uprev') |
188 return | 189 return |
189 | 190 |
190 package_str = '' | 191 packages = [] |
191 for package, revision in revision_list: | 192 for package, revision in revision_list: |
192 package_str += package + ' ' | 193 packages.append(package) |
193 | |
194 package_str = package_str.strip() | |
195 | 194 |
196 cwd = os.path.join(buildroot, 'src', 'scripts') | 195 cwd = os.path.join(buildroot, 'src', 'scripts') |
197 # TODO(davidjames): --foo="bar baz" only works here because we're using | |
198 # enter_chroot. | |
199 RunCommand(['./cros_mark_as_stable', | 196 RunCommand(['./cros_mark_as_stable', |
200 '--board=%s' % board, | 197 '--board=%s' % board, |
201 '--tracking_branch="%s"' % tracking_branch, | 198 '--tracking_branch=%s' % tracking_branch, |
202 '--packages="%s"' % package_str, | 199 '--overlays=%s' % ':'.join(overlays), |
200 '--packages=%s' % ':'.join(packages), | |
203 'commit'], | 201 'commit'], |
204 cwd=cwd, enter_chroot=True) | 202 cwd=cwd, enter_chroot=True) |
205 | 203 |
206 | 204 |
207 def _UprevAllPackages(buildroot, tracking_branch, board): | 205 def _UprevAllPackages(buildroot, tracking_branch, board, overlays): |
208 """Uprevs all packages that have been updated since last uprev.""" | 206 """Uprevs all packages that have been updated since last uprev.""" |
209 cwd = os.path.join(buildroot, 'src', 'scripts') | 207 cwd = os.path.join(buildroot, 'src', 'scripts') |
210 # TODO(davidjames): --foo="bar baz" only works here because we're using | |
211 # enter_chroot. | |
212 RunCommand(['./cros_mark_as_stable', '--all', | 208 RunCommand(['./cros_mark_as_stable', '--all', |
213 '--board=%s' % board, | 209 '--board=%s' % board, |
214 '--tracking_branch="%s"' % tracking_branch, 'commit'], | 210 '--overlays=%s' % ':'.join(overlays), |
211 '--tracking_branch=%s' % tracking_branch, 'commit'], | |
215 cwd=cwd, enter_chroot=True) | 212 cwd=cwd, enter_chroot=True) |
216 | 213 |
217 | 214 |
218 def _GetVMConstants(buildroot): | 215 def _GetVMConstants(buildroot): |
219 """Returns minimum (vdisk_size, statefulfs_size) recommended for VM's.""" | 216 """Returns minimum (vdisk_size, statefulfs_size) recommended for VM's.""" |
220 cwd = os.path.join(buildroot, 'src', 'scripts', 'lib') | 217 cwd = os.path.join(buildroot, 'src', 'scripts', 'lib') |
221 source_cmd = 'source %s/cros_vm_constants.sh' % cwd | 218 source_cmd = 'source %s/cros_vm_constants.sh' % cwd |
222 vdisk_size = RunCommand([ | 219 vdisk_size = RunCommand([ |
223 '/bin/bash', '-c', '%s && echo $MIN_VDISK_SIZE_FULL' % source_cmd], | 220 '/bin/bash', '-c', '%s && echo $MIN_VDISK_SIZE_FULL' % source_cmd], |
224 redirect_stdout=True) | 221 redirect_stdout=True) |
225 statefulfs_size = RunCommand([ | 222 statefulfs_size = RunCommand([ |
226 '/bin/bash', '-c', '%s && echo $MIN_STATEFUL_FS_SIZE_FULL' % source_cmd], | 223 '/bin/bash', '-c', '%s && echo $MIN_STATEFUL_FS_SIZE_FULL' % source_cmd], |
227 redirect_stdout=True) | 224 redirect_stdout=True) |
228 return (vdisk_size.strip(), statefulfs_size.strip()) | 225 return (vdisk_size.strip(), statefulfs_size.strip()) |
229 | 226 |
230 | 227 |
231 def _GitCleanup(buildroot, board, tracking_branch): | 228 def _GitCleanup(buildroot, board, tracking_branch, overlays): |
232 """Clean up git branch after previous uprev attempt.""" | 229 """Clean up git branch after previous uprev attempt.""" |
233 cwd = os.path.join(buildroot, 'src', 'scripts') | 230 cwd = os.path.join(buildroot, 'src', 'scripts') |
234 if os.path.exists(cwd): | 231 if os.path.exists(cwd): |
235 RunCommand(['./cros_mark_as_stable', '--srcroot=..', | 232 RunCommand(['./cros_mark_as_stable', '--srcroot=..', |
236 '--board=%s' % board, | 233 '--board=%s' % board, |
234 '--overlays=%s' % ':'.join(overlays), | |
237 '--tracking_branch=%s' % tracking_branch, 'clean'], | 235 '--tracking_branch=%s' % tracking_branch, 'clean'], |
238 cwd=cwd, error_ok=True) | 236 cwd=cwd, error_ok=True) |
239 | 237 |
240 | 238 |
241 def _CleanUpMountPoints(buildroot): | 239 def _CleanUpMountPoints(buildroot): |
242 """Cleans up any stale mount points from previous runs.""" | 240 """Cleans up any stale mount points from previous runs.""" |
243 mount_output = RunCommand(['mount'], redirect_stdout=True) | 241 mount_output = RunCommand(['mount'], redirect_stdout=True) |
244 mount_pts_in_buildroot = RunCommand(['grep', buildroot], input=mount_output, | 242 mount_pts_in_buildroot = RunCommand(['grep', buildroot], input=mount_output, |
245 redirect_stdout=True, error_ok=True) | 243 redirect_stdout=True, error_ok=True) |
246 | 244 |
247 for mount_pt_str in mount_pts_in_buildroot.splitlines(): | 245 for mount_pt_str in mount_pts_in_buildroot.splitlines(): |
248 mount_pt = mount_pt_str.rpartition(' type ')[0].partition(' on ')[2] | 246 mount_pt = mount_pt_str.rpartition(' type ')[0].partition(' on ')[2] |
249 RunCommand(['sudo', 'umount', '-l', mount_pt], error_ok=True) | 247 RunCommand(['sudo', 'umount', '-l', mount_pt], error_ok=True) |
250 | 248 |
251 | 249 |
252 def _WipeOldOutput(buildroot): | 250 def _WipeOldOutput(buildroot): |
253 """Wipes out build output directories.""" | 251 """Wipes out build output directories.""" |
254 RunCommand(['rm', '-rf', 'src/build/images'], cwd=buildroot) | 252 RunCommand(['rm', '-rf', 'src/build/images'], cwd=buildroot) |
255 | 253 |
256 | 254 |
257 # =========================== Main Commands =================================== | 255 # =========================== Main Commands =================================== |
258 | 256 |
259 | 257 |
260 def _PreFlightRinse(buildroot, board, tracking_branch): | 258 def _PreFlightRinse(buildroot, board, tracking_branch, overlays): |
261 """Cleans up any leftover state from previous runs.""" | 259 """Cleans up any leftover state from previous runs.""" |
262 _GitCleanup(buildroot, board, tracking_branch) | 260 _GitCleanup(buildroot, board, tracking_branch, overlays) |
263 _CleanUpMountPoints(buildroot) | 261 _CleanUpMountPoints(buildroot) |
264 RunCommand(['sudo', 'killall', 'kvm'], error_ok=True) | 262 RunCommand(['sudo', 'killall', 'kvm'], error_ok=True) |
265 | 263 |
266 | 264 |
267 def _FullCheckout(buildroot, tracking_branch, rw_checkout=True, | 265 def _FullCheckout(buildroot, tracking_branch, rw_checkout=True, |
268 retries=_DEFAULT_RETRIES, | 266 retries=_DEFAULT_RETRIES, |
269 url='http://git.chromium.org/git/manifest'): | 267 url='http://git.chromium.org/git/manifest'): |
270 """Performs a full checkout and clobbers any previous checkouts.""" | 268 """Performs a full checkout and clobbers any previous checkouts.""" |
271 RunCommand(['sudo', 'rm', '-rf', buildroot]) | 269 RunCommand(['sudo', 'rm', '-rf', buildroot]) |
272 MakeDir(buildroot, parents=True) | 270 MakeDir(buildroot, parents=True) |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
340 shutil.rmtree(results_dir_in_chroot) | 338 shutil.rmtree(results_dir_in_chroot) |
341 | 339 |
342 cwd = os.path.join(buildroot, 'src', 'scripts') | 340 cwd = os.path.join(buildroot, 'src', 'scripts') |
343 RunCommand(['bin/cros_run_vm_test', | 341 RunCommand(['bin/cros_run_vm_test', |
344 '--no_graphics', | 342 '--no_graphics', |
345 '--test_case=suite_Smoke', | 343 '--test_case=suite_Smoke', |
346 '--results_dir_root=%s' % results_dir, | 344 '--results_dir_root=%s' % results_dir, |
347 ], cwd=cwd, error_ok=False) | 345 ], cwd=cwd, error_ok=False) |
348 | 346 |
349 | 347 |
350 def _UprevPackages(buildroot, tracking_branch, revisionfile, board): | 348 def _UprevPackages(buildroot, tracking_branch, revisionfile, board, overlays): |
351 """Uprevs a package based on given revisionfile. | 349 """Uprevs a package based on given revisionfile. |
352 | 350 |
353 If revisionfile is set to None or does not resolve to an actual file, this | 351 If revisionfile is set to None or does not resolve to an actual file, this |
354 function will uprev all packages. | 352 function will uprev all packages. |
355 | 353 |
356 Keyword arguments: | 354 Keyword arguments: |
357 revisionfile -- string specifying a file that contains a list of revisions to | 355 revisionfile -- string specifying a file that contains a list of revisions to |
358 uprev. | 356 uprev. |
359 """ | 357 """ |
360 # Purposefully set to None as it means Force Build was pressed. | 358 # Purposefully set to None as it means Force Build was pressed. |
361 revisions = 'None' | 359 revisions = 'None' |
362 if (revisionfile): | 360 if (revisionfile): |
363 try: | 361 try: |
364 rev_file = open(revisionfile) | 362 rev_file = open(revisionfile) |
365 revisions = rev_file.read() | 363 revisions = rev_file.read() |
366 rev_file.close() | 364 rev_file.close() |
367 except Exception, e: | 365 except Exception, e: |
368 Warning('Error reading %s, revving all' % revisionfile) | 366 Warning('Error reading %s, revving all' % revisionfile) |
369 revisions = 'None' | 367 revisions = 'None' |
370 | 368 |
371 revisions = revisions.strip() | 369 revisions = revisions.strip() |
372 | 370 |
373 # TODO(sosa): Un-comment once we close individual trees. | 371 # TODO(sosa): Un-comment once we close individual trees. |
374 # revisions == "None" indicates a Force Build. | 372 # revisions == "None" indicates a Force Build. |
375 #if revisions != 'None': | 373 #if revisions != 'None': |
376 # print >> sys.stderr, 'CBUILDBOT Revision list found %s' % revisions | 374 # print >> sys.stderr, 'CBUILDBOT Revision list found %s' % revisions |
377 # revision_list = _ParseRevisionString(revisions, | 375 # revision_list = _ParseRevisionString(revisions, |
378 # _CreateRepoDictionary(buildroot, board)) | 376 # _CreateRepoDictionary(buildroot, board)) |
379 # _UprevFromRevisionList(buildroot, tracking_branch, revision_list, board) | 377 # _UprevFromRevisionList(buildroot, tracking_branch, revision_list, board, |
378 # overlays) | |
380 #else: | 379 #else: |
381 Info('CBUILDBOT Revving all') | 380 Info('CBUILDBOT Revving all') |
382 _UprevAllPackages(buildroot, tracking_branch, board) | 381 _UprevAllPackages(buildroot, tracking_branch, board, overlays) |
383 | 382 |
384 | 383 |
385 def _UprevPush(buildroot, tracking_branch, board, overlays): | 384 def _UprevPush(buildroot, tracking_branch, board, overlays): |
386 """Pushes uprev changes to the main line.""" | 385 """Pushes uprev changes to the main line.""" |
387 cwd = os.path.join(buildroot, 'src', 'scripts') | 386 cwd = os.path.join(buildroot, 'src', 'scripts') |
388 public_overlay = '%s/src/third_party/chromiumos-overlay' % buildroot | |
389 private_overlay = '%s/src/private-overlays/chromeos-overlay' % buildroot | |
390 if overlays == 'private': | |
391 overlays = [private_overlay] | |
392 elif overlays == 'public': | |
393 overlays = [public_overlay] | |
394 else: | |
395 overlays = [public_overlay, private_overlay] | |
396 RunCommand(['./cros_mark_as_stable', '--srcroot=..', | 387 RunCommand(['./cros_mark_as_stable', '--srcroot=..', |
397 '--board=%s' % board, | 388 '--board=%s' % board, |
398 '--overlays=%s' % " ".join(overlays), | 389 '--overlays=%s' % ':'.join(overlays), |
399 '--tracking_branch=%s' % tracking_branch, | 390 '--tracking_branch=%s' % tracking_branch, |
400 '--push_options=--bypass-hooks -f', 'push'], | 391 '--push_options=--bypass-hooks -f', 'push'], |
401 cwd=cwd) | 392 cwd=cwd) |
402 | 393 |
403 | 394 |
404 def _ArchiveTestResults(buildroot, board, archive_dir, test_results_dir): | 395 def _ArchiveTestResults(buildroot, board, archive_dir, test_results_dir): |
405 """Archives the test results into the www dir for later use. | 396 """Archives the test results into the www dir for later use. |
406 | 397 |
407 Takes the results from the test_results_dir and dumps them into the archive | 398 Takes the results from the test_results_dir and dumps them into the archive |
408 dir specified. This also archives the last qemu image. | 399 dir specified. This also archives the last qemu image. |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
459 sys.exit(1) | 450 sys.exit(1) |
460 | 451 |
461 buildconfig = config[config_name] | 452 buildconfig = config[config_name] |
462 | 453 |
463 for key in default.iterkeys(): | 454 for key in default.iterkeys(): |
464 if not buildconfig.has_key(key): | 455 if not buildconfig.has_key(key): |
465 buildconfig[key] = default[key] | 456 buildconfig[key] = default[key] |
466 | 457 |
467 return buildconfig | 458 return buildconfig |
468 | 459 |
460 def ResolveOverlays(overlays): | |
461 """Return the list of overlays to use for a given buildbot.""" | |
diandersAtChromium
2010/11/03 23:53:34
nit: Should describe overlays arg in docstring.
davidjames
2010/11/10 18:30:10
Done.
| |
462 public_overlay = '%s/src/third_party/chromiumos-overlay' % buildroot | |
sosa
2010/11/03 23:49:06
May want to os.path.exists below.
davidjames
2010/11/10 18:30:10
Done.
| |
463 private_overlay = '%s/src/private-overlays/chromeos-overlay' % buildroot | |
464 if overlays == 'private': | |
465 return [private_overlay] | |
466 elif overlays == 'public': | |
467 return [public_overlay] | |
468 elif overlays == 'both': | |
469 return [public_overlay, private_overlay] | |
470 else: | |
471 Die('Incorrect overlay configuration: %s' % overlays) | |
472 | |
469 | 473 |
470 def main(): | 474 def main(): |
471 # Parse options | 475 # Parse options |
472 usage = "usage: %prog [options] cbuildbot_config" | 476 usage = "usage: %prog [options] cbuildbot_config" |
473 parser = optparse.OptionParser(usage=usage) | 477 parser = optparse.OptionParser(usage=usage) |
474 parser.add_option('-r', '--buildroot', | 478 parser.add_option('-r', '--buildroot', |
475 help='root directory where build occurs', default=".") | 479 help='root directory where build occurs', default=".") |
476 parser.add_option('-n', '--buildnumber', | 480 parser.add_option('-n', '--buildnumber', |
477 help='build number', type='int', default=0) | 481 help='build number', type='int', default=0) |
478 parser.add_option('-f', '--revisionfile', | 482 parser.add_option('-f', '--revisionfile', |
(...skipping 16 matching lines...) Expand all Loading... | |
495 revisionfile = options.revisionfile | 499 revisionfile = options.revisionfile |
496 tracking_branch = options.tracking_branch | 500 tracking_branch = options.tracking_branch |
497 | 501 |
498 if len(args) >= 1: | 502 if len(args) >= 1: |
499 buildconfig = _GetConfig(args[-1]) | 503 buildconfig = _GetConfig(args[-1]) |
500 else: | 504 else: |
501 Warning('Missing configuration description') | 505 Warning('Missing configuration description') |
502 parser.print_usage() | 506 parser.print_usage() |
503 sys.exit(1) | 507 sys.exit(1) |
504 | 508 |
509 # Calculate list of overlay directories. | |
510 overlays = ResolveOverlays(buildconfig['overlays']) | |
511 | |
505 try: | 512 try: |
506 _PreFlightRinse(buildroot, buildconfig['board'], tracking_branch) | 513 _PreFlightRinse(buildroot, buildconfig['board'], tracking_branch, overlays) |
507 if options.clobber or not os.path.isdir(buildroot): | 514 if options.clobber or not os.path.isdir(buildroot): |
508 _FullCheckout(buildroot, tracking_branch, url=options.url) | 515 _FullCheckout(buildroot, tracking_branch, url=options.url) |
509 else: | 516 else: |
510 _IncrementalCheckout(buildroot) | 517 _IncrementalCheckout(buildroot) |
511 | 518 |
512 chroot_path = os.path.join(buildroot, 'chroot') | 519 chroot_path = os.path.join(buildroot, 'chroot') |
513 if not os.path.isdir(chroot_path): | 520 if not os.path.isdir(chroot_path): |
514 _MakeChroot(buildroot) | 521 _MakeChroot(buildroot) |
515 | 522 |
516 boardpath = os.path.join(chroot_path, 'build', buildconfig['board']) | 523 boardpath = os.path.join(chroot_path, 'build', buildconfig['board']) |
517 if not os.path.isdir(boardpath): | 524 if not os.path.isdir(boardpath): |
518 _SetupBoard(buildroot, board=buildconfig['board']) | 525 _SetupBoard(buildroot, board=buildconfig['board']) |
519 | 526 |
520 if buildconfig['uprev']: | 527 if buildconfig['uprev']: |
521 _UprevPackages(buildroot, tracking_branch, revisionfile, | 528 _UprevPackages(buildroot, tracking_branch, revisionfile, |
522 board=buildconfig['board']) | 529 buildconfig['board'], overlays) |
523 | 530 |
524 _EnableLocalAccount(buildroot) | 531 _EnableLocalAccount(buildroot) |
525 _Build(buildroot) | 532 _Build(buildroot) |
526 if buildconfig['unittests']: | 533 if buildconfig['unittests']: |
527 _RunUnitTests(buildroot) | 534 _RunUnitTests(buildroot) |
528 | 535 |
529 _BuildImage(buildroot) | 536 _BuildImage(buildroot) |
530 | 537 |
531 if buildconfig['smoke_bvt']: | 538 if buildconfig['smoke_bvt']: |
532 _BuildVMImageForTesting(buildroot) | 539 _BuildVMImageForTesting(buildroot) |
533 test_results_dir = '/tmp/run_remote_tests.%s' % options.buildnumber | 540 test_results_dir = '/tmp/run_remote_tests.%s' % options.buildnumber |
534 try: | 541 try: |
535 _RunSmokeSuite(buildroot, test_results_dir) | 542 _RunSmokeSuite(buildroot, test_results_dir) |
536 finally: | 543 finally: |
537 _ArchiveTestResults(buildroot, buildconfig['board'], | 544 _ArchiveTestResults(buildroot, buildconfig['board'], |
538 archive_dir=options.buildnumber, | 545 archive_dir=options.buildnumber, |
539 test_results_dir=test_results_dir) | 546 test_results_dir=test_results_dir) |
540 | 547 |
541 if buildconfig['uprev']: | 548 if buildconfig['uprev']: |
542 # Don't push changes for developers. | 549 # Don't push changes for developers. |
543 if not options.debug: | 550 if not options.debug: |
544 if buildconfig['master']: | 551 if buildconfig['master']: |
545 # Master bot needs to check if the other slaves completed. | 552 # Master bot needs to check if the other slaves completed. |
546 if cbuildbot_comm.HaveSlavesCompleted(config): | 553 if cbuildbot_comm.HaveSlavesCompleted(config): |
547 _UprevPush(buildroot, tracking_branch, buildconfig['board'], | 554 _UprevPush(buildroot, tracking_branch, buildconfig['board'], |
548 buildconfig['overlays']) | 555 overlays) |
549 else: | 556 else: |
550 Die('CBUILDBOT - One of the slaves has failed!!!') | 557 Die('CBUILDBOT - One of the slaves has failed!!!') |
551 | 558 |
552 else: | 559 else: |
553 # Publish my status to the master if its expecting it. | 560 # Publish my status to the master if its expecting it. |
554 if buildconfig['important']: | 561 if buildconfig['important']: |
555 cbuildbot_comm.PublishStatus(cbuildbot_comm.STATUS_BUILD_COMPLETE) | 562 cbuildbot_comm.PublishStatus(cbuildbot_comm.STATUS_BUILD_COMPLETE) |
556 | 563 |
557 except: | 564 except: |
558 # Send failure to master bot. | 565 # Send failure to master bot. |
559 if not buildconfig['master'] and buildconfig['important']: | 566 if not buildconfig['master'] and buildconfig['important']: |
560 cbuildbot_comm.PublishStatus(cbuildbot_comm.STATUS_BUILD_FAILED) | 567 cbuildbot_comm.PublishStatus(cbuildbot_comm.STATUS_BUILD_FAILED) |
561 | 568 |
562 raise | 569 raise |
563 | 570 |
564 | 571 |
565 if __name__ == '__main__': | 572 if __name__ == '__main__': |
566 main() | 573 main() |
OLD | NEW |