diff --git a/recipe_modules/bot_update/api.py b/recipe_modules/bot_update/api.py index 2e62e6fd24..9bee87cb5d 100644 --- a/recipe_modules/bot_update/api.py +++ b/recipe_modules/bot_update/api.py @@ -53,6 +53,27 @@ class BotUpdateApi(recipe_api.RecipeApi): def last_returned_properties(self): return self._last_returned_properties + # DO NOT USE. + # The below method will be removed after there are no more callers of + # tryserver.maybe_apply_issue (skbug.com/5588). + def apply_gerrit_ref(self, root, gerrit_no_reset=False, + gerrit_rebase_patch_ref=True, **kwargs): + apply_gerrit_path = self.resource('apply_gerrit.py') + kwargs.setdefault('infra_step', True) + kwargs.setdefault('env', {}).setdefault('PATH', '%(PATH)s') + kwargs['env']['PATH'] = self.m.path.pathsep.join([ + kwargs['env']['PATH'], str(self._module.PACKAGE_REPO_ROOT)]) + cmd = [ + '--gerrit_repo', self._repository, + '--gerrit_ref', self._gerrit_ref or '', + '--root', str(root), + ] + if gerrit_no_reset: + cmd.append('--gerrit_no_reset') + if gerrit_rebase_patch_ref: + cmd.append('--gerrit_rebase_patch_ref') + return self.m.python('apply_gerrit', apply_gerrit_path, cmd, **kwargs) + def ensure_checkout(self, gclient_config=None, suffix=None, patch=True, update_presentation=True, force=False, patch_root=None, no_shallow=False, diff --git a/recipe_modules/bot_update/example.expected/apply_gerrit_ref.json b/recipe_modules/bot_update/example.expected/apply_gerrit_ref.json new file mode 100644 index 0000000000..f4bf481861 --- /dev/null +++ b/recipe_modules/bot_update/example.expected/apply_gerrit_ref.json @@ -0,0 +1,26 @@ +[ + { + "cmd": [ + "python", + "-u", + "RECIPE_MODULE[depot_tools::bot_update]/resources/apply_gerrit.py", + "--gerrit_repo", + "chromium", + "--gerrit_ref", + "", + "--root", + "/tmp/test/root", + "--gerrit_no_reset", + "--gerrit_rebase_patch_ref" + ], + "env": { + "PATH": "%(PATH)s:RECIPE_PACKAGE_REPO[depot_tools]" + }, + "name": "apply_gerrit" + }, + { + "name": "$result", + "recipe_result": null, + "status_code": 0 + } +] \ No newline at end of file diff --git a/recipe_modules/bot_update/example.py b/recipe_modules/bot_update/example.py index 10b4d11850..6020f9127c 100644 --- a/recipe_modules/bot_update/example.py +++ b/recipe_modules/bot_update/example.py @@ -35,18 +35,25 @@ def RunSteps(api): suffix = api.properties.get('suffix') gerrit_no_reset = True if api.properties.get('gerrit_no_reset') else False gerrit_rebase_patch_ref = bool(api.properties.get('gerrit_rebase_patch_ref')) - api.bot_update.ensure_checkout( - force=force, - no_shallow=no_shallow, - patch=patch, - with_branch_heads=with_branch_heads, - output_manifest=output_manifest, - refs=refs, patch_oauth2=oauth2, - clobber=clobber, - root_solution_revision=root_solution_revision, - suffix=suffix, - gerrit_no_reset=gerrit_no_reset, - gerrit_rebase_patch_ref=gerrit_rebase_patch_ref) + + if api.properties.get('test_apply_gerrit_ref'): + api.bot_update.apply_gerrit_ref( + root='/tmp/test/root', + gerrit_no_reset=gerrit_no_reset, + gerrit_rebase_patch_ref=gerrit_rebase_patch_ref) + else: + api.bot_update.ensure_checkout( + force=force, + no_shallow=no_shallow, + patch=patch, + with_branch_heads=with_branch_heads, + output_manifest=output_manifest, + refs=refs, patch_oauth2=oauth2, + clobber=clobber, + root_solution_revision=root_solution_revision, + suffix=suffix, + gerrit_no_reset=gerrit_no_reset, + gerrit_rebase_patch_ref=gerrit_rebase_patch_ref) def GenTests(api): @@ -163,6 +170,12 @@ def GenTests(api): slavename='somehost', gerrit_rebase_patch_ref=True ) + yield api.test('apply_gerrit_ref') + api.properties( + repository='chromium', + gerrit_rebase_patch_ref=True, + gerrit_no_reset=1, + test_apply_gerrit_ref=True, + ) yield api.test('tryjob_v8') + api.properties( mastername='tryserver.chromium.linux', buildername='linux_rel', diff --git a/recipe_modules/bot_update/resources/apply_gerrit.py b/recipe_modules/bot_update/resources/apply_gerrit.py new file mode 100755 index 0000000000..7cfa20452d --- /dev/null +++ b/recipe_modules/bot_update/resources/apply_gerrit.py @@ -0,0 +1,33 @@ +#!/usr/bin/env python +# Copyright 2016 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +import optparse +import sys + +import bot_update # pylint: disable=relative-import + + +if __name__ == '__main__': + parse = optparse.OptionParser() + + parse.add_option('--gerrit_repo', + help='Gerrit repository to pull the ref from.') + parse.add_option('--gerrit_ref', help='Gerrit ref to apply.') + parse.add_option('--root', help='The location of the checkout.') + parse.add_option('--gerrit_no_reset', action='store_true', + help='Bypass calling reset after applying a gerrit ref.') + parse.add_option('--gerrit_rebase_patch_ref', action='store_true', + help='Rebase Gerrit patch ref after of checking it out.') + + options, _ = parse.parse_args() + + sys.exit( + bot_update.apply_gerrit_ref( + options.gerrit_repo, + options.gerrit_ref, + options.root, + not options.gerrit_no_reset, + options.gerrit_rebase_patch_ref) + )