Commit 5702f0ba authored by Robert Iannucci's avatar Robert Iannucci Committed by Commit Bot

[recipes] convert all recipe_modules to use new context module.

R=recipe-roller@chromium.org

Bug:
Change-Id: I84c19965b779f1010c00cd8c857b7533eec7413f
Reviewed-on: https://chromium-review.googlesource.com/502929Reviewed-by: 's avatarPaweł Hajdan Jr. <phajdan.jr@chromium.org>
Commit-Queue: Robbie Iannucci <iannucci@chromium.org>
parent 1a91c608
DEPS = [
'gclient',
'recipe_engine/context',
'recipe_engine/json',
'recipe_engine/path',
'recipe_engine/platform',
'recipe_engine/properties',
'recipe_engine/python',
'recipe_engine/raw_io',
'rietveld',
'recipe_engine/step',
'rietveld',
'tryserver',
]
......
......@@ -33,7 +33,7 @@ class BotUpdateApi(recipe_api.RecipeApi):
assert isinstance(cmd, (list, tuple))
bot_update_path = self.resource('bot_update.py')
kwargs.setdefault('infra_step', True)
env = self.m.step.get_from_context('env', {})
env = self.m.context.env
env.setdefault('PATH', '%(PATH)s')
env['PATH'] = self.m.path.pathsep.join([
env['PATH'], str(self._module.PACKAGE_REPO_ROOT)])
......@@ -42,7 +42,7 @@ class BotUpdateApi(recipe_api.RecipeApi):
# and die with an error "error: RPC failed; curl 28 Operation too slow"
env['GIT_HTTP_LOW_SPEED_LIMIT'] = 1000
env['GIT_HTTP_LOW_SPEED_TIME'] = 300
with self.m.step.context({'env': env}):
with self.m.context(env=env):
return self.m.python(name, bot_update_path, cmd, **kwargs)
@property
......@@ -55,7 +55,7 @@ class BotUpdateApi(recipe_api.RecipeApi):
gerrit_no_rebase_patch_ref=False, **kwargs):
apply_gerrit_path = self.resource('apply_gerrit.py')
kwargs.setdefault('infra_step', True)
env = self.m.step.get_from_context('env', {})
env = self.m.context.env
env.setdefault('PATH', '%(PATH)s')
env['PATH'] = self.m.path.pathsep.join([
env['PATH'], str(self._module.PACKAGE_REPO_ROOT)])
......@@ -68,7 +68,7 @@ class BotUpdateApi(recipe_api.RecipeApi):
cmd.append('--gerrit_no_reset')
if gerrit_no_rebase_patch_ref:
cmd.append('--gerrit_no_rebase_patch_ref')
with self.m.step.context({'env': env}):
with self.m.context(env=env):
return self.m.python('apply_gerrit', apply_gerrit_path, cmd, **kwargs)
def ensure_checkout(self, gclient_config=None, suffix=None,
......@@ -291,7 +291,7 @@ class BotUpdateApi(recipe_api.RecipeApi):
try:
if return_code == 3:
# This is download failure, hence an infra failure.
with self.m.step.context({'infra_step': True}):
with self.m.context(infra_steps=True):
self.m.python.failing_step(
'Patch failure', 'Git reported a download failure')
else:
......@@ -308,7 +308,7 @@ class BotUpdateApi(recipe_api.RecipeApi):
# first solution.
if result['did_run']:
co_root = result['root']
cwd = self.m.step.get_from_context('cwd', self.m.path['start_dir'])
cwd = self.m.context.cwd or self.m.path['start_dir']
if 'checkout' not in self.m.path:
self.m.path['checkout'] = cwd.join(*co_root.split(self.m.path.sep))
......
DEPS = [
'infra_paths',
'recipe_engine/context',
'recipe_engine/json',
'recipe_engine/path',
'recipe_engine/platform',
......
......@@ -80,12 +80,12 @@ class GclientApi(recipe_api.RecipeApi):
prefix = ('[spec: %s] ' % self.spec_alias) + prefix
# TODO(phajdan.jr): create a helper for adding to PATH.
env = self.m.step.get_from_context('env', {})
env = self.m.context.env
env.setdefault('PATH', '%(PATH)s')
env['PATH'] = self.m.path.pathsep.join([
env['PATH'], str(self._module.PACKAGE_REPO_ROOT)])
with self.m.step.context({'env': env}):
with self.m.context(env=env):
return self.m.python(prefix + name,
self.package_repo_resource('gclient.py'),
cmd,
......@@ -268,12 +268,8 @@ class GclientApi(recipe_api.RecipeApi):
def runhooks(self, args=None, name='runhooks', **kwargs):
args = args or []
assert isinstance(args, (list, tuple))
context = {}
if not self.m.step.get_from_context('cwd') and self.m.path['checkout']:
context['cwd'] = self.m.path['checkout']
with self.m.step.context(context):
return self(
name, ['runhooks'] + list(args), infra_step=False, **kwargs)
with self.m.context(cwd=(self.m.context.cwd or self.m.path['checkout'])):
return self(name, ['runhooks'] + list(args), infra_step=False, **kwargs)
@property
def is_blink_mode(self):
......
......@@ -4,6 +4,7 @@
DEPS = [
'gclient',
'recipe_engine/context',
'recipe_engine/path',
'recipe_engine/properties',
'recipe_engine/step',
......@@ -61,8 +62,7 @@ def RunSteps(api):
bl_cfg.revisions['src/third_party/angle'] = 'refs/heads/lkgr'
bl_cfg.got_revision_mapping['src/blatley'] = 'got_blatley_revision'
with api.step.context({
'cwd': api.path['start_dir'].join('src', 'third_party')}):
with api.context(cwd=api.path['start_dir'].join('src', 'third_party')):
api.gclient.checkout(
gclient_config=bl_cfg,
with_branch_heads=True)
......
DEPS = [
'recipe_engine/context',
'recipe_engine/json',
'recipe_engine/path',
'recipe_engine/python',
......
......@@ -12,12 +12,12 @@ class GerritApi(recipe_api.RecipeApi):
assert isinstance(cmd, (list, tuple))
prefix = 'gerrit '
env = self.m.step.get_from_context('env', {})
env = self.m.context.env
env.setdefault('PATH', '%(PATH)s')
env['PATH'] = self.m.path.pathsep.join([
env['PATH'], str(self._module.PACKAGE_REPO_ROOT)])
with self.m.step.context({'env': env}):
with self.m.context(env=env):
return self.m.python(prefix + name,
self.package_repo_resource('gerrit_client.py'),
cmd,
......
DEPS = [
'infra_paths',
'recipe_engine/context',
'recipe_engine/path',
'recipe_engine/platform',
'recipe_engine/properties',
......
......@@ -27,10 +27,7 @@ class GitApi(recipe_api.RecipeApi):
git_cmd.extend(['-c', '%s=%s' % (k, v)])
can_fail_build = kwargs.pop('can_fail_build', True)
try:
context = {}
if not self.m.step.get_from_context('cwd') and self.m.path['checkout']:
context['cwd'] = self.m.path['checkout']
with self.m.step.context(context):
with self.m.context(cwd=(self.m.context.cwd or self.m.path['checkout'])):
return self.m.step(name, git_cmd + list(args), infra_step=infra_step,
**kwargs)
except self.m.step.StepFailure as f:
......@@ -43,7 +40,7 @@ class GitApi(recipe_api.RecipeApi):
"""Ensures that depot_tools/git.bat actually exists."""
if not self.m.platform.is_win or self.initialized_win_git:
return
with self.m.step.context({'cwd': self.package_repo_resource()}):
with self.m.context(cwd=self.package_repo_resource()):
self.m.python(
'ensure git tooling on windows',
self.package_repo_resource('bootstrap', 'win', 'git_bootstrap.py'),
......@@ -215,9 +212,9 @@ class GitApi(recipe_api.RecipeApi):
path = self.m.path.pathsep.join([
str(self.package_repo_resource()), '%(PATH)s'])
with self.m.step.context({'cwd': dir_path}):
with self.m.context(cwd=dir_path):
if use_git_cache:
with self.m.step.context({'env': {'PATH': path}}):
with self.m.context(env={'PATH': path}):
self('retry', 'cache', 'populate', '-c',
self.m.infra_paths.default_git_cache_dir, url,
......@@ -278,7 +275,7 @@ class GitApi(recipe_api.RecipeApi):
name='count-objects before %s' % fetch_step_name,
step_test_data=lambda: self.m.raw_io.test_api.stream_output(
self.test_api.count_objects_output(1000)))
with self.m.step.context({'env': fetch_env}):
with self.m.context(env=fetch_env):
self('retry', 'fetch', *fetch_args,
name=fetch_step_name,
stderr=fetch_stderr,
......@@ -355,7 +352,7 @@ class GitApi(recipe_api.RecipeApi):
remote_name (str): the remote name to rebase from if not origin
"""
remote_name = remote_name or 'origin'
with self.m.step.context({'cwd': dir_path}):
with self.m.context(cwd=dir_path):
try:
self('rebase', '%s/master' % remote_name,
name="%s rebase" % name_prefix, **kwargs)
......@@ -413,7 +410,7 @@ class GitApi(recipe_api.RecipeApi):
upstream (str): to origin/master.
kwargs: Forwarded to '__call__'.
"""
env = self.m.step.get_from_context('env', {})
env = self.m.context.env
env['PATH'] = self.m.path.pathsep.join([
str(self.package_repo_resource()), '%(PATH)s'])
args = ['new-branch', branch]
......@@ -421,5 +418,5 @@ class GitApi(recipe_api.RecipeApi):
args.extend(['--upstream', upstream])
if not name:
name = 'git new-branch %s' % branch
with self.m.step.context({'env': env}):
with self.m.context(env=env):
return self(*args, name=name, **kwargs)
......@@ -4,6 +4,7 @@
DEPS = [
'git',
'recipe_engine/context',
'recipe_engine/path',
'recipe_engine/platform',
'recipe_engine/properties',
......@@ -59,7 +60,7 @@ def RunSteps(api):
# If you need to run more arbitrary git commands, you can use api.git itself,
# which behaves like api.step(), but automatically sets the name of the step.
with api.step.context({'cwd': api.path['checkout']}):
with api.context(cwd=api.path['checkout']):
api.git('status')
api.git('status', name='git status can_fail_build',
......
DEPS = [
'recipe_engine/context',
'recipe_engine/raw_io',
'recipe_engine/step',
]
......@@ -14,9 +14,8 @@ class GitClApi(recipe_api.RecipeApi):
if kwargs.get('suffix'):
name = name + ' (%s)' % kwargs.pop('suffix')
with self.m.step.context({
'cwd': self.m.step.get_from_context(
'cwd', (self.c and self.c.repo_location) or None)}):
my_loc = self.c.repo_location if self.c else None
with self.m.context(cwd=self.m.context.cwd or my_loc):
return self.m.step(
name, [self.package_repo_resource('git_cl.py'), subcmd] + args,
**kwargs)
......
DEPS = [
'recipe_engine/context',
'recipe_engine/path',
'recipe_engine/python',
'recipe_engine/step',
......
......@@ -14,11 +14,11 @@ class PresubmitApi(recipe_api.RecipeApi):
name = kwargs.pop('name', 'presubmit')
env = self.m.step.get_from_context('env', {})
env = self.m.context.env
env.setdefault('PATH', '%(PATH)s')
env['PATH'] = self.m.path.pathsep.join([
env['PATH'], str(self._module.PACKAGE_REPO_ROOT)])
with self.m.step.context({'env': env}):
with self.m.context(env=env):
return self.m.python(
name, self.presubmit_support_path, list(args), **kwargs)
......@@ -5,12 +5,13 @@
DEPS = [
'git',
'git_cl',
'recipe_engine/context',
'recipe_engine/json',
'recipe_engine/path',
'recipe_engine/platform',
'recipe_engine/properties',
'recipe_engine/python',
'recipe_engine/raw_io',
'rietveld',
'recipe_engine/step',
'rietveld',
]
......@@ -84,7 +84,7 @@ class TryserverApi(recipe_api.RecipeApi):
patch_path = patch_dir.join('patch.diff')
self.m.python('patch git setup', git_setup_py, git_setup_args)
with self.m.step.context({'cwd': patch_dir}):
with self.m.context(cwd=patch_dir):
self.m.git('fetch', 'origin', patch_ref, name='patch fetch')
self.m.git('clean', '-f', '-d', '-x', name='patch clean')
self.m.git('checkout', '-f', 'FETCH_HEAD', name='patch git checkout')
......@@ -138,9 +138,9 @@ class TryserverApi(recipe_api.RecipeApi):
# removed.
if patch_root is None:
return self._old_get_files_affected_by_patch()
with self.m.step.context({
'cwd': self.m.step.get_from_context(
'cwd', self.m.path['start_dir'].join(patch_root))}):
cwd = self.m.context.cwd or self.m.path['start_dir'].join(patch_root)
with self.m.context(cwd=cwd):
step_result = self.m.git('diff', '--cached', '--name-only',
name='git diff to analyze patch',
stdout=self.m.raw_io.output(),
......@@ -158,11 +158,10 @@ class TryserverApi(recipe_api.RecipeApi):
def _old_get_files_affected_by_patch(self):
context = {}
issue_root = self.m.rietveld.calculate_issue_root()
if issue_root:
context['cwd'] = self.m.path['checkout'].join(issue_root)
with self.m.step.context(context):
cwd = self.m.path['checkout'].join(issue_root) if issue_root else None
with self.m.context(cwd=cwd):
step_result = self.m.git('diff', '--cached', '--name-only',
name='git diff to analyze patch',
stdout=self.m.raw_io.output(),
......
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