mirror of
https://chromium.googlesource.com/chromium/tools/depot_tools.git
synced 2026-01-11 18:51:29 +00:00
Fix roll-dep commit message on Windows and add suggestions
roll-dep would confidently print "Commit message:" but then on Windows
would only actually give the first line of the message to git. This is
because multi-line command-lines don't actually work on all shells. This
change passes the commit message using a temporary file so that the full
message is retained on all operating systems.
This change also teaches roll-dep to give suggestions when a specified
dependency is not quite correct. This is particularly helpful if a
leading or trailing directory name is used. For instance, this command
seems plausible:
roll-dep third_party/openh264
But in fact it is wrong and a new user has to realize that a src prefix
is needed (in general) and in this specific case a src suffix is needed
as well. Prior to this change the error message would be:
KeyError: 'Could not find any dependency called third_party/openh264.'
But after this message it will instead say:
KeyError: 'Could not find any dependency called third_party/openh264. Did you mean src/third_party/openh264/src'
Past me wishes I'd done this years ago.
Change-Id: I6e0d6c703906b1c1ec947788fa259bae7b7520cf
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/4120534
Reviewed-by: Joanna Wang <jojwang@chromium.org>
Commit-Queue: Bruce Dawson <brucedawson@chromium.org>
This commit is contained in:
@@ -42,7 +42,7 @@ class ConstantString(object):
|
|||||||
return self.value == other
|
return self.value == other
|
||||||
|
|
||||||
def __hash__(self):
|
def __hash__(self):
|
||||||
return self.value.__hash__()
|
return self.value.__hash__()
|
||||||
|
|
||||||
|
|
||||||
class _NodeDict(collections_abc.MutableMapping):
|
class _NodeDict(collections_abc.MutableMapping):
|
||||||
@@ -893,6 +893,15 @@ def GetCIPD(gclient_dict, dep_name, package_name):
|
|||||||
|
|
||||||
def GetRevision(gclient_dict, dep_name):
|
def GetRevision(gclient_dict, dep_name):
|
||||||
if 'deps' not in gclient_dict or dep_name not in gclient_dict['deps']:
|
if 'deps' not in gclient_dict or dep_name not in gclient_dict['deps']:
|
||||||
|
suggestions = []
|
||||||
|
if 'deps' in gclient_dict:
|
||||||
|
for key in gclient_dict['deps']:
|
||||||
|
if dep_name in key:
|
||||||
|
suggestions.append(key)
|
||||||
|
if suggestions:
|
||||||
|
raise KeyError(
|
||||||
|
"Could not find any dependency called %s. Did you mean %s" %
|
||||||
|
(dep_name, ' or '.join(suggestions)))
|
||||||
raise KeyError(
|
raise KeyError(
|
||||||
"Could not find any dependency called %s." % dep_name)
|
"Could not find any dependency called %s." % dep_name)
|
||||||
|
|
||||||
|
|||||||
10
roll_dep.py
10
roll_dep.py
@@ -17,6 +17,7 @@ import os
|
|||||||
import re
|
import re
|
||||||
import subprocess2
|
import subprocess2
|
||||||
import sys
|
import sys
|
||||||
|
import tempfile
|
||||||
|
|
||||||
NEED_SHELL = sys.platform.startswith('win')
|
NEED_SHELL = sys.platform.startswith('win')
|
||||||
GCLIENT_PATH = os.path.join(
|
GCLIENT_PATH = os.path.join(
|
||||||
@@ -187,7 +188,14 @@ def finalize(commit_msg, current_dir, rolls):
|
|||||||
print('\n'.join(' ' + i for i in commit_msg.splitlines()))
|
print('\n'.join(' ' + i for i in commit_msg.splitlines()))
|
||||||
|
|
||||||
check_call(['git', 'add', 'DEPS'], cwd=current_dir)
|
check_call(['git', 'add', 'DEPS'], cwd=current_dir)
|
||||||
check_call(['git', 'commit', '--quiet', '-m', commit_msg], cwd=current_dir)
|
# We have to set delete=False and then let the object go out of scope so
|
||||||
|
# that the file can be opened by name on Windows.
|
||||||
|
with tempfile.NamedTemporaryFile('w+', newline='', delete=False) as f:
|
||||||
|
commit_filename = f.name
|
||||||
|
f.write(commit_msg)
|
||||||
|
check_call(['git', 'commit', '--quiet', '--file', commit_filename],
|
||||||
|
cwd=current_dir)
|
||||||
|
os.remove(commit_filename)
|
||||||
|
|
||||||
# Pull the dependency to the right revision. This is surprising to users
|
# Pull the dependency to the right revision. This is surprising to users
|
||||||
# otherwise.
|
# otherwise.
|
||||||
|
|||||||
Reference in New Issue
Block a user