Roll src/third_party/WebKit a3b4a2e:7441784 (svn 202551:202552)
[chromium-blink-merge.git] / build / android / gyp / create_test_runner_script.py
blob22ef260125e298939bd7f7a859e135c4aa6148bb
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 os
22 import subprocess
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 sorted(test_runner_path_args.iteritems()):
37 test_runner_args.extend([arg, ResolvePath(path)])
39 test_runner_cmd = [test_runner_path] + test_runner_args + sys.argv[1:]
40 print ' '.join(test_runner_cmd)
41 return subprocess.call(test_runner_cmd)
43 if __name__ == '__main__':
44 sys.exit(main())
45 """
47 def main():
48 parser = argparse.ArgumentParser()
49 parser.add_argument('--script-output-path',
50 help='Output path for executable script.')
51 parser.add_argument('--depfile',
52 help='Path to the depfile. This must be specified as '
53 "the action's first output.")
54 # We need to intercept any test runner path arguments and make all
55 # of the paths relative to the output script directory.
56 group = parser.add_argument_group('Test runner path arguments.')
57 group.add_argument('--output-directory')
58 group.add_argument('--isolate-file-path')
59 args, test_runner_args = parser.parse_known_args()
61 def RelativizePathToScript(path):
62 """Returns the path relative to the output script directory."""
63 return os.path.relpath(path, os.path.dirname(args.script_output_path))
65 test_runner_path = os.path.join(
66 os.path.dirname(__file__), os.path.pardir, 'test_runner.py')
67 test_runner_path = RelativizePathToScript(test_runner_path)
69 test_runner_path_args = {}
70 if args.output_directory:
71 test_runner_path_args['--output-directory'] = RelativizePathToScript(
72 args.output_directory)
73 if args.isolate_file_path:
74 test_runner_path_args['--isolate-file-path'] = RelativizePathToScript(
75 args.isolate_file_path)
77 with open(args.script_output_path, 'w') as script:
78 script.write(SCRIPT_TEMPLATE.format(
79 test_runner_path=str(test_runner_path),
80 test_runner_args=str(test_runner_args),
81 test_runner_path_args=str(test_runner_path_args)))
83 os.chmod(args.script_output_path, 0750)
85 if args.depfile:
86 build_utils.WriteDepfile(
87 args.depfile,
88 build_utils.GetPythonDependencies())
90 if __name__ == '__main__':
91 sys.exit(main())