Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 1 | #!/usr/bin/python |
| 2 | |
Mike Frysinger | 110750a | 2012-03-26 14:19:20 -0400 | [diff] [blame] | 3 | # Copyright (c) 2012 The Chromium OS Authors. All rights reserved. |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 4 | # Use of this source code is governed by a BSD-style license that can be |
| 5 | # found in the LICENSE file. |
| 6 | |
| 7 | """This module uprevs a given package's ebuild to the next revision.""" |
| 8 | |
Mike Frysinger | 110750a | 2012-03-26 14:19:20 -0400 | [diff] [blame] | 9 | import multiprocessing |
Chris Sosa | 62ad852 | 2011-03-08 17:46:17 -0800 | [diff] [blame] | 10 | import optparse |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 11 | import os |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 12 | import sys |
| 13 | |
Mike Frysinger | 6cb624a | 2012-05-24 18:17:38 -0400 | [diff] [blame^] | 14 | from chromite.buildbot import constants |
Mike Frysinger | b7ab9b8 | 2012-04-04 16:22:43 -0400 | [diff] [blame] | 15 | from chromite.buildbot import cbuildbot_background as background |
David James | 6600946 | 2012-03-25 10:08:38 -0700 | [diff] [blame] | 16 | from chromite.buildbot import portage_utilities |
Chris Sosa | c13bba5 | 2011-05-24 15:14:09 -0700 | [diff] [blame] | 17 | from chromite.lib import cros_build_lib |
| 18 | |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 19 | |
Chris Sosa | 62ad852 | 2011-03-08 17:46:17 -0800 | [diff] [blame] | 20 | # TODO(sosa): Remove during OO refactor. |
| 21 | VERBOSE = False |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 22 | |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 23 | # Dictionary of valid commands with usage information. |
| 24 | COMMAND_DICTIONARY = { |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 25 | 'commit': |
| 26 | 'Marks given ebuilds as stable locally', |
| 27 | 'push': |
| 28 | 'Pushes previous marking of ebuilds to remote repo', |
| 29 | } |
| 30 | |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 31 | |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 32 | # ======================= Global Helper Functions ======================== |
| 33 | |
| 34 | |
| 35 | def _Print(message): |
| 36 | """Verbose print function.""" |
Chris Sosa | c31bd2d | 2011-04-29 17:53:35 -0700 | [diff] [blame] | 37 | if VERBOSE: |
Chris Sosa | c13bba5 | 2011-05-24 15:14:09 -0700 | [diff] [blame] | 38 | cros_build_lib.Info(message) |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 39 | |
| 40 | |
David James | cc09c9b | 2012-01-26 22:10:13 -0800 | [diff] [blame] | 41 | def CleanStalePackages(boards, package_atoms): |
Chris Sosa | bf15387 | 2011-04-28 14:21:09 -0700 | [diff] [blame] | 42 | """Cleans up stale package info from a previous build. |
| 43 | Args: |
David James | cc09c9b | 2012-01-26 22:10:13 -0800 | [diff] [blame] | 44 | boards: Boards to clean the packages from. |
Chris Sosa | bf15387 | 2011-04-28 14:21:09 -0700 | [diff] [blame] | 45 | package_atoms: The actual package atom to unmerge. |
| 46 | """ |
| 47 | if package_atoms: |
Chris Sosa | c13bba5 | 2011-05-24 15:14:09 -0700 | [diff] [blame] | 48 | cros_build_lib.Info('Cleaning up stale packages %s.' % package_atoms) |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 49 | |
Mike Frysinger | b7ab9b8 | 2012-04-04 16:22:43 -0400 | [diff] [blame] | 50 | # First unmerge all the packages for a board, then eclean it. |
| 51 | # We need these two steps to run in order (unmerge/eclean), |
| 52 | # but we can let all the boards run in parallel. |
| 53 | def _CleanStalePackages(board): |
| 54 | if board: |
| 55 | suffix = '-' + board |
| 56 | runcmd = cros_build_lib.RunCommand |
| 57 | else: |
| 58 | suffix = '' |
| 59 | runcmd = cros_build_lib.SudoRunCommand |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 60 | |
Mike Frysinger | b7ab9b8 | 2012-04-04 16:22:43 -0400 | [diff] [blame] | 61 | if package_atoms: |
| 62 | runcmd(['emerge' + suffix, '-q', '--unmerge'] + package_atoms); |
| 63 | runcmd(['eclean' + suffix, '-d', 'packages'], |
| 64 | redirect_stdout=True, redirect_stderr=True) |
| 65 | |
| 66 | tasks = [] |
David James | cc09c9b | 2012-01-26 22:10:13 -0800 | [diff] [blame] | 67 | for board in boards: |
Mike Frysinger | b7ab9b8 | 2012-04-04 16:22:43 -0400 | [diff] [blame] | 68 | tasks.append([board]) |
| 69 | tasks.append([None]) |
| 70 | |
| 71 | background.RunTasksInProcessPool(_CleanStalePackages, tasks) |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 72 | |
| 73 | |
Mike Frysinger | 2ebe373 | 2012-05-08 17:04:12 -0400 | [diff] [blame] | 74 | # TODO(build): This code needs to be gutted and rebased to cros_build_lib. |
| 75 | def _DoWeHaveLocalCommits(stable_branch, tracking_branch, cwd): |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 76 | """Returns true if there are local commits.""" |
Brian Harring | 609dc4e | 2012-05-07 02:17:44 -0700 | [diff] [blame] | 77 | current_branch = cros_build_lib.GetCurrentBranch(cwd) |
| 78 | |
| 79 | if current_branch != stable_branch: |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 80 | return False |
Brian Harring | 609dc4e | 2012-05-07 02:17:44 -0700 | [diff] [blame] | 81 | output = cros_build_lib.RunGitCommand( |
| 82 | cwd, ['rev-parse', 'HEAD', tracking_branch]).output.split() |
Brian Harring | 5b86b5e | 2012-05-25 18:27:40 -0700 | [diff] [blame] | 83 | return output[0] != output[1] |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 84 | |
| 85 | |
Chris Sosa | 62ad852 | 2011-03-08 17:46:17 -0800 | [diff] [blame] | 86 | def _CheckSaneArguments(package_list, command, options): |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 87 | """Checks to make sure the flags are sane. Dies if arguments are not sane.""" |
| 88 | if not command in COMMAND_DICTIONARY.keys(): |
| 89 | _PrintUsageAndDie('%s is not a valid command' % command) |
Chris Sosa | 62ad852 | 2011-03-08 17:46:17 -0800 | [diff] [blame] | 90 | if not options.packages and command == 'commit' and not options.all: |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 91 | _PrintUsageAndDie('Please specify at least one package') |
David James | cc09c9b | 2012-01-26 22:10:13 -0800 | [diff] [blame] | 92 | if not options.boards and command == 'commit': |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 93 | _PrintUsageAndDie('Please specify a board') |
Chris Sosa | 62ad852 | 2011-03-08 17:46:17 -0800 | [diff] [blame] | 94 | if not os.path.isdir(options.srcroot): |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 95 | _PrintUsageAndDie('srcroot is not a valid path') |
Chris Sosa | 62ad852 | 2011-03-08 17:46:17 -0800 | [diff] [blame] | 96 | options.srcroot = os.path.abspath(options.srcroot) |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 97 | |
| 98 | |
| 99 | def _PrintUsageAndDie(error_message=''): |
| 100 | """Prints optional error_message the usage and returns an error exit code.""" |
| 101 | command_usage = 'Commands: \n' |
| 102 | # Add keys and usage information from dictionary. |
| 103 | commands = sorted(COMMAND_DICTIONARY.keys()) |
| 104 | for command in commands: |
| 105 | command_usage += ' %s: %s\n' % (command, COMMAND_DICTIONARY[command]) |
| 106 | commands_str = '|'.join(commands) |
Chris Sosa | c13bba5 | 2011-05-24 15:14:09 -0700 | [diff] [blame] | 107 | cros_build_lib.Warning('Usage: %s FLAGS [%s]\n\n%s' % ( |
| 108 | sys.argv[0], commands_str, command_usage)) |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 109 | if error_message: |
Chris Sosa | c13bba5 | 2011-05-24 15:14:09 -0700 | [diff] [blame] | 110 | cros_build_lib.Die(error_message) |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 111 | else: |
| 112 | sys.exit(1) |
| 113 | |
| 114 | |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 115 | # ======================= End Global Helper Functions ======================== |
| 116 | |
| 117 | |
Mike Frysinger | 2ebe373 | 2012-05-08 17:04:12 -0400 | [diff] [blame] | 118 | def PushChange(stable_branch, tracking_branch, dryrun, cwd): |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 119 | """Pushes commits in the stable_branch to the remote git repository. |
| 120 | |
David James | ee2da62 | 2012-02-23 09:32:16 -0800 | [diff] [blame] | 121 | Pushes local commits from calls to CommitChange to the remote git |
David James | 6600946 | 2012-03-25 10:08:38 -0700 | [diff] [blame] | 122 | repository specified by current working directory. If changes are |
| 123 | found to commit, they will be merged to the merge branch and pushed. |
| 124 | In that case, the local repository will be left on the merge branch. |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 125 | |
| 126 | Args: |
| 127 | stable_branch: The local branch with commits we want to push. |
| 128 | tracking_branch: The tracking branch of the local branch. |
Chris Sosa | 62ad852 | 2011-03-08 17:46:17 -0800 | [diff] [blame] | 129 | dryrun: Use git push --dryrun to emulate a push. |
Mike Frysinger | 2ebe373 | 2012-05-08 17:04:12 -0400 | [diff] [blame] | 130 | cwd: The directory to run commands in. |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 131 | Raises: |
| 132 | OSError: Error occurred while pushing. |
| 133 | """ |
Mike Frysinger | 2ebe373 | 2012-05-08 17:04:12 -0400 | [diff] [blame] | 134 | if not _DoWeHaveLocalCommits(stable_branch, tracking_branch, cwd): |
Brian Harring | 609dc4e | 2012-05-07 02:17:44 -0700 | [diff] [blame] | 135 | cros_build_lib.Info('No work found to push in %s. Exiting', cwd) |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 136 | return |
| 137 | |
David James | 6600946 | 2012-03-25 10:08:38 -0700 | [diff] [blame] | 138 | # For the commit queue, our local branch may contain commits that were |
| 139 | # just tested and pushed during the CommitQueueCompletion stage. Sync |
| 140 | # and rebase our local branch on top of the remote commits. |
Brian Harring | 609dc4e | 2012-05-07 02:17:44 -0700 | [diff] [blame] | 141 | remote, push_branch = cros_build_lib.GetTrackingBranch(cwd, for_push=True) |
David James | 6600946 | 2012-03-25 10:08:38 -0700 | [diff] [blame] | 142 | cros_build_lib.SyncPushBranch(cwd, remote, push_branch) |
| 143 | |
| 144 | # Check whether any local changes remain after the sync. |
Brian Harring | 609dc4e | 2012-05-07 02:17:44 -0700 | [diff] [blame] | 145 | if not _DoWeHaveLocalCommits(stable_branch, push_branch, cwd): |
| 146 | cros_build_lib.Info('All changes already pushed for %s. Exiting', cwd) |
David James | 6600946 | 2012-03-25 10:08:38 -0700 | [diff] [blame] | 147 | return |
| 148 | |
Mike Frysinger | 7dafd0e | 2012-05-08 15:47:16 -0400 | [diff] [blame] | 149 | description = cros_build_lib.RunCommandCaptureOutput( |
Brian Harring | 609dc4e | 2012-05-07 02:17:44 -0700 | [diff] [blame] | 150 | ['git', 'log', '--format=format:%s%n%n%b', '%s..%s' % ( |
| 151 | push_branch, stable_branch)], cwd=cwd).output |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 152 | description = 'Marking set of ebuilds as stable\n\n%s' % description |
Brian Harring | 609dc4e | 2012-05-07 02:17:44 -0700 | [diff] [blame] | 153 | cros_build_lib.Info('For %s, using description %s', cwd, description) |
David James | 6600946 | 2012-03-25 10:08:38 -0700 | [diff] [blame] | 154 | cros_build_lib.CreatePushBranch(constants.MERGE_BRANCH, cwd) |
Brian Harring | 609dc4e | 2012-05-07 02:17:44 -0700 | [diff] [blame] | 155 | cros_build_lib.RunGitCommand(cwd, ['merge', '--squash', stable_branch]) |
| 156 | cros_build_lib.RunGitCommand(cwd, ['commit', '-m', description]) |
| 157 | cros_build_lib.RunGitCommand(cwd, ['config', 'push.default', 'tracking']) |
| 158 | cros_build_lib.GitPushWithRetry(constants.MERGE_BRANCH, cwd, |
Ryan Cui | 05a31ba | 2011-05-31 17:47:37 -0700 | [diff] [blame] | 159 | dryrun=dryrun) |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 160 | |
| 161 | |
| 162 | class GitBranch(object): |
| 163 | """Wrapper class for a git branch.""" |
| 164 | |
Mike Frysinger | 2ebe373 | 2012-05-08 17:04:12 -0400 | [diff] [blame] | 165 | def __init__(self, branch_name, tracking_branch, cwd): |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 166 | """Sets up variables but does not create the branch.""" |
| 167 | self.branch_name = branch_name |
| 168 | self.tracking_branch = tracking_branch |
Mike Frysinger | 2ebe373 | 2012-05-08 17:04:12 -0400 | [diff] [blame] | 169 | self.cwd = cwd |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 170 | |
| 171 | def CreateBranch(self): |
Mike Frysinger | 2ebe373 | 2012-05-08 17:04:12 -0400 | [diff] [blame] | 172 | self.Checkout() |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 173 | |
Mike Frysinger | 2ebe373 | 2012-05-08 17:04:12 -0400 | [diff] [blame] | 174 | def Checkout(self, branch=None): |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 175 | """Function used to check out to another GitBranch.""" |
Mike Frysinger | 2ebe373 | 2012-05-08 17:04:12 -0400 | [diff] [blame] | 176 | if not branch: |
| 177 | branch = self.branch_name |
| 178 | if branch == self.tracking_branch or self.Exists(branch): |
| 179 | git_cmd = ['git', 'checkout', '-f', branch] |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 180 | else: |
Mike Frysinger | 2ebe373 | 2012-05-08 17:04:12 -0400 | [diff] [blame] | 181 | git_cmd = ['repo', 'start', branch, '.'] |
| 182 | cros_build_lib.RunCommandCaptureOutput(git_cmd, print_cmd=False, |
| 183 | cwd=self.cwd) |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 184 | |
Mike Frysinger | 2ebe373 | 2012-05-08 17:04:12 -0400 | [diff] [blame] | 185 | def Exists(self, branch=None): |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 186 | """Returns True if the branch exists.""" |
Mike Frysinger | 2ebe373 | 2012-05-08 17:04:12 -0400 | [diff] [blame] | 187 | if not branch: |
| 188 | branch = self.branch_name |
Mike Frysinger | 7dafd0e | 2012-05-08 15:47:16 -0400 | [diff] [blame] | 189 | branches = cros_build_lib.RunCommandCaptureOutput(['git', 'branch'], |
Mike Frysinger | 2ebe373 | 2012-05-08 17:04:12 -0400 | [diff] [blame] | 190 | print_cmd=False, |
| 191 | cwd=self.cwd).output |
| 192 | return branch in branches.split() |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 193 | |
| 194 | |
Mike Frysinger | 368bbb7 | 2012-05-23 15:57:10 -0400 | [diff] [blame] | 195 | def main(argv): |
Chris Sosa | 62ad852 | 2011-03-08 17:46:17 -0800 | [diff] [blame] | 196 | parser = optparse.OptionParser('cros_mark_as_stable OPTIONS packages') |
| 197 | parser.add_option('--all', action='store_true', |
| 198 | help='Mark all packages as stable.') |
David James | cc09c9b | 2012-01-26 22:10:13 -0800 | [diff] [blame] | 199 | parser.add_option('-b', '--boards', |
| 200 | help='Colon-separated list of boards') |
Chris Sosa | 62ad852 | 2011-03-08 17:46:17 -0800 | [diff] [blame] | 201 | parser.add_option('--drop_file', |
| 202 | help='File to list packages that were revved.') |
| 203 | parser.add_option('--dryrun', action='store_true', |
| 204 | help='Passes dry-run to git push if pushing a change.') |
| 205 | parser.add_option('-o', '--overlays', |
| 206 | help='Colon-separated list of overlays to modify.') |
| 207 | parser.add_option('-p', '--packages', |
| 208 | help='Colon separated list of packages to rev.') |
| 209 | parser.add_option('-r', '--srcroot', |
| 210 | default='%s/trunk/src' % os.environ['HOME'], |
| 211 | help='Path to root src directory.') |
Chris Sosa | 62ad852 | 2011-03-08 17:46:17 -0800 | [diff] [blame] | 212 | parser.add_option('--verbose', action='store_true', |
| 213 | help='Prints out debug info.') |
| 214 | (options, args) = parser.parse_args() |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 215 | |
Chris Sosa | 62ad852 | 2011-03-08 17:46:17 -0800 | [diff] [blame] | 216 | global VERBOSE |
| 217 | VERBOSE = options.verbose |
J. Richard Barnette | 2fa9fd6 | 2011-12-02 17:10:10 -0800 | [diff] [blame] | 218 | portage_utilities.EBuild.VERBOSE = options.verbose |
Chris Sosa | 62ad852 | 2011-03-08 17:46:17 -0800 | [diff] [blame] | 219 | |
| 220 | if len(args) != 1: |
Ryan Cui | 05a31ba | 2011-05-31 17:47:37 -0700 | [diff] [blame] | 221 | _PrintUsageAndDie('Must specify a valid command [commit, push]') |
Chris Sosa | 62ad852 | 2011-03-08 17:46:17 -0800 | [diff] [blame] | 222 | |
| 223 | command = args[0] |
| 224 | package_list = None |
| 225 | if options.packages: |
| 226 | package_list = options.packages.split(':') |
| 227 | |
| 228 | _CheckSaneArguments(package_list, command, options) |
| 229 | if options.overlays: |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 230 | overlays = {} |
Chris Sosa | 62ad852 | 2011-03-08 17:46:17 -0800 | [diff] [blame] | 231 | for path in options.overlays.split(':'): |
Ryan Cui | 05a31ba | 2011-05-31 17:47:37 -0700 | [diff] [blame] | 232 | if not os.path.isdir(path): |
Chris Sosa | c13bba5 | 2011-05-24 15:14:09 -0700 | [diff] [blame] | 233 | cros_build_lib.Die('Cannot find overlay: %s' % path) |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 234 | overlays[path] = [] |
| 235 | else: |
Chris Sosa | c13bba5 | 2011-05-24 15:14:09 -0700 | [diff] [blame] | 236 | cros_build_lib.Warning('Missing --overlays argument') |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 237 | overlays = { |
Chris Sosa | 62ad852 | 2011-03-08 17:46:17 -0800 | [diff] [blame] | 238 | '%s/private-overlays/chromeos-overlay' % options.srcroot: [], |
| 239 | '%s/third_party/chromiumos-overlay' % options.srcroot: [] |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 240 | } |
| 241 | |
| 242 | if command == 'commit': |
J. Richard Barnette | f6697cf | 2011-11-18 12:42:08 -0800 | [diff] [blame] | 243 | portage_utilities.BuildEBuildDictionary( |
J. Richard Barnette | d422f62 | 2011-11-17 09:39:46 -0800 | [diff] [blame] | 244 | overlays, options.all, package_list) |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 245 | |
Brian Harring | 609dc4e | 2012-05-07 02:17:44 -0700 | [diff] [blame] | 246 | manifest = cros_build_lib.ManifestCheckout.Cached(options.srcroot) |
Ryan Cui | 4656a3c | 2011-05-24 12:30:30 -0700 | [diff] [blame] | 247 | |
David James | a8457b5 | 2011-05-28 00:03:20 -0700 | [diff] [blame] | 248 | # Contains the array of packages we actually revved. |
| 249 | revved_packages = [] |
| 250 | new_package_atoms = [] |
| 251 | |
Mike Frysinger | b9bd2f8 | 2012-05-08 14:55:23 -0400 | [diff] [blame] | 252 | # Slight optimization hack: process the chromiumos overlay before any other |
| 253 | # cros-workon overlay first so we can do background cache generation in it. |
| 254 | # A perfect solution would walk all the overlays, figure out any dependencies |
| 255 | # between them (with layout.conf), and then process them in dependency order. |
| 256 | # However, this operation isn't slow enough to warrant that level of |
| 257 | # complexity, so we'll just special case the main overlay. |
| 258 | # |
| 259 | # Similarly, generate the cache in the portage-stable tree asap. We know |
| 260 | # we won't have any cros-workon packages in there, so generating the cache |
| 261 | # is the only thing it'll be doing. The chromiumos overlay instead might |
| 262 | # have revbumping to do before it can generate the cache. |
Mike Frysinger | 110750a | 2012-03-26 14:19:20 -0400 | [diff] [blame] | 263 | keys = overlays.keys() |
Mike Frysinger | b9bd2f8 | 2012-05-08 14:55:23 -0400 | [diff] [blame] | 264 | for overlay in ('/third_party/chromiumos-overlay', |
| 265 | '/third_party/portage-stable'): |
| 266 | for k in keys: |
| 267 | if k.endswith(overlay): |
| 268 | keys.remove(k) |
| 269 | keys.insert(0, k) |
| 270 | break |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 271 | |
Mike Frysinger | 110750a | 2012-03-26 14:19:20 -0400 | [diff] [blame] | 272 | cache_queue = multiprocessing.Queue() |
| 273 | with background.BackgroundTaskRunner(cache_queue, |
| 274 | portage_utilities.RegenCache): |
| 275 | for overlay in keys: |
| 276 | ebuilds = overlays[overlay] |
| 277 | if not os.path.isdir(overlay): |
| 278 | cros_build_lib.Warning("Skipping %s" % overlay) |
| 279 | continue |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 280 | |
Brian Harring | e08e442 | 2012-05-30 12:40:50 -0700 | [diff] [blame] | 281 | # Note we intentionally work from the non push tracking branch; |
| 282 | # everything built thus far has been against it (meaning, http mirrors), |
| 283 | # thus we should honor that. During the actual push, the code switches |
| 284 | # to the correct urls, and does an appropriate rebasing. |
Brian Harring | 609dc4e | 2012-05-07 02:17:44 -0700 | [diff] [blame] | 285 | tracking_branch = cros_build_lib.GetTrackingBranchViaManifest( |
Brian Harring | e08e442 | 2012-05-30 12:40:50 -0700 | [diff] [blame] | 286 | overlay, manifest=manifest)[1] |
Brian Harring | 609dc4e | 2012-05-07 02:17:44 -0700 | [diff] [blame] | 287 | |
Mike Frysinger | 110750a | 2012-03-26 14:19:20 -0400 | [diff] [blame] | 288 | if command == 'push': |
| 289 | PushChange(constants.STABLE_EBUILD_BRANCH, tracking_branch, |
Mike Frysinger | 2ebe373 | 2012-05-08 17:04:12 -0400 | [diff] [blame] | 290 | options.dryrun, cwd=overlay) |
Mike Frysinger | 110750a | 2012-03-26 14:19:20 -0400 | [diff] [blame] | 291 | elif command == 'commit' and ebuilds: |
Mike Frysinger | 2ebe373 | 2012-05-08 17:04:12 -0400 | [diff] [blame] | 292 | existing_branch = cros_build_lib.GetCurrentBranch(overlay) |
| 293 | work_branch = GitBranch(constants.STABLE_EBUILD_BRANCH, tracking_branch, |
| 294 | cwd=overlay) |
Mike Frysinger | 110750a | 2012-03-26 14:19:20 -0400 | [diff] [blame] | 295 | work_branch.CreateBranch() |
| 296 | if not work_branch.Exists(): |
| 297 | cros_build_lib.Die('Unable to create stabilizing branch in %s' % |
| 298 | overlay) |
Ryan Cui | f0d57b4 | 2011-07-27 17:43:42 -0700 | [diff] [blame] | 299 | |
Mike Frysinger | 110750a | 2012-03-26 14:19:20 -0400 | [diff] [blame] | 300 | # In the case of uprevving overlays that have patches applied to them, |
| 301 | # include the patched changes in the stabilizing branch. |
| 302 | if existing_branch: |
Mike Frysinger | 7dafd0e | 2012-05-08 15:47:16 -0400 | [diff] [blame] | 303 | cros_build_lib.RunCommand(['git', 'rebase', existing_branch], |
Mike Frysinger | 2ebe373 | 2012-05-08 17:04:12 -0400 | [diff] [blame] | 304 | print_cmd=False, cwd=overlay) |
Mike Frysinger | 110750a | 2012-03-26 14:19:20 -0400 | [diff] [blame] | 305 | |
| 306 | for ebuild in ebuilds: |
| 307 | try: |
| 308 | _Print('Working on %s' % ebuild.package) |
| 309 | new_package = ebuild.RevWorkOnEBuild(options.srcroot) |
| 310 | if new_package: |
| 311 | revved_packages.append(ebuild.package) |
| 312 | new_package_atoms.append('=%s' % new_package) |
| 313 | except (OSError, IOError): |
| 314 | cros_build_lib.Warning('Cannot rev %s\n' % ebuild.package + |
| 315 | 'Note you will have to go into %s ' |
| 316 | 'and reset the git repo yourself.' % overlay) |
| 317 | raise |
| 318 | |
Mike Frysinger | b9bd2f8 | 2012-05-08 14:55:23 -0400 | [diff] [blame] | 319 | if command == 'commit': |
Mike Frysinger | 110750a | 2012-03-26 14:19:20 -0400 | [diff] [blame] | 320 | # Regenerate caches if need be. We do this all the time to |
| 321 | # catch when users make changes without updating cache files. |
| 322 | cache_queue.put([overlay]) |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 323 | |
David James | a8457b5 | 2011-05-28 00:03:20 -0700 | [diff] [blame] | 324 | if command == 'commit': |
David James | cc09c9b | 2012-01-26 22:10:13 -0800 | [diff] [blame] | 325 | CleanStalePackages(options.boards.split(':'), new_package_atoms) |
David James | a8457b5 | 2011-05-28 00:03:20 -0700 | [diff] [blame] | 326 | if options.drop_file: |
| 327 | fh = open(options.drop_file, 'w') |
| 328 | fh.write(' '.join(revved_packages)) |
| 329 | fh.close() |