| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright 2014 The Chromium Authors. All rights reserved. | 2 # Copyright 2014 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 # This a simple script to make building/testing Mojo components easier. | 6 # This a simple script to make building/testing Mojo components easier. |
| 7 | 7 |
| 8 import argparse | 8 import argparse |
| 9 import os | 9 import os |
| 10 import platform | 10 import platform |
| 11 import re | 11 import re |
| 12 import subprocess | 12 import subprocess |
| 13 import sys | 13 import sys |
| 14 | 14 |
| 15 import mopy.paths | 15 import mopy.paths |
| 16 | 16 |
| 17 | 17 |
| 18 def call(args, command, shell=False): |
| 19 if args.dry_run: |
| 20 if isinstance(command, list): |
| 21 command = ' '.join(command) |
| 22 print command |
| 23 else: |
| 24 return subprocess.call(command, shell=shell) |
| 25 |
| 26 |
| 18 def get_out_dir(args): | 27 def get_out_dir(args): |
| 19 out_dir = "out" | 28 out_dir = "out" |
| 20 prefix = '' | 29 prefix = '' |
| 21 if args.android: | 30 if args.android: |
| 22 prefix = 'android_' | 31 prefix = 'android_' |
| 23 elif args.chromeos: | 32 elif args.chromeos: |
| 24 prefix = 'chromeos_' | 33 prefix = 'chromeos_' |
| 25 subdir = prefix + ('Debug' if args.debug else 'Release') | 34 subdir = prefix + ('Debug' if args.debug else 'Release') |
| 26 return os.path.join(out_dir, subdir) | 35 return os.path.join(out_dir, subdir) |
| 27 | 36 |
| 28 | 37 |
| 29 def sync(args): | 38 def sync(args): |
| 30 # pylint: disable=W0613 | 39 # pylint: disable=W0613 |
| 31 return subprocess.call(['gclient', 'sync']) | 40 return call(args, ['gclient', 'sync']) |
| 32 | 41 |
| 33 | 42 |
| 34 def gn(args): | 43 def gn(args): |
| 35 command = ['gn', 'gen'] | 44 command = ['gn', 'gen'] |
| 36 | 45 |
| 37 gn_args = [] | 46 gn_args = [] |
| 38 gn_args.append('is_debug=' + ('true' if args.debug else 'false')) | 47 gn_args.append('is_debug=' + ('true' if args.debug else 'false')) |
| 39 gn_args.append('is_asan=' + ('true' if args.asan else 'false')) | 48 gn_args.append('is_asan=' + ('true' if args.asan else 'false')) |
| 40 gn_args.append('is_clang=' + ('true' if args.clang else 'false')) | 49 gn_args.append('is_clang=' + ('true' if args.clang else 'false')) |
| 41 | 50 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 57 gn_args.append(r'''os=\"android\" cpu_arch=\"arm\"''') | 66 gn_args.append(r'''os=\"android\" cpu_arch=\"arm\"''') |
| 58 elif args.chromeos: | 67 elif args.chromeos: |
| 59 gn_args.append(r'''os=\"chromeos\" ui_base_build_ime=false | 68 gn_args.append(r'''os=\"chromeos\" ui_base_build_ime=false |
| 60 use_system_harfbuzz=false''') | 69 use_system_harfbuzz=false''') |
| 61 | 70 |
| 62 out_dir = get_out_dir(args) | 71 out_dir = get_out_dir(args) |
| 63 command.append(out_dir) | 72 command.append(out_dir) |
| 64 command.append('--args="%s"' % ' '.join(gn_args)) | 73 command.append('--args="%s"' % ' '.join(gn_args)) |
| 65 | 74 |
| 66 print 'Running %s ...' % ' '.join(command) | 75 print 'Running %s ...' % ' '.join(command) |
| 67 return subprocess.call(' '.join(command), shell=True) | 76 return call(args, ' '.join(command), shell=True) |
| 68 | 77 |
| 69 | 78 |
| 70 def get_gn_arg_value(out_dir, arg): | 79 def get_gn_arg_value(out_dir, arg): |
| 71 args_file_path = os.path.join(out_dir, "args.gn") | 80 args_file_path = os.path.join(out_dir, "args.gn") |
| 72 if os.path.isfile(args_file_path): | 81 if os.path.isfile(args_file_path): |
| 73 key_value_regex = re.compile(r'^%s = (.+)$' % arg) | 82 key_value_regex = re.compile(r'^%s = (.+)$' % arg) |
| 74 with open(args_file_path, "r") as args_file: | 83 with open(args_file_path, "r") as args_file: |
| 75 for line in args_file.readlines(): | 84 for line in args_file.readlines(): |
| 76 m = key_value_regex.search(line) | 85 m = key_value_regex.search(line) |
| 77 if m: | 86 if m: |
| 78 return m.group(1).strip('"') | 87 return m.group(1).strip('"') |
| 79 return '' | 88 return '' |
| 80 | 89 |
| 81 | 90 |
| 82 def build(args): | 91 def build(args): |
| 83 out_dir = get_out_dir(args) | 92 out_dir = get_out_dir(args) |
| 84 print 'Building in %s ...' % out_dir | 93 print 'Building in %s ...' % out_dir |
| 85 if get_gn_arg_value(out_dir, 'use_goma') == 'true': | 94 if get_gn_arg_value(out_dir, 'use_goma') == 'true': |
| 86 # Use the configured goma directory. | 95 # Use the configured goma directory. |
| 87 local_goma_dir = get_gn_arg_value(out_dir, 'goma_dir') | 96 local_goma_dir = get_gn_arg_value(out_dir, 'goma_dir') |
| 88 print 'Ensuring goma (in %s) started ...' % local_goma_dir | 97 print 'Ensuring goma (in %s) started ...' % local_goma_dir |
| 89 command = ['python', | 98 command = ['python', |
| 90 os.path.join(local_goma_dir, 'goma_ctl.py'), | 99 os.path.join(local_goma_dir, 'goma_ctl.py'), |
| 91 'ensure_start'] | 100 'ensure_start'] |
| 92 exit_code = subprocess.call(command) | 101 exit_code = call(args, command) |
| 93 if exit_code: | 102 if exit_code: |
| 94 return exit_code | 103 return exit_code |
| 95 | 104 |
| 96 return subprocess.call(['ninja', '-j', '1000', '-l', '100', '-C', out_dir, | 105 return call(args, ['ninja', '-j', '1000', '-l', '100', '-C', out_dir, |
| 97 'root']) | 106 'root']) |
| 98 else: | 107 else: |
| 99 return subprocess.call(['ninja', '-C', out_dir, 'root']) | 108 return call(args, ['ninja', '-C', out_dir, 'root']) |
| 100 | 109 |
| 101 | 110 |
| 102 def run_unittests(args): | 111 def run_unittests(args): |
| 103 out_dir = get_out_dir(args) | 112 out_dir = get_out_dir(args) |
| 104 print 'Running unit tests in %s ...' % out_dir | 113 print 'Running unit tests in %s ...' % out_dir |
| 105 command = ['python'] | 114 command = ['python'] |
| 106 if platform.system() == 'Linux': | 115 if platform.system() == 'Linux' and not args.android: |
| 107 command.append('./testing/xvfb.py') | 116 command.append('./testing/xvfb.py') |
| 108 command.append(out_dir) | 117 command.append(out_dir) |
| 109 | 118 |
| 110 command.append(os.path.join('mojo', 'tools', 'test_runner.py')) | 119 command.append(os.path.join('mojo', 'tools', 'test_runner.py')) |
| 111 command.append(os.path.join('mojo', 'tools', 'data', 'unittests')) | 120 if args.android: |
| 121 command.append('--android') |
| 122 command.append(os.path.join('mojo', 'tools', 'data', 'android_unittests')) |
| 123 else: |
| 124 command.append(os.path.join('mojo', 'tools', 'data', 'unittests')) |
| 112 command.append(out_dir) | 125 command.append(out_dir) |
| 113 command.append('mojob_test_successes') | 126 command.append('mojob_test_successes') |
| 114 return subprocess.call(command) | 127 return call(args, command) |
| 115 | 128 |
| 116 def run_apptests(args): | 129 def run_apptests(args): |
| 117 out_dir = get_out_dir(args) | 130 out_dir = get_out_dir(args) |
| 131 if args.android: |
| 132 return 0 |
| 133 |
| 118 print 'Running application tests in %s ...' % out_dir | 134 print 'Running application tests in %s ...' % out_dir |
| 119 command = ['python'] | 135 command = ['python'] |
| 120 if platform.system() == 'Linux': | 136 if platform.system() == 'Linux': |
| 121 command.append('./testing/xvfb.py') | 137 command.append('./testing/xvfb.py') |
| 122 command.append(out_dir) | 138 command.append(out_dir) |
| 123 | 139 |
| 124 command.append(os.path.join('mojo', 'tools', 'apptest_runner.py')) | 140 command.append(os.path.join('mojo', 'tools', 'apptest_runner.py')) |
| 125 command.append(os.path.join('mojo', 'tools', 'data', 'apptests')) | 141 command.append(os.path.join('mojo', 'tools', 'data', 'apptests')) |
| 126 command.append(out_dir) | 142 command.append(out_dir) |
| 127 return subprocess.call(command) | 143 return call(args, command) |
| 128 | 144 |
| 129 def run_skytests(args): | 145 def run_skytests(args): |
| 130 out_dir = get_out_dir(args) | 146 out_dir = get_out_dir(args) |
| 131 if platform.system() != 'Linux': | 147 if platform.system() != 'Linux' or args.android: |
| 132 return 0 | 148 return 0 |
| 133 | 149 |
| 134 command = [] | 150 command = [] |
| 135 command.append('./testing/xvfb.py') | 151 command.append('./testing/xvfb.py') |
| 136 command.append(out_dir) | 152 command.append(out_dir) |
| 137 command.append('sky/tools/test_sky') | 153 command.append('sky/tools/test_sky') |
| 138 command.append('-t') | 154 command.append('-t') |
| 139 command.append('Debug' if args.debug else 'Release') | 155 command.append('Debug' if args.debug else 'Release') |
| 140 command.append('--no-new-test-results') | 156 command.append('--no-new-test-results') |
| 141 command.append('--no-show-results') | 157 command.append('--no-show-results') |
| 142 command.append('--verbose') | 158 command.append('--verbose') |
| 143 | 159 |
| 144 if args.builder_name: | 160 if args.builder_name: |
| 145 command.append('--builder-name') | 161 command.append('--builder-name') |
| 146 command.append(args.builder_name) | 162 command.append(args.builder_name) |
| 147 | 163 |
| 148 if args.build_number: | 164 if args.build_number: |
| 149 command.append('--build-number') | 165 command.append('--build-number') |
| 150 command.append(args.build_number) | 166 command.append(args.build_number) |
| 151 | 167 |
| 152 if args.master_name: | 168 if args.master_name: |
| 153 command.append('--master-name') | 169 command.append('--master-name') |
| 154 command.append(args.master_name) | 170 command.append(args.master_name) |
| 155 | 171 |
| 156 if args.test_results_server: | 172 if args.test_results_server: |
| 157 command.append('--test-results-server') | 173 command.append('--test-results-server') |
| 158 command.append(args.test_results_server) | 174 command.append(args.test_results_server) |
| 159 | 175 |
| 160 return subprocess.call(command) | 176 return call(args, command) |
| 161 | 177 |
| 162 | 178 |
| 163 def run_pytests(args): | 179 def run_pytests(args): |
| 164 out_dir = get_out_dir(args) | 180 out_dir = get_out_dir(args) |
| 165 print 'Running python tests in %s ...' % out_dir | 181 print 'Running python tests in %s ...' % out_dir |
| 166 command = ['python'] | 182 command = ['python'] |
| 167 command.append(os.path.join('mojo', 'tools', 'run_mojo_python_tests.py')) | 183 command.append(os.path.join('mojo', 'tools', 'run_mojo_python_tests.py')) |
| 168 exit_code = subprocess.call(command) | 184 exit_code = call(args, command) |
| 169 if exit_code: | 185 if exit_code: |
| 170 return exit_code | 186 return exit_code |
| 171 | 187 |
| 172 if platform.system() != 'Linux': | 188 if platform.system() != 'Linux' or args.android: |
| 173 print ('Python bindings tests are only supported on Linux.') | 189 print ('Python bindings tests are only supported on Linux.') |
| 174 return | 190 return |
| 175 | 191 |
| 176 command = ['python'] | 192 command = ['python'] |
| 177 command.append(os.path.join('mojo', 'tools', | 193 command.append(os.path.join('mojo', 'tools', |
| 178 'run_mojo_python_bindings_tests.py')) | 194 'run_mojo_python_bindings_tests.py')) |
| 179 command.append('--build-dir=' + out_dir) | 195 command.append('--build-dir=' + out_dir) |
| 180 return subprocess.call(command) | 196 return call(args, command) |
| 181 | 197 |
| 182 | 198 |
| 183 def test(args): | 199 def test(args): |
| 184 test_suites = [run_unittests, run_apptests, run_pytests, run_skytests] | 200 test_suites = [run_unittests, run_apptests, run_pytests, run_skytests] |
| 185 final_exit_code = 0 | 201 final_exit_code = 0 |
| 186 | 202 |
| 187 for test_suite in test_suites: | 203 for test_suite in test_suites: |
| 188 exit_code = test_suite(args) | 204 exit_code = test_suite(args) |
| 189 # TODO(ojan): Find a better way to do this. We want to run all the tests | 205 # TODO(ojan): Find a better way to do this. We want to run all the tests |
| 190 # so we get coverage even if an early test suite fails, but we only have | 206 # so we get coverage even if an early test suite fails, but we only have |
| 191 # one exit code. | 207 # one exit code. |
| 192 if not final_exit_code: | 208 if not final_exit_code: |
| 193 final_exit_code = exit_code | 209 final_exit_code = exit_code |
| 194 | 210 |
| 195 return final_exit_code | 211 return final_exit_code |
| 196 | 212 |
| 197 def perftest(args): | 213 def perftest(args): |
| 198 out_dir = get_out_dir(args) | 214 out_dir = get_out_dir(args) |
| 199 print 'Running perf tests in %s ...' % out_dir | 215 print 'Running perf tests in %s ...' % out_dir |
| 200 command = [] | 216 command = [] |
| 201 command.append(os.path.join(out_dir, 'mojo_public_system_perftests')) | 217 command.append(os.path.join(out_dir, 'mojo_public_system_perftests')) |
| 202 return subprocess.call(command) | 218 return call(args, command) |
| 203 | 219 |
| 204 | 220 |
| 205 def pytest(args): | 221 def pytest(args): |
| 206 return run_pytests(args) | 222 return run_pytests(args) |
| 207 | 223 |
| 208 | 224 |
| 209 def darttest(args): | 225 def darttest(args): |
| 210 out_dir = get_out_dir(args) | 226 out_dir = get_out_dir(args) |
| 211 print 'Running Dart tests in %s ...' % out_dir | 227 print 'Running Dart tests in %s ...' % out_dir |
| 212 command = [] | 228 command = [] |
| 213 command.append('dart') | 229 command.append('dart') |
| 214 command.append('--checked') | 230 command.append('--checked') |
| 215 command.append('--enable-async') | 231 command.append('--enable-async') |
| 216 command.append(os.path.join('mojo', 'tools', 'dart_test_runner.dart')) | 232 command.append(os.path.join('mojo', 'tools', 'dart_test_runner.dart')) |
| 217 command.append(os.path.join(out_dir, 'gen')) | 233 command.append(os.path.join(out_dir, 'gen')) |
| 218 return subprocess.call(command) | 234 return call(args, command) |
| 219 | 235 |
| 220 | 236 |
| 221 def main(): | 237 def main(): |
| 222 os.chdir(mopy.paths.Paths().src_root) | 238 os.chdir(mopy.paths.Paths().src_root) |
| 223 | 239 |
| 224 parser = argparse.ArgumentParser(description='A script to make building' | 240 parser = argparse.ArgumentParser(description='A script to make building' |
| 225 '/testing Mojo components easier.') | 241 '/testing Mojo components easier.') |
| 226 | 242 |
| 227 parent_parser = argparse.ArgumentParser(add_help=False) | 243 parent_parser = argparse.ArgumentParser(add_help=False) |
| 228 debug_group = parent_parser.add_mutually_exclusive_group() | 244 debug_group = parent_parser.add_mutually_exclusive_group() |
| 229 debug_group.add_argument('--debug', help='Debug build (default)', | 245 debug_group.add_argument('--debug', help='Debug build (default)', |
| 230 default=True, action='store_true') | 246 default=True, action='store_true') |
| 231 debug_group.add_argument('--release', help='Release build', default=False, | 247 debug_group.add_argument('--release', help='Release build', default=False, |
| 232 dest='debug', action='store_false') | 248 dest='debug', action='store_false') |
| 233 | 249 |
| 234 os_group = parent_parser.add_mutually_exclusive_group() | 250 os_group = parent_parser.add_mutually_exclusive_group() |
| 235 os_group.add_argument('--android', help='Build for Android', | 251 os_group.add_argument('--android', help='Build for Android', |
| 236 action='store_true') | 252 action='store_true') |
| 237 os_group.add_argument('--chromeos', help='Build for ChromeOS', | 253 os_group.add_argument('--chromeos', help='Build for ChromeOS', |
| 238 action='store_true') | 254 action='store_true') |
| 239 | 255 |
| 256 parent_parser.add_argument('--dry-run', help='Print commands', |
| 257 action='store_true') |
| 258 |
| 240 subparsers = parser.add_subparsers() | 259 subparsers = parser.add_subparsers() |
| 241 | 260 |
| 242 sync_parser = subparsers.add_parser('sync', parents=[parent_parser], | 261 sync_parser = subparsers.add_parser('sync', parents=[parent_parser], |
| 243 help='Sync using gclient (does not run gn).') | 262 help='Sync using gclient (does not run gn).') |
| 244 sync_parser.set_defaults(func=sync) | 263 sync_parser.set_defaults(func=sync) |
| 245 | 264 |
| 246 gn_parser = subparsers.add_parser('gn', parents=[parent_parser], | 265 gn_parser = subparsers.add_parser('gn', parents=[parent_parser], |
| 247 help='Run gn for mojo (does not sync).') | 266 help='Run gn for mojo (does not sync).') |
| 248 gn_parser.set_defaults(func=gn) | 267 gn_parser.set_defaults(func=gn) |
| 249 gn_parser.add_argument('--asan', help='Uses Address Sanitizer', | 268 gn_parser.add_argument('--asan', help='Uses Address Sanitizer', |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 302 args.clang = False | 321 args.clang = False |
| 303 | 322 |
| 304 if platform.system() == 'Windows': | 323 if platform.system() == 'Windows': |
| 305 args.clang = False | 324 args.clang = False |
| 306 | 325 |
| 307 return args.func(args) | 326 return args.func(args) |
| 308 | 327 |
| 309 | 328 |
| 310 if __name__ == '__main__': | 329 if __name__ == '__main__': |
| 311 sys.exit(main()) | 330 sys.exit(main()) |
| OLD | NEW |