Add post upload Python 3 option

Adds --no-python2-post-upload-hooks to git_cl.py. This causes any
post upload hooks to only run under Python 3. Without this, uploading
CLs from builders that omit Python 2 causes the CL the step to fail
after the CL is uploaded.

Bug: 1340617
Change-Id: I5fb45922fb05b28ad570091f9e285dd533d92336
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/3996467
Auto-Submit: Brian Sheedy <bsheedy@chromium.org>
Commit-Queue: Joanna Wang <jojwang@chromium.org>
Reviewed-by: Joanna Wang <jojwang@chromium.org>
changes/67/3996467/2
Brian Sheedy 2 years ago committed by LUCI CQ
parent 1adbbff2c0
commit 7326ca218b

@ -1455,17 +1455,19 @@ class Changelist(object):
py2_results.get('warnings', []) + py3_results.get('warnings', []))
}
def RunPostUploadHook(self, verbose, upstream, description):
def RunPostUploadHook(self, verbose, upstream, description, py3_only):
args = self._GetCommonPresubmitArgs(verbose, upstream)
args.append('--post_upload')
with gclient_utils.temporary_file() as description_file:
gclient_utils.FileWrite(description_file, description)
args.extend(['--description_file', description_file])
p_py2 = subprocess2.Popen(['vpython', PRESUBMIT_SUPPORT] + args)
if not py3_only:
p_py2 = subprocess2.Popen(['vpython', PRESUBMIT_SUPPORT] + args)
p_py3 = subprocess2.Popen(['vpython3', PRESUBMIT_SUPPORT] + args +
['--use-python3'])
p_py2.wait()
if not py3_only:
p_py2.wait()
p_py3.wait()
def _GetDescriptionForUpload(self, options, git_diff_args, files):
@ -1599,8 +1601,9 @@ class Changelist(object):
'last-upload-hash', scm.GIT.ResolveCommit(settings.GetRoot(), 'HEAD'))
# Run post upload hooks, if specified.
if settings.GetRunPostUploadHook():
self.RunPostUploadHook(
options.verbose, base_branch, change_desc.description)
self.RunPostUploadHook(options.verbose, base_branch,
change_desc.description,
options.no_python2_post_upload_hooks)
# Upload all dependencies if specified.
if options.dependencies:
@ -4402,6 +4405,9 @@ def CMDupload(parser, args):
action='store_true',
dest='no_add_changeid',
help='Do not add change-ids to messages.')
parser.add_option('--no-python2-post-upload-hooks',
action='store_true',
help='Only run post-upload hooks in Python 3.')
orig_args = args
(options, args) = parser.parse_args(args)

@ -3315,7 +3315,7 @@ class ChangelistTest(unittest.TestCase):
def testRunPostUploadHook(self):
cl = git_cl.Changelist()
cl.RunPostUploadHook(2, 'upstream', 'description')
cl.RunPostUploadHook(2, 'upstream', 'description', False)
subprocess2.Popen.assert_any_call([
'vpython',
@ -3372,6 +3372,40 @@ class ChangelistTest(unittest.TestCase):
gclient_utils.FileWrite.assert_called_once_with(
'/tmp/fake-temp1', 'description')
def testRunPostUploadHookPy3Only(self):
cl = git_cl.Changelist()
cl.RunPostUploadHook(2, 'upstream', 'description', True)
subprocess2.Popen.assert_called_once_with([
'vpython3',
'PRESUBMIT_SUPPORT',
'--root',
'root',
'--upstream',
'upstream',
'--verbose',
'--verbose',
'--gerrit_url',
'https://chromium-review.googlesource.com',
'--gerrit_project',
'project',
'--gerrit_branch',
'refs/heads/main',
'--author',
'author',
'--issue',
'123456',
'--patchset',
'7',
'--post_upload',
'--description_file',
'/tmp/fake-temp1',
'--use-python3',
])
gclient_utils.FileWrite.assert_called_once_with('/tmp/fake-temp1',
'description')
@mock.patch('git_cl.RunGit', _mock_run_git)
def testDefaultTitleEmptyMessage(self):
cl = git_cl.Changelist()

Loading…
Cancel
Save