Commit 3c2e098b authored by Paweł Hajdan, Jr's avatar Paweł Hajdan, Jr Committed by Commit Bot

Pass cwd via context rather than api.step kwargs

See https://groups.google.com/a/chromium.org/d/msg/infra-dev/p8Iq9v9Y4k0/w__b1zTWAQAJ
for more context.

BUG=685746

Change-Id: Iab46d78e92d67e9a2523cce8b22d9798a6121dd8
Reviewed-on: https://chromium-review.googlesource.com/439328
Commit-Queue: Paweł Hajdan Jr. <phajdan.jr@chromium.org>
Reviewed-by: 's avatarDirk Pranke <dpranke@chromium.org>
parent 4dbec672
...@@ -5,5 +5,5 @@ deps { ...@@ -5,5 +5,5 @@ deps {
project_id: "recipe_engine" project_id: "recipe_engine"
url: "https://chromium.googlesource.com/external/github.com/luci/recipes-py.git" url: "https://chromium.googlesource.com/external/github.com/luci/recipes-py.git"
branch: "master" branch: "master"
revision: "32e585682faac9148b8760742148d8222ef68a94" revision: "e8470584a8a0a7a00541b1ab57e48f2793795743"
} }
...@@ -306,7 +306,7 @@ class BotUpdateApi(recipe_api.RecipeApi): ...@@ -306,7 +306,7 @@ class BotUpdateApi(recipe_api.RecipeApi):
# first solution. # first solution.
if step_result.json.output['did_run']: if step_result.json.output['did_run']:
co_root = step_result.json.output['root'] co_root = step_result.json.output['root']
cwd = kwargs.get('cwd', self.m.path['start_dir']) cwd = self.m.step.get_from_context('cwd', self.m.path['start_dir'])
if 'checkout' not in self.m.path: if 'checkout' not in self.m.path:
self.m.path['checkout'] = cwd.join(*co_root.split(self.m.path.sep)) self.m.path['checkout'] = cwd.join(*co_root.split(self.m.path.sep))
......
...@@ -248,7 +248,10 @@ class GclientApi(recipe_api.RecipeApi): ...@@ -248,7 +248,10 @@ class GclientApi(recipe_api.RecipeApi):
def runhooks(self, args=None, name='runhooks', **kwargs): def runhooks(self, args=None, name='runhooks', **kwargs):
args = args or [] args = args or []
assert isinstance(args, (list, tuple)) assert isinstance(args, (list, tuple))
kwargs.setdefault('cwd', self.m.path['checkout']) 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( return self(
name, ['runhooks'] + list(args), infra_step=False, **kwargs) name, ['runhooks'] + list(args), infra_step=False, **kwargs)
......
...@@ -6,6 +6,7 @@ DEPS = [ ...@@ -6,6 +6,7 @@ DEPS = [
'gclient', 'gclient',
'recipe_engine/path', 'recipe_engine/path',
'recipe_engine/properties', 'recipe_engine/properties',
'recipe_engine/step',
] ]
...@@ -80,10 +81,11 @@ def RunSteps(api): ...@@ -80,10 +81,11 @@ def RunSteps(api):
bl_cfg.revisions['src/third_party/angle'] = 'refs/heads/lkgr' bl_cfg.revisions['src/third_party/angle'] = 'refs/heads/lkgr'
bl_cfg.got_revision_mapping['src/blatley'] = 'got_blatley_revision' bl_cfg.got_revision_mapping['src/blatley'] = 'got_blatley_revision'
with api.step.context({
'cwd': api.path['start_dir'].join('src', 'third_party')}):
api.gclient.checkout( api.gclient.checkout(
gclient_config=bl_cfg, gclient_config=bl_cfg,
with_branch_heads=True, with_branch_heads=True)
cwd=api.path['start_dir'].join('src', 'third_party'))
api.gclient.break_locks() api.gclient.break_locks()
......
...@@ -18,8 +18,6 @@ class GitApi(recipe_api.RecipeApi): ...@@ -18,8 +18,6 @@ class GitApi(recipe_api.RecipeApi):
"""Return a git command step.""" """Return a git command step."""
name = kwargs.pop('name', 'git ' + args[0]) name = kwargs.pop('name', 'git ' + args[0])
infra_step = kwargs.pop('infra_step', True) infra_step = kwargs.pop('infra_step', True)
if 'cwd' not in kwargs:
kwargs.setdefault('cwd', self.m.path['checkout'])
git_cmd = ['git'] git_cmd = ['git']
if self.m.platform.is_win: if self.m.platform.is_win:
self.ensure_win_git_tooling() self.ensure_win_git_tooling()
...@@ -29,6 +27,10 @@ class GitApi(recipe_api.RecipeApi): ...@@ -29,6 +27,10 @@ class GitApi(recipe_api.RecipeApi):
git_cmd.extend(['-c', '%s=%s' % (k, v)]) git_cmd.extend(['-c', '%s=%s' % (k, v)])
can_fail_build = kwargs.pop('can_fail_build', True) can_fail_build = kwargs.pop('can_fail_build', True)
try: 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):
return self.m.step(name, git_cmd + list(args), infra_step=infra_step, return self.m.step(name, git_cmd + list(args), infra_step=infra_step,
**kwargs) **kwargs)
except self.m.step.StepFailure as f: except self.m.step.StepFailure as f:
...@@ -41,12 +43,12 @@ class GitApi(recipe_api.RecipeApi): ...@@ -41,12 +43,12 @@ class GitApi(recipe_api.RecipeApi):
"""Ensures that depot_tools/git.bat actually exists.""" """Ensures that depot_tools/git.bat actually exists."""
if not self.m.platform.is_win or self.initialized_win_git: if not self.m.platform.is_win or self.initialized_win_git:
return return
with self.m.step.context({'cwd': self.package_repo_resource()}):
self.m.python( self.m.python(
'ensure git tooling on windows', 'ensure git tooling on windows',
self.package_repo_resource('bootstrap', 'win', 'git_bootstrap.py'), self.package_repo_resource('bootstrap', 'win', 'git_bootstrap.py'),
['--verbose'], ['--verbose'],
infra_step=True, infra_step=True,
cwd=self.package_repo_resource(),
timeout=300) timeout=300)
self.initialized_win_git = True self.initialized_win_git = True
...@@ -213,26 +215,24 @@ class GitApi(recipe_api.RecipeApi): ...@@ -213,26 +215,24 @@ class GitApi(recipe_api.RecipeApi):
path = self.m.path.pathsep.join([ path = self.m.path.pathsep.join([
str(self.package_repo_resource()), '%(PATH)s']) str(self.package_repo_resource()), '%(PATH)s'])
with self.m.step.context({'cwd': dir_path}):
if use_git_cache: if use_git_cache:
with self.m.step.context({'env': {'PATH': path}}): with self.m.step.context({'env': {'PATH': path}}):
self('retry', 'cache', 'populate', '-c', self('retry', 'cache', 'populate', '-c',
self.m.infra_paths.default_git_cache_dir, url, self.m.infra_paths.default_git_cache_dir, url,
name='populate cache', name='populate cache',
can_fail_build=can_fail_build, can_fail_build=can_fail_build)
cwd=dir_path)
dir_cmd = self( dir_cmd = self(
'cache', 'exists', '--quiet', 'cache', 'exists', '--quiet',
'--cache-dir', self.m.infra_paths.default_git_cache_dir, url, '--cache-dir', self.m.infra_paths.default_git_cache_dir, url,
can_fail_build=can_fail_build, can_fail_build=can_fail_build,
stdout=self.m.raw_io.output(), stdout=self.m.raw_io.output(),
step_test_data=lambda: step_test_data=lambda:
self.m.raw_io.test_api.stream_output('mirror_dir'), self.m.raw_io.test_api.stream_output('mirror_dir'))
cwd=dir_path)
mirror_dir = dir_cmd.stdout.strip() mirror_dir = dir_cmd.stdout.strip()
self('remote', 'set-url', 'origin', mirror_dir, self('remote', 'set-url', 'origin', mirror_dir,
can_fail_build=can_fail_build, can_fail_build=can_fail_build)
cwd=dir_path)
# There are five kinds of refs we can be handed: # There are five kinds of refs we can be handed:
# 0) None. In this case, we default to properties['branch']. # 0) None. In this case, we default to properties['branch'].
...@@ -276,11 +276,9 @@ class GitApi(recipe_api.RecipeApi): ...@@ -276,11 +276,9 @@ class GitApi(recipe_api.RecipeApi):
if display_fetch_size: if display_fetch_size:
count_objects_before_fetch = self.count_objects( count_objects_before_fetch = self.count_objects(
name='count-objects before %s' % fetch_step_name, name='count-objects before %s' % fetch_step_name,
cwd=dir_path,
step_test_data=lambda: self.m.raw_io.test_api.stream_output( step_test_data=lambda: self.m.raw_io.test_api.stream_output(
self.test_api.count_objects_output(1000))) self.test_api.count_objects_output(1000)))
self('retry', 'fetch', *fetch_args, self('retry', 'fetch', *fetch_args,
cwd=dir_path,
name=fetch_step_name, name=fetch_step_name,
env=fetch_env, env=fetch_env,
stderr=fetch_stderr, stderr=fetch_stderr,
...@@ -288,25 +286,21 @@ class GitApi(recipe_api.RecipeApi): ...@@ -288,25 +286,21 @@ class GitApi(recipe_api.RecipeApi):
if display_fetch_size: if display_fetch_size:
self.count_objects( self.count_objects(
name='count-objects after %s' % fetch_step_name, name='count-objects after %s' % fetch_step_name,
cwd=dir_path,
previous_result=count_objects_before_fetch, previous_result=count_objects_before_fetch,
step_test_data=lambda: self.m.raw_io.test_api.stream_output( step_test_data=lambda: self.m.raw_io.test_api.stream_output(
self.test_api.count_objects_output(2000))) self.test_api.count_objects_output(2000)))
if file_name: if file_name:
self('checkout', '-f', checkout_ref, '--', file_name, self('checkout', '-f', checkout_ref, '--', file_name,
cwd=dir_path,
name='git checkout%s' % step_suffix, name='git checkout%s' % step_suffix,
can_fail_build=can_fail_build) can_fail_build=can_fail_build)
else: else:
self('checkout', '-f', checkout_ref, self('checkout', '-f', checkout_ref,
cwd=dir_path,
name='git checkout%s' % step_suffix, name='git checkout%s' % step_suffix,
can_fail_build=can_fail_build) can_fail_build=can_fail_build)
rev_parse_step = self('rev-parse', 'HEAD', rev_parse_step = self('rev-parse', 'HEAD',
cwd=dir_path,
name='read revision', name='read revision',
stdout=self.m.raw_io.output(), stdout=self.m.raw_io.output(),
can_fail_build=False, can_fail_build=False,
...@@ -325,13 +319,11 @@ class GitApi(recipe_api.RecipeApi): ...@@ -325,13 +319,11 @@ class GitApi(recipe_api.RecipeApi):
self('clean', '-f', '-d', '-x', *clean_args, self('clean', '-f', '-d', '-x', *clean_args,
name='git clean%s' % step_suffix, name='git clean%s' % step_suffix,
cwd=dir_path,
can_fail_build=can_fail_build) can_fail_build=can_fail_build)
if submodules: if submodules:
self('submodule', 'sync', self('submodule', 'sync',
name='submodule sync%s' % step_suffix, name='submodule sync%s' % step_suffix,
cwd=dir_path,
can_fail_build=can_fail_build) can_fail_build=can_fail_build)
submodule_update = ['submodule', 'update', '--init'] submodule_update = ['submodule', 'update', '--init']
if submodule_update_recursive: if submodule_update_recursive:
...@@ -340,7 +332,6 @@ class GitApi(recipe_api.RecipeApi): ...@@ -340,7 +332,6 @@ class GitApi(recipe_api.RecipeApi):
submodule_update.append('--force') submodule_update.append('--force')
self(*submodule_update, self(*submodule_update,
name='submodule update%s' % step_suffix, name='submodule update%s' % step_suffix,
cwd=dir_path,
can_fail_build=can_fail_build) can_fail_build=can_fail_build)
return retVal return retVal
...@@ -364,12 +355,13 @@ class GitApi(recipe_api.RecipeApi): ...@@ -364,12 +355,13 @@ class GitApi(recipe_api.RecipeApi):
remote_name (str): the remote name to rebase from if not origin remote_name (str): the remote name to rebase from if not origin
""" """
remote_name = remote_name or 'origin' remote_name = remote_name or 'origin'
with self.m.step.context({'cwd': dir_path}):
try: try:
self('rebase', '%s/master' % remote_name, self('rebase', '%s/master' % remote_name,
name="%s rebase" % name_prefix, cwd=dir_path, **kwargs) name="%s rebase" % name_prefix, **kwargs)
except self.m.step.StepFailure: except self.m.step.StepFailure:
self('rebase', '--abort', name='%s rebase abort' % name_prefix, self('rebase', '--abort', name='%s rebase abort' % name_prefix,
cwd=dir_path, **kwargs) **kwargs)
raise raise
def config_get(self, prop_name, **kwargs): def config_get(self, prop_name, **kwargs):
......
...@@ -59,7 +59,8 @@ def RunSteps(api): ...@@ -59,7 +59,8 @@ def RunSteps(api):
# If you need to run more arbitrary git commands, you can use api.git itself, # 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. # which behaves like api.step(), but automatically sets the name of the step.
api.git('status', cwd=api.path['checkout']) with api.step.context({'cwd': api.path['checkout']}):
api.git('status')
api.git('status', name='git status can_fail_build', api.git('status', name='git status can_fail_build',
can_fail_build=True) can_fail_build=True)
......
...@@ -14,9 +14,9 @@ class GitClApi(recipe_api.RecipeApi): ...@@ -14,9 +14,9 @@ class GitClApi(recipe_api.RecipeApi):
if kwargs.get('suffix'): if kwargs.get('suffix'):
name = name + ' (%s)' % kwargs.pop('suffix') name = name + ' (%s)' % kwargs.pop('suffix')
if 'cwd' not in kwargs: with self.m.step.context({
kwargs['cwd'] = (self.c and self.c.repo_location) or None 'cwd': self.m.step.get_from_context(
'cwd', (self.c and self.c.repo_location) or None)}):
return self.m.step( return self.m.step(
name, [self.package_repo_resource('git_cl.py'), subcmd] + args, name, [self.package_repo_resource('git_cl.py'), subcmd] + args,
**kwargs) **kwargs)
......
...@@ -84,12 +84,10 @@ class TryserverApi(recipe_api.RecipeApi): ...@@ -84,12 +84,10 @@ class TryserverApi(recipe_api.RecipeApi):
patch_path = patch_dir.join('patch.diff') patch_path = patch_dir.join('patch.diff')
self.m.python('patch git setup', git_setup_py, git_setup_args) self.m.python('patch git setup', git_setup_py, git_setup_args)
self.m.git('fetch', 'origin', patch_ref, with self.m.step.context({'cwd': patch_dir}):
name='patch fetch', cwd=patch_dir) self.m.git('fetch', 'origin', patch_ref, name='patch fetch')
self.m.git('clean', '-f', '-d', '-x', self.m.git('clean', '-f', '-d', '-x', name='patch clean')
name='patch clean', cwd=patch_dir) self.m.git('checkout', '-f', 'FETCH_HEAD', name='patch git checkout')
self.m.git('checkout', '-f', 'FETCH_HEAD',
name='patch git checkout', cwd=patch_dir)
self._apply_patch_step(patch_file=patch_path, root=cwd) self._apply_patch_step(patch_file=patch_path, root=cwd)
self.m.step('remove patch', ['rm', '-rf', patch_dir]) self.m.step('remove patch', ['rm', '-rf', patch_dir])
...@@ -140,8 +138,9 @@ class TryserverApi(recipe_api.RecipeApi): ...@@ -140,8 +138,9 @@ class TryserverApi(recipe_api.RecipeApi):
# removed. # removed.
if patch_root is None: if patch_root is None:
return self._old_get_files_affected_by_patch() return self._old_get_files_affected_by_patch()
if not kwargs.get('cwd'): with self.m.step.context({
kwargs['cwd'] = self.m.path['start_dir'].join(patch_root) 'cwd': self.m.step.get_from_context(
'cwd', self.m.path['start_dir'].join(patch_root))}):
step_result = self.m.git('diff', '--cached', '--name-only', step_result = self.m.git('diff', '--cached', '--name-only',
name='git diff to analyze patch', name='git diff to analyze patch',
stdout=self.m.raw_io.output(), stdout=self.m.raw_io.output(),
...@@ -159,16 +158,16 @@ class TryserverApi(recipe_api.RecipeApi): ...@@ -159,16 +158,16 @@ class TryserverApi(recipe_api.RecipeApi):
def _old_get_files_affected_by_patch(self): def _old_get_files_affected_by_patch(self):
git_diff_kwargs = {} context = {}
issue_root = self.m.rietveld.calculate_issue_root() issue_root = self.m.rietveld.calculate_issue_root()
if issue_root: if issue_root:
git_diff_kwargs['cwd'] = self.m.path['checkout'].join(issue_root) context['cwd'] = self.m.path['checkout'].join(issue_root)
with self.m.step.context(context):
step_result = self.m.git('diff', '--cached', '--name-only', step_result = self.m.git('diff', '--cached', '--name-only',
name='git diff to analyze patch', name='git diff to analyze patch',
stdout=self.m.raw_io.output(), stdout=self.m.raw_io.output(),
step_test_data=lambda: step_test_data=lambda:
self.m.raw_io.test_api.stream_output('foo.cc'), self.m.raw_io.test_api.stream_output('foo.cc'))
**git_diff_kwargs)
paths = step_result.stdout.split() paths = step_result.stdout.split()
if issue_root: if issue_root:
paths = [self.m.path.join(issue_root, path) for path in paths] paths = [self.m.path.join(issue_root, path) for path in paths]
......
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