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