| 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 | CHROMIUM_OUTPUT_DIR=' + out_dir + | 50 return run('adb logcat -d | CHROMIUM_OUTPUT_DIR=' + out_dir + |
| 50 ' third_party/android_platform/development/scripts/stack') | 51 ' third_party/android_platform/development/scripts/stack') |
| 51 | 52 |
| 52 def main(): | 53 def main(): |
| 53 parser = argparse.ArgumentParser() | 54 parser = argparse.ArgumentParser() |
| 54 parser.add_argument('command', | 55 parser.add_argument('command', |
| 55 choices=['gyp', | 56 choices=['gyp', |
| 56 'gn', | 57 'gn', |
| 57 'sync', | 58 'sync', |
| 58 'build', | 59 'build', |
| 59 'install', | 60 'install', |
| 60 'proguard', | 61 'proguard', |
| 61 'test', | 62 'test', |
| 62 'build-test', | 63 'build-test', |
| 63 'stack', | 64 'stack', |
| 64 'debug', | 65 'debug', |
| 65 'build-debug']) | 66 'build-debug']) |
| 67 parser.add_argument('-i', '--iphoneos', action='store_true', |
| 68 help='build for physical iphone') |
| 66 parser.add_argument('-r', '--release', action='store_true', | 69 parser.add_argument('-r', '--release', action='store_true', |
| 67 help='use release configuration') | 70 help='use release configuration') |
| 68 | 71 |
| 69 options, extra_options_list = parser.parse_known_args() | 72 options, extra_options_list = parser.parse_known_args() |
| 70 print options | 73 print options |
| 71 print extra_options_list | 74 print extra_options_list |
| 72 gyp_defines = 'GYP_DEFINES="OS=android enable_websockets=0 '+ \ | 75 |
| 76 is_os = (sys.platform == 'darwin') |
| 77 if is_os: |
| 78 target_os = 'ios' |
| 79 test_target = 'cronet_test' |
| 80 out_dir_suffix = '-iphonesimulator' |
| 81 if options.iphoneos: |
| 82 out_dir_suffix = '-iphoneos' |
| 83 else: |
| 84 target_os = 'android' |
| 85 test_target = 'cronet_test_instrumentation_apk' |
| 86 out_dir_suffix = '' |
| 87 |
| 88 gyp_defines = 'GYP_DEFINES="OS=' + target_os + ' enable_websockets=0 '+ \ |
| 73 'disable_file_support=1 disable_ftp_support=1 '+ \ | 89 'disable_file_support=1 disable_ftp_support=1 '+ \ |
| 74 'enable_errorprone=1 use_platform_icu_alternatives=1 ' + \ | 90 'enable_errorprone=1 use_platform_icu_alternatives=1 ' + \ |
| 75 'disable_brotli_filter=1"' | 91 'disable_brotli_filter=1 use_openssl=1"' |
| 76 gn_args = 'target_os="android" enable_websockets=false '+ \ | 92 gn_args = 'target_os="' + target_os + '" enable_websockets=false '+ \ |
| 77 'disable_file_support=true disable_ftp_support=true '+ \ | 93 'disable_file_support=true disable_ftp_support=true '+ \ |
| 78 'use_errorprone_java_compiler=true use_platform_icu_alternatives=true '+ \ | 94 'use_errorprone_java_compiler=true use_platform_icu_alternatives=true '+ \ |
| 79 'disable_brotli_filter=true' | 95 'disable_brotli_filter=true' |
| 80 out_dir = 'out/Debug' | 96 |
| 97 out_dir = 'out/Debug' + out_dir_suffix |
| 81 release_arg = '' | 98 release_arg = '' |
| 82 extra_options = ' '.join(extra_options_list) | 99 extra_options = ' '.join(extra_options_list) |
| 83 if options.release: | 100 if options.release: |
| 84 out_dir = 'out/Release' | 101 out_dir = 'out/Release' + out_dir_suffix |
| 85 release_arg = ' --release' | 102 release_arg = ' --release' |
| 86 gn_args += ' is_debug=false ' | 103 gn_args += ' is_debug=false ' |
| 87 | 104 |
| 88 if (options.command=='gyp'): | 105 if (options.command=='gyp'): |
| 89 return run (gyp_defines + ' gclient runhooks') | 106 return run (gyp_defines + ' gclient runhooks') |
| 90 if (options.command=='gn'): | 107 if (options.command=='gn'): |
| 91 return run ('gn gen ' + out_dir + ' --args=\'' + gn_args + '\'') | 108 return run ('gn gen ' + out_dir + ' --args=\'' + gn_args + '\'') |
| 92 if (options.command=='sync'): | 109 if (options.command=='sync'): |
| 93 return run ('git pull --rebase && ' + gyp_defines + ' gclient sync') | 110 return run ('git pull --rebase && ' + gyp_defines + ' gclient sync') |
| 94 if (options.command=='build'): | 111 if (options.command=='build'): |
| 95 return build(out_dir, extra_options) | 112 return build(out_dir, test_target, extra_options) |
| 96 if (options.command=='install'): | 113 if (not is_os): |
| 97 return install(release_arg) | 114 if (options.command=='install'): |
| 98 if (options.command=='proguard'): | 115 return install(release_arg) |
| 99 return run ('ninja -C ' + out_dir + ' cronet_sample_proguard_apk') | 116 if (options.command=='proguard'): |
| 100 if (options.command=='test'): | 117 return run ('ninja -C ' + out_dir + ' cronet_sample_proguard_apk') |
| 101 return install(release_arg) or test(release_arg, extra_options) | 118 if (options.command=='test'): |
| 102 if (options.command=='build-test'): | 119 return install(release_arg) or test(release_arg, extra_options) |
| 103 return build(out_dir) or install(release_arg) or \ | 120 if (options.command=='build-test'): |
| 104 test(release_arg, extra_options) | 121 return build(out_dir, test_target) or install(release_arg) or \ |
| 105 if (options.command=='stack'): | 122 test(release_arg, extra_options) |
| 106 return stack(out_dir) | 123 if (options.command=='stack'): |
| 107 if (options.command=='debug'): | 124 return stack(out_dir) |
| 108 return install(release_arg) or debug(extra_options) | 125 if (options.command=='debug'): |
| 109 if (options.command=='build-debug'): | 126 return install(release_arg) or debug(extra_options) |
| 110 return build(out_dir) or install(release_arg) or debug(extra_options) | 127 if (options.command=='build-debug'): |
| 128 return build(out_dir) or install(release_arg) or debug(extra_options) |
| 129 else: |
| 130 if (options.command=='test'): |
| 131 return test_ios(out_dir, extra_options) |
| 132 if (options.command=='build-test'): |
| 133 return build(out_dir, test_target) or test_ios(out_dir, extra_options) |
| 111 | 134 |
| 112 parser.print_help() | 135 parser.print_help() |
| 113 return 1 | 136 return 1 |
| 114 | 137 |
| 115 | 138 |
| 116 if __name__ == '__main__': | 139 if __name__ == '__main__': |
| 117 sys.exit(main()) | 140 sys.exit(main()) |
| OLD | NEW |