mirror of
https://chromium.googlesource.com/chromium/tools/depot_tools.git
synced 2026-01-11 18:51:29 +00:00
bot_update: Use 'gclient' from same repository.
Currently, 'bot_update' uses the 'gclient' that is on the system path. Now, it will use the 'gclient.py' that is in the same 'depot_tools' checkout as the 'bot_update' recipe module. Also don't ignore "git_cache" move errors. BUG=664254,663990,663440 TEST=None Review-Url: https://codereview.chromium.org/2492963002
This commit is contained in:
13
git_cache.py
13
git_cache.py
@@ -439,16 +439,9 @@ class Mirror(object):
|
||||
self._fetch(tempdir or self.mirror_path, verbose, depth)
|
||||
finally:
|
||||
if tempdir:
|
||||
try:
|
||||
if os.path.exists(self.mirror_path):
|
||||
gclient_utils.rmtree(self.mirror_path)
|
||||
os.rename(tempdir, self.mirror_path)
|
||||
except OSError as e:
|
||||
# This is somehow racy on Windows.
|
||||
# Catching OSError because WindowsError isn't portable and
|
||||
# pylint complains.
|
||||
self.print('Error moving %s to %s: %s' % (tempdir, self.mirror_path,
|
||||
str(e)))
|
||||
if os.path.exists(self.mirror_path):
|
||||
gclient_utils.rmtree(self.mirror_path)
|
||||
os.rename(tempdir, self.mirror_path)
|
||||
if not ignore_lock:
|
||||
lockfile.unlock()
|
||||
|
||||
|
||||
@@ -82,6 +82,7 @@ cache_dir = r%(cache_dir)s
|
||||
ATTEMPTS = 5
|
||||
|
||||
GIT_CACHE_PATH = path.join(DEPOT_TOOLS_DIR, 'git_cache.py')
|
||||
GCLIENT_PATH = path.join(DEPOT_TOOLS_DIR, 'gclient.py')
|
||||
|
||||
# If there is less than 100GB of disk space on the system, then we do
|
||||
# a shallow checkout.
|
||||
@@ -319,6 +320,18 @@ def ensure_no_checkout(dir_names):
|
||||
print 'done'
|
||||
|
||||
|
||||
def call_gclient(*args, **kwargs):
|
||||
"""Run the "gclient.py" tool with the supplied arguments.
|
||||
|
||||
Args:
|
||||
args: command-line arguments to pass to gclient.
|
||||
kwargs: keyword arguments to pass to call.
|
||||
"""
|
||||
cmd = [sys.executable, '-u', GCLIENT_PATH]
|
||||
cmd.extend(args)
|
||||
return call(*cmd, **kwargs)
|
||||
|
||||
|
||||
def gclient_configure(solutions, target_os, target_os_only, git_cache_dir):
|
||||
"""Should do the same thing as gclient --spec='...'."""
|
||||
with codecs.open('.gclient', mode='w', encoding='utf-8') as f:
|
||||
@@ -330,19 +343,19 @@ def gclient_sync(with_branch_heads, shallow, break_repo_locks):
|
||||
# We just need to allocate a filename.
|
||||
fd, gclient_output_file = tempfile.mkstemp(suffix='.json')
|
||||
os.close(fd)
|
||||
gclient_bin = 'gclient.bat' if sys.platform.startswith('win') else 'gclient'
|
||||
cmd = [gclient_bin, 'sync', '--verbose', '--reset', '--force',
|
||||
|
||||
args = ['sync', '--verbose', '--reset', '--force',
|
||||
'--ignore_locks', '--output-json', gclient_output_file,
|
||||
'--nohooks', '--noprehooks', '--delete_unversioned_trees']
|
||||
if with_branch_heads:
|
||||
cmd += ['--with_branch_heads']
|
||||
args += ['--with_branch_heads']
|
||||
if shallow:
|
||||
cmd += ['--shallow']
|
||||
args += ['--shallow']
|
||||
if break_repo_locks:
|
||||
cmd += ['--break_repo_locks']
|
||||
args += ['--break_repo_locks']
|
||||
|
||||
try:
|
||||
call(*cmd, tries=1)
|
||||
call_gclient(*args, tries=1)
|
||||
except SubprocessFailed as e:
|
||||
# Throw a GclientSyncFailed exception so we can catch this independently.
|
||||
raise GclientSyncFailed(e.message, e.code, e.output)
|
||||
@@ -354,8 +367,7 @@ def gclient_sync(with_branch_heads, shallow, break_repo_locks):
|
||||
|
||||
|
||||
def gclient_revinfo():
|
||||
gclient_bin = 'gclient.bat' if sys.platform.startswith('win') else 'gclient'
|
||||
return call(gclient_bin, 'revinfo', '-a') or ''
|
||||
return call_gclient('revinfo', '-a') or ''
|
||||
|
||||
|
||||
def create_manifest():
|
||||
|
||||
@@ -167,7 +167,9 @@ class BotUpdateUnittests(unittest.TestCase):
|
||||
self.filesystem = FakeFilesystem()
|
||||
self.call = MockedCall(self.filesystem)
|
||||
self.gclient = MockedGclientSync(self.filesystem)
|
||||
self.call.expect(('gclient', 'sync')).returns(self.gclient)
|
||||
self.call.expect(
|
||||
(sys.executable, '-u', bot_update.GCLIENT_PATH, 'sync')
|
||||
).returns(self.gclient)
|
||||
self.old_call = getattr(bot_update, 'call')
|
||||
self.params = copy.deepcopy(DEFAULT_PARAMS)
|
||||
setattr(bot_update, 'call', self.call)
|
||||
@@ -188,7 +190,9 @@ class BotUpdateUnittests(unittest.TestCase):
|
||||
|
||||
def overrideSetupForWindows(self):
|
||||
sys.platform = 'win'
|
||||
self.call.expect(('gclient.bat', 'sync')).returns(self.gclient)
|
||||
self.call.expect(
|
||||
(sys.executable, '-u', bot_update.GCLIENT_PATH, 'sync')
|
||||
).returns(self.gclient)
|
||||
|
||||
def testBasic(self):
|
||||
bot_update.ensure_checkout(**self.params)
|
||||
@@ -205,7 +209,7 @@ class BotUpdateUnittests(unittest.TestCase):
|
||||
gclient_sync_cmd = None
|
||||
for record in self.call.records:
|
||||
args = record[0]
|
||||
if args[0] == 'gclient.bat' and args[1] == 'sync':
|
||||
if args[:4] == (sys.executable, '-u', bot_update.GCLIENT_PATH, 'sync'):
|
||||
gclient_sync_cmd = args
|
||||
self.assertTrue('--break_repo_locks' in gclient_sync_cmd)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user