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