bot_update: make location of git cache configurable

Depends on https://codereview.chromium.org/1667713002

BUG=583626

Review URL: https://codereview.chromium.org/1663493005

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@298552 0039d316-1c4b-4281-b951-d872f2087c98
parent 2c460df0
...@@ -5,5 +5,5 @@ deps { ...@@ -5,5 +5,5 @@ deps {
project_id: "recipe_engine" project_id: "recipe_engine"
url: "https://chromium.googlesource.com/external/github.com/luci/recipes-py.git" url: "https://chromium.googlesource.com/external/github.com/luci/recipes-py.git"
branch: "master" branch: "master"
revision: "44b384f9b4f1085e9cfe43ea6308735a3af8d4e5" revision: "4bde23de86ea54a8a0dc0f1658cd59c763475e7d"
} }
...@@ -141,6 +141,7 @@ class BotUpdateApi(recipe_api.RecipeApi): ...@@ -141,6 +141,7 @@ class BotUpdateApi(recipe_api.RecipeApi):
['--spec', spec_string], ['--spec', spec_string],
['--root', root], ['--root', root],
['--revision_mapping_file', self.m.json.input(rev_map)], ['--revision_mapping_file', self.m.json.input(rev_map)],
['--git-cache-dir', self.m.path['git_cache']],
# 3. How to find the patch, if any (issue/patchset/patch_url). # 3. How to find the patch, if any (issue/patchset/patch_url).
['--issue', issue], ['--issue', issue],
......
...@@ -16,6 +16,8 @@ ...@@ -16,6 +16,8 @@
"src", "src",
"--revision_mapping_file", "--revision_mapping_file",
"{\"src\": \"got_cr_revision\"}", "{\"src\": \"got_cr_revision\"}",
"--git-cache-dir",
"[GIT_CACHE]",
"--output_json", "--output_json",
"/path/to/tmp/json", "/path/to/tmp/json",
"--revision", "--revision",
......
...@@ -16,6 +16,8 @@ ...@@ -16,6 +16,8 @@
"src", "src",
"--revision_mapping_file", "--revision_mapping_file",
"{\"src\": \"got_cr_revision\"}", "{\"src\": \"got_cr_revision\"}",
"--git-cache-dir",
"[GIT_CACHE]",
"--output_json", "--output_json",
"/path/to/tmp/json", "/path/to/tmp/json",
"--revision", "--revision",
......
...@@ -16,6 +16,8 @@ ...@@ -16,6 +16,8 @@
"src", "src",
"--revision_mapping_file", "--revision_mapping_file",
"{\"src\": \"got_cr_revision\"}", "{\"src\": \"got_cr_revision\"}",
"--git-cache-dir",
"[GIT_CACHE]",
"--output_json", "--output_json",
"/path/to/tmp/json", "/path/to/tmp/json",
"--revision", "--revision",
......
...@@ -16,6 +16,8 @@ ...@@ -16,6 +16,8 @@
"src", "src",
"--revision_mapping_file", "--revision_mapping_file",
"{\"src\": \"got_cr_revision\"}", "{\"src\": \"got_cr_revision\"}",
"--git-cache-dir",
"[GIT_CACHE]",
"--output_json", "--output_json",
"/path/to/tmp/json", "/path/to/tmp/json",
"--revision", "--revision",
......
...@@ -16,6 +16,8 @@ ...@@ -16,6 +16,8 @@
"src", "src",
"--revision_mapping_file", "--revision_mapping_file",
"{\"src\": \"got_cr_revision\"}", "{\"src\": \"got_cr_revision\"}",
"--git-cache-dir",
"[GIT_CACHE]",
"--output_json", "--output_json",
"/path/to/tmp/json", "/path/to/tmp/json",
"--revision", "--revision",
......
...@@ -16,6 +16,8 @@ ...@@ -16,6 +16,8 @@
"src", "src",
"--revision_mapping_file", "--revision_mapping_file",
"{\"src\": \"got_cr_revision\"}", "{\"src\": \"got_cr_revision\"}",
"--git-cache-dir",
"[GIT_CACHE]",
"--output_json", "--output_json",
"/path/to/tmp/json", "/path/to/tmp/json",
"--revision", "--revision",
......
...@@ -16,6 +16,8 @@ ...@@ -16,6 +16,8 @@
"src", "src",
"--revision_mapping_file", "--revision_mapping_file",
"{\"src\": \"got_cr_revision\"}", "{\"src\": \"got_cr_revision\"}",
"--git-cache-dir",
"[GIT_CACHE]",
"--output_json", "--output_json",
"/path/to/tmp/json", "/path/to/tmp/json",
"--revision", "--revision",
......
...@@ -16,6 +16,8 @@ ...@@ -16,6 +16,8 @@
"src", "src",
"--revision_mapping_file", "--revision_mapping_file",
"{\"src\": \"got_cr_revision\"}", "{\"src\": \"got_cr_revision\"}",
"--git-cache-dir",
"[GIT_CACHE]",
"--output_json", "--output_json",
"/path/to/tmp/json", "/path/to/tmp/json",
"--revision", "--revision",
......
...@@ -16,6 +16,8 @@ ...@@ -16,6 +16,8 @@
"src", "src",
"--revision_mapping_file", "--revision_mapping_file",
"{\"src\": \"got_cr_revision\"}", "{\"src\": \"got_cr_revision\"}",
"--git-cache-dir",
"[GIT_CACHE]",
"--output_json", "--output_json",
"/path/to/tmp/json", "/path/to/tmp/json",
"--revision", "--revision",
......
...@@ -16,6 +16,8 @@ ...@@ -16,6 +16,8 @@
"src", "src",
"--revision_mapping_file", "--revision_mapping_file",
"{\"src\": \"got_cr_revision\"}", "{\"src\": \"got_cr_revision\"}",
"--git-cache-dir",
"[GIT_CACHE]",
"--output_json", "--output_json",
"/path/to/tmp/json", "/path/to/tmp/json",
"--revision", "--revision",
......
...@@ -16,6 +16,8 @@ ...@@ -16,6 +16,8 @@
"src", "src",
"--revision_mapping_file", "--revision_mapping_file",
"{\"src\": \"got_cr_revision\"}", "{\"src\": \"got_cr_revision\"}",
"--git-cache-dir",
"[GIT_CACHE]",
"--apply_issue_email_file", "--apply_issue_email_file",
"[BUILD]/site_config/.rietveld_client_email", "[BUILD]/site_config/.rietveld_client_email",
"--apply_issue_key_file", "--apply_issue_key_file",
......
...@@ -16,6 +16,8 @@ ...@@ -16,6 +16,8 @@
"src", "src",
"--revision_mapping_file", "--revision_mapping_file",
"{\"src\": \"got_cr_revision\"}", "{\"src\": \"got_cr_revision\"}",
"--git-cache-dir",
"[GIT_CACHE]",
"--patch_url", "--patch_url",
"http://src.chromium.org/foo/bar", "http://src.chromium.org/foo/bar",
"--output_json", "--output_json",
......
...@@ -16,6 +16,8 @@ ...@@ -16,6 +16,8 @@
"src", "src",
"--revision_mapping_file", "--revision_mapping_file",
"{\"src\": \"got_cr_revision\"}", "{\"src\": \"got_cr_revision\"}",
"--git-cache-dir",
"[GIT_CACHE]",
"--patch_url", "--patch_url",
"http://src.chromium.org/foo/bar", "http://src.chromium.org/foo/bar",
"--output_json", "--output_json",
......
...@@ -16,6 +16,8 @@ ...@@ -16,6 +16,8 @@
"src", "src",
"--revision_mapping_file", "--revision_mapping_file",
"{\"src\": \"got_cr_revision\"}", "{\"src\": \"got_cr_revision\"}",
"--git-cache-dir",
"[GIT_CACHE]",
"--patch_url", "--patch_url",
"http://src.chromium.org/foo/bar", "http://src.chromium.org/foo/bar",
"--output_json", "--output_json",
......
...@@ -16,6 +16,8 @@ ...@@ -16,6 +16,8 @@
"src", "src",
"--revision_mapping_file", "--revision_mapping_file",
"{\"src\": \"got_cr_revision\"}", "{\"src\": \"got_cr_revision\"}",
"--git-cache-dir",
"[GIT_CACHE]",
"--patch_url", "--patch_url",
"http://src.chromium.org/foo/bar", "http://src.chromium.org/foo/bar",
"--output_json", "--output_json",
......
...@@ -16,6 +16,8 @@ ...@@ -16,6 +16,8 @@
"src/v8", "src/v8",
"--revision_mapping_file", "--revision_mapping_file",
"{\"src\": \"got_cr_revision\"}", "{\"src\": \"got_cr_revision\"}",
"--git-cache-dir",
"[GIT_CACHE]",
"--patch_url", "--patch_url",
"http://src.chromium.org/foo/bar", "http://src.chromium.org/foo/bar",
"--output_json", "--output_json",
......
...@@ -352,15 +352,7 @@ DEPS2GIT_DIR_PATH = path.join(SCRIPTS_DIR, 'tools', 'deps2git') ...@@ -352,15 +352,7 @@ DEPS2GIT_DIR_PATH = path.join(SCRIPTS_DIR, 'tools', 'deps2git')
DEPS2GIT_PATH = path.join(DEPS2GIT_DIR_PATH, 'deps2git.py') DEPS2GIT_PATH = path.join(DEPS2GIT_DIR_PATH, 'deps2git.py')
S2G_INTERNAL_PATH = path.join(SCRIPTS_DIR, 'tools', 'deps2git_internal', S2G_INTERNAL_PATH = path.join(SCRIPTS_DIR, 'tools', 'deps2git_internal',
'svn_to_git_internal.py') 'svn_to_git_internal.py')
# ../../cache_dir aka /b/build/slave/cache_dir
GIT_CACHE_PATH = path.join(DEPOT_TOOLS_DIR, 'git_cache.py') GIT_CACHE_PATH = path.join(DEPOT_TOOLS_DIR, 'git_cache.py')
CACHE_DIR = path.join(SLAVE_DIR, 'cache_dir')
# Because we print CACHE_DIR out into a .gclient file, and then later run
# eval() on it, backslashes need to be escaped, otherwise "E:\b\build" gets
# parsed as "E:[\x08][\x08]uild".
if sys.platform.startswith('win'):
CACHE_DIR = CACHE_DIR.replace('\\', '\\\\')
# Find the patch tool. # Find the patch tool.
if sys.platform.startswith('win'): if sys.platform.startswith('win'):
...@@ -525,10 +517,10 @@ def git(*args, **kwargs): # pragma: no cover ...@@ -525,10 +517,10 @@ def git(*args, **kwargs): # pragma: no cover
return call(*cmd, **kwargs) return call(*cmd, **kwargs)
def get_gclient_spec(solutions, target_os, target_os_only): def get_gclient_spec(solutions, target_os, target_os_only, git_cache_dir):
return GCLIENT_TEMPLATE % { return GCLIENT_TEMPLATE % {
'solutions': pprint.pformat(solutions, indent=4), 'solutions': pprint.pformat(solutions, indent=4),
'cache_dir': '"%s"' % CACHE_DIR, 'cache_dir': '"%s"' % git_cache_dir,
'target_os': ('\ntarget_os=%s' % target_os) if target_os else '', 'target_os': ('\ntarget_os=%s' % target_os) if target_os else '',
'target_os_only': '\ntarget_os_only=%s' % target_os_only 'target_os_only': '\ntarget_os_only=%s' % target_os_only
} }
...@@ -700,10 +692,11 @@ def ensure_no_checkout(dir_names, scm_dirname): ...@@ -700,10 +692,11 @@ def ensure_no_checkout(dir_names, scm_dirname):
print 'done' print 'done'
def gclient_configure(solutions, target_os, target_os_only): def gclient_configure(solutions, target_os, target_os_only, git_cache_dir):
"""Should do the same thing as gclient --spec='...'.""" """Should do the same thing as gclient --spec='...'."""
with codecs.open('.gclient', mode='w', encoding='utf-8') as f: with codecs.open('.gclient', mode='w', encoding='utf-8') as f:
f.write(get_gclient_spec(solutions, target_os, target_os_only)) f.write(get_gclient_spec(
solutions, target_os, target_os_only, git_cache_dir))
def gclient_sync(with_branch_heads, shallow): def gclient_sync(with_branch_heads, shallow):
...@@ -842,7 +835,7 @@ def need_to_run_deps2git(repo_base, deps_file, deps_git_file): ...@@ -842,7 +835,7 @@ def need_to_run_deps2git(repo_base, deps_file, deps_git_file):
return last_known_deps_ref != merge_base_ref return last_known_deps_ref != merge_base_ref
def ensure_deps2git(solution, shallow): def ensure_deps2git(solution, shallow, git_cache_dir):
repo_base = path.join(os.getcwd(), solution['name']) repo_base = path.join(os.getcwd(), solution['name'])
deps_file = path.join(repo_base, 'DEPS') deps_file = path.join(repo_base, 'DEPS')
deps_git_file = path.join(repo_base, '.DEPS.git') deps_git_file = path.join(repo_base, '.DEPS.git')
...@@ -857,7 +850,7 @@ def ensure_deps2git(solution, shallow): ...@@ -857,7 +850,7 @@ def ensure_deps2git(solution, shallow):
print '===DEPS file modified, need to run deps2git===' print '===DEPS file modified, need to run deps2git==='
cmd = [sys.executable, DEPS2GIT_PATH, cmd = [sys.executable, DEPS2GIT_PATH,
'--workspace', os.getcwd(), '--workspace', os.getcwd(),
'--cache_dir', CACHE_DIR, '--cache_dir', git_cache_dir,
'--deps', deps_file, '--deps', deps_file,
'--out', deps_git_file] '--out', deps_git_file]
if 'chrome-internal.googlesource' in solution['url']: if 'chrome-internal.googlesource' in solution['url']:
...@@ -932,13 +925,14 @@ def force_revision(folder_name, revision): ...@@ -932,13 +925,14 @@ def force_revision(folder_name, revision):
ref = branch if branch.startswith('refs/') else 'origin/%s' % branch ref = branch if branch.startswith('refs/') else 'origin/%s' % branch
git('checkout', '--force', ref, cwd=folder_name) git('checkout', '--force', ref, cwd=folder_name)
def git_checkout(solutions, revisions, shallow, refs): def git_checkout(solutions, revisions, shallow, refs, git_cache_dir):
build_dir = os.getcwd() build_dir = os.getcwd()
# Before we do anything, break all git_cache locks. # Before we do anything, break all git_cache locks.
if path.isdir(CACHE_DIR): if path.isdir(git_cache_dir):
git('cache', 'unlock', '-vv', '--force', '--all', '--cache-dir', CACHE_DIR) git('cache', 'unlock', '-vv', '--force', '--all',
for item in os.listdir(CACHE_DIR): '--cache-dir', git_cache_dir)
filename = os.path.join(CACHE_DIR, item) for item in os.listdir(git_cache_dir):
filename = os.path.join(git_cache_dir, item)
if item.endswith('.lock'): if item.endswith('.lock'):
raise Exception('%s exists after cache unlock' % filename) raise Exception('%s exists after cache unlock' % filename)
first_solution = True first_solution = True
...@@ -957,12 +951,13 @@ def git_checkout(solutions, revisions, shallow, refs): ...@@ -957,12 +951,13 @@ def git_checkout(solutions, revisions, shallow, refs):
sln_dir = path.join(build_dir, name) sln_dir = path.join(build_dir, name)
s = ['--shallow'] if shallow else [] s = ['--shallow'] if shallow else []
populate_cmd = (['cache', 'populate', '--ignore_locks', '-v', populate_cmd = (['cache', 'populate', '--ignore_locks', '-v',
'--cache-dir', CACHE_DIR] + s + [url]) '--cache-dir', git_cache_dir] + s + [url])
for ref in refs: for ref in refs:
populate_cmd.extend(['--ref', ref]) populate_cmd.extend(['--ref', ref])
git(*populate_cmd) git(*populate_cmd)
mirror_dir = git( mirror_dir = git(
'cache', 'exists', '--quiet', '--cache-dir', CACHE_DIR, url).strip() 'cache', 'exists', '--quiet',
'--cache-dir', git_cache_dir, url).strip()
clone_cmd = ( clone_cmd = (
'clone', '--no-checkout', '--local', '--shared', mirror_dir, sln_dir) 'clone', '--no-checkout', '--local', '--shared', mirror_dir, sln_dir)
...@@ -1300,13 +1295,13 @@ def ensure_checkout(solutions, revisions, first_sln, target_os, target_os_only, ...@@ -1300,13 +1295,13 @@ def ensure_checkout(solutions, revisions, first_sln, target_os, target_os_only,
patch_root, issue, patchset, patch_url, rietveld_server, patch_root, issue, patchset, patch_url, rietveld_server,
gerrit_repo, gerrit_ref, revision_mapping, gerrit_repo, gerrit_ref, revision_mapping,
apply_issue_email_file, apply_issue_key_file, buildspec, apply_issue_email_file, apply_issue_key_file, buildspec,
gyp_env, shallow, runhooks, refs): gyp_env, shallow, runhooks, refs, git_cache_dir):
# Get a checkout of each solution, without DEPS or hooks. # Get a checkout of each solution, without DEPS or hooks.
# Calling git directly because there is no way to run Gclient without # Calling git directly because there is no way to run Gclient without
# invoking DEPS. # invoking DEPS.
print 'Fetching Git checkout' print 'Fetching Git checkout'
git_ref = git_checkout(solutions, revisions, shallow, refs) git_ref = git_checkout(solutions, revisions, shallow, refs, git_cache_dir)
patches = None patches = None
if patch_url: if patch_url:
...@@ -1331,10 +1326,10 @@ def ensure_checkout(solutions, revisions, first_sln, target_os, target_os_only, ...@@ -1331,10 +1326,10 @@ def ensure_checkout(solutions, revisions, first_sln, target_os, target_os_only,
if not buildspec: if not buildspec:
# Run deps2git if there is a DEPS change after the last .DEPS.git commit. # Run deps2git if there is a DEPS change after the last .DEPS.git commit.
for solution in solutions: for solution in solutions:
ensure_deps2git(solution, shallow) ensure_deps2git(solution, shallow, git_cache_dir)
# Ensure our build/ directory is set up with the correct .gclient file. # Ensure our build/ directory is set up with the correct .gclient file.
gclient_configure(solutions, target_os, target_os_only) gclient_configure(solutions, target_os, target_os_only, git_cache_dir)
# Let gclient do the DEPS syncing. # Let gclient do the DEPS syncing.
# The branch-head refspec is a special case because its possible Chrome # The branch-head refspec is a special case because its possible Chrome
...@@ -1371,7 +1366,7 @@ def ensure_checkout(solutions, revisions, first_sln, target_os, target_os_only, ...@@ -1371,7 +1366,7 @@ def ensure_checkout(solutions, revisions, first_sln, target_os, target_os_only,
# Reset the deps_file point in the solutions so that hooks get run properly. # Reset the deps_file point in the solutions so that hooks get run properly.
for sln in solutions: for sln in solutions:
sln['deps_file'] = sln.get('deps_file', 'DEPS').replace('.DEPS.git', 'DEPS') sln['deps_file'] = sln.get('deps_file', 'DEPS').replace('.DEPS.git', 'DEPS')
gclient_configure(solutions, target_os, target_os_only) gclient_configure(solutions, target_os, target_os_only, git_cache_dir)
return gclient_output return gclient_output
...@@ -1494,6 +1489,8 @@ def parse_args(): ...@@ -1494,6 +1489,8 @@ def parse_args():
parse.add_option('--with_branch_heads', action='store_true', parse.add_option('--with_branch_heads', action='store_true',
help='Always pass --with_branch_heads to gclient. This ' help='Always pass --with_branch_heads to gclient. This '
'does the same thing as --refs +refs/branch-heads/*') 'does the same thing as --refs +refs/branch-heads/*')
parse.add_option('--git-cache-dir', default=path.join(SLAVE_DIR, 'cache_dir'),
help='Path to git cache directory.')
options, args = parse.parse_args() options, args = parse.parse_args()
...@@ -1520,6 +1517,12 @@ def parse_args(): ...@@ -1520,6 +1517,12 @@ def parse_args():
% (str(e),) % (str(e),)
) )
# Because we print CACHE_DIR out into a .gclient file, and then later run
# eval() on it, backslashes need to be escaped, otherwise "E:\b\build" gets
# parsed as "E:[\x08][\x08]uild".
if sys.platform.startswith('win'):
options.git_cache_dir = options.git_cache_dir.replace('\\', '\\\\')
return options, args return options, args
...@@ -1605,7 +1608,8 @@ def checkout(options, git_slns, specs, buildspec, master, ...@@ -1605,7 +1608,8 @@ def checkout(options, git_slns, specs, buildspec, master,
# Finally, extra configurations such as shallowness of the clone. # Finally, extra configurations such as shallowness of the clone.
shallow=options.shallow, shallow=options.shallow,
refs=options.refs) refs=options.refs,
git_cache_dir=options.git_cache_dir)
gclient_output = ensure_checkout(**checkout_parameters) gclient_output = ensure_checkout(**checkout_parameters)
except GclientSyncFailed: except GclientSyncFailed:
print 'We failed gclient sync, lets delete the checkout and retry.' print 'We failed gclient sync, lets delete the checkout and retry.'
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment