Index: recipe_engine/run.py |
diff --git a/recipe_engine/run.py b/recipe_engine/run.py |
index d87694619e1c1e335d236fd1b9677e84aa548b77..d9971e80e1cf613bd1fd38d37397e2b014744d83 100644 |
--- a/recipe_engine/run.py |
+++ b/recipe_engine/run.py |
@@ -66,7 +66,6 @@ iterable_of_things. |
import collections |
import json |
import os |
-import sys |
import traceback |
from . import env |
@@ -188,45 +187,30 @@ RecipeResult = collections.namedtuple('RecipeResult', 'result') |
# TODO(dnj): Replace "properties" with a generic runtime instance. This instance |
# will be used to seed recipe clients and expanded to include managed runtime |
# entities. |
-def run_steps(properties, stream_engine, step_runner, universe_view): |
+def run_steps(rt, stream_engine, step_runner, universe_view): |
"""Runs a recipe (given by the 'recipe' property). |
Args: |
- properties: a dictionary of properties to pass to the recipe. The |
- 'recipe' property defines which recipe to actually run. |
+ rt (Runtime): The runtime instance. |
stream_engine: the StreamEngine to use to create individual step streams. |
step_runner: The StepRunner to use to 'actually run' the steps. |
universe_view: The RecipeUniverse to use to load the recipes & modules. |
Returns: RecipeResult |
""" |
- # NOTE(iannucci): 'root' was a terribly bad idea and has been replaced by |
dnj
2016/10/13 01:08:23
Talked with iannucci@, probably don't need this.
|
- # 'patch_project'. 'root' had Rietveld knowing about the implementation of |
- # the builders. 'patch_project' lets the builder (recipe) decide its own |
- # destiny. |
- properties.pop('root', None) |
- |
- # TODO(iannucci): A much better way to do this would be to dynamically |
dnj
2016/10/13 01:08:23
Transplanted into "recipes.py", closer to other pr
|
- # detect if the mirrors are actually available during the execution of the |
- # recipe. |
- if ('use_mirror' not in properties and ( |
- 'TESTING_MASTERNAME' in os.environ or |
- 'TESTING_SLAVENAME' in os.environ)): |
- properties['use_mirror'] = False |
- |
with stream_engine.make_step_stream('setup_build') as s: |
- engine = RecipeEngine(step_runner, properties, universe_view) |
+ engine = RecipeEngine(step_runner, rt, universe_view) |
# Create all API modules and top level RunSteps function. It doesn't launch |
# any recipe code yet; RunSteps needs to be called. |
api = None |
- assert 'recipe' in properties |
- recipe = properties['recipe'] |
+ assert 'recipe' in rt.properties |
+ recipe = rt.properties['recipe'] |
- properties_to_print = properties.copy() |
- if 'use_mirror' in properties: |
- del properties_to_print['use_mirror'] |
+ # Remove domain-specific properties. |
+ properties_to_print = rt.properties.copy() |
+ properties_to_print.pop('use_mirror', None) |
iannucci
2016/10/15 00:39:45
I would ditch this
dnj
2016/10/15 00:59:27
altogether, or this specific change?
iannucci
2016/10/15 01:04:09
Well you're moving the other property stuff in thi
dnj
2016/10/15 15:42:05
Done.
|
root_package = universe_view.universe.package_deps.root_package |
run_recipe_help_lines = [ |
@@ -247,12 +231,12 @@ def run_steps(properties, stream_engine, step_runner, universe_view): |
for line in run_recipe_help_lines: |
l.write_line(line) |
- _isolate_environment() |
+ os.environ = _isolate_environment(rt, os.environ) |
# Find and load the recipe to run. |
try: |
recipe_script = universe_view.load_recipe(recipe, engine=engine) |
- s.write_line('Running recipe with %s' % (properties,)) |
+ s.write_line('Running recipe with %s' % (rt.properties,)) |
api = loader.create_recipe_api(recipe_script.LOADED_DEPS, |
engine, |
@@ -270,23 +254,38 @@ def run_steps(properties, stream_engine, step_runner, universe_view): |
# Run the steps emitted by a recipe via the engine, emitting annotations |
# into |stream| along the way. |
- return engine.run(recipe_script, api, properties) |
+ return engine.run(recipe_script, api, rt.properties) |
-def _isolate_environment(): |
+def _isolate_environment(rt, env): |
"""Isolate the environment to a known subset set.""" |
- if sys.platform.startswith('win'): |
+ if rt.platform.is_win(): |
whitelist = ENV_WHITELIST_WIN |
- elif sys.platform in ('darwin', 'posix', 'linux2'): |
+ elif rt.platform.is_posix(): |
whitelist = ENV_WHITELIST_POSIX |
else: |
- print ('WARNING: unknown platform %s, not isolating environment.' % |
- sys.platform) |
- return |
+ print 'WARNING: unknown platform %s, not isolating environment.' % ( |
+ rt.platform,) |
+ return env |
+ return {k: v for k, v in env.iteritems() if k in whitelist} |
+ |
- for k in os.environ.keys(): |
- if k not in whitelist: |
- del os.environ[k] |
+class Runtime(object): |
+ """Container for instance-global state.""" |
+ |
+ def __init__(self, properties, platform=None): |
+ self._properties = properties |
+ self._platform = platform if platform else util.Platform.probe() |
+ |
+ @property |
+ def properties(self): |
+ """Returns (dict): The input properties.""" |
+ return self._properties |
+ |
+ @property |
+ def platform(self): |
+ """Returns (util.Platform): The current running Platform.""" |
+ return self._platform |
class RecipeEngine(object): |
@@ -294,23 +293,20 @@ class RecipeEngine(object): |
Knows how to execute steps emitted by a recipe, holds global state such as |
step history and build properties. Each recipe module API has a reference to |
this object. |
- |
- Recipe modules that are aware of the engine: |
- * properties - uses engine.properties. |
- * step - uses engine.create_step(...), and previous_step_result. |
""" |
ActiveStep = collections.namedtuple('ActiveStep', ( |
'config', 'step_result', 'open_step')) |
- def __init__(self, step_runner, properties, universe_view): |
+ def __init__(self, step_runner, rt, universe_view): |
"""See run_steps() for parameter meanings.""" |
self._step_runner = step_runner |
- self._properties = properties |
+ self._rt = rt |
self._universe_view = universe_view |
self._clients = {client.IDENT: client for client in ( |
recipe_api.StepClient(self), |
- recipe_api.PropertiesClient(self), |
+ recipe_api.PropertiesClient(self._rt.properties), |
+ recipe_api.PlatformClient(self._rt.platform), |
recipe_api.DependencyManagerClient(self), |
)} |
@@ -321,8 +317,8 @@ class RecipeEngine(object): |
# TODO(iannucci): come up with a more structured way to advertise/set mode |
iannucci
2016/10/15 00:39:45
I think this isn't used any more. you can delete t
dnj
2016/10/15 00:59:27
Done.
|
# flags/options for the engine. |
- if '$recipe_engine' in properties: |
- options = properties['$recipe_engine'] |
+ options = self._rt.properties.get('$recipe_engine') |
+ if options is not None: |
try: |
mode_flags = options.get('mode_flags') |
if mode_flags: |
@@ -333,7 +329,7 @@ class RecipeEngine(object): |
@property |
def properties(self): |
- return self._properties |
+ return self._rt.properties |
@property |
def universe(self): |