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