From d8fe52139faf160f46f2da1213156fc77c4128df Mon Sep 17 00:00:00 2001 From: Josip Sokcevic Date: Tue, 15 Dec 2020 21:38:16 +0000 Subject: [PATCH] Check PACKFILE_OFFLOADING env variable If set, set git config fetch.uriprotocols to https. This will be initially set by codesearch builders. Once tested, this env variable can be removed. R=ehmaldonaldo@chromium.org Bug: 1136986 Change-Id: I1c3da87bdbc74d18585ed00ffdc2cf21b84b16fa Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/2591808 Reviewed-by: Edward Lesmes Commit-Queue: Josip Sokcevic --- .../bot_update/resources/bot_update.py | 41 ++++++++++++------- tests/bot_update_coverage_test.py | 6 +++ 2 files changed, 33 insertions(+), 14 deletions(-) diff --git a/recipes/recipe_modules/bot_update/resources/bot_update.py b/recipes/recipe_modules/bot_update/resources/bot_update.py index a6440df29..7585318dd 100755 --- a/recipes/recipe_modules/bot_update/resources/bot_update.py +++ b/recipes/recipe_modules/bot_update/resources/bot_update.py @@ -13,6 +13,7 @@ from contextlib import contextmanager import copy import ctypes from datetime import datetime +import functools import json import optparse import os @@ -676,6 +677,19 @@ def _maybe_break_locks(checkout_path, tries=3): pass +def _set_git_config(fn): + @functools.wraps(fn) + def wrapper(*args, **kwargs): + with git_config_if_not_set('user.name', 'chrome-bot'), \ + git_config_if_not_set('user.email', 'chrome-bot@chromium.org'): + if os.getenv('PACKFILE_OFFLOADING') == '1': + with git_config_if_not_set('fetch.uriprotocols', 'https'): + return fn(*args, **kwargs) + + return fn(*args, **kwargs) + + return wrapper + def git_checkouts(solutions, revisions, refs, no_fetch_tags, git_cache_dir, cleanup_dir, enforce_fetch): @@ -864,6 +878,7 @@ def emit_json(out_file, did_run, gclient_output=None, **kwargs): f.write(json.dumps(output, sort_keys=True)) +@_set_git_config def ensure_checkout(solutions, revisions, first_sln, target_os, target_os_only, target_cpu, patch_root, patch_refs, gerrit_rebase_patch_ref, no_fetch_tags, refs, git_cache_dir, cleanup_dir, @@ -894,20 +909,18 @@ def ensure_checkout(solutions, revisions, first_sln, target_os, target_os_only, for solution_name in list(solution_dirs): gc_revisions[solution_name] = 'unmanaged' - with git_config_if_not_set('user.name', 'chrome-bot'), \ - git_config_if_not_set('user.email', 'chrome-bot@chromium.org'): - # Let gclient do the DEPS syncing. - # The branch-head refspec is a special case because it's possible Chrome - # src, which contains the branch-head refspecs, is DEPSed in. - gclient_output = gclient_sync( - BRANCH_HEADS_REFSPEC in refs, - TAGS_REFSPEC in refs, - gc_revisions, - break_repo_locks, - disable_syntax_validation, - patch_refs, - gerrit_reset, - gerrit_rebase_patch_ref) + # Let gclient do the DEPS syncing. + # The branch-head refspec is a special case because it's possible Chrome + # src, which contains the branch-head refspecs, is DEPSed in. + gclient_output = gclient_sync( + BRANCH_HEADS_REFSPEC in refs, + TAGS_REFSPEC in refs, + gc_revisions, + break_repo_locks, + disable_syntax_validation, + patch_refs, + gerrit_reset, + gerrit_rebase_patch_ref) # Now that gclient_sync has finished, we should revert any .DEPS.git so that # presubmit doesn't complain about it being modified. diff --git a/tests/bot_update_coverage_test.py b/tests/bot_update_coverage_test.py index 4a971a462..db81077bd 100755 --- a/tests/bot_update_coverage_test.py +++ b/tests/bot_update_coverage_test.py @@ -196,6 +196,12 @@ class BotUpdateUnittests(unittest.TestCase): bot_update.ensure_checkout(**self.params) return self.call.records + def testBasicCachepackOffloading(self): + os.environ['PACKFILE_OFFLOADING'] = '1' + bot_update.ensure_checkout(**self.params) + os.environ.pop('PACKFILE_OFFLOADING') + return self.call.records + def testBasicRevision(self): self.params['revisions'] = { 'src': 'HEAD', 'src/v8': 'deadbeef', 'somename': 'DNE'}