| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 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 """Reads a .isolated, creates a tree of hardlinks and runs the test. | 6 """Reads a .isolated, creates a tree of hardlinks and runs the test. |
| 7 | 7 |
| 8 Keeps a local cache. | 8 Keeps a local cache. |
| 9 """ | 9 """ |
| 10 | 10 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 import isolateserver | 32 import isolateserver |
| 33 | 33 |
| 34 | 34 |
| 35 # Absolute path to this file (can be None if running from zip on Mac). | 35 # Absolute path to this file (can be None if running from zip on Mac). |
| 36 THIS_FILE_PATH = os.path.abspath(__file__) if __file__ else None | 36 THIS_FILE_PATH = os.path.abspath(__file__) if __file__ else None |
| 37 | 37 |
| 38 # Directory that contains this file (might be inside zip package). | 38 # Directory that contains this file (might be inside zip package). |
| 39 BASE_DIR = os.path.dirname(THIS_FILE_PATH) if __file__ else None | 39 BASE_DIR = os.path.dirname(THIS_FILE_PATH) if __file__ else None |
| 40 | 40 |
| 41 # Directory that contains currently running script file. | 41 # Directory that contains currently running script file. |
| 42 MAIN_DIR = os.path.dirname(os.path.abspath(zip_package.get_main_script_path())) | 42 if zip_package.get_main_script_path(): |
| 43 MAIN_DIR = os.path.dirname( |
| 44 os.path.abspath(zip_package.get_main_script_path())) |
| 45 else: |
| 46 # This happens when 'import run_isolated' is executed at the python |
| 47 # interactive prompt, in that case __file__ is undefined. |
| 48 MAIN_DIR = None |
| 43 | 49 |
| 44 # Types of action accepted by link_file(). | 50 # Types of action accepted by link_file(). |
| 45 HARDLINK, HARDLINK_WITH_FALLBACK, SYMLINK, COPY = range(1, 5) | 51 HARDLINK, HARDLINK_WITH_FALLBACK, SYMLINK, COPY = range(1, 5) |
| 46 | 52 |
| 47 # The name of the log file to use. | 53 # The name of the log file to use. |
| 48 RUN_ISOLATED_LOG_FILE = 'run_isolated.log' | 54 RUN_ISOLATED_LOG_FILE = 'run_isolated.log' |
| 49 | 55 |
| 50 # The name of the log to use for the run_test_cases.py command | 56 # The name of the log to use for the run_test_cases.py command |
| 51 RUN_TEST_CASES_LOG = 'run_test_cases.log' | 57 RUN_TEST_CASES_LOG = 'run_test_cases.log' |
| 52 | 58 |
| (...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 507 if settings.read_only: | 513 if settings.read_only: |
| 508 logging.info('Making files read only') | 514 logging.info('Making files read only') |
| 509 make_writable(outdir, True) | 515 make_writable(outdir, True) |
| 510 cwd = os.path.normpath(os.path.join(outdir, settings.relative_cwd)) | 516 cwd = os.path.normpath(os.path.join(outdir, settings.relative_cwd)) |
| 511 logging.info('Running %s, cwd=%s' % (settings.command, cwd)) | 517 logging.info('Running %s, cwd=%s' % (settings.command, cwd)) |
| 512 | 518 |
| 513 # TODO(csharp): This should be specified somewhere else. | 519 # TODO(csharp): This should be specified somewhere else. |
| 514 # TODO(vadimsh): Pass it via 'env_vars' in manifest. | 520 # TODO(vadimsh): Pass it via 'env_vars' in manifest. |
| 515 # Add a rotating log file if one doesn't already exist. | 521 # Add a rotating log file if one doesn't already exist. |
| 516 env = os.environ.copy() | 522 env = os.environ.copy() |
| 517 env.setdefault('RUN_TEST_CASES_LOG_FILE', | 523 if MAIN_DIR: |
| 518 os.path.join(MAIN_DIR, RUN_TEST_CASES_LOG)) | 524 env.setdefault('RUN_TEST_CASES_LOG_FILE', |
| 525 os.path.join(MAIN_DIR, RUN_TEST_CASES_LOG)) |
| 519 try: | 526 try: |
| 520 with tools.Profiler('RunTest'): | 527 with tools.Profiler('RunTest'): |
| 521 return subprocess.call(settings.command, cwd=cwd, env=env) | 528 return subprocess.call(settings.command, cwd=cwd, env=env) |
| 522 except OSError: | 529 except OSError: |
| 523 print >> sys.stderr, 'Failed to run %s; cwd=%s' % (settings.command, cwd) | 530 print >> sys.stderr, 'Failed to run %s; cwd=%s' % (settings.command, cwd) |
| 524 return 1 | 531 return 1 |
| 525 finally: | 532 finally: |
| 526 if outdir: | 533 if outdir: |
| 527 rmtree(outdir) | 534 rmtree(outdir) |
| 528 | 535 |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 606 except Exception, e: | 613 except Exception, e: |
| 607 # Make sure any exception is logged. | 614 # Make sure any exception is logged. |
| 608 logging.exception(e) | 615 logging.exception(e) |
| 609 return 1 | 616 return 1 |
| 610 | 617 |
| 611 | 618 |
| 612 if __name__ == '__main__': | 619 if __name__ == '__main__': |
| 613 # Ensure that we are always running with the correct encoding. | 620 # Ensure that we are always running with the correct encoding. |
| 614 fix_encoding.fix_encoding() | 621 fix_encoding.fix_encoding() |
| 615 sys.exit(main()) | 622 sys.exit(main()) |
| OLD | NEW |