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