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