[skia] convert recipes and module to new context module

This is a syntax-only change to convert to the new (documented) context
module.

R=borenet@google.com

Bug: skia:
Change-Id: Id907c309d3cf38b85a46f6d8d7ce90ed58ba026f
Reviewed-on: https://skia-review.googlesource.com/16840
Commit-Queue: Eric Boren <borenet@google.com>
Reviewed-by: Eric Boren <borenet@google.com>
diff --git a/infra/bots/recipe_modules/core/__init__.py b/infra/bots/recipe_modules/core/__init__.py
index 9112c1c..6b541c3 100644
--- a/infra/bots/recipe_modules/core/__init__.py
+++ b/infra/bots/recipe_modules/core/__init__.py
@@ -8,6 +8,7 @@
   'depot_tools/gclient',
   'depot_tools/tryserver',
   'flavor',
+  'recipe_engine/context',
   'recipe_engine/path',
   'recipe_engine/properties',
   'recipe_engine/python',
diff --git a/infra/bots/recipe_modules/core/api.py b/infra/bots/recipe_modules/core/api.py
index 0a2cb4e..7474164 100644
--- a/infra/bots/recipe_modules/core/api.py
+++ b/infra/bots/recipe_modules/core/api.py
@@ -41,7 +41,7 @@
         git = 'git.bat'
       else:
         git = 'git'
-      with self.m.step.context({'cwd': repo_path}):
+      with self.m.context(cwd=repo_path):
         self.m.step('git remote set-url',
                     cmd=[git, 'remote', 'set-url', 'origin', repo.url],
                     infra_step=True)
@@ -159,13 +159,13 @@
       self.m.bot_update._repository = patch_repo
 
     self.m.gclient.c = gclient_cfg
-    with self.m.step.context({'cwd': self.m.vars.checkout_root}):
+    with self.m.context(cwd=self.m.vars.checkout_root):
       update_step = self.m.bot_update.ensure_checkout(patch_root=patch_root)
 
     self.m.vars.got_revision = (
         update_step.presentation.properties['got_revision'])
 
     if self.m.vars.need_chromium_checkout:
-      with self.m.step.context({'cwd': self.m.vars.checkout_root,
-                                'env': self.m.vars.gclient_env}):
+      with self.m.context(cwd=self.m.vars.checkout_root,
+                          env=self.m.vars.gclient_env):
         self.m.gclient.runhooks()
diff --git a/infra/bots/recipe_modules/env/__init__.py b/infra/bots/recipe_modules/env/__init__.py
index 67d72f4..774cf5f 100644
--- a/infra/bots/recipe_modules/env/__init__.py
+++ b/infra/bots/recipe_modules/env/__init__.py
@@ -4,6 +4,6 @@
 
 
 DEPS = [
-  'recipe_engine/step',
+  'recipe_engine/context',
 ]
 
diff --git a/infra/bots/recipe_modules/env/api.py b/infra/bots/recipe_modules/env/api.py
index 8060a0f..ea9ed52 100644
--- a/infra/bots/recipe_modules/env/api.py
+++ b/infra/bots/recipe_modules/env/api.py
@@ -8,7 +8,7 @@
 
 class EnvApi(recipe_api.RecipeApi):
   def __call__(self, env_dict):
-    env = self.m.step.get_from_context('env', {})
+    env = self.m.context.env
     # If PATH is defined in both, merge them together, merging default_env into
     # path by replacing %(PATH)s
     upstream_path = env.get('PATH', '')
@@ -17,4 +17,4 @@
     if upstream_path and my_path and upstream_path != my_path:
       env['PATH'] = upstream_path.replace(r'%(PATH)s', my_path)
 
-    return self.m.step.context({'env': env})
+    return self.m.context(env=env)
diff --git a/infra/bots/recipe_modules/env/example.py b/infra/bots/recipe_modules/env/example.py
index a22899b..d53ab57 100644
--- a/infra/bots/recipe_modules/env/example.py
+++ b/infra/bots/recipe_modules/env/example.py
@@ -5,6 +5,7 @@
 
 DEPS = [
   'env',
+  'recipe_engine/context',
   'recipe_engine/step',
 ]
 
