Mike Frysinger | e58c0e2 | 2017-10-04 15:43:30 -0400 | [diff] [blame] | 1 | # -*- coding: utf-8 -*- |
Mike Frysinger | 110750a | 2012-03-26 14:19:20 -0400 | [diff] [blame] | 2 | # Copyright (c) 2012 The Chromium OS Authors. All rights reserved. |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 3 | # Use of this source code is governed by a BSD-style license that can be |
| 4 | # found in the LICENSE file. |
| 5 | |
| 6 | """This module uprevs a given package's ebuild to the next revision.""" |
| 7 | |
Mike Frysinger | 383367e | 2014-09-16 15:06:17 -0400 | [diff] [blame] | 8 | from __future__ import print_function |
| 9 | |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 10 | import os |
Mike Frysinger | 3278140 | 2020-04-19 06:34:17 -0400 | [diff] [blame] | 11 | import sys |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 12 | |
Aviv Keshet | b7519e1 | 2016-10-04 00:50:00 -0700 | [diff] [blame] | 13 | from chromite.lib import constants |
Mike Frysinger | e8dcbfd | 2015-03-08 21:45:52 -0400 | [diff] [blame] | 14 | from chromite.lib import commandline |
Chris Sosa | c13bba5 | 2011-05-24 15:14:09 -0700 | [diff] [blame] | 15 | from chromite.lib import cros_build_lib |
Ralph Nathan | 0304728 | 2015-03-23 11:09:32 -0700 | [diff] [blame] | 16 | from chromite.lib import cros_logging as logging |
David James | 97d9587 | 2012-11-16 15:09:56 -0800 | [diff] [blame] | 17 | from chromite.lib import git |
Mike Frysinger | fddaeb5 | 2012-11-20 11:17:31 -0500 | [diff] [blame] | 18 | from chromite.lib import osutils |
David James | 6450a0a | 2012-12-04 07:59:53 -0800 | [diff] [blame] | 19 | from chromite.lib import parallel |
Alex Deymo | 075c229 | 2014-09-04 18:31:50 -0700 | [diff] [blame] | 20 | from chromite.lib import portage_util |
Lann Martin | b26e129 | 2018-08-09 13:59:19 -0600 | [diff] [blame] | 21 | from chromite.lib import repo_util |
Chris Sosa | c13bba5 | 2011-05-24 15:14:09 -0700 | [diff] [blame] | 22 | |
Don Garrett | 3dbb293 | 2018-10-02 14:41:26 -0700 | [diff] [blame] | 23 | from chromite.cbuildbot import manifest_version |
| 24 | |
Mike Frysinger | 3278140 | 2020-04-19 06:34:17 -0400 | [diff] [blame] | 25 | |
| 26 | assert sys.version_info >= (3, 6), 'This module requires Python 3.6+' |
| 27 | |
| 28 | |
Gabe Black | 71e963e | 2014-10-28 20:19:59 -0700 | [diff] [blame] | 29 | # Commit message subject for uprevving Portage packages. |
| 30 | GIT_COMMIT_SUBJECT = 'Marking set of ebuilds as stable' |
David James | 15ed130 | 2013-04-25 09:21:19 -0700 | [diff] [blame] | 31 | |
David James | 29e86d5 | 2013-04-19 09:41:29 -0700 | [diff] [blame] | 32 | # Commit message for uprevving Portage packages. |
| 33 | _GIT_COMMIT_MESSAGE = 'Marking 9999 ebuild for %s as stable.' |
| 34 | |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 35 | # Dictionary of valid commands with usage information. |
| 36 | COMMAND_DICTIONARY = { |
Mike Frysinger | 5cd8c74 | 2013-10-11 14:43:01 -0400 | [diff] [blame] | 37 | 'commit': 'Marks given ebuilds as stable locally', |
| 38 | 'push': 'Pushes previous marking of ebuilds to remote repo', |
| 39 | } |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 40 | |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 41 | |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 42 | # ======================= Global Helper Functions ======================== |
| 43 | |
| 44 | |
David James | 41124af | 2015-06-04 21:13:25 -0700 | [diff] [blame] | 45 | def CleanStalePackages(srcroot, boards, package_atoms): |
Chris Sosa | bf15387 | 2011-04-28 14:21:09 -0700 | [diff] [blame] | 46 | """Cleans up stale package info from a previous build. |
Mike Frysinger | 5cd8c74 | 2013-10-11 14:43:01 -0400 | [diff] [blame] | 47 | |
Chris Sosa | bf15387 | 2011-04-28 14:21:09 -0700 | [diff] [blame] | 48 | Args: |
David James | 41124af | 2015-06-04 21:13:25 -0700 | [diff] [blame] | 49 | srcroot: Root directory of the source tree. |
David James | cc09c9b | 2012-01-26 22:10:13 -0800 | [diff] [blame] | 50 | boards: Boards to clean the packages from. |
Mike Frysinger | de5ab0e | 2013-03-21 20:48:36 -0400 | [diff] [blame] | 51 | package_atoms: A list of package atoms to unmerge. |
Chris Sosa | bf15387 | 2011-04-28 14:21:09 -0700 | [diff] [blame] | 52 | """ |
David James | 15ed130 | 2013-04-25 09:21:19 -0700 | [diff] [blame] | 53 | if package_atoms: |
Lann Martin | ffb9516 | 2018-08-28 12:02:54 -0600 | [diff] [blame] | 54 | logging.info('Cleaning up stale packages %s.', package_atoms) |
David James | 15ed130 | 2013-04-25 09:21:19 -0700 | [diff] [blame] | 55 | |
Mike Frysinger | b7ab9b8 | 2012-04-04 16:22:43 -0400 | [diff] [blame] | 56 | # First unmerge all the packages for a board, then eclean it. |
| 57 | # We need these two steps to run in order (unmerge/eclean), |
| 58 | # but we can let all the boards run in parallel. |
| 59 | def _CleanStalePackages(board): |
| 60 | if board: |
| 61 | suffix = '-' + board |
Mike Frysinger | 45602c7 | 2019-09-22 02:15:11 -0400 | [diff] [blame] | 62 | runcmd = cros_build_lib.run |
Mike Frysinger | b7ab9b8 | 2012-04-04 16:22:43 -0400 | [diff] [blame] | 63 | else: |
| 64 | suffix = '' |
Mike Frysinger | 45602c7 | 2019-09-22 02:15:11 -0400 | [diff] [blame] | 65 | runcmd = cros_build_lib.sudo_run |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 66 | |
David James | 59a0a2b | 2013-03-22 14:04:44 -0700 | [diff] [blame] | 67 | emerge, eclean = 'emerge' + suffix, 'eclean' + suffix |
| 68 | if not osutils.FindMissingBinaries([emerge, eclean]): |
David James | 63841a8 | 2014-01-16 14:39:24 -0800 | [diff] [blame] | 69 | if package_atoms: |
| 70 | # If nothing was found to be unmerged, emerge will exit(1). |
Don Garrett | 7100fff | 2018-10-23 11:07:13 -0700 | [diff] [blame] | 71 | result = runcmd([emerge, '-q', '--unmerge'] + list(package_atoms), |
David James | 41124af | 2015-06-04 21:13:25 -0700 | [diff] [blame] | 72 | enter_chroot=True, extra_env={'CLEAN_DELAY': '0'}, |
Mike Frysinger | f5a3b2d | 2019-12-12 14:36:17 -0500 | [diff] [blame] | 73 | check=False, cwd=srcroot) |
Mike Frysinger | 0150411 | 2019-08-24 19:35:24 -0400 | [diff] [blame] | 74 | if result.returncode not in (0, 1): |
David James | 63841a8 | 2014-01-16 14:39:24 -0800 | [diff] [blame] | 75 | raise cros_build_lib.RunCommandError('unexpected error', result) |
David James | 59a0a2b | 2013-03-22 14:04:44 -0700 | [diff] [blame] | 76 | runcmd([eclean, '-d', 'packages'], |
David James | 41124af | 2015-06-04 21:13:25 -0700 | [diff] [blame] | 77 | cwd=srcroot, enter_chroot=True, |
Mike Frysinger | 0282d22 | 2019-12-17 17:15:48 -0500 | [diff] [blame] | 78 | stdout=True, stderr=True) |
Mike Frysinger | b7ab9b8 | 2012-04-04 16:22:43 -0400 | [diff] [blame] | 79 | |
| 80 | tasks = [] |
David James | cc09c9b | 2012-01-26 22:10:13 -0800 | [diff] [blame] | 81 | for board in boards: |
Mike Frysinger | b7ab9b8 | 2012-04-04 16:22:43 -0400 | [diff] [blame] | 82 | tasks.append([board]) |
| 83 | tasks.append([None]) |
| 84 | |
David James | 6450a0a | 2012-12-04 07:59:53 -0800 | [diff] [blame] | 85 | parallel.RunTasksInProcessPool(_CleanStalePackages, tasks) |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 86 | |
| 87 | |
Mike Frysinger | 2ebe373 | 2012-05-08 17:04:12 -0400 | [diff] [blame] | 88 | # TODO(build): This code needs to be gutted and rebased to cros_build_lib. |
| 89 | def _DoWeHaveLocalCommits(stable_branch, tracking_branch, cwd): |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 90 | """Returns true if there are local commits.""" |
David James | 97d9587 | 2012-11-16 15:09:56 -0800 | [diff] [blame] | 91 | output = git.RunGit( |
Paul Hobbs | 72d8e39 | 2015-10-21 17:24:23 -0700 | [diff] [blame] | 92 | cwd, ['rev-parse', stable_branch, tracking_branch]).output.split() |
Brian Harring | 5b86b5e | 2012-05-25 18:27:40 -0700 | [diff] [blame] | 93 | return output[0] != output[1] |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 94 | |
| 95 | |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 96 | # ======================= End Global Helper Functions ======================== |
| 97 | |
| 98 | |
Ningning Xia | 5200906 | 2016-05-09 14:33:51 -0700 | [diff] [blame] | 99 | def PushChange(stable_branch, tracking_branch, dryrun, cwd, |
| 100 | staging_branch=None): |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 101 | """Pushes commits in the stable_branch to the remote git repository. |
| 102 | |
David James | ee2da62 | 2012-02-23 09:32:16 -0800 | [diff] [blame] | 103 | Pushes local commits from calls to CommitChange to the remote git |
David James | 6600946 | 2012-03-25 10:08:38 -0700 | [diff] [blame] | 104 | repository specified by current working directory. If changes are |
| 105 | found to commit, they will be merged to the merge branch and pushed. |
| 106 | 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] | 107 | |
| 108 | Args: |
| 109 | stable_branch: The local branch with commits we want to push. |
| 110 | tracking_branch: The tracking branch of the local branch. |
Chris Sosa | 62ad852 | 2011-03-08 17:46:17 -0800 | [diff] [blame] | 111 | dryrun: Use git push --dryrun to emulate a push. |
Mike Frysinger | 2ebe373 | 2012-05-08 17:04:12 -0400 | [diff] [blame] | 112 | cwd: The directory to run commands in. |
Ningning Xia | 5200906 | 2016-05-09 14:33:51 -0700 | [diff] [blame] | 113 | staging_branch: The staging branch to push for a failed PFQ run |
Mike Frysinger | 1a736a8 | 2013-12-12 01:50:59 -0500 | [diff] [blame] | 114 | |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 115 | Raises: |
Mike Frysinger | 5cd8c74 | 2013-10-11 14:43:01 -0400 | [diff] [blame] | 116 | OSError: Error occurred while pushing. |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 117 | """ |
David James | 4795963 | 2015-10-23 07:56:01 -0700 | [diff] [blame] | 118 | if not git.DoesCommitExistInRepo(cwd, stable_branch): |
| 119 | logging.debug('No branch created for %s. Exiting', cwd) |
| 120 | return |
| 121 | |
Mike Frysinger | 2ebe373 | 2012-05-08 17:04:12 -0400 | [diff] [blame] | 122 | if not _DoWeHaveLocalCommits(stable_branch, tracking_branch, cwd): |
David James | 4795963 | 2015-10-23 07:56:01 -0700 | [diff] [blame] | 123 | logging.debug('No work found to push in %s. Exiting', cwd) |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 124 | return |
| 125 | |
David James | 6600946 | 2012-03-25 10:08:38 -0700 | [diff] [blame] | 126 | # For the commit queue, our local branch may contain commits that were |
| 127 | # just tested and pushed during the CommitQueueCompletion stage. Sync |
| 128 | # and rebase our local branch on top of the remote commits. |
Paul Hobbs | 72d8e39 | 2015-10-21 17:24:23 -0700 | [diff] [blame] | 129 | remote_ref = git.GetTrackingBranch(cwd, |
| 130 | branch=stable_branch, |
| 131 | for_push=True) |
Paul Hobbs | 1e46be8 | 2015-10-30 13:46:02 -0700 | [diff] [blame] | 132 | # SyncPushBranch rebases HEAD onto the updated remote. We need to checkout |
| 133 | # stable_branch here in order to update it. |
| 134 | git.RunGit(cwd, ['checkout', stable_branch]) |
Don Garrett | 9944959 | 2015-03-25 11:01:30 -0700 | [diff] [blame] | 135 | git.SyncPushBranch(cwd, remote_ref.remote, remote_ref.ref) |
David James | 6600946 | 2012-03-25 10:08:38 -0700 | [diff] [blame] | 136 | |
| 137 | # Check whether any local changes remain after the sync. |
Don Garrett | 9944959 | 2015-03-25 11:01:30 -0700 | [diff] [blame] | 138 | if not _DoWeHaveLocalCommits(stable_branch, remote_ref.ref, cwd): |
Ralph Nathan | 0304728 | 2015-03-23 11:09:32 -0700 | [diff] [blame] | 139 | logging.info('All changes already pushed for %s. Exiting', cwd) |
David James | 6600946 | 2012-03-25 10:08:38 -0700 | [diff] [blame] | 140 | return |
| 141 | |
Andrew Lamb | 7ef2c0b | 2019-07-17 09:43:27 -0600 | [diff] [blame] | 142 | # Add a failsafe check here. Only CLs from the 'chrome-bot' or |
| 143 | # 'chromeos-ci-prod' user should be involved here. If any other CLs are |
| 144 | # found then complain. In dryruns extra CLs are normal, though, and can |
| 145 | # be ignored. |
| 146 | bad_cl_cmd = [ |
| 147 | 'log', '--format=short', '--perl-regexp', '--author', |
| 148 | '^(?!chrome-bot|chromeos-ci-prod)', |
| 149 | '%s..%s' % (remote_ref.ref, stable_branch) |
| 150 | ] |
Matt Tennant | cb52205 | 2013-11-25 14:23:43 -0800 | [diff] [blame] | 151 | bad_cls = git.RunGit(cwd, bad_cl_cmd).output |
| 152 | if bad_cls.strip() and not dryrun: |
Andrew Lamb | 7ef2c0b | 2019-07-17 09:43:27 -0600 | [diff] [blame] | 153 | logging.error( |
| 154 | 'The Uprev stage found changes from users other than ' |
| 155 | 'chrome-bot or chromeos-ci-prod:\n\n%s', bad_cls) |
Matt Tennant | cb52205 | 2013-11-25 14:23:43 -0800 | [diff] [blame] | 156 | raise AssertionError('Unexpected CLs found during uprev stage.') |
| 157 | |
Lev Rumyantsev | 25352ba | 2016-09-07 15:53:58 -0700 | [diff] [blame] | 158 | if staging_branch is not None: |
| 159 | logging.info('PFQ FAILED. Pushing uprev change to staging branch %s', |
| 160 | staging_branch) |
| 161 | |
Mike Frysinger | e65f375 | 2014-12-08 00:46:39 -0500 | [diff] [blame] | 162 | description = git.RunGit( |
| 163 | cwd, |
| 164 | ['log', '--format=format:%s%n%n%b', |
Don Garrett | 9944959 | 2015-03-25 11:01:30 -0700 | [diff] [blame] | 165 | '%s..%s' % (remote_ref.ref, stable_branch)]).output |
Gabe Black | 71e963e | 2014-10-28 20:19:59 -0700 | [diff] [blame] | 166 | description = '%s\n\n%s' % (GIT_COMMIT_SUBJECT, description) |
Ralph Nathan | 0304728 | 2015-03-23 11:09:32 -0700 | [diff] [blame] | 167 | logging.info('For %s, using description %s', cwd, description) |
Paul Hobbs | f52ea8f | 2015-10-21 17:24:23 -0700 | [diff] [blame] | 168 | git.CreatePushBranch(constants.MERGE_BRANCH, cwd, |
| 169 | remote_push_branch=remote_ref) |
David James | 97d9587 | 2012-11-16 15:09:56 -0800 | [diff] [blame] | 170 | git.RunGit(cwd, ['merge', '--squash', stable_branch]) |
| 171 | git.RunGit(cwd, ['commit', '-m', description]) |
| 172 | git.RunGit(cwd, ['config', 'push.default', 'tracking']) |
Mike Nichols | a6818c5 | 2018-04-09 11:05:42 -0600 | [diff] [blame] | 173 | git.PushBranch(constants.MERGE_BRANCH, cwd, dryrun=dryrun, |
Sean Abraham | 11b57f8 | 2019-09-20 19:33:17 +0000 | [diff] [blame] | 174 | staging_branch=staging_branch) |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 175 | |
| 176 | |
| 177 | class GitBranch(object): |
| 178 | """Wrapper class for a git branch.""" |
| 179 | |
Mike Frysinger | 2ebe373 | 2012-05-08 17:04:12 -0400 | [diff] [blame] | 180 | def __init__(self, branch_name, tracking_branch, cwd): |
David James | c7c4ff5 | 2013-09-18 17:57:13 -0700 | [diff] [blame] | 181 | """Sets up variables but does not create the branch. |
| 182 | |
Mike Frysinger | 5cd8c74 | 2013-10-11 14:43:01 -0400 | [diff] [blame] | 183 | Args: |
David James | c7c4ff5 | 2013-09-18 17:57:13 -0700 | [diff] [blame] | 184 | branch_name: The name of the branch. |
| 185 | tracking_branch: The associated tracking branch. |
| 186 | cwd: The git repository to work in. |
| 187 | """ |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 188 | self.branch_name = branch_name |
| 189 | self.tracking_branch = tracking_branch |
Mike Frysinger | 2ebe373 | 2012-05-08 17:04:12 -0400 | [diff] [blame] | 190 | self.cwd = cwd |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 191 | |
| 192 | def CreateBranch(self): |
Mike Frysinger | 2ebe373 | 2012-05-08 17:04:12 -0400 | [diff] [blame] | 193 | self.Checkout() |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 194 | |
Mike Frysinger | 2ebe373 | 2012-05-08 17:04:12 -0400 | [diff] [blame] | 195 | def Checkout(self, branch=None): |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 196 | """Function used to check out to another GitBranch.""" |
Mike Frysinger | 2ebe373 | 2012-05-08 17:04:12 -0400 | [diff] [blame] | 197 | if not branch: |
| 198 | branch = self.branch_name |
| 199 | if branch == self.tracking_branch or self.Exists(branch): |
Lann Martin | b26e129 | 2018-08-09 13:59:19 -0600 | [diff] [blame] | 200 | git.RunGit(self.cwd, ['checkout', '-f', branch], quiet=True) |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 201 | else: |
Lann Martin | b26e129 | 2018-08-09 13:59:19 -0600 | [diff] [blame] | 202 | repo = repo_util.Repository.MustFind(self.cwd) |
| 203 | repo.StartBranch(branch, projects=['.'], cwd=self.cwd) |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 204 | |
Mike Frysinger | 2ebe373 | 2012-05-08 17:04:12 -0400 | [diff] [blame] | 205 | def Exists(self, branch=None): |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 206 | """Returns True if the branch exists.""" |
Mike Frysinger | 2ebe373 | 2012-05-08 17:04:12 -0400 | [diff] [blame] | 207 | if not branch: |
| 208 | branch = self.branch_name |
David James | 67d7325 | 2013-09-19 17:33:12 -0700 | [diff] [blame] | 209 | branches = git.RunGit(self.cwd, ['branch']).output |
Mike Frysinger | 2ebe373 | 2012-05-08 17:04:12 -0400 | [diff] [blame] | 210 | return branch in branches.split() |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 211 | |
| 212 | |
Mike Frysinger | e8dcbfd | 2015-03-08 21:45:52 -0400 | [diff] [blame] | 213 | def GetParser(): |
| 214 | """Creates the argparse parser.""" |
| 215 | parser = commandline.ArgumentParser() |
| 216 | parser.add_argument('--all', action='store_true', |
| 217 | help='Mark all packages as stable.') |
| 218 | parser.add_argument('-b', '--boards', default='', |
| 219 | help='Colon-separated list of boards.') |
Mike Nichols | f7f13a8 | 2019-01-11 17:11:04 +0000 | [diff] [blame] | 220 | parser.add_argument('--drop_file', |
| 221 | help='File to list packages that were revved.') |
Mike Frysinger | e8dcbfd | 2015-03-08 21:45:52 -0400 | [diff] [blame] | 222 | parser.add_argument('--dryrun', action='store_true', |
| 223 | help='Passes dry-run to git push if pushing a change.') |
Bertrand SIMONNET | 6af5430 | 2015-08-05 10:12:49 -0700 | [diff] [blame] | 224 | parser.add_argument('--force', action='store_true', |
| 225 | help='Force the stabilization of blacklisted packages. ' |
| 226 | '(only compatible with -p)') |
Sam McNally | eb5e205 | 2018-09-05 16:34:55 +1000 | [diff] [blame] | 227 | parser.add_argument('--list_revisions', action='store_true', |
| 228 | help='List all revisions included in the commit message.') |
Mike Frysinger | e8dcbfd | 2015-03-08 21:45:52 -0400 | [diff] [blame] | 229 | parser.add_argument('-o', '--overlays', |
| 230 | help='Colon-separated list of overlays to modify.') |
Don Garrett | f9eff95 | 2018-08-10 16:50:04 -0700 | [diff] [blame] | 231 | parser.add_argument('--overlay-type', |
| 232 | help='Populates --overlays based on "public", "private"' |
| 233 | ', or "both".') |
Mike Frysinger | e8dcbfd | 2015-03-08 21:45:52 -0400 | [diff] [blame] | 234 | parser.add_argument('-p', '--packages', |
| 235 | help='Colon separated list of packages to rev.') |
Don Garrett | 4fef8c3 | 2018-08-10 18:04:01 -0700 | [diff] [blame] | 236 | parser.add_argument('--buildroot', type='path', |
| 237 | help='Path to buildroot.') |
Mike Frysinger | e8dcbfd | 2015-03-08 21:45:52 -0400 | [diff] [blame] | 238 | parser.add_argument('-r', '--srcroot', type='path', |
Don Garrett | 4fef8c3 | 2018-08-10 18:04:01 -0700 | [diff] [blame] | 239 | help='Path to root src. Deprecated in favor of ' |
| 240 | '--buildroot') |
Ningning Xia | 5200906 | 2016-05-09 14:33:51 -0700 | [diff] [blame] | 241 | parser.add_argument('--staging_branch', |
| 242 | help='The staging branch to push changes') |
Mike Frysinger | 1f4478c | 2019-10-20 18:33:17 -0400 | [diff] [blame] | 243 | parser.add_argument('command', choices=sorted(COMMAND_DICTIONARY), |
Mike Frysinger | e8dcbfd | 2015-03-08 21:45:52 -0400 | [diff] [blame] | 244 | help='Command to run.') |
| 245 | return parser |
| 246 | |
| 247 | |
| 248 | def main(argv): |
| 249 | parser = GetParser() |
| 250 | options = parser.parse_args(argv) |
Don Garrett | 4fef8c3 | 2018-08-10 18:04:01 -0700 | [diff] [blame] | 251 | |
| 252 | # TODO: Remove this code in favor of a simple default on buildroot when |
| 253 | # srcroot is removed. |
| 254 | if options.srcroot and not options.buildroot: |
| 255 | # Convert /<repo>/src -> <repo> |
| 256 | options.buildroot = os.path.dirname(options.srcroot) |
| 257 | if not options.buildroot: |
| 258 | options.buildroot = constants.SOURCE_ROOT |
| 259 | options.srcroot = None |
| 260 | |
Bertrand SIMONNET | 6af5430 | 2015-08-05 10:12:49 -0700 | [diff] [blame] | 261 | options.Freeze() |
Mike Frysinger | e8dcbfd | 2015-03-08 21:45:52 -0400 | [diff] [blame] | 262 | |
Bertrand SIMONNET | 6af5430 | 2015-08-05 10:12:49 -0700 | [diff] [blame] | 263 | if options.command == 'commit': |
| 264 | if not options.packages and not options.all: |
| 265 | parser.error('Please specify at least one package (--packages)') |
| 266 | if options.force and options.all: |
| 267 | parser.error('Cannot use --force with --all. You must specify a list of ' |
| 268 | 'packages you want to force uprev.') |
| 269 | |
Don Garrett | 4fef8c3 | 2018-08-10 18:04:01 -0700 | [diff] [blame] | 270 | if not os.path.isdir(options.buildroot): |
| 271 | parser.error('buildroot is not a valid path: %s' % options.buildroot) |
Mike Frysinger | e8dcbfd | 2015-03-08 21:45:52 -0400 | [diff] [blame] | 272 | |
Don Garrett | f9eff95 | 2018-08-10 16:50:04 -0700 | [diff] [blame] | 273 | if options.overlay_type and options.overlays: |
| 274 | parser.error('Cannot use --overlay-type with --overlays.') |
| 275 | |
Alex Deymo | 075c229 | 2014-09-04 18:31:50 -0700 | [diff] [blame] | 276 | portage_util.EBuild.VERBOSE = options.verbose |
Chris Sosa | 62ad852 | 2011-03-08 17:46:17 -0800 | [diff] [blame] | 277 | |
Chris Sosa | 62ad852 | 2011-03-08 17:46:17 -0800 | [diff] [blame] | 278 | package_list = None |
| 279 | if options.packages: |
| 280 | package_list = options.packages.split(':') |
| 281 | |
Ningning Xia | db88432 | 2018-01-26 16:27:06 -0800 | [diff] [blame] | 282 | overlays = [] |
Chris Sosa | 62ad852 | 2011-03-08 17:46:17 -0800 | [diff] [blame] | 283 | if options.overlays: |
Chris Sosa | 62ad852 | 2011-03-08 17:46:17 -0800 | [diff] [blame] | 284 | for path in options.overlays.split(':'): |
Ryan Cui | 05a31ba | 2011-05-31 17:47:37 -0700 | [diff] [blame] | 285 | if not os.path.isdir(path): |
Chris Sosa | c13bba5 | 2011-05-24 15:14:09 -0700 | [diff] [blame] | 286 | cros_build_lib.Die('Cannot find overlay: %s' % path) |
Ningning Xia | db88432 | 2018-01-26 16:27:06 -0800 | [diff] [blame] | 287 | overlays.append(os.path.realpath(path)) |
Don Garrett | f9eff95 | 2018-08-10 16:50:04 -0700 | [diff] [blame] | 288 | elif options.overlay_type: |
| 289 | overlays = portage_util.FindOverlays( |
Don Garrett | 4fef8c3 | 2018-08-10 18:04:01 -0700 | [diff] [blame] | 290 | options.overlay_type, buildroot=options.buildroot) |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 291 | else: |
Ralph Nathan | 446aee9 | 2015-03-23 14:44:56 -0700 | [diff] [blame] | 292 | logging.warning('Missing --overlays argument') |
Ningning Xia | db88432 | 2018-01-26 16:27:06 -0800 | [diff] [blame] | 293 | overlays.extend([ |
Don Garrett | 4fef8c3 | 2018-08-10 18:04:01 -0700 | [diff] [blame] | 294 | '%s/src/private-overlays/chromeos-overlay' % options.buildroot, |
| 295 | '%s/src/third_party/chromiumos-overlay' % options.buildroot]) |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 296 | |
Don Garrett | 4fef8c3 | 2018-08-10 18:04:01 -0700 | [diff] [blame] | 297 | manifest = git.ManifestCheckout.Cached(options.buildroot) |
Ryan Cui | 4656a3c | 2011-05-24 12:30:30 -0700 | [diff] [blame] | 298 | |
Ningning Xia | 419e4eb | 2018-02-05 10:30:36 -0800 | [diff] [blame] | 299 | # Dict mapping from each overlay to its tracking branch. |
| 300 | overlay_tracking_branch = {} |
| 301 | # Dict mapping from each git repository (project) to a list of its overlays. |
| 302 | git_project_overlays = {} |
| 303 | |
| 304 | for overlay in overlays: |
| 305 | remote_ref = git.GetTrackingBranchViaManifest(overlay, manifest=manifest) |
| 306 | overlay_tracking_branch[overlay] = remote_ref.ref |
| 307 | git_project_overlays.setdefault(remote_ref.project_name, []).append(overlay) |
| 308 | |
| 309 | if options.command == 'push': |
| 310 | _WorkOnPush(options, overlay_tracking_branch, git_project_overlays) |
| 311 | elif options.command == 'commit': |
| 312 | _WorkOnCommit(options, overlays, overlay_tracking_branch, |
| 313 | git_project_overlays, manifest, package_list) |
| 314 | |
| 315 | |
| 316 | def _WorkOnPush(options, overlay_tracking_branch, git_project_overlays): |
| 317 | """Push uprevs of overlays belonging to differet git projects in parallel. |
| 318 | |
| 319 | Args: |
| 320 | options: The options object returned by the argument parser. |
| 321 | overlay_tracking_branch: A dict mapping from each overlay to its tracking |
| 322 | branch. |
| 323 | git_project_overlays: A dict mapping from each git repository to a list of |
| 324 | its overlays. |
| 325 | """ |
| 326 | inputs = [[options, overlays_per_project, overlay_tracking_branch] |
Mike Frysinger | 0bdbc10 | 2019-06-13 15:27:29 -0400 | [diff] [blame] | 327 | for overlays_per_project in git_project_overlays.values()] |
Ningning Xia | 419e4eb | 2018-02-05 10:30:36 -0800 | [diff] [blame] | 328 | parallel.RunTasksInProcessPool(_PushOverlays, inputs) |
| 329 | |
| 330 | |
| 331 | def _PushOverlays(options, overlays, overlay_tracking_branch): |
| 332 | """Push uprevs for overlays in sequence. |
| 333 | |
| 334 | Args: |
| 335 | options: The options object returned by the argument parser. |
| 336 | overlays: A list of overlays to push uprevs in sequence. |
| 337 | overlay_tracking_branch: A dict mapping from each overlay to its tracking |
| 338 | branch. |
| 339 | """ |
| 340 | for overlay in overlays: |
| 341 | if not os.path.isdir(overlay): |
| 342 | logging.warning('Skipping %s, which is not a directory.', overlay) |
| 343 | continue |
| 344 | |
| 345 | tracking_branch = overlay_tracking_branch[overlay] |
| 346 | PushChange(constants.STABLE_EBUILD_BRANCH, tracking_branch, options.dryrun, |
| 347 | cwd=overlay, staging_branch=options.staging_branch) |
| 348 | |
| 349 | |
| 350 | def _WorkOnCommit(options, overlays, overlay_tracking_branch, |
| 351 | git_project_overlays, manifest, package_list): |
| 352 | """Commit uprevs of overlays belonging to different git projects in parallel. |
| 353 | |
| 354 | Args: |
| 355 | options: The options object returned by the argument parser. |
| 356 | overlays: A list of overlays to work on. |
| 357 | overlay_tracking_branch: A dict mapping from each overlay to its tracking |
| 358 | branch. |
| 359 | git_project_overlays: A dict mapping from each git repository to a list of |
| 360 | its overlays. |
| 361 | manifest: The manifest of the given source root. |
| 362 | package_list: A list of packages passed from commandline to work on. |
| 363 | """ |
Mike Frysinger | 62ff8d7 | 2020-05-19 03:06:51 -0400 | [diff] [blame] | 364 | # We cleaned up self referential ebuilds by this version, but don't enforce |
| 365 | # the check on older ones to avoid breaking factory/firmware branches. |
| 366 | root_version = manifest_version.VersionInfo.from_repo(options.buildroot) |
| 367 | no_self_repos_version = manifest_version.VersionInfo('13099.0.0') |
| 368 | reject_self_repo = root_version >= no_self_repos_version |
| 369 | |
Ningning Xia | 419e4eb | 2018-02-05 10:30:36 -0800 | [diff] [blame] | 370 | overlay_ebuilds = _GetOverlayToEbuildsMap(options, overlays, package_list) |
David James | 84e953c | 2013-04-23 18:44:06 -0700 | [diff] [blame] | 371 | |
Ningning Xia | 783efc0 | 2018-01-24 13:39:51 -0800 | [diff] [blame] | 372 | with parallel.Manager() as manager: |
| 373 | # Contains the array of packages we actually revved. |
| 374 | revved_packages = manager.list() |
| 375 | new_package_atoms = manager.list() |
David James | a8457b5 | 2011-05-28 00:03:20 -0700 | [diff] [blame] | 376 | |
Ningning Xia | 419e4eb | 2018-02-05 10:30:36 -0800 | [diff] [blame] | 377 | inputs = [[options, manifest, overlays_per_project, overlay_tracking_branch, |
Mike Frysinger | 62ff8d7 | 2020-05-19 03:06:51 -0400 | [diff] [blame] | 378 | overlay_ebuilds, revved_packages, new_package_atoms, |
| 379 | reject_self_repo] |
Mike Frysinger | 0bdbc10 | 2019-06-13 15:27:29 -0400 | [diff] [blame] | 380 | for overlays_per_project in git_project_overlays.values()] |
Ningning Xia | 419e4eb | 2018-02-05 10:30:36 -0800 | [diff] [blame] | 381 | parallel.RunTasksInProcessPool(_CommitOverlays, inputs) |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 382 | |
Don Garrett | 4fef8c3 | 2018-08-10 18:04:01 -0700 | [diff] [blame] | 383 | chroot_path = os.path.join(options.buildroot, constants.DEFAULT_CHROOT_DIR) |
Ningning Xia | 419e4eb | 2018-02-05 10:30:36 -0800 | [diff] [blame] | 384 | if os.path.exists(chroot_path): |
Don Garrett | 4fef8c3 | 2018-08-10 18:04:01 -0700 | [diff] [blame] | 385 | CleanStalePackages(options.buildroot, options.boards.split(':'), |
Ningning Xia | 419e4eb | 2018-02-05 10:30:36 -0800 | [diff] [blame] | 386 | new_package_atoms) |
Mike Nichols | f7f13a8 | 2019-01-11 17:11:04 +0000 | [diff] [blame] | 387 | if options.drop_file: |
| 388 | osutils.WriteFile(options.drop_file, ' '.join(revved_packages)) |
Chris Sosa | dad0d32 | 2011-01-31 16:37:33 -0800 | [diff] [blame] | 389 | |
Brian Harring | 609dc4e | 2012-05-07 02:17:44 -0700 | [diff] [blame] | 390 | |
Ningning Xia | 419e4eb | 2018-02-05 10:30:36 -0800 | [diff] [blame] | 391 | def _GetOverlayToEbuildsMap(options, overlays, package_list): |
| 392 | """Get ebuilds for overlays. |
David James | 15ed130 | 2013-04-25 09:21:19 -0700 | [diff] [blame] | 393 | |
Ningning Xia | 783efc0 | 2018-01-24 13:39:51 -0800 | [diff] [blame] | 394 | Args: |
Ningning Xia | 783efc0 | 2018-01-24 13:39:51 -0800 | [diff] [blame] | 395 | options: The options object returned by the argument parser. |
Ningning Xia | 419e4eb | 2018-02-05 10:30:36 -0800 | [diff] [blame] | 396 | overlays: A list of overlays to work on. |
| 397 | package_list: A list of packages passed from commandline to work on. |
| 398 | |
| 399 | Returns: |
| 400 | A dict mapping each overlay to a list of ebuilds belonging to it. |
| 401 | """ |
Don Garrett | 3dbb293 | 2018-10-02 14:41:26 -0700 | [diff] [blame] | 402 | root_version = manifest_version.VersionInfo.from_repo(options.buildroot) |
| 403 | subdir_removal = manifest_version.VersionInfo('10363.0.0') |
| 404 | require_subdir_support = root_version < subdir_removal |
| 405 | |
Ningning Xia | 419e4eb | 2018-02-05 10:30:36 -0800 | [diff] [blame] | 406 | overlay_ebuilds = {} |
Don Garrett | 3dbb293 | 2018-10-02 14:41:26 -0700 | [diff] [blame] | 407 | inputs = [[overlay, options.all, package_list, options.force, |
| 408 | require_subdir_support] |
Ningning Xia | 419e4eb | 2018-02-05 10:30:36 -0800 | [diff] [blame] | 409 | for overlay in overlays] |
| 410 | result = parallel.RunTasksInProcessPool( |
| 411 | portage_util.GetOverlayEBuilds, inputs) |
| 412 | for idx, ebuilds in enumerate(result): |
| 413 | overlay_ebuilds[overlays[idx]] = ebuilds |
| 414 | |
| 415 | return overlay_ebuilds |
| 416 | |
| 417 | |
| 418 | def _CommitOverlays(options, manifest, overlays, overlay_tracking_branch, |
Mike Frysinger | 62ff8d7 | 2020-05-19 03:06:51 -0400 | [diff] [blame] | 419 | overlay_ebuilds, revved_packages, new_package_atoms, |
| 420 | reject_self_repo=True): |
Ningning Xia | 419e4eb | 2018-02-05 10:30:36 -0800 | [diff] [blame] | 421 | """Commit uprevs for overlays in sequence. |
| 422 | |
| 423 | Args: |
| 424 | options: The options object returned by the argument parser. |
| 425 | manifest: The manifest of the given source root. |
| 426 | overlays: A list over overlays to commit. |
| 427 | overlay_tracking_branch: A dict mapping from each overlay to its tracking |
| 428 | branch. |
| 429 | overlay_ebuilds: A dict mapping overlays to their ebuilds. |
Ningning Xia | 783efc0 | 2018-01-24 13:39:51 -0800 | [diff] [blame] | 430 | revved_packages: A shared list of revved packages. |
| 431 | new_package_atoms: A shared list of new package atoms. |
Mike Frysinger | 62ff8d7 | 2020-05-19 03:06:51 -0400 | [diff] [blame] | 432 | reject_self_repo: Whether to abort if the ebuild lives in the same git |
| 433 | repo as it is tracking for uprevs. |
Ningning Xia | 783efc0 | 2018-01-24 13:39:51 -0800 | [diff] [blame] | 434 | """ |
Ningning Xia | 419e4eb | 2018-02-05 10:30:36 -0800 | [diff] [blame] | 435 | for overlay in overlays: |
| 436 | if not os.path.isdir(overlay): |
| 437 | logging.warning('Skipping %s, which is not a directory.', overlay) |
| 438 | continue |
Ningning Xia | 783efc0 | 2018-01-24 13:39:51 -0800 | [diff] [blame] | 439 | |
Ningning Xia | 419e4eb | 2018-02-05 10:30:36 -0800 | [diff] [blame] | 440 | # Note we intentionally work from the non push tracking branch; |
| 441 | # everything built thus far has been against it (meaning, http mirrors), |
| 442 | # thus we should honor that. During the actual push, the code switches |
| 443 | # to the correct urls, and does an appropriate rebasing. |
| 444 | tracking_branch = overlay_tracking_branch[overlay] |
Ningning Xia | 783efc0 | 2018-01-24 13:39:51 -0800 | [diff] [blame] | 445 | |
Ningning Xia | 783efc0 | 2018-01-24 13:39:51 -0800 | [diff] [blame] | 446 | existing_commit = git.GetGitRepoRevision(overlay) |
Lann Martin | e0ef98c | 2018-06-11 13:12:24 -0600 | [diff] [blame] | 447 | |
| 448 | # Make sure we run in the top-level git directory in case we are |
| 449 | # adding/removing an overlay in existing_commit. |
| 450 | git_root = git.FindGitTopLevel(overlay) |
| 451 | if git_root is None: |
| 452 | cros_build_lib.Die('No git repo at overlay directory %s.', overlay) |
| 453 | |
Ningning Xia | 783efc0 | 2018-01-24 13:39:51 -0800 | [diff] [blame] | 454 | work_branch = GitBranch(constants.STABLE_EBUILD_BRANCH, tracking_branch, |
Lann Martin | e0ef98c | 2018-06-11 13:12:24 -0600 | [diff] [blame] | 455 | cwd=git_root) |
Ningning Xia | 783efc0 | 2018-01-24 13:39:51 -0800 | [diff] [blame] | 456 | work_branch.CreateBranch() |
| 457 | if not work_branch.Exists(): |
| 458 | cros_build_lib.Die('Unable to create stabilizing branch in %s' % |
| 459 | overlay) |
| 460 | |
| 461 | # In the case of uprevving overlays that have patches applied to them, |
| 462 | # include the patched changes in the stabilizing branch. |
Lann Martin | e0ef98c | 2018-06-11 13:12:24 -0600 | [diff] [blame] | 463 | git.RunGit(git_root, ['rebase', existing_commit]) |
Ningning Xia | 783efc0 | 2018-01-24 13:39:51 -0800 | [diff] [blame] | 464 | |
Ningning Xia | db88432 | 2018-01-26 16:27:06 -0800 | [diff] [blame] | 465 | ebuilds = overlay_ebuilds.get(overlay, []) |
Ningning Xia | 783efc0 | 2018-01-24 13:39:51 -0800 | [diff] [blame] | 466 | if ebuilds: |
Ningning Xia | 419e4eb | 2018-02-05 10:30:36 -0800 | [diff] [blame] | 467 | with parallel.Manager() as manager: |
| 468 | # Contains the array of packages we actually revved. |
| 469 | messages = manager.list() |
| 470 | ebuild_paths_to_add = manager.list() |
| 471 | ebuild_paths_to_remove = manager.list() |
Ningning Xia | 783efc0 | 2018-01-24 13:39:51 -0800 | [diff] [blame] | 472 | |
Ningning Xia | 419e4eb | 2018-02-05 10:30:36 -0800 | [diff] [blame] | 473 | inputs = [[overlay, ebuild, manifest, options, ebuild_paths_to_add, |
| 474 | ebuild_paths_to_remove, messages, revved_packages, |
Mike Frysinger | 62ff8d7 | 2020-05-19 03:06:51 -0400 | [diff] [blame] | 475 | new_package_atoms, reject_self_repo] |
| 476 | for ebuild in ebuilds] |
Ningning Xia | 419e4eb | 2018-02-05 10:30:36 -0800 | [diff] [blame] | 477 | parallel.RunTasksInProcessPool(_WorkOnEbuild, inputs) |
Ningning Xia | 783efc0 | 2018-01-24 13:39:51 -0800 | [diff] [blame] | 478 | |
Ningning Xia | 419e4eb | 2018-02-05 10:30:36 -0800 | [diff] [blame] | 479 | if ebuild_paths_to_add: |
| 480 | logging.info('Adding new stable ebuild paths %s in overlay %s.', |
| 481 | ebuild_paths_to_add, overlay) |
| 482 | git.RunGit(overlay, ['add'] + list(ebuild_paths_to_add)) |
David James | 15ed130 | 2013-04-25 09:21:19 -0700 | [diff] [blame] | 483 | |
Ningning Xia | 419e4eb | 2018-02-05 10:30:36 -0800 | [diff] [blame] | 484 | if ebuild_paths_to_remove: |
| 485 | logging.info('Removing old ebuild paths %s in overlay %s.', |
| 486 | ebuild_paths_to_remove, overlay) |
| 487 | git.RunGit(overlay, ['rm', '-f'] + list(ebuild_paths_to_remove)) |
| 488 | |
| 489 | if messages: |
| 490 | portage_util.EBuild.CommitChange('\n\n'.join(messages), overlay) |
David James | 15ed130 | 2013-04-25 09:21:19 -0700 | [diff] [blame] | 491 | |
Ningning Xia | 783efc0 | 2018-01-24 13:39:51 -0800 | [diff] [blame] | 492 | |
| 493 | def _WorkOnEbuild(overlay, ebuild, manifest, options, ebuild_paths_to_add, |
| 494 | ebuild_paths_to_remove, messages, revved_packages, |
Mike Frysinger | 62ff8d7 | 2020-05-19 03:06:51 -0400 | [diff] [blame] | 495 | new_package_atoms, reject_self_repo=True): |
Ningning Xia | 783efc0 | 2018-01-24 13:39:51 -0800 | [diff] [blame] | 496 | """Work on a single ebuild. |
| 497 | |
| 498 | Args: |
| 499 | overlay: The overlay where the ebuild belongs to. |
| 500 | ebuild: The ebuild to work on. |
| 501 | manifest: The manifest of the given source root. |
| 502 | options: The options object returned by the argument parser. |
| 503 | ebuild_paths_to_add: New stable ebuild paths to add to git. |
| 504 | ebuild_paths_to_remove: Old ebuild paths to remove from git. |
| 505 | messages: A share list of commit messages. |
| 506 | revved_packages: A shared list of revved packages. |
| 507 | new_package_atoms: A shared list of new package atoms. |
Mike Frysinger | 62ff8d7 | 2020-05-19 03:06:51 -0400 | [diff] [blame] | 508 | reject_self_repo: Whether to abort if the ebuild lives in the same git |
| 509 | repo as it is tracking for uprevs. |
Ningning Xia | 783efc0 | 2018-01-24 13:39:51 -0800 | [diff] [blame] | 510 | """ |
| 511 | if options.verbose: |
| 512 | logging.info('Working on %s, info %s', ebuild.package, |
| 513 | ebuild.cros_workon_vars) |
Mike Frysinger | 00ba05a | 2020-06-12 02:44:02 -0400 | [diff] [blame] | 514 | if not ebuild.cros_workon_vars: |
| 515 | logging.warning('%s: unable to parse workon settings', ebuild.ebuild_path) |
| 516 | |
Ningning Xia | 783efc0 | 2018-01-24 13:39:51 -0800 | [diff] [blame] | 517 | try: |
Don Garrett | 4fef8c3 | 2018-08-10 18:04:01 -0700 | [diff] [blame] | 518 | result = ebuild.RevWorkOnEBuild(os.path.join(options.buildroot, 'src'), |
Mike Frysinger | 62ff8d7 | 2020-05-19 03:06:51 -0400 | [diff] [blame] | 519 | manifest, reject_self_repo=reject_self_repo) |
Ningning Xia | 783efc0 | 2018-01-24 13:39:51 -0800 | [diff] [blame] | 520 | if result: |
| 521 | new_package, ebuild_path_to_add, ebuild_path_to_remove = result |
| 522 | |
| 523 | if ebuild_path_to_add: |
| 524 | ebuild_paths_to_add.append(ebuild_path_to_add) |
| 525 | if ebuild_path_to_remove: |
| 526 | ebuild_paths_to_remove.append(ebuild_path_to_remove) |
| 527 | |
| 528 | messages.append(_GIT_COMMIT_MESSAGE % ebuild.package) |
Sam McNally | eb5e205 | 2018-09-05 16:34:55 +1000 | [diff] [blame] | 529 | |
| 530 | if options.list_revisions: |
| 531 | info = ebuild.GetSourceInfo(os.path.join(options.buildroot, 'src'), |
Mike Frysinger | 62ff8d7 | 2020-05-19 03:06:51 -0400 | [diff] [blame] | 532 | manifest, reject_self_repo=reject_self_repo) |
Sam McNally | eb5e205 | 2018-09-05 16:34:55 +1000 | [diff] [blame] | 533 | srcdirs = [os.path.join(options.buildroot, 'src', srcdir) |
| 534 | for srcdir in ebuild.cros_workon_vars.localname] |
| 535 | old_commit_ids = dict( |
| 536 | zip(srcdirs, ebuild.cros_workon_vars.commit.split(','))) |
| 537 | git_log = [] |
| 538 | for srcdir in info.srcdirs: |
| 539 | old_commit_id = old_commit_ids.get(srcdir) |
| 540 | new_commit_id = ebuild.GetCommitId(srcdir) |
| 541 | if not old_commit_id or old_commit_id == new_commit_id: |
| 542 | continue |
| 543 | |
| 544 | logs = git.RunGit(srcdir, [ |
| 545 | 'log', '%s..%s' % (old_commit_id[:8], new_commit_id[:8]), |
| 546 | '--pretty=format:%h %<(63,trunc)%s']) |
| 547 | git_log.append('$ ' + logs.cmdstr) |
| 548 | git_log.extend(line.strip() for line in logs.output.splitlines()) |
| 549 | if git_log: |
| 550 | messages.append('\n'.join(git_log)) |
| 551 | |
Ningning Xia | 783efc0 | 2018-01-24 13:39:51 -0800 | [diff] [blame] | 552 | revved_packages.append(ebuild.package) |
| 553 | new_package_atoms.append('=%s' % new_package) |
David Burger | 8cf4a76 | 2020-03-09 10:33:38 -0600 | [diff] [blame] | 554 | except portage_util.InvalidUprevSourceError as e: |
| 555 | logging.error('An error occurred while uprevving %s: %s', |
| 556 | ebuild.package, e) |
| 557 | raise |
Alex Klein | 9992066 | 2019-10-14 15:30:15 -0600 | [diff] [blame] | 558 | except portage_util.EbuildVersionError as e: |
| 559 | logging.warning('Unable to rev %s: %s', ebuild.package, e) |
| 560 | raise |
Mike Frysinger | b32cc47 | 2020-05-15 00:17:54 -0400 | [diff] [blame] | 561 | except OSError: |
Ningning Xia | 783efc0 | 2018-01-24 13:39:51 -0800 | [diff] [blame] | 562 | logging.warning( |
| 563 | 'Cannot rev %s\n' |
| 564 | 'Note you will have to go into %s ' |
Ningning Xia | 419e4eb | 2018-02-05 10:30:36 -0800 | [diff] [blame] | 565 | 'and reset the git repo yourself.', ebuild.package, overlay) |
Ningning Xia | 783efc0 | 2018-01-24 13:39:51 -0800 | [diff] [blame] | 566 | raise |