Parcourir la source

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 <ehmaldonado@chromium.org>
Commit-Queue: Josip Sokcevic <sokcevic@google.com>
Josip Sokcevic il y a 4 ans
Parent
commit
d8fe52139f

+ 27 - 14
recipes/recipe_modules/bot_update/resources/bot_update.py

@@ -13,6 +13,7 @@ from contextlib import contextmanager
 import copy
 import copy
 import ctypes
 import ctypes
 from datetime import datetime
 from datetime import datetime
+import functools
 import json
 import json
 import optparse
 import optparse
 import os
 import os
@@ -676,6 +677,19 @@ def _maybe_break_locks(checkout_path, tries=3):
       pass
       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,
 def git_checkouts(solutions, revisions, refs, no_fetch_tags, git_cache_dir,
                   cleanup_dir, enforce_fetch):
                   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))
     f.write(json.dumps(output, sort_keys=True))
 
 
 
 
+@_set_git_config
 def ensure_checkout(solutions, revisions, first_sln, target_os, target_os_only,
 def ensure_checkout(solutions, revisions, first_sln, target_os, target_os_only,
                     target_cpu, patch_root, patch_refs, gerrit_rebase_patch_ref,
                     target_cpu, patch_root, patch_refs, gerrit_rebase_patch_ref,
                     no_fetch_tags, refs, git_cache_dir, cleanup_dir,
                     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):
   for solution_name in list(solution_dirs):
     gc_revisions[solution_name] = 'unmanaged'
     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
   # Now that gclient_sync has finished, we should revert any .DEPS.git so that
   # presubmit doesn't complain about it being modified.
   # presubmit doesn't complain about it being modified.

+ 6 - 0
tests/bot_update_coverage_test.py

@@ -196,6 +196,12 @@ class BotUpdateUnittests(unittest.TestCase):
     bot_update.ensure_checkout(**self.params)
     bot_update.ensure_checkout(**self.params)
     return self.call.records
     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):
   def testBasicRevision(self):
     self.params['revisions'] = {
     self.params['revisions'] = {
         'src': 'HEAD', 'src/v8': 'deadbeef', 'somename': 'DNE'}
         'src': 'HEAD', 'src/v8': 'deadbeef', 'somename': 'DNE'}