@@ -15,7 +16,7 @@
     api.step('2', cmd=['echo', 'hi'])
 
   path = 'mypath:%(PATH)s'
-  with api.step.context({'env': {'PATH': path}}):
+  with api.context(env={'PATH': path}):
     api.step('3', cmd=['echo', 'hi'])
     with api.env({'PATH': '%(PATH)s:otherpath'}):
       api.step('4', cmd=['echo', 'hi'])
diff --git a/infra/bots/recipe_modules/flavor/__init__.py b/infra/bots/recipe_modules/flavor/__init__.py
index f417682..a5ef064 100644
--- a/infra/bots/recipe_modules/flavor/__init__.py
+++ b/infra/bots/recipe_modules/flavor/__init__.py
@@ -7,6 +7,7 @@
   'build/file',
   'builder_name_schema',
   'depot_tools/bot_update',
+  'recipe_engine/context',
   'recipe_engine/path',
   'recipe_engine/platform',
   'recipe_engine/properties',
diff --git a/infra/bots/recipe_modules/flavor/flutter_flavor.py b/infra/bots/recipe_modules/flavor/flutter_flavor.py
index 0f0302b..6b95cb8 100644
--- a/infra/bots/recipe_modules/flavor/flutter_flavor.py
+++ b/infra/bots/recipe_modules/flavor/flutter_flavor.py
@@ -20,7 +20,7 @@
     extra_config = self.m.vars.builder_cfg.get('extra_config', '')
     out_dir = configuration
 
-    with self.m.step.context({'cwd': flutter_dir}):
+    with self.m.context(cwd=flutter_dir):
       # Runhook to generate the gn binary in buildtools.
       self.m.run(
           self.m.step,
diff --git a/infra/bots/recipe_modules/flavor/gn_android_flavor.py b/infra/bots/recipe_modules/flavor/gn_android_flavor.py
index 095a82c..1ff8b8c 100644
--- a/infra/bots/recipe_modules/flavor/gn_android_flavor.py
+++ b/infra/bots/recipe_modules/flavor/gn_android_flavor.py
@@ -24,11 +24,11 @@
         tmp_dir       = self.m.vars.android_data_dir)
 
   def _run(self, title, *cmd, **kwargs):
-    with self.m.step.context({'cwd': self.m.vars.skia_dir}):
+    with self.m.context(cwd=self.m.vars.skia_dir):
       return self.m.run(self.m.step, title, cmd=list(cmd), **kwargs)
 
   def _py(self, title, script, infra_step=True):
-    with self.m.step.context({'cwd': self.m.vars.skia_dir}):
+    with self.m.context(cwd=self.m.vars.skia_dir):
       return self.m.run(self.m.python, title, script=script,
                         infra_step=infra_step)
 
diff --git a/infra/bots/recipe_modules/flavor/gn_chromebook_flavor.py b/infra/bots/recipe_modules/flavor/gn_chromebook_flavor.py
index c004d99..3cf2cf1 100644
--- a/infra/bots/recipe_modules/flavor/gn_chromebook_flavor.py
+++ b/infra/bots/recipe_modules/flavor/gn_chromebook_flavor.py
@@ -135,13 +135,8 @@
     ninja = 'ninja.exe' if 'Win' in os else 'ninja'
     gn = self.m.vars.skia_dir.join('bin', gn)
 
-    context = {
-      'cwd': self.m.vars.skia_dir,
-      'env': {
-          'LD_LIBRARY_PATH': sysroot_dir.join('lib'),
-      }
-    }
-    with self.m.step.context(context):
+    with self.m.context(cwd=self.m.vars.skia_dir,
+                        env={'LD_LIBRARY_PATH': sysroot_dir.join('lib')}):
       self._py('fetch-gn', self.m.vars.skia_dir.join('bin', 'fetch-gn'))
       self._run('gn gen', [gn, 'gen', self.out_dir, '--args=' + gn_args])
       self._run('ninja', [ninja, '-C', self.out_dir, 'nanobench', 'dm'])
