Chromium Code Reviews| 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 re | 10 import re |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 211 source_cmd = 'source %s/cros_vm_constants.sh' % cwd | 211 source_cmd = 'source %s/cros_vm_constants.sh' % cwd |
| 212 vdisk_size = RunCommand([ | 212 vdisk_size = RunCommand([ |
| 213 '/bin/bash', '-c', '%s && echo $MIN_VDISK_SIZE_FULL' % source_cmd], | 213 '/bin/bash', '-c', '%s && echo $MIN_VDISK_SIZE_FULL' % source_cmd], |
| 214 redirect_stdout=True) | 214 redirect_stdout=True) |
| 215 statefulfs_size = RunCommand([ | 215 statefulfs_size = RunCommand([ |
| 216 '/bin/bash', '-c', '%s && echo $MIN_STATEFUL_FS_SIZE_FULL' % source_cmd], | 216 '/bin/bash', '-c', '%s && echo $MIN_STATEFUL_FS_SIZE_FULL' % source_cmd], |
| 217 redirect_stdout=True) | 217 redirect_stdout=True) |
| 218 return (vdisk_size.strip(), statefulfs_size.strip()) | 218 return (vdisk_size.strip(), statefulfs_size.strip()) |
| 219 | 219 |
| 220 | 220 |
| 221 def _GitCleanup(buildroot): | |
| 222 """Clean up git branch after previous uprev attempt.""" | |
| 223 cwd = os.path.join(buildroot, 'src', 'scripts') | |
| 224 if os.path.exists(cwd): | |
| 225 RunCommand(['./cros_mark_as_stable', '--srcroot=..', | |
| 226 '--tracking_branch="cros/master"', 'clean'], | |
| 227 cwd=cwd, error_ok=True) | |
| 228 | |
| 229 | |
| 230 def _CleanUpMountPoints(buildroot): | |
| 231 """Cleans up any stale mount points from previous runs.""" | |
| 232 mount_output = RunCommand(['mount'], redirect_stdout=True) | |
| 233 mount_pts_in_buildroot = RunCommand(['grep', buildroot], input=mount_output, | |
| 234 redirect_stdout=True, error_ok=True) | |
|
scottz
2010/10/22 00:07:32
if you are going to do this, you might as well jus
| |
| 235 | |
| 236 for mount_pt_str in mount_pts_in_buildroot.splitlines(): | |
| 237 mount_pt = mount_pt_str.rpartition(' type ')[0].partition(' on ')[2] | |
| 238 RunCommand(['sudo', 'umount', '-l', mount_pt], error_ok=True) | |
| 239 | |
| 240 | |
| 241 def _WipeOldOutput(buildroot): | |
| 242 """Wipes out build output directories.""" | |
| 243 RunCommand(['rm', '-rf', 'src/build/images'], cwd=buildroot) | |
| 244 | |
| 245 | |
| 221 # =========================== Main Commands =================================== | 246 # =========================== Main Commands =================================== |
| 222 | 247 |
| 248 | |
| 249 def _PreFlightRinse(buildroot): | |
| 250 """Cleans up any leftover state from previous runs.""" | |
| 251 _GitCleanup(buildroot) | |
| 252 _CleanUpMountPoints(buildroot) | |
| 253 RunCommand(['sudo', 'killall', 'kvm'], error_ok=True) | |
| 254 | |
| 255 | |
| 223 def _FullCheckout(buildroot, rw_checkout=True, retries=_DEFAULT_RETRIES): | 256 def _FullCheckout(buildroot, rw_checkout=True, retries=_DEFAULT_RETRIES): |
| 224 """Performs a full checkout and clobbers any previous checkouts.""" | 257 """Performs a full checkout and clobbers any previous checkouts.""" |
| 225 RunCommand(['sudo', 'rm', '-rf', buildroot]) | 258 RunCommand(['sudo', 'rm', '-rf', buildroot]) |
| 226 MakeDir(buildroot, parents=True) | 259 MakeDir(buildroot, parents=True) |
| 227 RunCommand(['repo', 'init', '-u', 'http://git.chromium.org/git/manifest'], | 260 RunCommand(['repo', 'init', '-u', 'http://git.chromium.org/git/manifest'], |
| 228 cwd=buildroot, input='\n\ny\n') | 261 cwd=buildroot, input='\n\ny\n') |
| 229 RepoSync(buildroot, rw_checkout, retries) | 262 RepoSync(buildroot, rw_checkout, retries) |
| 230 | 263 |
| 231 | 264 |
| 232 def _PreFlightRinse(buildroot): | |
| 233 """Cleans up any leftover state from previous runs.""" | |
| 234 RunCommand(['sudo', 'killall', 'kvm'], error_ok=True) | |
| 235 _UprevCleanup(buildroot, error_ok=True) | |
| 236 | |
| 237 | |
| 238 def _IncrementalCheckout(buildroot, rw_checkout=True, | 265 def _IncrementalCheckout(buildroot, rw_checkout=True, |
| 239 retries=_DEFAULT_RETRIES): | 266 retries=_DEFAULT_RETRIES): |
| 240 """Performs a checkout without clobbering previous checkout.""" | 267 """Performs a checkout without clobbering previous checkout.""" |
| 241 RepoSync(buildroot, rw_checkout, retries) | 268 RepoSync(buildroot, rw_checkout, retries) |
| 242 | 269 |
| 243 | 270 |
| 244 def _MakeChroot(buildroot): | 271 def _MakeChroot(buildroot): |
| 245 """Wrapper around make_chroot.""" | 272 """Wrapper around make_chroot.""" |
| 246 cwd = os.path.join(buildroot, 'src', 'scripts') | 273 cwd = os.path.join(buildroot, 'src', 'scripts') |
| 247 RunCommand(['./make_chroot', '--fast'], cwd=cwd) | 274 RunCommand(['./make_chroot', '--fast'], cwd=cwd) |
| 248 | 275 |
| 249 | 276 |
| 250 def _SetupBoard(buildroot, board='x86-generic'): | 277 def _SetupBoard(buildroot, board='x86-generic'): |
| 251 """Wrapper around setup_board.""" | 278 """Wrapper around setup_board.""" |
| 252 cwd = os.path.join(buildroot, 'src', 'scripts') | 279 cwd = os.path.join(buildroot, 'src', 'scripts') |
| 253 RunCommand(['./setup_board', '--fast', '--default', '--board=%s' % board], | 280 RunCommand(['./setup_board', '--fast', '--default', '--board=%s' % board], |
| 254 cwd=cwd, enter_chroot=True) | 281 cwd=cwd, enter_chroot=True) |
| 255 | 282 |
| 256 | 283 |
| 257 def _Build(buildroot): | 284 def _Build(buildroot): |
| 258 """Wrapper around build_packages.""" | 285 """Wrapper around build_packages.""" |
| 259 cwd = os.path.join(buildroot, 'src', 'scripts') | 286 cwd = os.path.join(buildroot, 'src', 'scripts') |
| 260 RunCommand(['./build_packages'], cwd=cwd, enter_chroot=True) | 287 RunCommand(['./build_packages'], cwd=cwd, enter_chroot=True) |
| 261 | 288 |
| 262 | 289 |
| 263 def _WipeOldOutput(buildroot): | |
| 264 RunCommand(['rm', '-rf', 'src/build/images'], cwd=buildroot) | |
| 265 | |
| 266 | |
| 267 def _EnableLocalAccount(buildroot): | 290 def _EnableLocalAccount(buildroot): |
| 268 cwd = os.path.join(buildroot, 'src', 'scripts') | 291 cwd = os.path.join(buildroot, 'src', 'scripts') |
| 269 # Set local account for test images. | 292 # Set local account for test images. |
| 270 RunCommand(['./enable_localaccount.sh', | 293 RunCommand(['./enable_localaccount.sh', |
| 271 'chronos'], | 294 'chronos'], |
| 272 print_cmd=False, cwd=cwd) | 295 print_cmd=False, cwd=cwd) |
| 273 | 296 |
| 274 | 297 |
| 275 def _BuildImage(buildroot): | 298 def _BuildImage(buildroot): |
| 276 _WipeOldOutput(buildroot) | 299 _WipeOldOutput(buildroot) |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 331 #if revisions != 'None': | 354 #if revisions != 'None': |
| 332 # print >> sys.stderr, 'CBUILDBOT Revision list found %s' % revisions | 355 # print >> sys.stderr, 'CBUILDBOT Revision list found %s' % revisions |
| 333 # revision_list = _ParseRevisionString(revisions, | 356 # revision_list = _ParseRevisionString(revisions, |
| 334 # _CreateRepoDictionary(buildroot, board)) | 357 # _CreateRepoDictionary(buildroot, board)) |
| 335 # _UprevFromRevisionList(buildroot, revision_list) | 358 # _UprevFromRevisionList(buildroot, revision_list) |
| 336 #else: | 359 #else: |
| 337 Info('CBUILDBOT Revving all') | 360 Info('CBUILDBOT Revving all') |
| 338 _UprevAllPackages(buildroot) | 361 _UprevAllPackages(buildroot) |
| 339 | 362 |
| 340 | 363 |
| 341 def _UprevCleanup(buildroot, error_ok=False): | |
| 342 """Clean up after a previous uprev attempt.""" | |
| 343 cwd = os.path.join(buildroot, 'src', 'scripts') | |
| 344 RunCommand(['./cros_mark_as_stable', '--srcroot=..', | |
| 345 '--tracking_branch="cros/master"', 'clean'], | |
| 346 cwd=cwd, error_ok=error_ok) | |
| 347 | |
| 348 | |
| 349 def _UprevPush(buildroot): | 364 def _UprevPush(buildroot): |
| 350 """Pushes uprev changes to the main line.""" | 365 """Pushes uprev changes to the main line.""" |
| 351 cwd = os.path.join(buildroot, 'src', 'scripts') | 366 cwd = os.path.join(buildroot, 'src', 'scripts') |
| 352 RunCommand(['./cros_mark_as_stable', '--srcroot=..', | 367 RunCommand(['./cros_mark_as_stable', '--srcroot=..', |
| 353 '--tracking_branch="cros/master"', | 368 '--tracking_branch="cros/master"', |
| 354 '--push_options="--bypass-hooks -f"', 'push'], | 369 '--push_options="--bypass-hooks -f"', 'push'], |
| 355 cwd=cwd) | 370 cwd=cwd) |
| 356 | 371 |
| 357 | 372 |
| 358 def _GetConfig(config_name): | 373 def _GetConfig(config_name): |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 391 default=False, | 406 default=False, |
| 392 help='Clobbers an old checkout before syncing') | 407 help='Clobbers an old checkout before syncing') |
| 393 parser.add_option('--debug', action='store_true', dest='debug', | 408 parser.add_option('--debug', action='store_true', dest='debug', |
| 394 default=False, | 409 default=False, |
| 395 help='Override some options to run as a developer.') | 410 help='Override some options to run as a developer.') |
| 396 (options, args) = parser.parse_args() | 411 (options, args) = parser.parse_args() |
| 397 | 412 |
| 398 buildroot = options.buildroot | 413 buildroot = options.buildroot |
| 399 revisionfile = options.revisionfile | 414 revisionfile = options.revisionfile |
| 400 | 415 |
| 401 # Passed option to clobber. | |
| 402 if options.clobber: | |
| 403 RunCommand(['sudo', 'rm', '-rf', buildroot]) | |
| 404 | |
| 405 if len(args) >= 1: | 416 if len(args) >= 1: |
| 406 buildconfig = _GetConfig(args[-1]) | 417 buildconfig = _GetConfig(args[-1]) |
| 407 else: | 418 else: |
| 408 Warning('Missing configuration description') | 419 Warning('Missing configuration description') |
| 409 parser.print_usage() | 420 parser.print_usage() |
| 410 sys.exit(1) | 421 sys.exit(1) |
| 411 | 422 |
| 412 try: | 423 try: |
| 413 if not os.path.isdir(buildroot): | 424 _PreFlightRinse(buildroot) |
| 425 if options.clobber or not os.path.isdir(buildroot): | |
| 414 _FullCheckout(buildroot) | 426 _FullCheckout(buildroot) |
| 415 else: | 427 else: |
| 416 _PreFlightRinse(buildroot) | |
| 417 _IncrementalCheckout(buildroot) | 428 _IncrementalCheckout(buildroot) |
| 418 | 429 |
| 419 chroot_path = os.path.join(buildroot, 'chroot') | 430 chroot_path = os.path.join(buildroot, 'chroot') |
| 420 if not os.path.isdir(chroot_path): | 431 if not os.path.isdir(chroot_path): |
| 421 _MakeChroot(buildroot) | 432 _MakeChroot(buildroot) |
| 422 | 433 |
| 423 boardpath = os.path.join(chroot_path, 'build', buildconfig['board']) | 434 boardpath = os.path.join(chroot_path, 'build', buildconfig['board']) |
| 424 if not os.path.isdir(boardpath): | 435 if not os.path.isdir(boardpath): |
| 425 _SetupBoard(buildroot, board=buildconfig['board']) | 436 _SetupBoard(buildroot, board=buildconfig['board']) |
| 426 | 437 |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 439 _RunSmokeSuite(buildroot) | 450 _RunSmokeSuite(buildroot) |
| 440 | 451 |
| 441 if buildconfig['uprev']: | 452 if buildconfig['uprev']: |
| 442 # Don't push changes for developers. | 453 # Don't push changes for developers. |
| 443 if not options.debug: | 454 if not options.debug: |
| 444 if buildconfig['master']: | 455 if buildconfig['master']: |
| 445 # Master bot needs to check if the other slaves completed. | 456 # Master bot needs to check if the other slaves completed. |
| 446 if cbuildbot_comm.HaveSlavesCompleted(config): | 457 if cbuildbot_comm.HaveSlavesCompleted(config): |
| 447 _UprevPush(buildroot) | 458 _UprevPush(buildroot) |
| 448 else: | 459 else: |
| 449 # At least one of the slaves failed or we timed out. | |
| 450 _UprevCleanup(buildroot) | |
| 451 Die('CBUILDBOT - One of the slaves has failed!!!') | 460 Die('CBUILDBOT - One of the slaves has failed!!!') |
| 452 | 461 |
| 453 else: | 462 else: |
| 454 # Publish my status to the master if its expecting it. | 463 # Publish my status to the master if its expecting it. |
| 455 if buildconfig['important']: | 464 if buildconfig['important']: |
| 456 cbuildbot_comm.PublishStatus(cbuildbot_comm.STATUS_BUILD_COMPLETE) | 465 cbuildbot_comm.PublishStatus(cbuildbot_comm.STATUS_BUILD_COMPLETE) |
| 457 | 466 |
| 458 _UprevCleanup(buildroot) | |
| 459 except: | 467 except: |
| 460 # Send failure to master bot. | 468 # Send failure to master bot. |
| 461 if not buildconfig['master'] and buildconfig['important']: | 469 if not buildconfig['master'] and buildconfig['important']: |
| 462 cbuildbot_comm.PublishStatus(cbuildbot_comm.STATUS_BUILD_FAILED) | 470 cbuildbot_comm.PublishStatus(cbuildbot_comm.STATUS_BUILD_FAILED) |
| 463 | 471 |
| 464 raise | 472 raise |
| 465 | 473 |
| 466 | 474 |
| 467 if __name__ == '__main__': | 475 if __name__ == '__main__': |
| 468 main() | 476 main() |
| OLD | NEW |