Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(574)

Unified Diff: gclient_scm.py

Issue 10103024: Check binary existence in gclient: 2nd try. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools/
Patch Set: Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | gclient_utils.py » ('j') | tests/gclient_scm_test.py » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: gclient_scm.py
===================================================================
--- gclient_scm.py (revision 132543)
+++ gclient_scm.py (working copy)
@@ -85,7 +85,10 @@
scm_name = GetScmName(url)
if not scm_name in SCM_MAP:
raise gclient_utils.Error('No SCM found for url %s' % url)
- return SCM_MAP[scm_name](url, root_dir, relpath)
+ found_scm = SCM_MAP[scm_name](url, root_dir, relpath)
+ if not found_scm.BinaryExists():
+ raise gclient_utils.Error('%s command not found' % scm_name)
+ return found_scm
# SCMWrapper base class
@@ -105,7 +108,19 @@
self.relpath = self.relpath.replace('/', os.sep)
if self.relpath and self._root_dir:
self.checkout_path = os.path.join(self._root_dir, self.relpath)
+ self._checker_command = 'help'
+ self._binary_name = None
+ def BinaryExists(self):
M-A Ruel 2012/04/17 12:15:55 This function may be called over 100 times for a g
Jun Mukai 2012/04/18 02:46:36 Oh, got it. Modified to use AssertVersion.
+ """Returns true if the command exists."""
+ # Do not call _Run() because this we don't want to leave any messages for
+ # this check.
+ try:
+ return gclient_utils.CheckCallAndFilter(
+ [self._binary_name, self._checker_command], print_stdout=False) == 0
+ except OSError:
+ return False
+
def RunCommand(self, command, options, args, file_list=None):
# file_list will have all files that are modified appended to it.
if file_list is None:
@@ -132,6 +147,7 @@
if url.startswith('git+http://') or url.startswith('git+https://'):
url = url[4:]
SCMWrapper.__init__(self, url, root_dir, relpath)
+ self._binary_name = 'git'
def GetRevisionDate(self, revision):
"""Returns the given revision's date in ISO-8601 format (which contains the
@@ -759,7 +775,7 @@
def _Capture(self, args):
return subprocess2.check_output(
- ['git'] + args,
+ [self._binary_name] + args,
stderr=subprocess2.PIPE,
cwd=self.checkout_path).strip()
@@ -769,12 +785,16 @@
stdout = kwargs.get('stdout', sys.stdout)
stdout.write('\n________ running \'git %s\' in \'%s\'\n' % (
' '.join(args), kwargs['cwd']))
- gclient_utils.CheckCallAndFilter(['git'] + args, **kwargs)
+ gclient_utils.CheckCallAndFilter([self._binary_name] + args, **kwargs)
class SVNWrapper(SCMWrapper):
""" Wrapper for SVN """
+ def __init__(self, url=None, root_dir=None, relpath=None):
+ SCMWrapper.__init__(self, url, root_dir, relpath)
+ self._binary_name = 'svn'
+
def GetRevisionDate(self, revision):
"""Returns the given revision's date in ISO-8601 format (which contains the
time zone)."""
@@ -1094,7 +1114,7 @@
def _Run(self, args, options, **kwargs):
"""Runs a commands that goes to stdout."""
kwargs.setdefault('cwd', self.checkout_path)
- gclient_utils.CheckCallAndFilterAndHeader(['svn'] + args,
+ gclient_utils.CheckCallAndFilterAndHeader([self._binary_name] + args,
always=options.verbose, **kwargs)
def _RunAndGetFileList(self, args, options, file_list, cwd=None):
« no previous file with comments | « no previous file | gclient_utils.py » ('j') | tests/gclient_scm_test.py » ('J')

Powered by Google App Engine
This is Rietveld 408576698