OLD | NEW |
(Empty) | |
| 1 # Copyright 2016 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 __future__ import print_function |
| 6 |
| 7 import contextlib |
| 8 import logging |
| 9 import os |
| 10 import shutil |
| 11 import subprocess |
| 12 import sys |
| 13 import tempfile |
| 14 |
| 15 from recipe_engine import fetch |
| 16 from recipe_engine import package |
| 17 |
| 18 |
| 19 @contextlib.contextmanager |
| 20 def ensure_workdir(args): |
| 21 workdir_tempdir = False |
| 22 if not args.workdir: |
| 23 workdir_tempdir = True |
| 24 args.workdir = tempfile.mkdtemp(prefix='recipe_engine_remote_run_') |
| 25 logging.info('Created temporary workdir %s', args.workdir) |
| 26 |
| 27 try: |
| 28 yield |
| 29 finally: |
| 30 if workdir_tempdir: |
| 31 shutil.rmtree(args.workdir, ignore_errors=True) |
| 32 |
| 33 |
| 34 def main(args): |
| 35 with ensure_workdir(args): |
| 36 checkout_dir = os.path.join(args.workdir, 'checkout') |
| 37 fetch.ensure_git_checkout( |
| 38 args.repository, args.revision, checkout_dir, allow_fetch=True) |
| 39 recipes_cfg = package.ProtoFile( |
| 40 package.InfraRepoConfig().to_recipes_cfg(checkout_dir)) |
| 41 cmd = [ |
| 42 sys.executable, |
| 43 os.path.join( |
| 44 checkout_dir, |
| 45 recipes_cfg.read().recipes_path, |
| 46 'recipes.py'), |
| 47 'run' |
| 48 ] + args.run_args |
| 49 logging.info('Running %r', cmd) |
| 50 return subprocess.call(cmd) |
OLD | NEW |