Update mojo sdk to rev c02a28868825edfa57ab77947b8cb15e741c5598
[chromium-blink-merge.git] / components / cronet / tools / cr_cronet.py
bloba334cd21e609894c58f4af3bbec76a58537ae81a
1 #!/usr/bin/python
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
4 # found in the LICENSE file.
6 """
7 cr_cronet.py - cr - like helper tool for cronet developers
8 """
10 import argparse
11 import os
12 import sys
15 def run(command, extra_options=''):
16 command = command + ' ' + extra_options
17 print command
18 return os.system(command)
21 def build(out_dir, extra_options=''):
22 return run('ninja -C ' + out_dir + ' cronet_test_instrumentation_apk',
23 extra_options)
26 def install(release_arg):
27 return run('build/android/adb_install_apk.py ' + release_arg + \
28 ' --apk=CronetTest.apk')
31 def test(release_arg, extra_options):
32 return run('build/android/test_runner.py instrumentation '+ \
33 release_arg + ' --test-apk=CronetTestInstrumentation',
34 extra_options)
37 def debug(extra_options):
38 return run('build/android/adb_gdb --start ' + \
39 '--activity=.CronetTestActivity ' + \
40 '--program-name=CronetTest ' + \
41 '--package-name=org.chromium.net',
42 extra_options)
45 def stack(out_dir):
46 return run('adb logcat -d | third_party/android_tools/ndk/ndk-stack ' + \
47 '-sym ' + out_dir + '/lib')
50 def main():
51 parser = argparse.ArgumentParser()
52 parser.add_argument('command',
53 choices=['gyp',
54 'sync',
55 'build',
56 'install',
57 'proguard',
58 'test',
59 'build-test',
60 'stack',
61 'debug',
62 'build-debug'])
63 parser.add_argument('-r', '--release', action='store_true',
64 help='use release configuration')
66 options, extra_options_list = parser.parse_known_args()
67 print options
68 print extra_options_list
69 gyp_defines = 'GYP_DEFINES="OS=android run_findbugs=1 enable_websockets=0 '+ \
70 'disable_file_support=1 disable_ftp_support=1 '+ \
71 'use_icu_alternatives_on_android=1" '
72 out_dir = 'out/Debug'
73 release_arg = ''
74 extra_options = ' '.join(extra_options_list)
75 if options.release:
76 out_dir = 'out/Release'
77 release_arg = ' --release'
79 if (options.command=='gyp'):
80 return run (gyp_defines + ' gclient runhooks')
81 if (options.command=='sync'):
82 return run ('git pull --rebase && ' + gyp_defines + ' gclient sync')
83 if (options.command=='build'):
84 return build(out_dir, extra_options)
85 if (options.command=='install'):
86 return install(release_arg)
87 if (options.command=='proguard'):
88 return run ('ninja -C ' + out_dir + ' cronet_sample_proguard_apk')
89 if (options.command=='test'):
90 return install(release_arg) or test(release_arg, extra_options)
91 if (options.command=='build-test'):
92 return build(out_dir) or install(release_arg) or \
93 test(release_arg, extra_options)
94 if (options.command=='stack'):
95 return stack(out_dir)
96 if (options.command=='debug'):
97 return install(release_arg) or debug(extra_options)
98 if (options.command=='build-debug'):
99 return build(out_dir) or install(release_arg) or debug(extra_options)
101 parser.print_help()
102 return 1
105 if __name__ == '__main__':
106 sys.exit(main())