OLD | NEW |
(Empty) | |
| 1 # Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. |
| 4 |
| 5 from recipe_engine import recipe_api |
| 6 |
| 7 class GeneratorScriptApi(recipe_api.RecipeApi): |
| 8 def __call__(self, path_to_script, *args, **kwargs): |
| 9 """Run a script and generate the steps emitted by that script. |
| 10 |
| 11 If a step has a key 'outputs_presentation_json' whose value is |
| 12 True, its command is extended with a --presentation-json argument |
| 13 pointing to a file where it is expected to write presentation json |
| 14 which is used to update that step's presentation on the waterfall. |
| 15 |
| 16 Presentation keys are: |
| 17 logs: A map of log names to log text. |
| 18 links: A map of link text to URIs. |
| 19 perf_logs: A map of log names to text. |
| 20 step_summary_text: A string to set as the step summary. |
| 21 step_text: A string to set as the step text. |
| 22 properties: A map of build_property names to JSON-encoded values. |
| 23 |
| 24 kwargs: |
| 25 env - The environment for the generated steps. |
| 26 """ |
| 27 f = '--output-json' |
| 28 step_name = 'gen step(%s)' % self.m.path.basename(path_to_script) |
| 29 |
| 30 step_test_data = kwargs.pop('step_test_data', None) |
| 31 if str(path_to_script).endswith('.py'): |
| 32 step_result = self.m.python( |
| 33 step_name, |
| 34 path_to_script, list(args) + [f, self.m.json.output()], |
| 35 cwd=self.m.path['checkout'], step_test_data=step_test_data) |
| 36 else: |
| 37 step_result = self.m.step( |
| 38 step_name, |
| 39 [path_to_script,] + list(args) + [f, self.m.json.output()], |
| 40 cwd=self.m.path['checkout'], step_test_data=step_test_data) |
| 41 new_steps = step_result.json.output |
| 42 assert isinstance(new_steps, list) |
| 43 env = kwargs.get('env') |
| 44 |
| 45 failed_steps = [] |
| 46 for step in new_steps: |
| 47 if env: |
| 48 new_env = dict(env) |
| 49 new_env.update(step.get('env', {})) |
| 50 step['env'] = new_env |
| 51 outputs_json = step.pop('outputs_presentation_json', False) |
| 52 if outputs_json: |
| 53 # This step has requested a JSON file which the binary that |
| 54 # it invokes can write to, so provide it with one. |
| 55 step['cmd'].extend(['--presentation-json', self.m.json.output(False)]) |
| 56 |
| 57 #TODO(martiniss) change this to use a regular step call |
| 58 step['ok_ret'] = set(step.pop('ok_ret', {0})) |
| 59 step['infra_step'] = bool(step.pop('infra_step', False)) |
| 60 step['step_nest_level'] = int(step.pop('step_nest_level', 0)) |
| 61 |
| 62 if step.pop('always_run', False) or not failed_steps: |
| 63 try: |
| 64 self.m.step.run_from_dict(step) |
| 65 except self.m.step.StepFailure: |
| 66 failed_steps.append(step['name']) |
| 67 finally: |
| 68 step_result = self.m.step.active_result |
| 69 if outputs_json: |
| 70 p = step_result.presentation |
| 71 j = step_result.json.output |
| 72 |
| 73 if j: |
| 74 p.logs.update(j.get('logs', {})) |
| 75 p.links.update(j.get('links', {})) |
| 76 p.perf_logs.update(j.get('perf_logs', {})) |
| 77 p.step_summary_text = j.get('step_summary_text', '') |
| 78 p.step_text = j.get('step_text', '') |
| 79 p.properties.update(j.get('properties', {})) |
| 80 |
| 81 if failed_steps: |
| 82 raise self.m.step.StepFailure( |
| 83 "the following steps in %s failed: %s" % |
| 84 (step_name, failed_steps)) |
OLD | NEW |