diff --git a/infra/bots/recipe_modules/flavor/gn_flavor.py b/infra/bots/recipe_modules/flavor/gn_flavor.py
index 744cc5a..1b24371 100644
--- a/infra/bots/recipe_modules/flavor/gn_flavor.py
+++ b/infra/bots/recipe_modules/flavor/gn_flavor.py
@@ -127,7 +127,7 @@
     ninja = 'ninja.exe' if 'Win' in os else 'ninja'
     gn = self.m.vars.skia_dir.join('bin', gn)
 
-    with self.m.step.context({'cwd': self.m.vars.skia_dir}):
+    with self.m.context(cwd=self.m.vars.skia_dir):
       self._py('fetch-gn', self.m.vars.skia_dir.join('bin', 'fetch-gn'))
       self._run('gn gen', [gn, 'gen', self.out_dir, '--args=' + gn_args])
       self._run('ninja', [ninja, '-C', self.out_dir])
@@ -171,12 +171,12 @@
       # Convert path objects or placeholders into strings such that they can
       # be passed to symbolize_stack_trace.py
       args = [self.m.vars.slave_dir] + [str(x) for x in cmd]
-      with self.m.step.context({'cwd': self.m.vars.skia_dir, 'env': env}):
+      with self.m.context(cwd=self.m.vars.skia_dir, env=env):
         self._py('symbolized %s' % name,
                  self.module.resource('symbolize_stack_trace.py'),
                  args=args,
                  infra_step=False)
 
     else:
-      with self.m.step.context({'env': env}):
+      with self.m.context(env=env):
         self._run(name, cmd)
diff --git a/infra/bots/recipe_modules/flavor/pdfium_flavor.py b/infra/bots/recipe_modules/flavor/pdfium_flavor.py
index 84645f2..7c34a32 100644
--- a/infra/bots/recipe_modules/flavor/pdfium_flavor.py
+++ b/infra/bots/recipe_modules/flavor/pdfium_flavor.py
@@ -17,7 +17,7 @@
     pdfium_dir = self.m.vars.checkout_root.join('pdfium')
 
     # Runhook to generate the gn binary in buildtools.
