Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(27)

Side by Side Diff: build/android/gyp/create_test_runner_script.py

Issue 1120883002: [Android] Generate scripts at build time to run android tests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 from util import build_utils
15
16 script_template = """\
jbudorick 2015/05/15 13:19:56 nit: should be SCRIPT_TEMPLATE (or _SCRIPT_TEMPLAT
mikecase (-- gone --) 2015/05/18 17:39:03 Done.
17 #!/usr/bin/env python
18 #
19 # This file was generated by build/android/gyp/create_test_runner_script.py
20
21 import logging
22 import os
23 import sys
24
25 script_directory = os.path.dirname(__file__)
26
27 def ResolvePath(path):
28 \"\"\"Returns an absolute filepath given a path relative to this script.
29 \"\"\"
30 return os.path.abspath(os.path.join(script_directory, path))
31
32 test_runner_path = ResolvePath('{test_runner_path}')
jbudorick 2015/05/15 13:19:56 put an if __name__ == '__main__': guard in here, p
mikecase (-- gone --) 2015/05/18 17:39:03 Done.
33 test_runner_args = {test_runner_args}
34 test_runner_path_args = {test_runner_path_args}
35 for arg, path in test_runner_path_args.iteritems():
36 test_runner_args.extend([arg, ResolvePath(path)])
37
38 test_runner_cmd = ' '.join(
39 [test_runner_path] + test_runner_args + sys.argv[1:])
40 logging.critical(test_runner_cmd)
41 os.system(test_runner_cmd)
42 """
43
44 def main():
45 parser = argparse.ArgumentParser()
46 parser.add_argument('--script-output-path',
47 help='Output path for executable script.')
48 parser.add_argument('--depfile',
49 help='Path to the depfile. This must be specified as '
50 'the action\'s first output.')
51 # We need to intercept any test runner path arguments and make all
52 # of the paths relative to the output script directory.
53 group = parser.add_argument_group('Test runner path arguments.')
54 group.add_argument('--output-directory')
55 group.add_argument('--isolate-file-path')
56 args, test_runner_args = parser.parse_known_args()
57
58 def RelativizePathToScript(path):
59 """Returns the path relative to the output script directory."""
60 return os.path.relpath(path, os.path.dirname(args.script_output_path))
61
62 test_runner_path = os.path.join(
63 os.path.dirname(__file__), os.path.pardir, 'test_runner.py')
64 test_runner_path = RelativizePathToScript(test_runner_path)
65
66 test_runner_path_args = {}
67 if args.output_directory:
68 test_runner_path_args['--output-directory'] = RelativizePathToScript(
69 args.output_directory)
70 if args.isolate_file_path:
71 test_runner_path_args['--isolate-file-path'] = RelativizePathToScript(
72 args.isolate_file_path)
73
74 with open(args.script_output_path, 'w') as script:
75 script.write(script_template.format(
76 test_runner_path=str(test_runner_path),
77 test_runner_args=str(test_runner_args),
78 test_runner_path_args=str(test_runner_path_args)))
79
80 os.chmod(args.script_output_path, 0750)
81
82 if args.depfile:
83 build_utils.WriteDepfile(
84 args.depfile,
85 build_utils.GetPythonDependencies())
86
87 if __name__ == '__main__':
88 sys.exit(main())
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698