Chromium Code Reviews| 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 os | |
| 20 import sys | |
| 21 | |
| 22 script_directory = os.path.dirname(__file__) | |
| 23 | |
| 24 def ResolvePath(path): | |
| 25 \"\"\"Returns an absolute filepath given a path relative to this script. | |
| 26 \"\"\" | |
| 27 return os.path.abspath(os.path.join(script_directory, path)) | |
| 28 | |
| 29 test_runner_path = ResolvePath('{test_runner_path}') | |
|
jbudorick
2015/05/01 15:59:16
All of this should be in a main().
| |
| 30 test_runner_args = {test_runner_args} | |
| 31 test_runner_path_args = {test_runner_path_args} | |
| 32 for arg, path in test_runner_path_args.iteritems(): | |
| 33 test_runner_args.extend([arg, ResolvePath(path)]) | |
| 34 | |
| 35 test_runner_cmd = [test_runner_path] + test_runner_args + sys.argv[1:] | |
| 36 os.system(' '.join(test_runner_cmd)) | |
| 37 """ | |
| 38 | |
| 39 def main(): | |
| 40 parser = argparse.ArgumentParser() | |
| 41 parser.add_argument('--script-output-path', | |
| 42 help='Output path for executable script.') | |
| 43 # We need to intercept any test runner path arguments and make all | |
| 44 # of the paths relative to the output script directory. | |
| 45 group = parser.add_argument_group('Test runner path arguments.') | |
| 46 group.add_argument('--output-directory') | |
| 47 group.add_argument('--isolate-file-path') | |
| 48 args, test_runner_args = parser.parse_known_args() | |
| 49 | |
| 50 def RelativizePathToScript(path): | |
| 51 """Returns the path relative to the output script directory.""" | |
| 52 return os.path.relpath(path, os.path.dirname(args.script_output_path)) | |
| 53 | |
| 54 test_runner_path = os.path.join( | |
| 55 os.path.dirname(__file__), os.path.pardir, 'test_runner.py') | |
| 56 test_runner_path = RelativizePathToScript(test_runner_path) | |
| 57 | |
| 58 test_runner_path_args = {} | |
| 59 if args.output_directory: | |
| 60 test_runner_path_args['--output-directory'] = RelativizePathToScript( | |
| 61 args.output_directory) | |
| 62 if args.isolate_file_path: | |
| 63 test_runner_path_args['--isolate-file-path'] = RelativizePathToScript( | |
| 64 args.isolate_file_path) | |
| 65 | |
| 66 with open(args.script_output_path, 'w') as script: | |
| 67 script.write(script_template.format( | |
| 68 test_runner_path=str(test_runner_path), | |
| 69 test_runner_args=str(test_runner_args), | |
| 70 test_runner_path_args=str(test_runner_path_args))) | |
| 71 | |
| 72 os.chmod(args.script_output_path, 0750) | |
| 73 | |
| 74 if __name__ == '__main__': | |
| 75 sys.exit(main()) | |
| OLD | NEW |