| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2013 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 import argparse | 6 import argparse |
| 7 import json | 7 import json |
| 8 import logging | 8 import logging |
| 9 import os | 9 import os |
| 10 import subprocess | 10 import subprocess |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 from common import env | 21 from common import env |
| 22 from common import master_cfg_utils | 22 from common import master_cfg_utils |
| 23 from slave import logdog_bootstrap | 23 from slave import logdog_bootstrap |
| 24 from slave import monitoring_utils | 24 from slave import monitoring_utils |
| 25 from slave import robust_tempdir | 25 from slave import robust_tempdir |
| 26 from slave import update_scripts | 26 from slave import update_scripts |
| 27 | 27 |
| 28 # Logging instance. | 28 # Logging instance. |
| 29 LOGGER = logging.getLogger('annotated_run') | 29 LOGGER = logging.getLogger('annotated_run') |
| 30 | 30 |
| 31 # /b/build/slave/<slavename>/build/ |
| 32 BUILD_DIR = os.getcwd() |
| 33 # /b/build/slave/<slavename>/ |
| 34 BUILDER_DIR = os.path.dirname(BUILD_DIR) |
| 35 |
| 36 def _build_dir(): |
| 37 return BUILD_DIR |
| 38 |
| 39 def _builder_dir(): |
| 40 return BUILDER_DIR |
| 41 |
| 31 def _ensure_directory(*path): | 42 def _ensure_directory(*path): |
| 32 path = os.path.join(*path) | 43 path = os.path.join(*path) |
| 33 if not os.path.isdir(path): | 44 if not os.path.isdir(path): |
| 34 os.makedirs(path) | 45 os.makedirs(path) |
| 35 return path | 46 return path |
| 36 | 47 |
| 37 | 48 |
| 38 def _run_command(cmd, **kwargs): | 49 def _run_command(cmd, **kwargs): |
| 39 if kwargs.pop('dry_run', False): | 50 if kwargs.pop('dry_run', False): |
| 40 LOGGER.info('(Dry Run) Would have executed command: %s', cmd) | 51 LOGGER.info('(Dry Run) Would have executed command: %s', cmd) |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 245 | 256 |
| 246 # Dump properties to JSON and build recipe command. | 257 # Dump properties to JSON and build recipe command. |
| 247 props_file = os.path.join(tdir, 'recipe_properties.json') | 258 props_file = os.path.join(tdir, 'recipe_properties.json') |
| 248 with open(props_file, 'w') as fh: | 259 with open(props_file, 'w') as fh: |
| 249 json.dump(properties, fh) | 260 json.dump(properties, fh) |
| 250 | 261 |
| 251 recipe_cmd = [ | 262 recipe_cmd = [ |
| 252 sys.executable, '-u', recipe_runner, | 263 sys.executable, '-u', recipe_runner, |
| 253 '--verbose', | 264 '--verbose', |
| 254 'run', | 265 'run', |
| 255 '--workdir=%s' % os.getcwd(), | 266 '--workdir=%s' % _build_dir(), |
| 256 '--properties-file=%s' % props_file, | 267 '--properties-file=%s' % props_file, |
| 257 properties['recipe'], | 268 properties['recipe'], |
| 258 ] | 269 ] |
| 259 | 270 |
| 260 recipe_return_code = None | 271 recipe_return_code = None |
| 261 try: | 272 try: |
| 262 bs = logdog_bootstrap.bootstrap(rt, opts, basedir, tdir, properties, | 273 bs = logdog_bootstrap.bootstrap(rt, opts, basedir, tdir, properties, |
| 263 recipe_cmd) | 274 recipe_cmd) |
| 264 | 275 |
| 265 LOGGER.info('Bootstrapping through LogDog: %s', bs.cmd) | 276 LOGGER.info('Bootstrapping through LogDog: %s', bs.cmd) |
| (...skipping 17 matching lines...) Expand all Loading... |
| 283 | 294 |
| 284 if opts.verbose == 0: | 295 if opts.verbose == 0: |
| 285 level = logging.INFO | 296 level = logging.INFO |
| 286 else: | 297 else: |
| 287 level = logging.DEBUG | 298 level = logging.DEBUG |
| 288 logging.getLogger().setLevel(level) | 299 logging.getLogger().setLevel(level) |
| 289 | 300 |
| 290 clean_old_recipe_engine() | 301 clean_old_recipe_engine() |
| 291 | 302 |
| 292 # Enter our runtime environment. | 303 # Enter our runtime environment. |
| 293 basedir = os.getcwd() | 304 basedir = _builder_dir() |
| 294 with robust_tempdir.RobustTempdir( | 305 with robust_tempdir.RobustTempdir( |
| 295 prefix='.recipe_runtime', leak=opts.leak) as rt: | 306 prefix='.recipe_runtime', leak=opts.leak) as rt: |
| 296 tdir = rt.tempdir(base=basedir) | 307 tdir = rt.tempdir(base=basedir) |
| 297 LOGGER.debug('Using temporary directory: [%s].', tdir) | 308 LOGGER.debug('Using temporary directory: [%s].', tdir) |
| 298 | 309 |
| 299 # Load factory properties and configuration. | 310 # Load factory properties and configuration. |
| 300 # TODO(crbug.com/551165): remove flag "factory_properties". | 311 # TODO(crbug.com/551165): remove flag "factory_properties". |
| 301 use_factory_properties_from_disk = (opts.use_factory_properties_from_disk or | 312 use_factory_properties_from_disk = (opts.use_factory_properties_from_disk or |
| 302 bool(opts.factory_properties)) | 313 bool(opts.factory_properties)) |
| 303 properties = get_recipe_properties( | 314 properties = get_recipe_properties( |
| (...skipping 16 matching lines...) Expand all Loading... |
| 320 # Re-execute with the updated annotated_run.py. | 331 # Re-execute with the updated annotated_run.py. |
| 321 rv, _ = _run_command([sys.executable] + argv) | 332 rv, _ = _run_command([sys.executable] + argv) |
| 322 return rv | 333 return rv |
| 323 else: | 334 else: |
| 324 return main(argv[1:]) | 335 return main(argv[1:]) |
| 325 | 336 |
| 326 | 337 |
| 327 if __name__ == '__main__': | 338 if __name__ == '__main__': |
| 328 logging.basicConfig(level=logging.INFO) | 339 logging.basicConfig(level=logging.INFO) |
| 329 sys.exit(shell_main(sys.argv)) | 340 sys.exit(shell_main(sys.argv)) |
| OLD | NEW |