From 9e8fb0e5d70589e04c3dc47970cb294842beb9ac Mon Sep 17 00:00:00 2001 From: Aleksandr Derbenev Date: Tue, 1 Aug 2017 20:18:31 +0300 Subject: [PATCH] Add --cache-dir argument to gclient. There are some usecases where it is simpler to pass path to the cache by an environment variable or command-line argument than to modify the gclient config file. With this change: * GCLIENT_CACHE_DIR environment variable overrides cache_dir variable from .gclient file. * --cache-dir argument moved from gclient config to all gclient commands and overrides values from .gclient file and environment variable. R=dpranke@chromium.org Bug: Change-Id: Iae107f1d5f02a2eee1896d0d3108dc20a83d597f Reviewed-on: https://chromium-review.googlesource.com/596089 Reviewed-by: Dirk Pranke Reviewed-by: Daniel Jacques Commit-Queue: Aleksandr Derbenev --- gclient.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/gclient.py b/gclient.py index 1872623f03..898183eaa8 100755 --- a/gclient.py +++ b/gclient.py @@ -1267,7 +1267,7 @@ it or fix the checkout. else: self._enforced_os = tuple(set(self._enforced_os).union(target_os)) - cache_dir = config_dict.get('cache_dir') + cache_dir = config_dict.get('cache_dir', self._options.cache_dir) if cache_dir: cache_dir = os.path.join(self.root_dir, cache_dir) cache_dir = os.path.abspath(cache_dir) @@ -2043,10 +2043,6 @@ def CMDconfig(parser, args): 'to have the main solution untouched by gclient ' '(gclient will check out unmanaged dependencies but ' 'will never sync them)') - parser.add_option('--cache-dir', - help='(git only) Cache all git repos into this dir and do ' - 'shared clones from the cache, instead of cloning ' - 'directly from the remote. (experimental)') parser.set_defaults(config_filename=None) (options, args) = parser.parse_args(args) if options.output_config_file: @@ -2417,6 +2413,12 @@ class OptionParser(optparse.OptionParser): '--spec', help='create a gclient file containing the provided string. Due to ' 'Cygwin/Python brokenness, it can\'t contain any newlines.') + self.add_option( + '--cache-dir', + help='(git only) Cache all git repos into this dir and do ' + 'shared clones from the cache, instead of cloning ' + 'directly from the remote. (experimental)', + default=os.environ.get('GCLIENT_CACHE_DIR')) self.add_option( '--no-nag-max', default=False, action='store_true', help='Ignored for backwards compatibility.')