OLD | NEW |
(Empty) | |
| 1 #!/usr/bin/env python |
| 2 # |
| 3 # Copyright 2015 The Chromium Authors. All rights reserved. |
| 4 # Use of this source code is governed by a BSD-style license that can be |
| 5 # found in the LICENSE file. |
| 6 |
| 7 """Creates a script to run an android test using build/android/test_runner.py. |
| 8 """ |
| 9 |
| 10 import argparse |
| 11 import os |
| 12 import sys |
| 13 |
| 14 script_template = """\ |
| 15 #!/usr/bin/env python |
| 16 # |
| 17 # This file was generated by build/android/gyp/create_test_runner_script.py |
| 18 |
| 19 import logging |
| 20 import os |
| 21 import sys |
| 22 |
| 23 script_directory = os.path.dirname(__file__) |
| 24 |
| 25 def ResolvePath(path): |
| 26 \"\"\"Returns an absolute filepath given a path relative to this script. |
| 27 \"\"\" |
| 28 return os.path.abspath(os.path.join(script_directory, path)) |
| 29 |
| 30 test_runner_path = ResolvePath('{test_runner_path}') |
| 31 test_runner_args = {test_runner_args} |
| 32 test_runner_path_args = {test_runner_path_args} |
| 33 for arg, path in test_runner_path_args.iteritems(): |
| 34 test_runner_args.extend([arg, ResolvePath(path)]) |
| 35 |
| 36 test_runner_cmd = ' '.join( |
| 37 [test_runner_path] + test_runner_args + sys.argv[1:]) |
| 38 logging.critical(test_runner_cmd) |
| 39 os.system(test_runner_cmd) |
| 40 """ |
| 41 |
| 42 def main(): |
| 43 parser = argparse.ArgumentParser() |
| 44 parser.add_argument('--script-output-path', |
| 45 help='Output path for executable script.') |
| 46 # We need to intercept any test runner path arguments and make all |
| 47 # of the paths relative to the output script directory. |
| 48 group = parser.add_argument_group('Test runner path arguments.') |
| 49 group.add_argument('--output-directory') |
| 50 group.add_argument('--isolate-file-path') |
| 51 args, test_runner_args = parser.parse_known_args() |
| 52 |
| 53 def RelativizePathToScript(path): |
| 54 """Returns the path relative to the output script directory.""" |
| 55 return os.path.relpath(path, os.path.dirname(args.script_output_path)) |
| 56 |
| 57 test_runner_path = os.path.join( |
| 58 os.path.dirname(__file__), os.path.pardir, 'test_runner.py') |
| 59 test_runner_path = RelativizePathToScript(test_runner_path) |
| 60 |
| 61 test_runner_path_args = {} |
| 62 if args.output_directory: |
| 63 test_runner_path_args['--output-directory'] = RelativizePathToScript( |
| 64 args.output_directory) |
| 65 if args.isolate_file_path: |
| 66 test_runner_path_args['--isolate-file-path'] = RelativizePathToScript( |
| 67 args.isolate_file_path) |
| 68 |
| 69 with open(args.script_output_path, 'w') as script: |
| 70 script.write(script_template.format( |
| 71 test_runner_path=str(test_runner_path), |
| 72 test_runner_args=str(test_runner_args), |
| 73 test_runner_path_args=str(test_runner_path_args))) |
| 74 |
| 75 os.chmod(args.script_output_path, 0750) |
| 76 |
| 77 if __name__ == '__main__': |
| 78 sys.exit(main()) |
OLD | NEW |