Move core/forwarders to internal.
[chromium-blink-merge.git] / build / android / gyp / create_test_runner_script.py
blobe72f364aad0cf49af953830187f5cbe8ef80acb3
1 #!/usr/bin/env python
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.
7 """Creates a script to run an android test using build/android/test_runner.py.
8 """
10 import argparse
11 import os
12 import sys
14 from util import build_utils
16 SCRIPT_TEMPLATE = """\
17 #!/usr/bin/env python
19 # This file was generated by build/android/gyp/create_test_runner_script.py
21 import logging
22 import os
23 import sys
25 def main():
26 script_directory = os.path.dirname(__file__)
28 def ResolvePath(path):
29 \"\"\"Returns an absolute filepath given a path relative to this script.
30 \"\"\"
31 return os.path.abspath(os.path.join(script_directory, path))
33 test_runner_path = ResolvePath('{test_runner_path}')
34 test_runner_args = {test_runner_args}
35 test_runner_path_args = {test_runner_path_args}
36 for arg, path in test_runner_path_args.iteritems():
37 test_runner_args.extend([arg, ResolvePath(path)])
39 test_runner_cmd = ' '.join(
40 [test_runner_path] + test_runner_args + sys.argv[1:])
41 logging.critical(test_runner_cmd)
42 os.system(test_runner_cmd)
44 if __name__ == '__main__':
45 sys.exit(main())
46 """
48 def main():
49 parser = argparse.ArgumentParser()
50 parser.add_argument('--script-output-path',
51 help='Output path for executable script.')
52 parser.add_argument('--depfile',
53 help='Path to the depfile. This must be specified as '
54 "the action's first output.")
55 # We need to intercept any test runner path arguments and make all
56 # of the paths relative to the output script directory.
57 group = parser.add_argument_group('Test runner path arguments.')
58 group.add_argument('--output-directory')
59 group.add_argument('--isolate-file-path')
60 args, test_runner_args = parser.parse_known_args()
62 def RelativizePathToScript(path):
63 """Returns the path relative to the output script directory."""
64 return os.path.relpath(path, os.path.dirname(args.script_output_path))
66 test_runner_path = os.path.join(
67 os.path.dirname(__file__), os.path.pardir, 'test_runner.py')
68 test_runner_path = RelativizePathToScript(test_runner_path)
70 test_runner_path_args = {}
71 if args.output_directory:
72 test_runner_path_args['--output-directory'] = RelativizePathToScript(
73 args.output_directory)
74 if args.isolate_file_path:
75 test_runner_path_args['--isolate-file-path'] = RelativizePathToScript(
76 args.isolate_file_path)
78 with open(args.script_output_path, 'w') as script:
79 script.write(SCRIPT_TEMPLATE.format(
80 test_runner_path=str(test_runner_path),
81 test_runner_args=str(test_runner_args),
82 test_runner_path_args=str(test_runner_path_args)))
84 os.chmod(args.script_output_path, 0750)
86 if args.depfile:
87 build_utils.WriteDepfile(
88 args.depfile,
89 build_utils.GetPythonDependencies())
91 if __name__ == '__main__':
92 sys.exit(main())