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 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
170 repo_name = revision_tuple[0].replace('.git', '') | 170 repo_name = revision_tuple[0].replace('.git', '') |
171 # Might not have entry if no matching ebuild. | 171 # Might not have entry if no matching ebuild. |
172 if repo_dictionary.has_key(repo_name): | 172 if repo_dictionary.has_key(repo_name): |
173 # May be many corresponding packages to a given git repo e.g. kernel). | 173 # May be many corresponding packages to a given git repo e.g. kernel). |
174 for package in repo_dictionary[repo_name]: | 174 for package in repo_dictionary[repo_name]: |
175 revisions[package] = revision_tuple[1] | 175 revisions[package] = revision_tuple[1] |
176 | 176 |
177 return revisions.items() | 177 return revisions.items() |
178 | 178 |
179 | 179 |
180 def _UprevFromRevisionList(buildroot, revision_list): | 180 def _UprevFromRevisionList(buildroot, tracking_branch, revision_list): |
181 """Uprevs based on revision list.""" | 181 """Uprevs based on revision list.""" |
182 if not revision_list: | 182 if not revision_list: |
183 Info('No packages found to uprev') | 183 Info('No packages found to uprev') |
184 return | 184 return |
185 | 185 |
186 package_str = '' | 186 package_str = '' |
187 for package, revision in revision_list: | 187 for package, revision in revision_list: |
188 package_str += package + ' ' | 188 package_str += package + ' ' |
189 | 189 |
190 package_str = package_str.strip() | 190 package_str = package_str.strip() |
191 | 191 |
192 cwd = os.path.join(buildroot, 'src', 'scripts') | 192 cwd = os.path.join(buildroot, 'src', 'scripts') |
193 RunCommand(['./cros_mark_as_stable', | 193 RunCommand(['./cros_mark_as_stable', |
194 '--tracking_branch="cros/master"', | 194 '--tracking_branch="%s"' % tracking_branch, |
195 '--packages="%s"' % package_str, | 195 '--packages="%s"' % package_str, |
196 'commit'], | 196 'commit'], |
197 cwd=cwd, enter_chroot=True) | 197 cwd=cwd, enter_chroot=True) |
198 | 198 |
199 | 199 |
200 def _UprevAllPackages(buildroot): | 200 def _UprevAllPackages(buildroot, tracking_branch): |
201 """Uprevs all packages that have been updated since last uprev.""" | 201 """Uprevs all packages that have been updated since last uprev.""" |
202 cwd = os.path.join(buildroot, 'src', 'scripts') | 202 cwd = os.path.join(buildroot, 'src', 'scripts') |
203 RunCommand(['./cros_mark_as_stable', '--all', | 203 RunCommand(['./cros_mark_as_stable', '--all', |
204 '--tracking_branch="cros/master"', 'commit'], | 204 '--tracking_branch="%s"' % tracking_branch, 'commit'], |
205 cwd=cwd, enter_chroot=True) | 205 cwd=cwd, enter_chroot=True) |
206 | 206 |
207 | 207 |
208 def _GetVMConstants(buildroot): | 208 def _GetVMConstants(buildroot): |
209 """Returns minimum (vdisk_size, statefulfs_size) recommended for VM's.""" | 209 """Returns minimum (vdisk_size, statefulfs_size) recommended for VM's.""" |
210 cwd = os.path.join(buildroot, 'src', 'scripts', 'lib') | 210 cwd = os.path.join(buildroot, 'src', 'scripts', 'lib') |
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) |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
246 # =========================== Main Commands =================================== | 246 # =========================== Main Commands =================================== |
247 | 247 |
248 | 248 |
249 def _PreFlightRinse(buildroot): | 249 def _PreFlightRinse(buildroot): |
250 """Cleans up any leftover state from previous runs.""" | 250 """Cleans up any leftover state from previous runs.""" |
251 _GitCleanup(buildroot) | 251 _GitCleanup(buildroot) |
252 _CleanUpMountPoints(buildroot) | 252 _CleanUpMountPoints(buildroot) |
253 RunCommand(['sudo', 'killall', 'kvm'], error_ok=True) | 253 RunCommand(['sudo', 'killall', 'kvm'], error_ok=True) |
254 | 254 |
255 | 255 |
256 def _FullCheckout(buildroot, rw_checkout=True, retries=_DEFAULT_RETRIES): | 256 def _FullCheckout(buildroot, tracking_branch, rw_checkout=True, |
257 retries=_DEFAULT_RETRIES, | |
258 url='http://git.chromium.org/git/manifest'): | |
257 """Performs a full checkout and clobbers any previous checkouts.""" | 259 """Performs a full checkout and clobbers any previous checkouts.""" |
258 RunCommand(['sudo', 'rm', '-rf', buildroot]) | 260 RunCommand(['sudo', 'rm', '-rf', buildroot]) |
259 MakeDir(buildroot, parents=True) | 261 MakeDir(buildroot, parents=True) |
260 RunCommand(['repo', 'init', '-u', 'http://git.chromium.org/git/manifest'], | 262 branch = tracking_branch.split('/'); |
sosa
2010/10/22 06:20:06
Nit: may wanna consider just using os.path.basenam
| |
261 cwd=buildroot, input='\n\ny\n') | 263 RunCommand(['repo', 'init', '-u', |
264 url, '-b', | |
265 '%s' % branch[-1]], cwd=buildroot, input='\n\ny\n') | |
262 RepoSync(buildroot, rw_checkout, retries) | 266 RepoSync(buildroot, rw_checkout, retries) |
263 | 267 |
264 | 268 |
265 def _IncrementalCheckout(buildroot, rw_checkout=True, | 269 def _IncrementalCheckout(buildroot, rw_checkout=True, |
266 retries=_DEFAULT_RETRIES): | 270 retries=_DEFAULT_RETRIES): |
267 """Performs a checkout without clobbering previous checkout.""" | 271 """Performs a checkout without clobbering previous checkout.""" |
268 RepoSync(buildroot, rw_checkout, retries) | 272 RepoSync(buildroot, rw_checkout, retries) |
269 | 273 |
270 | 274 |
271 def _MakeChroot(buildroot): | 275 def _MakeChroot(buildroot): |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
319 | 323 |
320 | 324 |
321 def _RunSmokeSuite(buildroot): | 325 def _RunSmokeSuite(buildroot): |
322 cwd = os.path.join(buildroot, 'src', 'scripts') | 326 cwd = os.path.join(buildroot, 'src', 'scripts') |
323 RunCommand(['bin/cros_run_vm_test', | 327 RunCommand(['bin/cros_run_vm_test', |
324 '--no_graphics', | 328 '--no_graphics', |
325 '--test_case=suite_Smoke', | 329 '--test_case=suite_Smoke', |
326 ], cwd=cwd, error_ok=False) | 330 ], cwd=cwd, error_ok=False) |
327 | 331 |
328 | 332 |
329 def _UprevPackages(buildroot, revisionfile, board): | 333 def _UprevPackages(buildroot, tracking_branch, revisionfile, board): |
330 """Uprevs a package based on given revisionfile. | 334 """Uprevs a package based on given revisionfile. |
331 | 335 |
332 If revisionfile is set to None or does not resolve to an actual file, this | 336 If revisionfile is set to None or does not resolve to an actual file, this |
333 function will uprev all packages. | 337 function will uprev all packages. |
334 | 338 |
335 Keyword arguments: | 339 Keyword arguments: |
336 revisionfile -- string specifying a file that contains a list of revisions to | 340 revisionfile -- string specifying a file that contains a list of revisions to |
337 uprev. | 341 uprev. |
338 """ | 342 """ |
339 # Purposefully set to None as it means Force Build was pressed. | 343 # Purposefully set to None as it means Force Build was pressed. |
340 revisions = 'None' | 344 revisions = 'None' |
341 if (revisionfile): | 345 if (revisionfile): |
342 try: | 346 try: |
343 rev_file = open(revisionfile) | 347 rev_file = open(revisionfile) |
344 revisions = rev_file.read() | 348 revisions = rev_file.read() |
345 rev_file.close() | 349 rev_file.close() |
346 except Exception, e: | 350 except Exception, e: |
347 Warning('Error reading %s, revving all' % revisionfile) | 351 Warning('Error reading %s, revving all' % revisionfile) |
348 revisions = 'None' | 352 revisions = 'None' |
349 | 353 |
350 revisions = revisions.strip() | 354 revisions = revisions.strip() |
351 | 355 |
352 # TODO(sosa): Un-comment once we close individual trees. | 356 # TODO(sosa): Un-comment once we close individual trees. |
353 # revisions == "None" indicates a Force Build. | 357 # revisions == "None" indicates a Force Build. |
354 #if revisions != 'None': | 358 #if revisions != 'None': |
355 # print >> sys.stderr, 'CBUILDBOT Revision list found %s' % revisions | 359 # print >> sys.stderr, 'CBUILDBOT Revision list found %s' % revisions |
356 # revision_list = _ParseRevisionString(revisions, | 360 # revision_list = _ParseRevisionString(revisions, |
357 # _CreateRepoDictionary(buildroot, board)) | 361 # _CreateRepoDictionary(buildroot, board)) |
358 # _UprevFromRevisionList(buildroot, revision_list) | 362 # _UprevFromRevisionList(buildroot, tracking_branch, revision_list) |
359 #else: | 363 #else: |
360 Info('CBUILDBOT Revving all') | 364 Info('CBUILDBOT Revving all') |
361 _UprevAllPackages(buildroot) | 365 _UprevAllPackages(buildroot, tracking_branch) |
362 | 366 |
363 | 367 |
364 def _UprevPush(buildroot): | 368 def _UprevPush(buildroot, tracking_branch): |
365 """Pushes uprev changes to the main line.""" | 369 """Pushes uprev changes to the main line.""" |
366 cwd = os.path.join(buildroot, 'src', 'scripts') | 370 cwd = os.path.join(buildroot, 'src', 'scripts') |
367 RunCommand(['./cros_mark_as_stable', '--srcroot=..', | 371 RunCommand(['./cros_mark_as_stable', '--srcroot=..', |
368 '--tracking_branch="cros/master"', | 372 '--tracking_branch="%s"' % tracking_branch, |
369 '--push_options="--bypass-hooks -f"', 'push'], | 373 '--push_options="--bypass-hooks -f"', 'push'], |
370 cwd=cwd) | 374 cwd=cwd) |
371 | 375 |
372 | 376 |
373 def _GetConfig(config_name): | 377 def _GetConfig(config_name): |
374 """Gets the configuration for the build""" | 378 """Gets the configuration for the build""" |
375 default = config['default'] | 379 default = config['default'] |
376 buildconfig = {} | 380 buildconfig = {} |
377 if not config.has_key(config_name): | 381 if not config.has_key(config_name): |
378 Warning('Non-existent configuration specified.') | 382 Warning('Non-existent configuration specified.') |
(...skipping 22 matching lines...) Expand all Loading... | |
401 parser.add_option('-n', '--buildnumber', | 405 parser.add_option('-n', '--buildnumber', |
402 help='build number', type='int', default=0) | 406 help='build number', type='int', default=0) |
403 parser.add_option('-f', '--revisionfile', | 407 parser.add_option('-f', '--revisionfile', |
404 help='file where new revisions are stored') | 408 help='file where new revisions are stored') |
405 parser.add_option('--clobber', action='store_true', dest='clobber', | 409 parser.add_option('--clobber', action='store_true', dest='clobber', |
406 default=False, | 410 default=False, |
407 help='Clobbers an old checkout before syncing') | 411 help='Clobbers an old checkout before syncing') |
408 parser.add_option('--debug', action='store_true', dest='debug', | 412 parser.add_option('--debug', action='store_true', dest='debug', |
409 default=False, | 413 default=False, |
410 help='Override some options to run as a developer.') | 414 help='Override some options to run as a developer.') |
415 parser.add_option('-t', '--tracking-branch', dest='tracking_branch', | |
416 default='cros/master', help='Run the buildbot on a branch') | |
417 parser.add_option('-u', '--url', dest='url', | |
418 default='http://git.chromium.org/git/manifest', | |
419 help='Run the buildbot on internal manifest') | |
420 | |
411 (options, args) = parser.parse_args() | 421 (options, args) = parser.parse_args() |
412 | 422 |
413 buildroot = options.buildroot | 423 buildroot = options.buildroot |
414 revisionfile = options.revisionfile | 424 revisionfile = options.revisionfile |
425 tracking_branch = options.tracking_branch | |
415 | 426 |
416 if len(args) >= 1: | 427 if len(args) >= 1: |
417 buildconfig = _GetConfig(args[-1]) | 428 buildconfig = _GetConfig(args[-1]) |
418 else: | 429 else: |
419 Warning('Missing configuration description') | 430 Warning('Missing configuration description') |
420 parser.print_usage() | 431 parser.print_usage() |
421 sys.exit(1) | 432 sys.exit(1) |
422 | 433 |
423 try: | 434 try: |
424 _PreFlightRinse(buildroot) | 435 _PreFlightRinse(buildroot) |
425 if options.clobber or not os.path.isdir(buildroot): | 436 if options.clobber or not os.path.isdir(buildroot): |
426 _FullCheckout(buildroot) | 437 _FullCheckout(buildroot, tracking_branch, url=options.url) |
427 else: | 438 else: |
428 _IncrementalCheckout(buildroot) | 439 _IncrementalCheckout(buildroot) |
429 | 440 |
430 chroot_path = os.path.join(buildroot, 'chroot') | 441 chroot_path = os.path.join(buildroot, 'chroot') |
431 if not os.path.isdir(chroot_path): | 442 if not os.path.isdir(chroot_path): |
432 _MakeChroot(buildroot) | 443 _MakeChroot(buildroot) |
433 | 444 |
434 boardpath = os.path.join(chroot_path, 'build', buildconfig['board']) | 445 boardpath = os.path.join(chroot_path, 'build', buildconfig['board']) |
435 if not os.path.isdir(boardpath): | 446 if not os.path.isdir(boardpath): |
436 _SetupBoard(buildroot, board=buildconfig['board']) | 447 _SetupBoard(buildroot, board=buildconfig['board']) |
437 | 448 |
438 if buildconfig['uprev']: | 449 if buildconfig['uprev']: |
439 _UprevPackages(buildroot, revisionfile, board=buildconfig['board']) | 450 _UprevPackages(buildroot, tracking_branch, revisionfile, |
451 board=buildconfig['board']) | |
440 | 452 |
441 _EnableLocalAccount(buildroot) | 453 _EnableLocalAccount(buildroot) |
442 _Build(buildroot) | 454 _Build(buildroot) |
443 if buildconfig['unittests']: | 455 if buildconfig['unittests']: |
444 _RunUnitTests(buildroot) | 456 _RunUnitTests(buildroot) |
445 | 457 |
446 _BuildImage(buildroot) | 458 _BuildImage(buildroot) |
447 | 459 |
448 if buildconfig['smoke_bvt']: | 460 if buildconfig['smoke_bvt']: |
449 _BuildVMImageForTesting(buildroot) | 461 _BuildVMImageForTesting(buildroot) |
450 _RunSmokeSuite(buildroot) | 462 _RunSmokeSuite(buildroot) |
451 | 463 |
452 if buildconfig['uprev']: | 464 if buildconfig['uprev']: |
453 # Don't push changes for developers. | 465 # Don't push changes for developers. |
454 if not options.debug: | 466 if not options.debug: |
455 if buildconfig['master']: | 467 if buildconfig['master']: |
456 # Master bot needs to check if the other slaves completed. | 468 # Master bot needs to check if the other slaves completed. |
457 if cbuildbot_comm.HaveSlavesCompleted(config): | 469 if cbuildbot_comm.HaveSlavesCompleted(config): |
458 _UprevPush(buildroot) | 470 _UprevPush(buildroot, tracking_branch) |
459 else: | 471 else: |
460 Die('CBUILDBOT - One of the slaves has failed!!!') | 472 Die('CBUILDBOT - One of the slaves has failed!!!') |
461 | 473 |
462 else: | 474 else: |
463 # Publish my status to the master if its expecting it. | 475 # Publish my status to the master if its expecting it. |
464 if buildconfig['important']: | 476 if buildconfig['important']: |
465 cbuildbot_comm.PublishStatus(cbuildbot_comm.STATUS_BUILD_COMPLETE) | 477 cbuildbot_comm.PublishStatus(cbuildbot_comm.STATUS_BUILD_COMPLETE) |
466 | 478 |
467 except: | 479 except: |
468 # Send failure to master bot. | 480 # Send failure to master bot. |
469 if not buildconfig['master'] and buildconfig['important']: | 481 if not buildconfig['master'] and buildconfig['important']: |
470 cbuildbot_comm.PublishStatus(cbuildbot_comm.STATUS_BUILD_FAILED) | 482 cbuildbot_comm.PublishStatus(cbuildbot_comm.STATUS_BUILD_FAILED) |
471 | 483 |
472 raise | 484 raise |
473 | 485 |
474 | 486 |
475 if __name__ == '__main__': | 487 if __name__ == '__main__': |
476 main() | 488 main() |
OLD | NEW |