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 def run(command): | 14 def run(command): |
15 print command | 15 print command |
16 return os.system(command) | 16 return os.system(command) |
17 | 17 |
18 def build(out_dir): | |
19 return run ('ninja -C ' + out_dir + ' cronet_test_instrumentation_apk') | |
20 | |
21 def install(release_arg): | |
22 return run ('build/android/adb_install_apk.py ' + release_arg + \ | |
23 ' --apk=CronetTest.apk') | |
24 | |
25 def test(release_arg, extra_options): | |
26 return run ('build/android/test_runner.py instrumentation '+ \ | |
27 release_arg + ' --test-apk=CronetTestInstrumentation ' + \ | |
28 extra_options) | |
29 | |
mef
2014/11/19 22:04:47
I think python guidelines suggest 2 blank lines be
mmenke
2014/11/19 22:06:56
Done.
| |
30 def debug(extra_options): | |
31 return run ('build/android/adb_gdb --start ' + \ | |
32 '--activity=.CronetTestActivity ' + \ | |
33 '--program-name=CronetTest ' + \ | |
34 '--package-name=org.chromium.cronet_test_apk ' + \ | |
35 ' '.join(extra_options)) | |
36 | |
18 def main(): | 37 def main(): |
19 parser = argparse.ArgumentParser() | 38 parser = argparse.ArgumentParser() |
20 parser.add_argument('command', | 39 parser.add_argument('command', |
21 choices=['gyp', | 40 choices=['gyp', |
22 'sync', | 41 'sync', |
23 'build', | 42 'build', |
24 'install', | 43 'install', |
25 'proguard', | 44 'proguard', |
26 'test', | 45 'test', |
27 'debug']) | 46 'build-test', |
47 'debug', | |
48 'build-debug']) | |
28 parser.add_argument('-r', '--release', action='store_true', | 49 parser.add_argument('-r', '--release', action='store_true', |
29 help='use release configuration') | 50 help='use release configuration') |
30 | 51 |
31 options, unknown_options = parser.parse_known_args() | 52 options, extra_options_list = parser.parse_known_args() |
32 print options | 53 print options |
33 print unknown_options | 54 print extra_options_list |
34 gyp_defines = 'GYP_DEFINES="OS=android enable_websockets=0 '+ \ | 55 gyp_defines = 'GYP_DEFINES="OS=android enable_websockets=0 '+ \ |
35 'disable_file_support=1 disable_ftp_support=1 '+ \ | 56 'disable_file_support=1 disable_ftp_support=1 '+ \ |
36 'use_icu_alternatives_on_android=1" ' | 57 'use_icu_alternatives_on_android=1" ' |
37 out_dir = 'out/Debug' | 58 out_dir = 'out/Debug' |
38 release_arg = '' | 59 release_arg = '' |
60 extra_options = ' '.join(extra_options_list) | |
39 if options.release: | 61 if options.release: |
40 out_dir = 'out/Release' | 62 out_dir = 'out/Release' |
41 release_arg = ' --release' | 63 release_arg = ' --release' |
42 | 64 |
43 if (options.command=='gyp'): | 65 if (options.command=='gyp'): |
44 return run (gyp_defines + ' gclient runhooks') | 66 return run (gyp_defines + ' gclient runhooks') |
45 if (options.command=='sync'): | 67 if (options.command=='sync'): |
46 return run ('git pull --rebase && ' + gyp_defines + ' gclient sync') | 68 return run ('git pull --rebase && ' + gyp_defines + ' gclient sync') |
47 if (options.command=='build'): | 69 if (options.command=='build'): |
48 return run ('ninja -C ' + out_dir + ' cronet_test_instrumentation_apk') | 70 return build(out_dir) |
49 if (options.command=='install'): | 71 if (options.command=='install'): |
50 return run ('build/android/adb_install_apk.py ' + release_arg + \ | 72 return install(release_arg) |
51 ' --apk=CronetTest.apk') | |
52 if (options.command=='proguard'): | 73 if (options.command=='proguard'): |
53 return run ('ninja -C ' + out_dir + ' cronet_sample_proguard_apk') | 74 return run ('ninja -C ' + out_dir + ' cronet_sample_proguard_apk') |
54 if (options.command=='test'): | 75 if (options.command=='test'): |
55 return run ('build/android/test_runner.py instrumentation '+ \ | 76 return install(release_arg) or test(release_arg, extra_options) |
56 release_arg + ' --test-apk=CronetTestInstrumentation ' + \ | 77 if (options.command=='build-test'): |
57 ' '.join(unknown_options)) | 78 return build(out_dir) or install(release_arg) or \ |
79 test(release_arg, extra_options) | |
58 if (options.command=='debug'): | 80 if (options.command=='debug'): |
59 return run ('build/android/adb_gdb --start ' + \ | 81 return install(release_arg) or debug(extra_options) |
60 '--activity=.CronetTestActivity ' + \ | 82 if (options.command=='build-debug'): |
61 '--program-name=CronetTest ' + \ | 83 return build(out_dir) or install(release_arg) or debug(extra_options) |
62 '--package-name=org.chromium.cronet_test_apk ' + \ | |
63 ' '.join(unknown_options)) | |
64 | 84 |
65 parser.print_help() | 85 parser.print_help() |
66 return 1 | 86 return 1 |
67 | 87 |
68 | 88 |
69 if __name__ == '__main__': | 89 if __name__ == '__main__': |
70 sys.exit(main()) | 90 sys.exit(main()) |
OLD | NEW |