OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright 2015 The LUCI Authors. All rights reserved. | 2 # Copyright 2015 The LUCI Authors. All rights reserved. |
3 # Use of this source code is governed under the Apache License, Version 2.0 | 3 # Use of this source code is governed under the Apache License, Version 2.0 |
4 # that can be found in the LICENSE file. | 4 # that can be found in the LICENSE file. |
5 | 5 |
6 """Tool to interact with recipe repositories. | 6 """Tool to interact with recipe repositories. |
7 | 7 |
8 This tool operates on the nearest ancestor directory containing an | 8 This tool operates on the nearest ancestor directory containing an |
9 infra/config/recipes.cfg. | 9 infra/config/recipes.cfg. |
10 """ | 10 """ |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 properties = get_properties_from_json(args.properties) | 139 properties = get_properties_from_json(args.properties) |
140 elif args.properties_file: | 140 elif args.properties_file: |
141 properties = get_properties_from_file(args.properties_file) | 141 properties = get_properties_from_file(args.properties_file) |
142 elif op_properties is not None: | 142 elif op_properties is not None: |
143 properties = op_properties | 143 properties = op_properties |
144 else: | 144 else: |
145 properties = arg_properties | 145 properties = arg_properties |
146 | 146 |
147 properties['recipe'] = args.recipe | 147 properties['recipe'] = args.recipe |
148 | 148 |
| 149 # TODO(iannucci): A much better way to do this would be to dynamically |
| 150 # detect if the mirrors are actually available during the execution of the |
| 151 # recipe. |
| 152 if ('use_mirror' not in properties and ( |
| 153 'TESTING_MASTERNAME' in os.environ or |
| 154 'TESTING_SLAVENAME' in os.environ)): |
| 155 properties['use_mirror'] = False |
| 156 |
149 os.environ['PYTHONUNBUFFERED'] = '1' | 157 os.environ['PYTHONUNBUFFERED'] = '1' |
150 os.environ['PYTHONIOENCODING'] = 'UTF-8' | 158 os.environ['PYTHONIOENCODING'] = 'UTF-8' |
151 | 159 |
152 _, config_file = get_package_config(args) | 160 _, config_file = get_package_config(args) |
153 universe_view = loader.UniverseView( | 161 universe_view = loader.UniverseView( |
154 loader.RecipeUniverse( | 162 loader.RecipeUniverse( |
155 package_deps, config_file), package_deps.root_package) | 163 package_deps, config_file), package_deps.root_package) |
156 | 164 |
157 workdir = (args.workdir or | 165 workdir = (args.workdir or |
158 os.path.join(os.path.dirname(os.path.realpath(__file__)), 'workdir')) | 166 os.path.join(os.path.dirname(os.path.realpath(__file__)), 'workdir')) |
159 logging.info('Using %s as work directory' % workdir) | 167 logging.info('Using %s as work directory' % workdir) |
160 if not os.path.exists(workdir): | 168 if not os.path.exists(workdir): |
161 os.makedirs(workdir) | 169 os.makedirs(workdir) |
162 | 170 |
163 old_cwd = os.getcwd() | 171 old_cwd = os.getcwd() |
164 os.chdir(workdir) | 172 os.chdir(workdir) |
165 | 173 |
| 174 # Generate our Runtime instance. |
| 175 rt = recipe_run.Runtime(properties) |
| 176 |
166 # Construct our stream engines. We may want to share stream events with more | 177 # Construct our stream engines. We may want to share stream events with more |
167 # than one StreamEngine implementation, so we will accumulate them in a | 178 # than one StreamEngine implementation, so we will accumulate them in a |
168 # "stream_engines" list and compose them into a MultiStreamEngine. | 179 # "stream_engines" list and compose them into a MultiStreamEngine. |
169 def build_annotation_stream_engine(): | 180 def build_annotation_stream_engine(): |
170 return stream.AnnotatorStreamEngine( | 181 return stream.AnnotatorStreamEngine( |
171 sys.stdout, | 182 sys.stdout, |
172 emit_timestamps=(args.timestamps or | 183 emit_timestamps=(args.timestamps or |
173 op_args.annotation_flags.emit_timestamp), | 184 op_args.annotation_flags.emit_timestamp), |
174 ) | 185 ) |
175 | 186 |
(...skipping 16 matching lines...) Expand all Loading... |
192 # Have a top-level set of invariants to enforce StreamEngine expectations. | 203 # Have a top-level set of invariants to enforce StreamEngine expectations. |
193 with stream.StreamEngineInvariants.wrap(multi_stream_engine) as stream_engine: | 204 with stream.StreamEngineInvariants.wrap(multi_stream_engine) as stream_engine: |
194 # Emit initial properties if configured to do so. | 205 # Emit initial properties if configured to do so. |
195 if op_args.annotation_flags.emit_initial_properties: | 206 if op_args.annotation_flags.emit_initial_properties: |
196 with stream_engine.new_step_stream('Initial Properties') as s: | 207 with stream_engine.new_step_stream('Initial Properties') as s: |
197 for key in sorted(properties.iterkeys()): | 208 for key in sorted(properties.iterkeys()): |
198 s.set_build_property(key, json.dumps(properties[key], sort_keys=True)) | 209 s.set_build_property(key, json.dumps(properties[key], sort_keys=True)) |
199 | 210 |
200 try: | 211 try: |
201 ret = recipe_run.run_steps( | 212 ret = recipe_run.run_steps( |
202 properties, stream_engine, | 213 rt, stream_engine, |
203 step_runner.SubprocessStepRunner(stream_engine), | 214 step_runner.SubprocessStepRunner(stream_engine), |
204 universe_view=universe_view) | 215 universe_view=universe_view) |
205 finally: | 216 finally: |
206 os.chdir(old_cwd) | 217 os.chdir(old_cwd) |
207 | 218 |
208 return handle_recipe_return(ret, args.output_result_json, stream_engine) | 219 return handle_recipe_return(ret, args.output_result_json, stream_engine) |
209 | 220 |
210 | 221 |
211 def remote(args): | 222 def remote(args): |
212 from recipe_engine import remote | 223 from recipe_engine import remote |
(...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
607 | 618 |
608 if not isinstance(ret, int): | 619 if not isinstance(ret, int): |
609 if ret is None: | 620 if ret is None: |
610 ret = 0 | 621 ret = 0 |
611 else: | 622 else: |
612 print >> sys.stderr, ret | 623 print >> sys.stderr, ret |
613 ret = 1 | 624 ret = 1 |
614 sys.stdout.flush() | 625 sys.stdout.flush() |
615 sys.stderr.flush() | 626 sys.stderr.flush() |
616 os._exit(ret) | 627 os._exit(ret) |
OLD | NEW |