-    with self.m.step.context({'cwd': pdfium_dir}):
+    with self.m.context(cwd=pdfium_dir):
       self.m.run(
           self.m.step,
           'runhook',
@@ -45,7 +45,7 @@
 
       env = self.m.step.get_from_context('env', {})
       env['CHROMIUM_BUILDTOOLS_PATH'] = str(pdfium_dir.join('buildtools'))
-      with self.m.step.context({'env': env}):
+      with self.m.context(env=env):
         self.m.run(
             self.m.step,
             'gn_gen',
diff --git a/infra/bots/recipe_modules/infra/__init__.py b/infra/bots/recipe_modules/infra/__init__.py
index ba20b52..94aa82a 100644
--- a/infra/bots/recipe_modules/infra/__init__.py
+++ b/infra/bots/recipe_modules/infra/__init__.py
@@ -3,6 +3,7 @@
 # found in the LICENSE file.
 
 DEPS = [
+  'recipe_engine/context',
   'recipe_engine/step',
   'run',
   'vars',
diff --git a/infra/bots/recipe_modules/infra/api.py b/infra/bots/recipe_modules/infra/api.py
index 4eb3aed..0a47842 100644
--- a/infra/bots/recipe_modules/infra/api.py
+++ b/infra/bots/recipe_modules/infra/api.py
@@ -39,7 +39,7 @@
     """Print the Go version."""
     env = self.m.step.get_from_context('env', {})
     env.update(self.go_env)
-    with self.m.step.context({'env': env}):
+    with self.m.context(env=env):
       self.m.run(
           self.m.step,
           'go version',
@@ -57,7 +57,7 @@
     self.go_version()
     env = self.m.step.get_from_context('env', {})
     env.update(self.go_env)
-    with self.m.step.context({'env': env}):
+    with self.m.context(env=env):
       self.m.run.with_retry(
           self.m.step,
           'update go pkgs',
diff --git a/infra/bots/recipe_modules/run/example.py b/infra/bots/recipe_modules/run/example.py
index dd4ddcb..162f679 100644
--- a/infra/bots/recipe_modules/run/example.py
+++ b/infra/bots/recipe_modules/run/example.py
@@ -4,6 +4,7 @@
 
 
 DEPS = [
+  'recipe_engine/context',
   'recipe_engine/path',
   'recipe_engine/properties',
   'recipe_engine/step',
@@ -36,7 +37,7 @@
   api.run.rmtree('mydir')
 
   # Merge PATHs.
-  with api.step.context({'env': {'PATH': 'mydir:%(PATH)s'}}):
+  with api.context(env={'PATH': 'mydir:%(PATH)s'}):
     api.run(api.step, 'env', cmd=['env'])
 
   # Copy build products.
diff --git a/infra/bots/recipe_modules/swarming/__init__.py b/infra/bots/recipe_modules/swarming/__init__.py
index 3e05b02..fbd0c00 100644
--- a/infra/bots/recipe_modules/swarming/__init__.py
+++ b/infra/bots/recipe_modules/swarming/__init__.py
@@ -8,6 +8,7 @@
   'build/swarming',
   'build/swarming_client',
   'depot_tools/depot_tools',
+  'recipe_engine/context',
   'recipe_engine/json',
   'recipe_engine/path',
   'recipe_engine/properties',
diff --git a/infra/bots/recipe_modules/swarming/api.py b/infra/bots/recipe_modules/swarming/api.py
index 81b05e0..35dddcf 100644
--- a/infra/bots/recipe_modules/swarming/api.py
+++ b/infra/bots/recipe_modules/swarming/api.py
@@ -44,7 +44,7 @@
     depot_tools_path = self.m.depot_tools.package_repo_resource()
     env = {'PATH': self.m.path.pathsep.join([
                        str(depot_tools_path), '%(PATH)s'])}
-    with self.m.step.context({'env': env}):
+    with self.m.context(env=env):
       self.m.step('download luci-go linux',
                   ['download_from_google_storage', '--no_resume',
                    '--platform=linux*', '--no_auth',
diff --git a/infra/bots/recipe_modules/vars/__init__.py b/infra/bots/recipe_modules/vars/__init__.py
index e0e9513..98c1d3e 100644
--- a/infra/bots/recipe_modules/vars/__init__.py
+++ b/infra/bots/recipe_modules/vars/__init__.py
@@ -5,6 +5,7 @@
 DEPS = [
   'builder_name_schema',
   'depot_tools/bot_update',
+  'recipe_engine/context',
   'recipe_engine/json',
   'recipe_engine/path',
   'recipe_engine/properties',
diff --git a/infra/bots/recipe_modules/vars/api.py b/infra/bots/recipe_modules/vars/api.py
index dbafc90..e48de5b 100644
--- a/infra/bots/recipe_modules/vars/api.py
+++ b/infra/bots/recipe_modules/vars/api.py
@@ -28,7 +28,7 @@
 
     self.slave_dir = self.m.path['start_dir']
     self.checkout_root = self.slave_dir
-    self.default_env = self.m.step.get_from_context('env', {})
+    self.default_env = self.m.context.env
     self.default_env['CHROME_HEADLESS'] = '1'
     self.default_env['PATH'] = self.m.path.pathsep.join([
         self.default_env.get('PATH', '%(PATH)s'),
diff --git a/infra/bots/recipes/bundle_recipes.py b/infra/bots/recipes/bundle_recipes.py
index d188ee1..ef0eccb 100644
--- a/infra/bots/recipes/bundle_recipes.py
+++ b/infra/bots/recipes/bundle_recipes.py
@@ -7,6 +7,7 @@
 
 
 DEPS = [
+  'recipe_engine/context',
   'recipe_engine/path',
   'recipe_engine/properties',
   'recipe_engine/shutil',
@@ -18,7 +19,7 @@
   bundle_dir = api.properties['swarm_out_dir'] + '/recipe_bundle'
   skia_dir = api.path['start_dir'].join('skia')
   recipes_py = api.path['start_dir'].join('skia', 'infra', 'bots', 'recipes.py')
-  with api.step.context({'cwd': skia_dir}):
+  with api.context(cwd=skia_dir):
     api.step('git init', infra_step=True,
              cmd=['git', 'init'])
     api.step('git add', infra_step=True,
diff --git a/infra/bots/recipes/compile.py b/infra/bots/recipes/compile.py
index 6b1c61c..222b255 100644
--- a/infra/bots/recipes/compile.py
+++ b/infra/bots/recipes/compile.py
@@ -8,6 +8,7 @@
 
 DEPS = [
   'core',
+  'recipe_engine/context',
   'recipe_engine/json',
   'recipe_engine/path',
   'recipe_engine/platform',
@@ -49,7 +50,7 @@
 
   try:
     for target in build_targets:
-      with api.step.context({'env': env}):
+      with api.context(env=env):
         api.flavor.compile(target)
     api.run.copy_build_products(
         api.flavor.out_dir,
diff --git a/infra/bots/recipes/ct_skps.py b/infra/bots/recipes/ct_skps.py
index 83bbf10..0abdd8f 100644
--- a/infra/bots/recipes/ct_skps.py
+++ b/infra/bots/recipes/ct_skps.py
@@ -9,6 +9,7 @@
 DEPS = [
   'build/file',
   'depot_tools/gsutil',
+  'recipe_engine/context',
   'recipe_engine/json',
   'recipe_engine/path',
   'recipe_engine/properties',
@@ -213,7 +214,7 @@
         gs_dest_dir = 'ct/%s/%d/%02d/%02d/%02d/' % (
             ct_page_type, utc.year, utc.month, utc.day, utc.hour)
         for json_output in api.file.listdir('output dir', output_dir):
-          with api.step.context({'env': env}):
+          with api.context(env=env):
             api.gsutil.upload(
                 name='upload json output',
                 source=output_dir.join(json_output),
diff --git a/infra/bots/recipes/housekeeper.py b/infra/bots/recipes/housekeeper.py
index af2ad4d..5d6a5f9 100644
--- a/infra/bots/recipes/housekeeper.py
+++ b/infra/bots/recipes/housekeeper.py
@@ -7,6 +7,7 @@
 
 DEPS = [
   'depot_tools/bot_update',
+  'recipe_engine/context',
   'recipe_engine/path',
   'recipe_engine/properties',
   'recipe_engine/python',
@@ -25,7 +26,7 @@
 
   # TODO(borenet): Detect static initializers?
 
-  with api.step.context({'cwd': cwd}):
+  with api.context(cwd=cwd):
     gsutil_path = api.bot_update._module.PACKAGE_REPO_ROOT.join('gsutil.py')
     if not api.vars.is_trybot:
       api.run(
diff --git a/infra/bots/recipes/infra.py b/infra/bots/recipes/infra.py
index 2c0222b..5482a7f 100644
--- a/infra/bots/recipes/infra.py
+++ b/infra/bots/recipes/infra.py
@@ -7,6 +7,7 @@
 
 
 DEPS = [
+  'recipe_engine/context',
   'recipe_engine/path',
   'recipe_engine/properties',
   'recipe_engine/step',
@@ -23,7 +24,7 @@
   api.infra.update_go_deps()
 
   # Run the infra tests.
-  with api.step.context({'cwd': api.vars.skia_dir, 'env': api.infra.go_env}):
+  with api.context(cwd=api.vars.skia_dir, env=api.infra.go_env):
     api.step('infra_tests', cmd=['make', '-C', 'infra/bots', 'test'])
 
 
diff --git a/infra/bots/recipes/recreate_skps.py b/infra/bots/recipes/recreate_skps.py
index c697bf1..b789975 100644
--- a/infra/bots/recipes/recreate_skps.py
+++ b/infra/bots/recipes/recreate_skps.py
@@ -9,6 +9,7 @@
 DEPS = [
   'build/file',
   'depot_tools/gclient',
+  'recipe_engine/context',
   'recipe_engine/path',
   'recipe_engine/properties',
   'recipe_engine/python',
@@ -89,13 +90,13 @@
   src_dir = api.vars.checkout_root.join('src')
   out_dir = src_dir.join('out', 'Release')
 
-  with api.step.context({'cwd': src_dir}):
+  with api.context(cwd=src_dir):
     # Call GN.
     platform = 'linux64'  # This bot only runs on linux; don't bother checking.
     gn = src_dir.join('buildtools', platform, 'gn')
     gn_env = {'CPPFLAGS': '-DSK_ALLOW_CROSSPROCESS_PICTUREIMAGEFILTERS=1',
               'GYP_GENERATORS': 'ninja'}
-    with api.step.context({'env': gn_env}):
+    with api.context(env=gn_env):
       api.run(api.step, 'GN', cmd=[gn, 'gen', out_dir])
 
     # Build Chrome.
@@ -115,7 +116,7 @@
          '--target_dir', output_dir]
   if 'Canary' not in api.properties['buildername']:
     cmd.append('--upload_to_partner_bucket')
-  with api.step.context({'cwd': api.vars.skia_dir}):
+  with api.context(cwd=api.vars.skia_dir):
     api.run(api.step, 'Recreate SKPs', cmd=cmd)
 
   # Upload the SKPs.
@@ -128,8 +129,7 @@
            '--target_dir', output_dir,
            '--gitcookies', str(update_skps_gitcookies)]
     with gitcookies_auth(api, UPDATE_SKPS_KEY):
-      with api.step.context({'cwd': api.vars.skia_dir,
-                             'env': api.infra.go_env}):
+      with api.context(cwd=api.vars.skia_dir, env=api.infra.go_env):
         api.run(api.step, 'Upload SKPs', cmd=cmd)
 
 
diff --git a/infra/bots/recipes/skpbench.py b/infra/bots/recipes/skpbench.py
index c59864b..08b60d9 100644
--- a/infra/bots/recipes/skpbench.py
+++ b/infra/bots/recipes/skpbench.py
@@ -12,6 +12,7 @@
 DEPS = [
   'build/file',
   'core',
+  'recipe_engine/context',
   'recipe_engine/path',
   'recipe_engine/properties',
   'recipe_engine/python',
@@ -25,7 +26,7 @@
 
 
 def _run(api, title, *cmd, **kwargs):
-  with api.step.context({'cwd': api.vars.skia_dir}):
+  with api.context(cwd=api.vars.skia_dir):
     return api.run(api.step, title, cmd=list(cmd), **kwargs)
 
 
diff --git a/infra/bots/recipes/test.py b/infra/bots/recipes/test.py
index 27bc301..9b709f0 100644
--- a/infra/bots/recipes/test.py
+++ b/infra/bots/recipes/test.py
@@ -11,6 +11,7 @@
   'core',
   'env',
   'flavor',
+  'recipe_engine/context',
   'recipe_engine/json',
   'recipe_engine/path',
   'recipe_engine/platform',
@@ -723,11 +724,11 @@
 
 def RunSteps(api):
   api.core.setup()
-  env = api.step.get_from_context('env', {})
+  env = {}
   if 'iOS' in api.vars.builder_name:
     env['IOS_BUNDLE_ID'] = 'com.google.dm'
     env['IOS_MOUNT_POINT'] = api.vars.slave_dir.join('mnt_iosdevice')
-  with api.step.context({'env': env}):
+  with api.context(env=env):
     try:
       api.flavor.install_everything()
       test_steps(api)
diff --git a/infra/bots/recipes/upload_nano_results.py b/infra/bots/recipes/upload_nano_results.py
index 8d917dd..20a723b 100644
--- a/infra/bots/recipes/upload_nano_results.py
+++ b/infra/bots/recipes/upload_nano_results.py
@@ -8,6 +8,7 @@
 
 DEPS = [
   'build/file',
+  'recipe_engine/context',
   'recipe_engine/path',
   'recipe_engine/properties',
   'recipe_engine/step',
@@ -22,7 +23,7 @@
   now = api.time.utcnow()
   src_path = api.path['start_dir'].join(
       'perfdata', builder_name, 'data')
-  with api.step.context({'cwd': src_path}):
+  with api.context(cwd=src_path):
     results = api.file.glob(
         'find results',
         src_path.join('*.json'),