Parcourir la source

Add --patch_ref to bot_update.

This doesn't expose --patch_ref in the bot_update recipe_module yet,
though.

Bug: 865882
Change-Id: I26abe59d2f6a8a3dd3945cce0bf13b238a7fffd3
Reviewed-on: https://chromium-review.googlesource.com/1151105
Commit-Queue: John Budorick <jbudorick@chromium.org>
Reviewed-by: Edward Lesmes <ehmaldonado@chromium.org>
Reviewed-by: Andrii Shyshkalov <tandrii@chromium.org>
John Budorick il y a 7 ans
Parent
commit
3e65878e5e

+ 22 - 8
recipes/recipe_modules/bot_update/resources/bot_update.py

@@ -347,7 +347,7 @@ def git_config_if_not_set(key, value):
 
 def gclient_sync(
     with_branch_heads, with_tags, revisions, break_repo_locks,
-    disable_syntax_validation, gerrit_repo, gerrit_ref, gerrit_reset,
+    disable_syntax_validation, patch_refs, gerrit_repo, gerrit_ref, gerrit_reset,
     gerrit_rebase_patch_ref, apply_patch_on_gclient):
   # We just need to allocate a filename.
   fd, gclient_output_file = tempfile.mkstemp(suffix='.json')
@@ -369,10 +369,12 @@ def gclient_sync(
       revision = 'origin/master'
     args.extend(['--revision', '%s@%s' % (name, revision)])
 
-  if apply_patch_on_gclient and gerrit_repo and gerrit_ref:
-    # TODO(ehmaldonado): Merge gerrit_repo and gerrit_ref into a patch-ref flag
-    # and add support for passing multiple patch refs.
-    args.extend(['--patch-ref', gerrit_repo + '@' + gerrit_ref])
+  if not patch_refs and gerrit_repo and gerrit_ref:
+    patch_refs = ['%s@%s' % (gerrit_repo, gerrit_ref)]
+
+  if apply_patch_on_gclient and patch_refs:
+    for patch_ref in patch_refs:
+      args.extend(['--patch-ref', patch_ref])
     if not gerrit_reset:
       args.append('--no-reset-patch-ref')
     if not gerrit_rebase_patch_ref:
@@ -871,7 +873,7 @@ def emit_json(out_file, did_run, gclient_output=None, **kwargs):
 
 
 def ensure_checkout(solutions, revisions, first_sln, target_os, target_os_only,
-                    target_cpu, patch_root, gerrit_repo, gerrit_ref,
+                    target_cpu, patch_root, patch_refs, gerrit_repo, gerrit_ref,
                     gerrit_rebase_patch_ref, refs, git_cache_dir,
                     cleanup_dir, gerrit_reset, disable_syntax_validation,
                     apply_patch_on_gclient):
@@ -928,6 +930,7 @@ def ensure_checkout(solutions, revisions, first_sln, target_os, target_os_only,
           gc_revisions,
           break_repo_locks,
           disable_syntax_validation,
+          patch_refs,
           gerrit_repo,
           gerrit_ref,
           gerrit_reset,
@@ -1003,9 +1006,11 @@ def parse_args():
   parse.add_option('--root', dest='patch_root',
                    help='DEPRECATED: Use --patch_root.')
   parse.add_option('--patch_root', help='Directory to patch on top of.')
+  parse.add_option('--patch_ref', dest='patch_refs', action='append', default=[],
+                   help='Git repository & ref to apply, as REPO@REF.')
   parse.add_option('--gerrit_repo',
-                   help='Gerrit repository to pull the ref from.')
-  parse.add_option('--gerrit_ref', help='Gerrit ref to apply.')
+                   help='Git repository to pull the ref from.')
+  parse.add_option('--gerrit_ref', help='Git ref to apply.')
   parse.add_option('--gerrit_no_rebase_patch_ref', action='store_true',
                    help='Bypass rebase of Gerrit patch ref after checkout.')
   parse.add_option('--gerrit_no_reset', action='store_true',
@@ -1085,6 +1090,14 @@ def parse_args():
         % (str(e),)
     )
 
+  if options.patch_refs:
+    if options.gerrit_repo or options.gerrit_ref:
+      parse.error('Using --patch_ref with --gerrit_repo or --gerrit_ref '
+                  + 'is not supported.')
+
+    if not options.apply_patch_on_gclient:
+      parse.error('--patch_ref cannot be used with --no-apply-patch-on-gclient')
+
   # 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".
@@ -1147,6 +1160,7 @@ def checkout(options, git_slns, specs, revisions, step_text):
 
           # Then, pass in information about how to patch.
           patch_root=options.patch_root,
+          patch_refs=options.patch_refs,
           gerrit_repo=options.gerrit_repo,
           gerrit_ref=options.gerrit_ref,
           gerrit_rebase_patch_ref=not options.gerrit_no_rebase_patch_ref,

+ 14 - 0
tests/bot_update_coverage_test.py

@@ -149,6 +149,7 @@ class BotUpdateUnittests(unittest.TestCase):
       'target_os_only': None,
       'target_cpu': None,
       'patch_root': None,
+      'patch_refs': [],
       'gerrit_repo': None,
       'gerrit_ref': None,
       'gerrit_rebase_patch_ref': None,
@@ -226,6 +227,19 @@ class BotUpdateUnittests(unittest.TestCase):
       self.assertNotIn('git fetch ' + self.params['gerrit_repo'],
                        ' '.join(record[0]))
 
+  def testPatchRefs(self):
+    self.params['patch_refs'] = [
+        'https://chromium.googlesource.com/chromium/src@refs/changes/12/345/6',
+        'https://chromium.googlesource.com/v8/v8@refs/changes/1/234/56']
+    self.params['apply_patch_on_gclient'] = True
+    bot_update.ensure_checkout(**self.params)
+    args = self.gclient.records[0]
+    patch_refs = set(
+        args[i+1] for i in xrange(len(args))
+        if args[i] == '--patch-ref' and i+1 < len(args))
+    self.assertIn(self.params['patch_refs'][0], patch_refs)
+    self.assertIn(self.params['patch_refs'][1], patch_refs)
+
   def testBreakLocks(self):
     self.overrideSetupForWindows()
     bot_update.ensure_checkout(**self.params)