| OLD | NEW |
| 1 #!/usr/bin/python | 1 #!/usr/bin/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 """ | 6 """ |
| 7 cr_cronet.py - cr - like helper tool for cronet developers | 7 cr_cronet.py - cr - like helper tool for cronet developers |
| 8 """ | 8 """ |
| 9 | 9 |
| 10 import argparse | 10 import argparse |
| 11 import os | 11 import os |
| 12 import sys | 12 import sys |
| 13 | 13 |
| 14 | |
| 15 def run(command, extra_options=''): | 14 def run(command, extra_options=''): |
| 16 command = command + ' ' + extra_options | 15 command = command + ' ' + extra_options |
| 17 print command | 16 print command |
| 18 return os.system(command) | 17 return os.system(command) |
| 19 | 18 |
| 20 | 19 |
| 21 def build(out_dir, extra_options=''): | 20 def build(out_dir, test_target, extra_options=''): |
| 22 return run('ninja -C ' + out_dir + ' cronet_test_instrumentation_apk', | 21 return run('ninja -C ' + out_dir + ' ' + test_target, |
| 23 extra_options) | 22 extra_options) |
| 24 | 23 |
| 25 | 24 |
| 26 def install(release_arg): | 25 def install(release_arg): |
| 27 return run('build/android/adb_install_apk.py ' + release_arg + \ | 26 return run('build/android/adb_install_apk.py ' + release_arg + \ |
| 28 ' --apk=CronetTest.apk') or \ | 27 ' --apk=CronetTest.apk') or \ |
| 29 run('build/android/adb_install_apk.py ' + release_arg + \ | 28 run('build/android/adb_install_apk.py ' + release_arg + \ |
| 30 ' --apk=ChromiumNetTestSupport.apk') | 29 ' --apk=ChromiumNetTestSupport.apk') |
| 31 | 30 |
| 32 | 31 |
| 33 def test(release_arg, extra_options): | 32 def test(release_arg, extra_options): |
| 34 return run('build/android/test_runner.py instrumentation '+ \ | 33 return run('build/android/test_runner.py instrumentation '+ \ |
| 35 release_arg + ' --test-apk=CronetTestInstrumentation' + \ | 34 release_arg + ' --test-apk=CronetTestInstrumentation' + \ |
| 36 ' --fast-local-dev', | 35 ' --fast-local-dev', |
| 37 extra_options) | 36 extra_options) |
| 38 | 37 |
| 38 def test_ios(out_dir, extra_options): |
| 39 return run(out_dir + '/iossim ' + out_dir + '/cronet_test.app', extra_options) |
| 39 | 40 |
| 40 def debug(extra_options): | 41 def debug(extra_options): |
| 41 return run('build/android/adb_gdb --start ' + \ | 42 return run('build/android/adb_gdb --start ' + \ |
| 42 '--activity=.CronetTestActivity ' + \ | 43 '--activity=.CronetTestActivity ' + \ |
| 43 '--program-name=CronetTest ' + \ | 44 '--program-name=CronetTest ' + \ |
| 44 '--package-name=org.chromium.net', | 45 '--package-name=org.chromium.net', |
| 45 extra_options) | 46 extra_options) |
| 46 | 47 |
| 47 | 48 |
| 48 def stack(out_dir): | 49 def stack(out_dir): |
| 49 return run('adb logcat -d | third_party/android_tools/ndk/ndk-stack ' + \ | 50 return run('adb logcat -d | third_party/android_tools/ndk/ndk-stack ' + \ |
| 50 '-sym ' + out_dir + '/lib') | 51 '-sym ' + out_dir + '/lib') |
| 51 | 52 |
| 52 | 53 |
| 53 def main(): | 54 def main(): |
| 54 parser = argparse.ArgumentParser() | 55 parser = argparse.ArgumentParser() |
| 55 parser.add_argument('command', | 56 parser.add_argument('command', |
| 56 choices=['gyp', | 57 choices=['gyp', |
| 57 'gn', | 58 'gn', |
| 58 'sync', | 59 'sync', |
| 59 'build', | 60 'build', |
| 60 'install', | 61 'install', |
| 61 'proguard', | 62 'proguard', |
| 62 'test', | 63 'test', |
| 63 'build-test', | 64 'build-test', |
| 64 'stack', | 65 'stack', |
| 65 'debug', | 66 'debug', |
| 66 'build-debug']) | 67 'build-debug']) |
| 68 parser.add_argument('-i', '--iphoneos', action='store_true', |
| 69 help='build for physical iphone') |
| 67 parser.add_argument('-r', '--release', action='store_true', | 70 parser.add_argument('-r', '--release', action='store_true', |
| 68 help='use release configuration') | 71 help='use release configuration') |
| 69 | 72 |
| 70 options, extra_options_list = parser.parse_known_args() | 73 options, extra_options_list = parser.parse_known_args() |
| 71 print options | 74 print options |
| 72 print extra_options_list | 75 print extra_options_list |
| 73 gyp_defines = 'GYP_DEFINES="OS=android enable_websockets=0 '+ \ | 76 |
| 77 is_os = (sys.platform == 'darwin') |
| 78 if is_os: |
| 79 target_os = 'ios' |
| 80 test_target = 'cronet_test' |
| 81 out_dir_suffix = '-iphonesimulator' |
| 82 if options.iphoneos: |
| 83 out_dir_suffix = '-iphoneos' |
| 84 else: |
| 85 target_os = 'android' |
| 86 test_target = 'cronet_test_instrumentation_apk' |
| 87 out_dir_suffix = '' |
| 88 |
| 89 gyp_defines = 'GYP_DEFINES="OS=' + target_os + ' enable_websockets=0 '+ \ |
| 74 'disable_file_support=1 disable_ftp_support=1 '+ \ | 90 'disable_file_support=1 disable_ftp_support=1 '+ \ |
| 75 'enable_errorprone=1 use_platform_icu_alternatives=1 ' + \ | 91 'enable_errorprone=1 use_platform_icu_alternatives=1 ' + \ |
| 76 'disable_brotli_filter=1"' | 92 'disable_brotli_filter=1 use_openssl=1"' |
| 77 gn_args = 'target_os="android" enable_websockets=false '+ \ | 93 gn_args = 'target_os="' + target_os + '" enable_websockets=false '+ \ |
| 78 'disable_file_support=true disable_ftp_support=true '+ \ | 94 'disable_file_support=true disable_ftp_support=true '+ \ |
| 79 'use_errorprone_java_compiler=true use_platform_icu_alternatives=true '+ \ | 95 'use_errorprone_java_compiler=true use_platform_icu_alternatives=true '+ \ |
| 80 'disable_brotli_filter=true' | 96 'disable_brotli_filter=true' |
| 81 out_dir = 'out/Debug' | 97 |
| 98 out_dir = 'out/Debug' + out_dir_suffix |
| 82 release_arg = '' | 99 release_arg = '' |
| 83 extra_options = ' '.join(extra_options_list) | 100 extra_options = ' '.join(extra_options_list) |
| 84 if options.release: | 101 if options.release: |
| 85 out_dir = 'out/Release' | 102 out_dir = 'out/Release' + out_dir_suffix |
| 86 release_arg = ' --release' | 103 release_arg = ' --release' |
| 87 gn_args += ' is_debug=false ' | 104 gn_args += ' is_debug=false ' |
| 88 | 105 |
| 89 if (options.command=='gyp'): | 106 if (options.command=='gyp'): |
| 90 return run (gyp_defines + ' gclient runhooks') | 107 return run (gyp_defines + ' gclient runhooks') |
| 91 if (options.command=='gn'): | 108 if (options.command=='gn'): |
| 92 return run ('gn gen ' + out_dir + ' --args=\'' + gn_args + '\'') | 109 return run ('gn gen ' + out_dir + ' --args=\'' + gn_args + '\'') |
| 93 if (options.command=='sync'): | 110 if (options.command=='sync'): |
| 94 return run ('git pull --rebase && ' + gyp_defines + ' gclient sync') | 111 return run ('git pull --rebase && ' + gyp_defines + ' gclient sync') |
| 95 if (options.command=='build'): | 112 if (options.command=='build'): |
| 96 return build(out_dir, extra_options) | 113 return build(out_dir, test_target, extra_options) |
| 97 if (options.command=='install'): | 114 if (not is_os): |
| 98 return install(release_arg) | 115 if (options.command=='install'): |
| 99 if (options.command=='proguard'): | 116 return install(release_arg) |
| 100 return run ('ninja -C ' + out_dir + ' cronet_sample_proguard_apk') | 117 if (options.command=='proguard'): |
| 101 if (options.command=='test'): | 118 return run ('ninja -C ' + out_dir + ' cronet_sample_proguard_apk') |
| 102 return install(release_arg) or test(release_arg, extra_options) | 119 if (options.command=='test'): |
| 103 if (options.command=='build-test'): | 120 return install(release_arg) or test(release_arg, extra_options) |
| 104 return build(out_dir) or install(release_arg) or \ | 121 if (options.command=='build-test'): |
| 105 test(release_arg, extra_options) | 122 return build(out_dir, test_target) or install(release_arg) or \ |
| 106 if (options.command=='stack'): | 123 test(release_arg, extra_options) |
| 107 return stack(out_dir) | 124 if (options.command=='stack'): |
| 108 if (options.command=='debug'): | 125 return stack(out_dir) |
| 109 return install(release_arg) or debug(extra_options) | 126 if (options.command=='debug'): |
| 110 if (options.command=='build-debug'): | 127 return install(release_arg) or debug(extra_options) |
| 111 return build(out_dir) or install(release_arg) or debug(extra_options) | 128 if (options.command=='build-debug'): |
| 129 return build(out_dir) or install(release_arg) or debug(extra_options) |
| 130 else: |
| 131 if (options.command=='test'): |
| 132 return test_ios(out_dir, extra_options) |
| 133 if (options.command=='build-test'): |
| 134 return build(out_dir, test_target) or test_ios(out_dir, extra_options) |
| 112 | 135 |
| 113 parser.print_help() | 136 parser.print_help() |
| 114 return 1 | 137 return 1 |
| 115 | 138 |
| 116 | 139 |
| 117 if __name__ == '__main__': | 140 if __name__ == '__main__': |
| 118 sys.exit(main()) | 141 sys.exit(main()) |
| OLD | NEW |