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

Side by Side Diff: cros_mark_as_stable.py

Issue 5513012: Be more selective about what packages we remove so that we can detect conflicts. (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/crosutils.git@master
Patch Set: Re-upload 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 | cros_mark_as_stable_unittest.py » ('j') | no next file with comments »
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 """This module uprevs a given package's ebuild to the next revision.""" 7 """This module uprevs a given package's ebuild to the next revision."""
8 8
9 9
10 import fileinput 10 import fileinput
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 71
72 # ======================= Global Helper Functions ======================== 72 # ======================= Global Helper Functions ========================
73 73
74 74
75 def _Print(message): 75 def _Print(message):
76 """Verbose print function.""" 76 """Verbose print function."""
77 if gflags.FLAGS.verbose: 77 if gflags.FLAGS.verbose:
78 Info(message) 78 Info(message)
79 79
80 80
81 def _CleanStalePackages(board, package_array): 81 def _CleanStalePackages(board, package_atoms):
82 """Cleans up stale package info from a previous build.""" 82 """Cleans up stale package info from a previous build."""
83 Info('Cleaning up stale packages %s.' % package_array) 83 Info('Cleaning up stale packages %s.' % package_atoms)
84 unmerge_board_cmd = ['emerge-%s' % board, '--unmerge'] 84 unmerge_board_cmd = ['emerge-%s' % board, '--unmerge']
85 unmerge_board_cmd.extend(package_array) 85 unmerge_board_cmd.extend(package_atoms)
86 RunCommand(unmerge_board_cmd) 86 RunCommand(unmerge_board_cmd)
87 87
88 unmerge_host_cmd = ['sudo', 'emerge', '--unmerge'] 88 unmerge_host_cmd = ['sudo', 'emerge', '--unmerge']
89 unmerge_host_cmd.extend(package_array) 89 unmerge_host_cmd.extend(package_atoms)
90 RunCommand(unmerge_host_cmd) 90 RunCommand(unmerge_host_cmd)
91 91
92 RunCommand(['eclean-%s' % board, '-d', 'packages'], redirect_stderr=True) 92 RunCommand(['eclean-%s' % board, '-d', 'packages'], redirect_stderr=True)
93 RunCommand(['sudo', 'eclean', '-d', 'packages'], redirect_stderr=True) 93 RunCommand(['sudo', 'eclean', '-d', 'packages'], redirect_stderr=True)
94 94
95 95
96 def _FindUprevCandidates(files): 96 def _FindUprevCandidates(files):
97 """Return a list of uprev candidates from specified list of files. 97 """Return a list of uprev candidates from specified list of files.
98 98
99 Usually an uprev candidate is a the stable ebuild in a cros_workon directory. 99 Usually an uprev candidate is a the stable ebuild in a cros_workon directory.
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
312 _SimpleRunCommand(delete_cmd) 312 _SimpleRunCommand(delete_cmd)
313 313
314 314
315 class EBuild(object): 315 class EBuild(object):
316 """Wrapper class for information about an ebuild.""" 316 """Wrapper class for information about an ebuild."""
317 317
318 def __init__(self, path): 318 def __init__(self, path):
319 """Sets up data about an ebuild from its path.""" 319 """Sets up data about an ebuild from its path."""
320 from portage.versions import pkgsplit 320 from portage.versions import pkgsplit
321 unused_path, self.category, self.pkgname, filename = path.rsplit('/', 3) 321 unused_path, self.category, self.pkgname, filename = path.rsplit('/', 3)
322 unused_pkgname, version_no_rev, rev = pkgsplit( 322 unused_pkgname, self.version_no_rev, rev = pkgsplit(
323 filename.replace('.ebuild', '')) 323 filename.replace('.ebuild', ''))
324 324
325 self.ebuild_path_no_version = os.path.join( 325 self.ebuild_path_no_version = os.path.join(
326 os.path.dirname(path), self.pkgname) 326 os.path.dirname(path), self.pkgname)
327 self.ebuild_path_no_revision = '%s-%s' % (self.ebuild_path_no_version, 327 self.ebuild_path_no_revision = '%s-%s' % (self.ebuild_path_no_version,
328 version_no_rev) 328 self.version_no_rev)
329 self.current_revision = int(rev.replace('r', '')) 329 self.current_revision = int(rev.replace('r', ''))
330 self.version = '%s-%s' % (version_no_rev, rev) 330 self.version = '%s-%s' % (self.version_no_rev, rev)
331 self.package = '%s/%s' % (self.category, self.pkgname) 331 self.package = '%s/%s' % (self.category, self.pkgname)
332 self.ebuild_path = path 332 self.ebuild_path = path
333 333
334 self.is_workon = False 334 self.is_workon = False
335 self.is_stable = False 335 self.is_stable = False
336 336
337 for line in fileinput.input(path): 337 for line in fileinput.input(path):
338 if line.startswith('inherit ') and 'cros-workon' in line: 338 if line.startswith('inherit ') and 'cros-workon' in line:
339 self.is_workon = True 339 self.is_workon = True
340 elif (line.startswith('KEYWORDS=') and '~' not in line and 340 elif (line.startswith('KEYWORDS=') and '~' not in line and
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
447 commit_id: String corresponding to the commit hash of the developer 447 commit_id: String corresponding to the commit hash of the developer
448 package to rev. 448 package to rev.
449 redirect_file: Optional file to write the new ebuild. By default 449 redirect_file: Optional file to write the new ebuild. By default
450 it is written using the standard rev'ing logic. This file must be 450 it is written using the standard rev'ing logic. This file must be
451 opened and closed by the caller. 451 opened and closed by the caller.
452 452
453 Raises: 453 Raises:
454 OSError: Error occurred while creating a new ebuild. 454 OSError: Error occurred while creating a new ebuild.
455 IOError: Error occurred while writing to the new revved ebuild file. 455 IOError: Error occurred while writing to the new revved ebuild file.
456 Returns: 456 Returns:
457 True if the revved package is different than the old ebuild. 457 If the revved package is different than the old ebuild, return the full
458 revved package name, including the version number. Otherwise, return None.
458 """ 459 """
459 if self._ebuild.is_stable: 460 if self._ebuild.is_stable:
460 new_stable_ebuild_path = '%s-r%d.ebuild' % ( 461 stable_version_no_rev = self._ebuild.version_no_rev
461 self._ebuild.ebuild_path_no_revision,
462 self._ebuild.current_revision + 1)
463 else: 462 else:
464 # If given unstable ebuild, use 0.0.1 rather than 9999. 463 # If given unstable ebuild, use 0.0.1 rather than 9999.
465 new_stable_ebuild_path = '%s-0.0.1-r%d.ebuild' % ( 464 stable_version_no_rev = '0.0.1'
466 self._ebuild.ebuild_path_no_version, 465
467 self._ebuild.current_revision + 1) 466 new_version = '%s-r%d' % (stable_version_no_rev,
467 self._ebuild.current_revision + 1)
468 new_stable_ebuild_path = '%s-%s.ebuild' % (
469 self._ebuild.ebuild_path_no_version, new_version)
468 470
469 _Print('Creating new stable ebuild %s' % new_stable_ebuild_path) 471 _Print('Creating new stable ebuild %s' % new_stable_ebuild_path)
470 unstable_ebuild_path = ('%s-9999.ebuild' % 472 unstable_ebuild_path = ('%s-9999.ebuild' %
471 self._ebuild.ebuild_path_no_version) 473 self._ebuild.ebuild_path_no_version)
472 if not os.path.exists(unstable_ebuild_path): 474 if not os.path.exists(unstable_ebuild_path):
473 Die('Missing unstable ebuild: %s' % unstable_ebuild_path) 475 Die('Missing unstable ebuild: %s' % unstable_ebuild_path)
474 476
475 self.MarkAsStable(unstable_ebuild_path, new_stable_ebuild_path, 477 self.MarkAsStable(unstable_ebuild_path, new_stable_ebuild_path,
476 'CROS_WORKON_COMMIT', commit_id, redirect_file) 478 'CROS_WORKON_COMMIT', commit_id, redirect_file)
477 479
478 old_ebuild_path = self._ebuild.ebuild_path 480 old_ebuild_path = self._ebuild.ebuild_path
479 diff_cmd = ['diff', '-Bu', old_ebuild_path, new_stable_ebuild_path] 481 diff_cmd = ['diff', '-Bu', old_ebuild_path, new_stable_ebuild_path]
480 if 0 == RunCommand(diff_cmd, exit_code=True, redirect_stdout=True, 482 if 0 == RunCommand(diff_cmd, exit_code=True, redirect_stdout=True,
481 redirect_stderr=True, print_cmd=gflags.FLAGS.verbose): 483 redirect_stderr=True, print_cmd=gflags.FLAGS.verbose):
482 os.unlink(new_stable_ebuild_path) 484 os.unlink(new_stable_ebuild_path)
483 return False 485 return None
484 else: 486 else:
485 _Print('Adding new stable ebuild to git') 487 _Print('Adding new stable ebuild to git')
486 _SimpleRunCommand('git add %s' % new_stable_ebuild_path) 488 _SimpleRunCommand('git add %s' % new_stable_ebuild_path)
487 489
488 if self._ebuild.is_stable: 490 if self._ebuild.is_stable:
489 _Print('Removing old ebuild from git') 491 _Print('Removing old ebuild from git')
490 _SimpleRunCommand('git rm %s' % old_ebuild_path) 492 _SimpleRunCommand('git rm %s' % old_ebuild_path)
491 493
492 return True 494 return '%s-%s' % (self._ebuild.package, new_version)
493 495
494 @classmethod 496 @classmethod
495 def CommitChange(cls, message): 497 def CommitChange(cls, message):
496 """Commits current changes in git locally with given commit message. 498 """Commits current changes in git locally with given commit message.
497 499
498 Args: 500 Args:
499 message: the commit string to write when committing to git. 501 message: the commit string to write when committing to git.
500 502
501 Raises: 503 Raises:
502 OSError: Error occurred while committing. 504 OSError: Error occurred while committing.
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
549 elif command == 'push': 551 elif command == 'push':
550 PushChange(STABLE_BRANCH_NAME, gflags.FLAGS.tracking_branch) 552 PushChange(STABLE_BRANCH_NAME, gflags.FLAGS.tracking_branch)
551 elif command == 'commit' and ebuilds: 553 elif command == 'commit' and ebuilds:
552 work_branch = GitBranch(STABLE_BRANCH_NAME, gflags.FLAGS.tracking_branch) 554 work_branch = GitBranch(STABLE_BRANCH_NAME, gflags.FLAGS.tracking_branch)
553 work_branch.CreateBranch() 555 work_branch.CreateBranch()
554 if not work_branch.Exists(): 556 if not work_branch.Exists():
555 Die('Unable to create stabilizing branch in %s' % overlay) 557 Die('Unable to create stabilizing branch in %s' % overlay)
556 558
557 # Contains the array of packages we actually revved. 559 # Contains the array of packages we actually revved.
558 revved_packages = [] 560 revved_packages = []
561 new_package_atoms = []
559 for ebuild in ebuilds: 562 for ebuild in ebuilds:
560 try: 563 try:
561 _Print('Working on %s' % ebuild.package) 564 _Print('Working on %s' % ebuild.package)
562 worker = EBuildStableMarker(ebuild) 565 worker = EBuildStableMarker(ebuild)
563 commit_id = ebuild.GetCommitId() 566 commit_id = ebuild.GetCommitId()
564 if worker.RevWorkOnEBuild(commit_id): 567 new_package = worker.RevWorkOnEBuild(commit_id)
568 if new_package:
565 message = _GIT_COMMIT_MESSAGE % (ebuild.package, commit_id) 569 message = _GIT_COMMIT_MESSAGE % (ebuild.package, commit_id)
566 worker.CommitChange(message) 570 worker.CommitChange(message)
567 revved_packages.append(ebuild.package) 571 revved_packages.append(ebuild.package)
568 572 new_package_atoms.append('=%s' % new_package)
569 except (OSError, IOError): 573 except (OSError, IOError):
570 Warning('Cannot rev %s\n' % ebuild.package, 574 Warning('Cannot rev %s\n' % ebuild.package,
571 'Note you will have to go into %s ' 575 'Note you will have to go into %s '
572 'and reset the git repo yourself.' % overlay) 576 'and reset the git repo yourself.' % overlay)
573 raise 577 raise
574 578
575 if revved_packages: 579 if revved_packages:
576 _CleanStalePackages(gflags.FLAGS.board, revved_packages) 580 _CleanStalePackages(gflags.FLAGS.board, new_package_atoms)
577 if gflags.FLAGS.drop_file: 581 if gflags.FLAGS.drop_file:
578 fh = open(gflags.FLAGS.drop_file, 'w') 582 fh = open(gflags.FLAGS.drop_file, 'w')
579 fh.write(' '.join(revved_packages)) 583 fh.write(' '.join(revved_packages))
580 fh.close() 584 fh.close()
581 else: 585 else:
582 work_branch.Delete() 586 work_branch.Delete()
583 587
584 588
585 if __name__ == '__main__': 589 if __name__ == '__main__':
586 main(sys.argv) 590 main(sys.argv)
OLDNEW
« no previous file with comments | « no previous file | cros_mark_as_stable_unittest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698