OLD | NEW |
---|---|
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # | 2 # |
3 # Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 4 # Use of this source code is governed by a BSD-style license that can be |
5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
6 | 6 |
7 """Creates a script to run an android test using build/android/test_runner.py. | 7 """Creates a script to run an android test using build/android/test_runner.py. |
8 """ | 8 """ |
9 | 9 |
10 import argparse | 10 import argparse |
11 import os | 11 import os |
12 import re | |
12 import sys | 13 import sys |
13 | 14 |
14 from util import build_utils | 15 from util import build_utils |
15 | 16 |
16 SCRIPT_TEMPLATE = """\ | 17 SCRIPT_TEMPLATE = """\ |
17 #!/usr/bin/env python | 18 #!/usr/bin/env python |
18 # | 19 # |
19 # This file was generated by build/android/gyp/create_test_runner_script.py | 20 # This file was generated by build/android/gyp/create_test_runner_script.py |
20 | 21 |
21 import os | 22 import os |
(...skipping 13 matching lines...) Expand all Loading... | |
35 for arg, path in test_runner_path_args: | 36 for arg, path in test_runner_path_args: |
36 test_runner_args.extend([arg, ResolvePath(path)]) | 37 test_runner_args.extend([arg, ResolvePath(path)]) |
37 | 38 |
38 os.execv(test_runner_path, | 39 os.execv(test_runner_path, |
39 [test_runner_path] + test_runner_args + sys.argv[1:]) | 40 [test_runner_path] + test_runner_args + sys.argv[1:]) |
40 | 41 |
41 if __name__ == '__main__': | 42 if __name__ == '__main__': |
42 sys.exit(main()) | 43 sys.exit(main()) |
43 """ | 44 """ |
44 | 45 |
46 | |
47 def _GetTargetFromIncrementalApk(incremental_apk): | |
agrieve
2016/12/15 16:22:30
We have a convention that makes the apk_name refle
estevenson
2016/12/15 18:19:06
Done.
| |
48 apk = re.match(r'^.*/(.*)_incremental.apk$', incremental_apk).group(1) | |
49 apk_target = '_'.join(re.findall(r'([A-Z][^A-Z]*)', apk)) | |
50 return apk_target.lower() + '_apk' | |
51 | |
52 | |
53 def _GenerateAdditionalApksErrorString(incremental_apks): | |
54 err_string = ('Apks that are listed as additional_apks for ' | |
55 'another target cannot be incremental. Please add never_incremental to the ' | |
agrieve
2016/12/15 16:22:30
nit: indent 4 spaces
estevenson
2016/12/15 18:19:06
Done.
| |
56 'following apks: %s') | |
57 return err_string % ', '.join( | |
58 _GetTargetFromIncrementalApk(a) for a in incremental_apks) | |
59 | |
60 | |
45 def main(args): | 61 def main(args): |
46 parser = argparse.ArgumentParser() | 62 parser = argparse.ArgumentParser() |
47 parser.add_argument('--script-output-path', | 63 parser.add_argument('--script-output-path', |
48 help='Output path for executable script.') | 64 help='Output path for executable script.') |
49 parser.add_argument('--depfile', | 65 parser.add_argument('--depfile', |
50 help='Path to the depfile. This must be specified as ' | 66 help='Path to the depfile. This must be specified as ' |
51 "the action's first output.") | 67 "the action's first output.") |
52 parser.add_argument('--test-runner-path', | 68 parser.add_argument('--test-runner-path', |
53 help='Path to test_runner.py (optional).') | 69 help='Path to test_runner.py (optional).') |
54 # We need to intercept any test runner path arguments and make all | 70 # We need to intercept any test runner path arguments and make all |
55 # of the paths relative to the output script directory. | 71 # of the paths relative to the output script directory. |
56 group = parser.add_argument_group('Test runner path arguments.') | 72 group = parser.add_argument_group('Test runner path arguments.') |
57 group.add_argument('--additional-apk', action='append', | 73 group.add_argument('--additional-apk', action='append', |
58 dest='additional_apks', default=[]) | 74 dest='additional_apks', default=[]) |
59 group.add_argument('--additional-apk-list') | 75 group.add_argument('--additional-apk-list') |
76 group.add_argument('--additional-apk-incremental', action='append', | |
77 dest='additional_apks_incremental', default=[]) | |
60 group.add_argument('--apk-under-test') | 78 group.add_argument('--apk-under-test') |
61 group.add_argument('--apk-under-test-incremental-install-script') | 79 group.add_argument('--apk-under-test-incremental-install-script') |
62 group.add_argument('--executable-dist-dir') | 80 group.add_argument('--executable-dist-dir') |
63 group.add_argument('--isolate-file-path') | 81 group.add_argument('--isolate-file-path') |
64 group.add_argument('--output-directory') | 82 group.add_argument('--output-directory') |
65 group.add_argument('--runtime-deps-path') | 83 group.add_argument('--runtime-deps-path') |
66 group.add_argument('--test-apk') | 84 group.add_argument('--test-apk') |
67 group.add_argument('--test-jar') | 85 group.add_argument('--test-jar') |
68 group.add_argument('--test-apk-incremental-install-script') | 86 group.add_argument('--test-apk-incremental-install-script') |
69 group.add_argument('--coverage-dir') | 87 group.add_argument('--coverage-dir') |
70 args, test_runner_args = parser.parse_known_args( | 88 args, test_runner_args = parser.parse_known_args( |
71 build_utils.ExpandFileArgs(args)) | 89 build_utils.ExpandFileArgs(args)) |
72 | 90 |
73 def RelativizePathToScript(path): | 91 def RelativizePathToScript(path): |
74 """Returns the path relative to the output script directory.""" | 92 """Returns the path relative to the output script directory.""" |
75 return os.path.relpath(path, os.path.dirname(args.script_output_path)) | 93 return os.path.relpath(path, os.path.dirname(args.script_output_path)) |
76 | 94 |
77 test_runner_path = args.test_runner_path or os.path.join( | 95 test_runner_path = args.test_runner_path or os.path.join( |
78 os.path.dirname(__file__), os.path.pardir, 'test_runner.py') | 96 os.path.dirname(__file__), os.path.pardir, 'test_runner.py') |
79 test_runner_path = RelativizePathToScript(test_runner_path) | 97 test_runner_path = RelativizePathToScript(test_runner_path) |
80 | 98 |
81 test_runner_path_args = [] | 99 test_runner_path_args = [] |
82 if args.additional_apk_list: | 100 if args.additional_apk_list: |
83 args.additional_apks.extend( | 101 args.additional_apks.extend( |
84 build_utils.ParseGnList(args.additional_apk_list)) | 102 build_utils.ParseGnList(args.additional_apk_list)) |
85 if args.additional_apks: | 103 if args.additional_apks: |
86 test_runner_path_args.extend( | 104 test_runner_path_args.extend( |
87 ('--additional-apk', RelativizePathToScript(a)) | 105 ('--additional-apk', RelativizePathToScript(a)) |
88 for a in args.additional_apks) | 106 for a in args.additional_apks) |
107 if args.additional_apks_incremental: | |
108 bad_additional_apks = [a for a in args.additional_apks_incremental | |
109 if a != 'None'] | |
110 if bad_additional_apks: | |
111 raise Exception(_GenerateAdditionalApksErrorString(bad_additional_apks)) | |
89 if args.apk_under_test: | 112 if args.apk_under_test: |
90 test_runner_path_args.append( | 113 test_runner_path_args.append( |
91 ('--apk-under-test', RelativizePathToScript(args.apk_under_test))) | 114 ('--apk-under-test', RelativizePathToScript(args.apk_under_test))) |
92 if args.apk_under_test_incremental_install_script: | 115 if args.apk_under_test_incremental_install_script: |
93 test_runner_path_args.append( | 116 test_runner_path_args.append( |
94 ('--apk-under-test-incremental-install-script', | 117 ('--apk-under-test-incremental-install-script', |
95 RelativizePathToScript( | 118 RelativizePathToScript( |
96 args.apk_under_test_incremental_install_script))) | 119 args.apk_under_test_incremental_install_script))) |
97 if args.executable_dist_dir: | 120 if args.executable_dist_dir: |
98 test_runner_path_args.append( | 121 test_runner_path_args.append( |
(...skipping 28 matching lines...) Expand all Loading... | |
127 test_runner_args=str(test_runner_args), | 150 test_runner_args=str(test_runner_args), |
128 test_runner_path_args=str(test_runner_path_args))) | 151 test_runner_path_args=str(test_runner_path_args))) |
129 | 152 |
130 os.chmod(args.script_output_path, 0750) | 153 os.chmod(args.script_output_path, 0750) |
131 | 154 |
132 if args.depfile: | 155 if args.depfile: |
133 build_utils.WriteDepfile(args.depfile, args.script_output_path) | 156 build_utils.WriteDepfile(args.depfile, args.script_output_path) |
134 | 157 |
135 if __name__ == '__main__': | 158 if __name__ == '__main__': |
136 sys.exit(main(sys.argv[1:])) | 159 sys.exit(main(sys.argv[1:])) |
OLD | NEW |