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 | |
Mike Frysinger | 383367e | 2014-09-16 15:06:17 -0400 | [diff] [blame] | 7 | from __future__ import print_function |
| 8 | |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 9 | import os |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 10 | |
Aviv Keshet | b7519e1 | 2016-10-04 00:50:00 -0700 | [diff] [blame] | 11 | from chromite.lib import constants |
Mike Frysinger | e8dcbfd | 2015-03-08 21:45:52 -0400 | [diff] [blame] | 12 | from chromite.lib import commandline |
Chris Sosa | c13bba5 | 2011-05-24 15:14:09 -0700 | [diff] [blame] | 13 | from chromite.lib import cros_build_lib |
Ralph Nathan | 0304728 | 2015-03-23 11:09:32 -0700 | [diff] [blame] | 14 | from chromite.lib import cros_logging as logging |
David James | 97d9587 | 2012-11-16 15:09:56 -0800 | [diff] [blame] | 15 | from chromite.lib import git |
Mike Frysinger | fddaeb5 | 2012-11-20 11:17:31 -0500 | [diff] [blame] | 16 | from chromite.lib import osutils |
David James | 6450a0a | 2012-12-04 07:59:53 -0800 | [diff] [blame] | 17 | from chromite.lib import parallel |
Alex Deymo | 075c229 | 2014-09-04 18:31:50 -0700 | [diff] [blame] | 18 | from chromite.lib import portage_util |
Chris Sosa | c13bba5 | 2011-05-24 15:14:09 -0700 | [diff] [blame] | 19 | |
Gabe Black | 71e963e | 2014-10-28 20:19:59 -0700 | [diff] [blame] | 20 | # Commit message subject for uprevving Portage packages. |
| 21 | GIT_COMMIT_SUBJECT = 'Marking set of ebuilds as stable' |
David James | 15ed130 | 2013-04-25 09:21:19 -0700 | [diff] [blame] | 22 | |
David James | 29e86d5 | 2013-04-19 09:41:29 -0700 | [diff] [blame] | 23 | # Commit message for uprevving Portage packages. |
| 24 | _GIT_COMMIT_MESSAGE = 'Marking 9999 ebuild for %s as stable.' |
| 25 | |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 26 | # Dictionary of valid commands with usage information. |
| 27 | COMMAND_DICTIONARY = { |
Mike Frysinger | 5cd8c74 | 2013-10-11 14:43:01 -0400 | [diff] [blame] | 28 | 'commit': 'Marks given ebuilds as stable locally', |
| 29 | 'push': 'Pushes previous marking of ebuilds to remote repo', |
| 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 | |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 33 | # ======================= Global Helper Functions ======================== |
| 34 | |
| 35 | |
David James | 41124af | 2015-06-04 21:13:25 -0700 | [diff] [blame] | 36 | def CleanStalePackages(srcroot, boards, package_atoms): |
Chris Sosa | bf15387 | 2011-04-28 14:21:09 -0700 | [diff] [blame] | 37 | """Cleans up stale package info from a previous build. |
Mike Frysinger | 5cd8c74 | 2013-10-11 14:43:01 -0400 | [diff] [blame] | 38 | |
Chris Sosa | bf15387 | 2011-04-28 14:21:09 -0700 | [diff] [blame] | 39 | Args: |
David James | 41124af | 2015-06-04 21:13:25 -0700 | [diff] [blame] | 40 | srcroot: Root directory of the source tree. |
David James | cc09c9b | 2012-01-26 22:10:13 -0800 | [diff] [blame] | 41 | boards: Boards to clean the packages from. |
Mike Frysinger | de5ab0e | 2013-03-21 20:48:36 -0400 | [diff] [blame] | 42 | package_atoms: A list of package atoms to unmerge. |
Chris Sosa | bf15387 | 2011-04-28 14:21:09 -0700 | [diff] [blame] | 43 | """ |
David James | 15ed130 | 2013-04-25 09:21:19 -0700 | [diff] [blame] | 44 | if package_atoms: |
Ralph Nathan | 0304728 | 2015-03-23 11:09:32 -0700 | [diff] [blame] | 45 | logging.info('Cleaning up stale packages %s.' % package_atoms) |
David James | 15ed130 | 2013-04-25 09:21:19 -0700 | [diff] [blame] | 46 | |
Mike Frysinger | b7ab9b8 | 2012-04-04 16:22:43 -0400 | [diff] [blame] | 47 | # First unmerge all the packages for a board, then eclean it. |
| 48 | # We need these two steps to run in order (unmerge/eclean), |
| 49 | # but we can let all the boards run in parallel. |
| 50 | def _CleanStalePackages(board): |
| 51 | if board: |
| 52 | suffix = '-' + board |
| 53 | runcmd = cros_build_lib.RunCommand |
| 54 | else: |
| 55 | suffix = '' |
| 56 | runcmd = cros_build_lib.SudoRunCommand |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 57 | |
David James | 59a0a2b | 2013-03-22 14:04:44 -0700 | [diff] [blame] | 58 | emerge, eclean = 'emerge' + suffix, 'eclean' + suffix |
| 59 | if not osutils.FindMissingBinaries([emerge, eclean]): |
David James | 63841a8 | 2014-01-16 14:39:24 -0800 | [diff] [blame] | 60 | if package_atoms: |
| 61 | # If nothing was found to be unmerged, emerge will exit(1). |
| 62 | result = runcmd([emerge, '-q', '--unmerge'] + package_atoms, |
David James | 41124af | 2015-06-04 21:13:25 -0700 | [diff] [blame] | 63 | enter_chroot=True, extra_env={'CLEAN_DELAY': '0'}, |
| 64 | error_code_ok=True, cwd=srcroot) |
David James | 63841a8 | 2014-01-16 14:39:24 -0800 | [diff] [blame] | 65 | if not result.returncode in (0, 1): |
| 66 | raise cros_build_lib.RunCommandError('unexpected error', result) |
David James | 59a0a2b | 2013-03-22 14:04:44 -0700 | [diff] [blame] | 67 | runcmd([eclean, '-d', 'packages'], |
David James | 41124af | 2015-06-04 21:13:25 -0700 | [diff] [blame] | 68 | cwd=srcroot, enter_chroot=True, |
David James | 59a0a2b | 2013-03-22 14:04:44 -0700 | [diff] [blame] | 69 | redirect_stdout=True, redirect_stderr=True) |
Mike Frysinger | b7ab9b8 | 2012-04-04 16:22:43 -0400 | [diff] [blame] | 70 | |
| 71 | tasks = [] |
David James | cc09c9b | 2012-01-26 22:10:13 -0800 | [diff] [blame] | 72 | for board in boards: |
Mike Frysinger | b7ab9b8 | 2012-04-04 16:22:43 -0400 | [diff] [blame] | 73 | tasks.append([board]) |
| 74 | tasks.append([None]) |
| 75 | |
David James | 6450a0a | 2012-12-04 07:59:53 -0800 | [diff] [blame] | 76 | parallel.RunTasksInProcessPool(_CleanStalePackages, tasks) |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 77 | |
| 78 | |
Mike Frysinger | 2ebe373 | 2012-05-08 17:04:12 -0400 | [diff] [blame] | 79 | # TODO(build): This code needs to be gutted and rebased to cros_build_lib. |
| 80 | def _DoWeHaveLocalCommits(stable_branch, tracking_branch, cwd): |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 81 | """Returns true if there are local commits.""" |
David James | 97d9587 | 2012-11-16 15:09:56 -0800 | [diff] [blame] | 82 | output = git.RunGit( |
Paul Hobbs | 72d8e39 | 2015-10-21 17:24:23 -0700 | [diff] [blame] | 83 | cwd, ['rev-parse', stable_branch, tracking_branch]).output.split() |
Brian Harring | 5b86b5e | 2012-05-25 18:27:40 -0700 | [diff] [blame] | 84 | return output[0] != output[1] |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 85 | |
| 86 | |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 87 | # ======================= End Global Helper Functions ======================== |
| 88 | |
| 89 | |
Ningning Xia | 5200906 | 2016-05-09 14:33:51 -0700 | [diff] [blame] | 90 | def PushChange(stable_branch, tracking_branch, dryrun, cwd, |
| 91 | staging_branch=None): |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 92 | """Pushes commits in the stable_branch to the remote git repository. |
| 93 | |
David James | ee2da62 | 2012-02-23 09:32:16 -0800 | [diff] [blame] | 94 | Pushes local commits from calls to CommitChange to the remote git |
David James | 6600946 | 2012-03-25 10:08:38 -0700 | [diff] [blame] | 95 | repository specified by current working directory. If changes are |
| 96 | found to commit, they will be merged to the merge branch and pushed. |
| 97 | 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] | 98 | |
| 99 | Args: |
| 100 | stable_branch: The local branch with commits we want to push. |
| 101 | tracking_branch: The tracking branch of the local branch. |
Chris Sosa | 62ad852 | 2011-03-08 17:46:17 -0800 | [diff] [blame] | 102 | dryrun: Use git push --dryrun to emulate a push. |
Mike Frysinger | 2ebe373 | 2012-05-08 17:04:12 -0400 | [diff] [blame] | 103 | cwd: The directory to run commands in. |
Ningning Xia | 5200906 | 2016-05-09 14:33:51 -0700 | [diff] [blame] | 104 | staging_branch: The staging branch to push for a failed PFQ run |
Mike Frysinger | 1a736a8 | 2013-12-12 01:50:59 -0500 | [diff] [blame] | 105 | |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 106 | Raises: |
Mike Frysinger | 5cd8c74 | 2013-10-11 14:43:01 -0400 | [diff] [blame] | 107 | OSError: Error occurred while pushing. |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 108 | """ |
David James | 4795963 | 2015-10-23 07:56:01 -0700 | [diff] [blame] | 109 | if not git.DoesCommitExistInRepo(cwd, stable_branch): |
| 110 | logging.debug('No branch created for %s. Exiting', cwd) |
| 111 | return |
| 112 | |
Mike Frysinger | 2ebe373 | 2012-05-08 17:04:12 -0400 | [diff] [blame] | 113 | if not _DoWeHaveLocalCommits(stable_branch, tracking_branch, cwd): |
David James | 4795963 | 2015-10-23 07:56:01 -0700 | [diff] [blame] | 114 | logging.debug('No work found to push in %s. Exiting', cwd) |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 115 | return |
| 116 | |
David James | 6600946 | 2012-03-25 10:08:38 -0700 | [diff] [blame] | 117 | # For the commit queue, our local branch may contain commits that were |
| 118 | # just tested and pushed during the CommitQueueCompletion stage. Sync |
| 119 | # and rebase our local branch on top of the remote commits. |
Paul Hobbs | 72d8e39 | 2015-10-21 17:24:23 -0700 | [diff] [blame] | 120 | remote_ref = git.GetTrackingBranch(cwd, |
| 121 | branch=stable_branch, |
| 122 | for_push=True) |
Paul Hobbs | 1e46be8 | 2015-10-30 13:46:02 -0700 | [diff] [blame] | 123 | # SyncPushBranch rebases HEAD onto the updated remote. We need to checkout |
| 124 | # stable_branch here in order to update it. |
| 125 | git.RunGit(cwd, ['checkout', stable_branch]) |
Don Garrett | 9944959 | 2015-03-25 11:01:30 -0700 | [diff] [blame] | 126 | git.SyncPushBranch(cwd, remote_ref.remote, remote_ref.ref) |
David James | 6600946 | 2012-03-25 10:08:38 -0700 | [diff] [blame] | 127 | |
| 128 | # Check whether any local changes remain after the sync. |
Don Garrett | 9944959 | 2015-03-25 11:01:30 -0700 | [diff] [blame] | 129 | if not _DoWeHaveLocalCommits(stable_branch, remote_ref.ref, cwd): |
Ralph Nathan | 0304728 | 2015-03-23 11:09:32 -0700 | [diff] [blame] | 130 | logging.info('All changes already pushed for %s. Exiting', cwd) |
David James | 6600946 | 2012-03-25 10:08:38 -0700 | [diff] [blame] | 131 | return |
| 132 | |
Matt Tennant | cb52205 | 2013-11-25 14:23:43 -0800 | [diff] [blame] | 133 | # Add a failsafe check here. Only CLs from the 'chrome-bot' user should |
| 134 | # be involved here. If any other CLs are found then complain. |
| 135 | # In dryruns extra CLs are normal, though, and can be ignored. |
| 136 | bad_cl_cmd = ['log', '--format=short', '--perl-regexp', |
| 137 | '--author', '^(?!chrome-bot)', '%s..%s' % ( |
Don Garrett | 9944959 | 2015-03-25 11:01:30 -0700 | [diff] [blame] | 138 | remote_ref.ref, stable_branch)] |
Matt Tennant | cb52205 | 2013-11-25 14:23:43 -0800 | [diff] [blame] | 139 | bad_cls = git.RunGit(cwd, bad_cl_cmd).output |
| 140 | if bad_cls.strip() and not dryrun: |
Ralph Nathan | 5990042 | 2015-03-24 10:41:17 -0700 | [diff] [blame] | 141 | logging.error('The Uprev stage found changes from users other than ' |
| 142 | 'chrome-bot:\n\n%s', bad_cls) |
Matt Tennant | cb52205 | 2013-11-25 14:23:43 -0800 | [diff] [blame] | 143 | raise AssertionError('Unexpected CLs found during uprev stage.') |
| 144 | |
Lev Rumyantsev | 25352ba | 2016-09-07 15:53:58 -0700 | [diff] [blame] | 145 | if staging_branch is not None: |
| 146 | logging.info('PFQ FAILED. Pushing uprev change to staging branch %s', |
| 147 | staging_branch) |
| 148 | |
Mike Frysinger | e65f375 | 2014-12-08 00:46:39 -0500 | [diff] [blame] | 149 | description = git.RunGit( |
| 150 | cwd, |
| 151 | ['log', '--format=format:%s%n%n%b', |
Don Garrett | 9944959 | 2015-03-25 11:01:30 -0700 | [diff] [blame] | 152 | '%s..%s' % (remote_ref.ref, stable_branch)]).output |
Gabe Black | 71e963e | 2014-10-28 20:19:59 -0700 | [diff] [blame] | 153 | description = '%s\n\n%s' % (GIT_COMMIT_SUBJECT, description) |
Ralph Nathan | 0304728 | 2015-03-23 11:09:32 -0700 | [diff] [blame] | 154 | logging.info('For %s, using description %s', cwd, description) |
Paul Hobbs | f52ea8f | 2015-10-21 17:24:23 -0700 | [diff] [blame] | 155 | git.CreatePushBranch(constants.MERGE_BRANCH, cwd, |
| 156 | remote_push_branch=remote_ref) |
David James | 97d9587 | 2012-11-16 15:09:56 -0800 | [diff] [blame] | 157 | git.RunGit(cwd, ['merge', '--squash', stable_branch]) |
| 158 | git.RunGit(cwd, ['commit', '-m', description]) |
| 159 | git.RunGit(cwd, ['config', 'push.default', 'tracking']) |
Ningning Xia | 5200906 | 2016-05-09 14:33:51 -0700 | [diff] [blame] | 160 | git.PushWithRetry(constants.MERGE_BRANCH, cwd, dryrun=dryrun, |
| 161 | staging_branch=staging_branch) |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 162 | |
| 163 | |
| 164 | class GitBranch(object): |
| 165 | """Wrapper class for a git branch.""" |
| 166 | |
Mike Frysinger | 2ebe373 | 2012-05-08 17:04:12 -0400 | [diff] [blame] | 167 | def __init__(self, branch_name, tracking_branch, cwd): |
David James | c7c4ff5 | 2013-09-18 17:57:13 -0700 | [diff] [blame] | 168 | """Sets up variables but does not create the branch. |
| 169 | |
Mike Frysinger | 5cd8c74 | 2013-10-11 14:43:01 -0400 | [diff] [blame] | 170 | Args: |
David James | c7c4ff5 | 2013-09-18 17:57:13 -0700 | [diff] [blame] | 171 | branch_name: The name of the branch. |
| 172 | tracking_branch: The associated tracking branch. |
| 173 | cwd: The git repository to work in. |
| 174 | """ |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 175 | self.branch_name = branch_name |
| 176 | self.tracking_branch = tracking_branch |
Mike Frysinger | 2ebe373 | 2012-05-08 17:04:12 -0400 | [diff] [blame] | 177 | self.cwd = cwd |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 178 | |
| 179 | def CreateBranch(self): |
Mike Frysinger | 2ebe373 | 2012-05-08 17:04:12 -0400 | [diff] [blame] | 180 | self.Checkout() |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 181 | |
Mike Frysinger | 2ebe373 | 2012-05-08 17:04:12 -0400 | [diff] [blame] | 182 | def Checkout(self, branch=None): |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 183 | """Function used to check out to another GitBranch.""" |
Mike Frysinger | 2ebe373 | 2012-05-08 17:04:12 -0400 | [diff] [blame] | 184 | if not branch: |
| 185 | branch = self.branch_name |
| 186 | if branch == self.tracking_branch or self.Exists(branch): |
| 187 | git_cmd = ['git', 'checkout', '-f', branch] |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 188 | else: |
Mike Frysinger | 2ebe373 | 2012-05-08 17:04:12 -0400 | [diff] [blame] | 189 | git_cmd = ['repo', 'start', branch, '.'] |
Yu-Ju Hong | 3add443 | 2014-01-30 11:46:15 -0800 | [diff] [blame] | 190 | cros_build_lib.RunCommand(git_cmd, print_cmd=False, cwd=self.cwd, |
| 191 | capture_output=True) |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 192 | |
Mike Frysinger | 2ebe373 | 2012-05-08 17:04:12 -0400 | [diff] [blame] | 193 | def Exists(self, branch=None): |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 194 | """Returns True if the branch exists.""" |
Mike Frysinger | 2ebe373 | 2012-05-08 17:04:12 -0400 | [diff] [blame] | 195 | if not branch: |
| 196 | branch = self.branch_name |
David James | 67d7325 | 2013-09-19 17:33:12 -0700 | [diff] [blame] | 197 | branches = git.RunGit(self.cwd, ['branch']).output |
Mike Frysinger | 2ebe373 | 2012-05-08 17:04:12 -0400 | [diff] [blame] | 198 | return branch in branches.split() |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 199 | |
| 200 | |
Mike Frysinger | e8dcbfd | 2015-03-08 21:45:52 -0400 | [diff] [blame] | 201 | def GetParser(): |
| 202 | """Creates the argparse parser.""" |
| 203 | parser = commandline.ArgumentParser() |
| 204 | parser.add_argument('--all', action='store_true', |
| 205 | help='Mark all packages as stable.') |
| 206 | parser.add_argument('-b', '--boards', default='', |
| 207 | help='Colon-separated list of boards.') |
| 208 | parser.add_argument('--drop_file', |
| 209 | help='File to list packages that were revved.') |
| 210 | parser.add_argument('--dryrun', action='store_true', |
| 211 | help='Passes dry-run to git push if pushing a change.') |
Bertrand SIMONNET | 6af5430 | 2015-08-05 10:12:49 -0700 | [diff] [blame] | 212 | parser.add_argument('--force', action='store_true', |
| 213 | help='Force the stabilization of blacklisted packages. ' |
| 214 | '(only compatible with -p)') |
Mike Frysinger | e8dcbfd | 2015-03-08 21:45:52 -0400 | [diff] [blame] | 215 | parser.add_argument('-o', '--overlays', |
| 216 | help='Colon-separated list of overlays to modify.') |
| 217 | parser.add_argument('-p', '--packages', |
| 218 | help='Colon separated list of packages to rev.') |
| 219 | parser.add_argument('-r', '--srcroot', type='path', |
| 220 | default=os.path.join(constants.SOURCE_ROOT, 'src'), |
| 221 | help='Path to root src directory.') |
| 222 | parser.add_argument('--verbose', action='store_true', |
| 223 | help='Prints out debug info.') |
Ningning Xia | 5200906 | 2016-05-09 14:33:51 -0700 | [diff] [blame] | 224 | parser.add_argument('--staging_branch', |
| 225 | help='The staging branch to push changes') |
Mike Frysinger | e8dcbfd | 2015-03-08 21:45:52 -0400 | [diff] [blame] | 226 | parser.add_argument('command', choices=COMMAND_DICTIONARY.keys(), |
| 227 | help='Command to run.') |
| 228 | return parser |
| 229 | |
| 230 | |
| 231 | def main(argv): |
| 232 | parser = GetParser() |
| 233 | options = parser.parse_args(argv) |
Bertrand SIMONNET | 6af5430 | 2015-08-05 10:12:49 -0700 | [diff] [blame] | 234 | options.Freeze() |
Mike Frysinger | e8dcbfd | 2015-03-08 21:45:52 -0400 | [diff] [blame] | 235 | |
Bertrand SIMONNET | 6af5430 | 2015-08-05 10:12:49 -0700 | [diff] [blame] | 236 | if options.command == 'commit': |
| 237 | if not options.packages and not options.all: |
| 238 | parser.error('Please specify at least one package (--packages)') |
| 239 | if options.force and options.all: |
| 240 | parser.error('Cannot use --force with --all. You must specify a list of ' |
| 241 | 'packages you want to force uprev.') |
| 242 | |
Mike Frysinger | e8dcbfd | 2015-03-08 21:45:52 -0400 | [diff] [blame] | 243 | if not os.path.isdir(options.srcroot): |
| 244 | parser.error('srcroot is not a valid path: %s' % options.srcroot) |
Mike Frysinger | e8dcbfd | 2015-03-08 21:45:52 -0400 | [diff] [blame] | 245 | |
Alex Deymo | 075c229 | 2014-09-04 18:31:50 -0700 | [diff] [blame] | 246 | portage_util.EBuild.VERBOSE = options.verbose |
Chris Sosa | 62ad852 | 2011-03-08 17:46:17 -0800 | [diff] [blame] | 247 | |
Chris Sosa | 62ad852 | 2011-03-08 17:46:17 -0800 | [diff] [blame] | 248 | package_list = None |
| 249 | if options.packages: |
| 250 | package_list = options.packages.split(':') |
| 251 | |
Chris Sosa | 62ad852 | 2011-03-08 17:46:17 -0800 | [diff] [blame] | 252 | if options.overlays: |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 253 | overlays = {} |
Chris Sosa | 62ad852 | 2011-03-08 17:46:17 -0800 | [diff] [blame] | 254 | for path in options.overlays.split(':'): |
Ryan Cui | 05a31ba | 2011-05-31 17:47:37 -0700 | [diff] [blame] | 255 | if not os.path.isdir(path): |
Chris Sosa | c13bba5 | 2011-05-24 15:14:09 -0700 | [diff] [blame] | 256 | cros_build_lib.Die('Cannot find overlay: %s' % path) |
Mike Frysinger | 359391c | 2016-11-15 16:13:34 -0500 | [diff] [blame] | 257 | overlays[os.path.realpath(path)] = [] |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 258 | else: |
Ralph Nathan | 446aee9 | 2015-03-23 14:44:56 -0700 | [diff] [blame] | 259 | logging.warning('Missing --overlays argument') |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 260 | overlays = { |
Mike Frysinger | e65f375 | 2014-12-08 00:46:39 -0500 | [diff] [blame] | 261 | '%s/private-overlays/chromeos-overlay' % options.srcroot: [], |
| 262 | '%s/third_party/chromiumos-overlay' % options.srcroot: [], |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 263 | } |
| 264 | |
David James | 97d9587 | 2012-11-16 15:09:56 -0800 | [diff] [blame] | 265 | manifest = git.ManifestCheckout.Cached(options.srcroot) |
Ryan Cui | 4656a3c | 2011-05-24 12:30:30 -0700 | [diff] [blame] | 266 | |
Mike Frysinger | e8dcbfd | 2015-03-08 21:45:52 -0400 | [diff] [blame] | 267 | if options.command == 'commit': |
Bertrand SIMONNET | 6af5430 | 2015-08-05 10:12:49 -0700 | [diff] [blame] | 268 | portage_util.BuildEBuildDictionary(overlays, options.all, package_list, |
| 269 | allow_blacklisted=options.force) |
David James | 84e953c | 2013-04-23 18:44:06 -0700 | [diff] [blame] | 270 | |
David James | 15ed130 | 2013-04-25 09:21:19 -0700 | [diff] [blame] | 271 | # Contains the array of packages we actually revved. |
| 272 | revved_packages = [] |
| 273 | new_package_atoms = [] |
David James | a8457b5 | 2011-05-28 00:03:20 -0700 | [diff] [blame] | 274 | |
David James | 41124af | 2015-06-04 21:13:25 -0700 | [diff] [blame] | 275 | for overlay in overlays: |
| 276 | ebuilds = overlays[overlay] |
| 277 | if not os.path.isdir(overlay): |
| 278 | logging.warning('Skipping %s' % overlay) |
| 279 | continue |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 280 | |
David James | 41124af | 2015-06-04 21:13:25 -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. |
| 285 | tracking_branch = git.GetTrackingBranchViaManifest( |
| 286 | overlay, manifest=manifest).ref |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 287 | |
David James | 41124af | 2015-06-04 21:13:25 -0700 | [diff] [blame] | 288 | if options.command == 'push': |
| 289 | PushChange(constants.STABLE_EBUILD_BRANCH, tracking_branch, |
Ningning Xia | 5200906 | 2016-05-09 14:33:51 -0700 | [diff] [blame] | 290 | options.dryrun, cwd=overlay, |
| 291 | staging_branch=options.staging_branch) |
David James | 41124af | 2015-06-04 21:13:25 -0700 | [diff] [blame] | 292 | elif options.command == 'commit': |
| 293 | existing_commit = git.GetGitRepoRevision(overlay) |
| 294 | work_branch = GitBranch(constants.STABLE_EBUILD_BRANCH, tracking_branch, |
| 295 | cwd=overlay) |
| 296 | work_branch.CreateBranch() |
| 297 | if not work_branch.Exists(): |
| 298 | cros_build_lib.Die('Unable to create stabilizing branch in %s' % |
| 299 | overlay) |
Brian Harring | 609dc4e | 2012-05-07 02:17:44 -0700 | [diff] [blame] | 300 | |
David James | 41124af | 2015-06-04 21:13:25 -0700 | [diff] [blame] | 301 | # In the case of uprevving overlays that have patches applied to them, |
| 302 | # include the patched changes in the stabilizing branch. |
| 303 | git.RunGit(overlay, ['rebase', existing_commit]) |
David James | 15ed130 | 2013-04-25 09:21:19 -0700 | [diff] [blame] | 304 | |
David James | 41124af | 2015-06-04 21:13:25 -0700 | [diff] [blame] | 305 | messages = [] |
| 306 | for ebuild in ebuilds: |
| 307 | if options.verbose: |
Aviv Keshet | 845602e | 2016-10-13 23:44:34 -0700 | [diff] [blame] | 308 | logging.info('Working on %s, info %s', ebuild.package, |
| 309 | ebuild.cros_workon_vars) |
David James | 41124af | 2015-06-04 21:13:25 -0700 | [diff] [blame] | 310 | try: |
Prashant Malani | 0a33d87 | 2017-07-25 23:19:13 +0000 | [diff] [blame] | 311 | new_package = ebuild.RevWorkOnEBuild(options.srcroot, manifest, enforce_subdir_rev=True) |
David James | 41124af | 2015-06-04 21:13:25 -0700 | [diff] [blame] | 312 | if new_package: |
| 313 | revved_packages.append(ebuild.package) |
| 314 | new_package_atoms.append('=%s' % new_package) |
| 315 | messages.append(_GIT_COMMIT_MESSAGE % ebuild.package) |
| 316 | except (OSError, IOError): |
| 317 | logging.warning( |
| 318 | 'Cannot rev %s\n' |
| 319 | 'Note you will have to go into %s ' |
| 320 | 'and reset the git repo yourself.' % (ebuild.package, overlay)) |
| 321 | raise |
David James | 15ed130 | 2013-04-25 09:21:19 -0700 | [diff] [blame] | 322 | |
David James | 41124af | 2015-06-04 21:13:25 -0700 | [diff] [blame] | 323 | if messages: |
| 324 | portage_util.EBuild.CommitChange('\n\n'.join(messages), overlay) |
David James | 15ed130 | 2013-04-25 09:21:19 -0700 | [diff] [blame] | 325 | |
Mike Frysinger | e8dcbfd | 2015-03-08 21:45:52 -0400 | [diff] [blame] | 326 | if options.command == 'commit': |
David James | 41124af | 2015-06-04 21:13:25 -0700 | [diff] [blame] | 327 | chroot_path = os.path.join(options.srcroot, constants.DEFAULT_CHROOT_DIR) |
| 328 | if os.path.exists(chroot_path): |
| 329 | CleanStalePackages(options.srcroot, options.boards.split(':'), |
| 330 | new_package_atoms) |
David James | 15ed130 | 2013-04-25 09:21:19 -0700 | [diff] [blame] | 331 | if options.drop_file: |
| 332 | osutils.WriteFile(options.drop_file, ' '.join(revved_packages)) |