| 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 """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 |
| 11 import gflags | 11 import gflags |
| 12 import os | 12 import os |
| 13 import re | 13 import re |
| 14 import shutil | 14 import shutil |
| 15 import subprocess | 15 import subprocess |
| 16 import sys | 16 import sys |
| 17 | 17 |
| 18 sys.path.append(os.path.join(os.path.dirname(__file__), 'lib')) | 18 sys.path.append(os.path.join(os.path.dirname(__file__), 'lib')) |
| 19 from cros_build_lib import Info, RunCommand, Warning, Die | 19 from cros_build_lib import Info, RunCommand, Warning, Die |
| 20 | 20 |
| 21 | 21 |
| 22 gflags.DEFINE_string('board', '', | 22 gflags.DEFINE_string('board', '', |
| 23 'Board for which the package belongs.', short_name='b') | 23 'Board for which the package belongs.', short_name='b') |
| 24 gflags.DEFINE_string('overlays', '', | 24 gflags.DEFINE_string('overlays', '', |
| 25 'Colon-separated list of overlays to modify.', | 25 'Space separated list of overlays to modify.', |
| 26 short_name='o') | 26 short_name='o') |
| 27 gflags.DEFINE_string('packages', '', | 27 gflags.DEFINE_string('packages', '', |
| 28 'Colon-separated list of packages to mark as stable.', | 28 'Space separated list of packages to mark as stable.', |
| 29 short_name='p') | 29 short_name='p') |
| 30 gflags.DEFINE_string('push_options', '', | 30 gflags.DEFINE_string('push_options', '', |
| 31 'Options to use with git-cl push using push command.') | 31 'Options to use with git-cl push using push command.') |
| 32 gflags.DEFINE_string('srcroot', '%s/trunk/src' % os.environ['HOME'], | 32 gflags.DEFINE_string('srcroot', '%s/trunk/src' % os.environ['HOME'], |
| 33 'Path to root src directory.', | 33 'Path to root src directory.', |
| 34 short_name='r') | 34 short_name='r') |
| 35 gflags.DEFINE_string('tracking_branch', 'cros/master', | 35 gflags.DEFINE_string('tracking_branch', 'cros/master', |
| 36 'Used with commit to specify branch to track against.', | 36 'Used with commit to specify branch to track against.', |
| 37 short_name='t') | 37 short_name='t') |
| 38 gflags.DEFINE_boolean('all', False, | 38 gflags.DEFINE_boolean('all', False, |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 _SimpleRunCommand('git commit -m "%s"' % description) | 238 _SimpleRunCommand('git commit -m "%s"' % description) |
| 239 # Ugh. There has got to be an easier way to push to a tracking branch | 239 # Ugh. There has got to be an easier way to push to a tracking branch |
| 240 _SimpleRunCommand('git config push.default tracking') | 240 _SimpleRunCommand('git config push.default tracking') |
| 241 _SimpleRunCommand('git push') | 241 _SimpleRunCommand('git push') |
| 242 | 242 |
| 243 | 243 |
| 244 def _SimpleRunCommand(command): | 244 def _SimpleRunCommand(command): |
| 245 """Runs a shell command and returns stdout back to caller.""" | 245 """Runs a shell command and returns stdout back to caller.""" |
| 246 _Print(' + %s' % command) | 246 _Print(' + %s' % command) |
| 247 proc_handle = subprocess.Popen(command, stdout=subprocess.PIPE, shell=True) | 247 proc_handle = subprocess.Popen(command, stdout=subprocess.PIPE, shell=True) |
| 248 stdout = proc_handle.communicate()[0] | 248 return proc_handle.communicate()[0] |
| 249 retcode = proc_handle.wait() | |
| 250 if retcode != 0: | |
| 251 raise subprocess.CalledProcessError(retcode, command, output=stdout) | |
| 252 return stdout | |
| 253 | 249 |
| 254 | 250 |
| 255 # ======================= End Global Helper Functions ======================== | 251 # ======================= End Global Helper Functions ======================== |
| 256 | 252 |
| 257 | 253 |
| 258 class _GitBranch(object): | 254 class _GitBranch(object): |
| 259 """Wrapper class for a git branch.""" | 255 """Wrapper class for a git branch.""" |
| 260 | 256 |
| 261 def __init__(self, branch_name): | 257 def __init__(self, branch_name): |
| 262 """Sets up variables but does not create the branch.""" | 258 """Sets up variables but does not create the branch.""" |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 320 elif (line.startswith('KEYWORDS=') and '~' not in line and | 316 elif (line.startswith('KEYWORDS=') and '~' not in line and |
| 321 ('amd64' in line or 'x86' in line or 'arm' in line)): | 317 ('amd64' in line or 'x86' in line or 'arm' in line)): |
| 322 self.is_stable = True | 318 self.is_stable = True |
| 323 fileinput.close() | 319 fileinput.close() |
| 324 | 320 |
| 325 def GetCommitId(self): | 321 def GetCommitId(self): |
| 326 """Get the commit id for this ebuild.""" | 322 """Get the commit id for this ebuild.""" |
| 327 | 323 |
| 328 # Grab and evaluate CROS_WORKON variables from this ebuild. | 324 # Grab and evaluate CROS_WORKON variables from this ebuild. |
| 329 unstable_ebuild = '%s-9999.ebuild' % self.ebuild_path_no_version | 325 unstable_ebuild = '%s-9999.ebuild' % self.ebuild_path_no_version |
| 330 cmd = ('export CROS_WORKON_LOCALNAME="%s" CROS_WORKON_PROJECT="%s"; ' | 326 cmd = ('CROS_WORKON_LOCALNAME="%s" CROS_WORKON_PROJECT="%s" ' |
| 331 'eval $(grep -E "^CROS_WORKON" %s) && ' | 327 'eval $(grep -E "^CROS_WORKON" %s) && ' |
| 332 'echo $CROS_WORKON_PROJECT ' | 328 'echo $CROS_WORKON_PROJECT ' |
| 333 '$CROS_WORKON_LOCALNAME/$CROS_WORKON_SUBDIR' | 329 '$CROS_WORKON_LOCALNAME/$CROS_WORKON_SUBDIR' |
| 334 % (self.pkgname, self.pkgname, unstable_ebuild)) | 330 % (self.pkgname, self.pkgname, unstable_ebuild)) |
| 335 project, subdir = _SimpleRunCommand(cmd).split() | 331 project, subdir = _SimpleRunCommand(cmd).split() |
| 336 | 332 |
| 337 # Calculate srcdir. | 333 # Calculate srcdir. |
| 338 srcroot = gflags.FLAGS.srcroot | 334 srcroot = gflags.FLAGS.srcroot |
| 339 if self.category == 'chromeos-base': | 335 if self.category == 'chromeos-base': |
| 340 dir = 'platform' | 336 dir = 'platform' |
| 341 else: | 337 else: |
| 342 dir = 'third_party' | 338 dir = 'third_party' |
| 343 srcdir = os.path.join(srcroot, dir, subdir) | 339 srcdir = os.path.join(srcroot, dir, subdir) |
| 344 | 340 |
| 345 # TODO(anush): This hack is only necessary because the kernel ebuild has | 341 # TODO(anush): This hack is only necessary because the kernel ebuild has |
| 346 # 'if' statements, so we can't grab the CROS_WORKON_LOCALNAME properly. | 342 # 'if' statements, so we can't grab the CROS_WORKON_LOCALNAME properly. |
| 347 # We should clean up the kernel ebuild and remove this hack. | 343 # We should clean up the kernel ebuild and remove this hack. |
| 348 if not os.path.isdir(srcdir) and subdir == 'kernel/': | 344 if not os.path.exists(srcdir) and subdir == 'kernel/': |
| 349 srcdir = os.path.join(srcroot, 'third_party/kernel/files') | 345 srcdir = os.path.join(srcroot, 'third_party/kernel/files') |
| 350 | 346 |
| 351 if not os.path.isdir(srcdir): | 347 if not os.path.exists(srcdir): |
| 352 Die('Cannot find commit id for %s' % self.ebuild_path) | 348 Die('Cannot find commit id for %s' % self.ebuild_path) |
| 353 | 349 |
| 354 # Verify that we're grabbing the commit id from the right project name. | 350 # Verify that we're grabbing the commit id from the right project name. |
| 355 # NOTE: chromeos-kernel has the wrong project name, so it fails this | 351 # NOTE: chromeos-kernel has the wrong project name, so it fails this |
| 356 # check. | 352 # check. |
| 357 # TODO(davidjames): Fix the project name in the chromeos-kernel ebuild. | 353 # TODO(davidjames): Fix the project name in the chromeos-kernel ebuild. |
| 358 cmd = 'cd %s && git config --get remote.cros.projectname' % srcdir | 354 cmd = 'cd %s && git config --get remote.cros.projectname' % srcdir |
| 359 actual_project = _SimpleRunCommand(cmd).rstrip() | 355 actual_project = _SimpleRunCommand(cmd).rstrip() |
| 360 if project not in (actual_project, 'chromeos-kernel'): | 356 if project not in (actual_project, 'chromeos-kernel'): |
| 361 Die('Project name mismatch for %s (%s != %s)' % (unstable_ebuild, project, | 357 Die('Project name mismatch for %s (%s != %s)' % (unstable_ebuild, project, |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 484 def main(argv): | 480 def main(argv): |
| 485 try: | 481 try: |
| 486 argv = gflags.FLAGS(argv) | 482 argv = gflags.FLAGS(argv) |
| 487 if len(argv) != 2: | 483 if len(argv) != 2: |
| 488 _PrintUsageAndDie('Must specify a valid command') | 484 _PrintUsageAndDie('Must specify a valid command') |
| 489 else: | 485 else: |
| 490 command = argv[1] | 486 command = argv[1] |
| 491 except gflags.FlagsError, e : | 487 except gflags.FlagsError, e : |
| 492 _PrintUsageAndDie(str(e)) | 488 _PrintUsageAndDie(str(e)) |
| 493 | 489 |
| 494 package_list = gflags.FLAGS.packages.split(':') | 490 package_list = gflags.FLAGS.packages.split() |
| 495 _CheckSaneArguments(package_list, command) | 491 _CheckSaneArguments(package_list, command) |
| 496 if gflags.FLAGS.overlays: | 492 if gflags.FLAGS.overlays: |
| 497 overlays = {} | 493 overlays = dict((path, []) for path in gflags.FLAGS.overlays.split()) |
| 498 for path in gflags.FLAGS.overlays.split(':'): | |
| 499 if not os.path.isdir(path): | |
| 500 Die('Cannot find overlay: %s' % path) | |
| 501 overlays[path] = [] | |
| 502 else: | 494 else: |
| 503 Warning('Missing --overlays argument') | |
| 504 overlays = { | 495 overlays = { |
| 505 '%s/private-overlays/chromeos-overlay' % gflags.FLAGS.srcroot: [], | 496 '%s/private-overlays/chromeos-overlay' % gflags.FLAGS.srcroot: [], |
| 506 '%s/third_party/chromiumos-overlay' % gflags.FLAGS.srcroot: [] | 497 '%s/third_party/chromiumos-overlay' % gflags.FLAGS.srcroot: [] |
| 507 } | 498 } |
| 508 | 499 |
| 509 if command == 'commit': | 500 if command == 'commit': |
| 510 _BuildEBuildDictionary(overlays, gflags.FLAGS.all, package_list) | 501 _BuildEBuildDictionary(overlays, gflags.FLAGS.all, package_list) |
| 511 | 502 |
| 512 for overlay, ebuilds in overlays.items(): | 503 for overlay, ebuilds in overlays.items(): |
| 513 if not os.path.isdir(overlay): | 504 if not os.path.exists(overlay): |
| 514 Warning("Skipping %s" % overlay) | 505 Warning("Skipping %s" % overlay) |
| 515 continue | 506 continue |
| 516 | |
| 517 # TODO(davidjames): Currently, all code that interacts with git depends on | |
| 518 # the cwd being set to the overlay directory. We should instead pass in | |
| 519 # this parameter so that we don't need to modify the cwd globally. | |
| 520 os.chdir(overlay) | 507 os.chdir(overlay) |
| 521 | 508 |
| 522 if command == 'clean': | 509 if command == 'clean': |
| 523 _Clean() | 510 _Clean() |
| 524 elif command == 'push': | 511 elif command == 'push': |
| 525 _PushChange() | 512 _PushChange() |
| 526 elif command == 'commit' and ebuilds: | 513 elif command == 'commit' and ebuilds: |
| 527 work_branch = _GitBranch(_STABLE_BRANCH_NAME) | 514 work_branch = _GitBranch(_STABLE_BRANCH_NAME) |
| 528 work_branch.CreateBranch() | 515 work_branch.CreateBranch() |
| 529 if not work_branch.Exists(): | 516 if not work_branch.Exists(): |
| (...skipping 18 matching lines...) Expand all Loading... |
| 548 raise | 535 raise |
| 549 | 536 |
| 550 if revved_packages: | 537 if revved_packages: |
| 551 _CleanStalePackages(gflags.FLAGS.board, revved_packages) | 538 _CleanStalePackages(gflags.FLAGS.board, revved_packages) |
| 552 else: | 539 else: |
| 553 work_branch.Delete() | 540 work_branch.Delete() |
| 554 | 541 |
| 555 | 542 |
| 556 if __name__ == '__main__': | 543 if __name__ == '__main__': |
| 557 main(sys.argv) | 544 main(sys.argv) |
| OLD | NEW |