blob: 5ba34fb303332fa3f5cd60cf832d173dc01b510e [file] [log] [blame]
John Abd-El-Malekda4596e2015-04-02 19:16:531#!/usr/bin/env 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.
5
6import argparse
7import logging
8import sys
9
msw209e4b12015-04-23 20:31:3010from mopy.android import AndroidShell
John Abd-El-Malekda4596e2015-04-02 19:16:5311from mopy.config import Config
msw209e4b12015-04-23 20:31:3012
mswb54a5f9c2015-07-15 23:10:5913USAGE = ('android_mojo_shell.py [<shell-and-app-args>] [<mojo-app>]')
John Abd-El-Malekda4596e2015-04-02 19:16:5314
John Abd-El-Malekda4596e2015-04-02 19:16:5315def main():
16 logging.basicConfig()
17
msw209e4b12015-04-23 20:31:3018 parser = argparse.ArgumentParser(usage=USAGE)
John Abd-El-Malekda4596e2015-04-02 19:16:5319
20 debug_group = parser.add_mutually_exclusive_group()
21 debug_group.add_argument('--debug', help='Debug build (default)',
22 default=True, action='store_true')
23 debug_group.add_argument('--release', help='Release build', default=False,
24 dest='debug', action='store_false')
25 parser.add_argument('--target-cpu', help='CPU architecture to run for.',
msw6c8ec832015-05-18 20:16:3526 choices=['x64', 'x86', 'arm'], default='arm')
msw7e92ef9c2015-06-02 01:27:2227 parser.add_argument('--device', help='Serial number of the target device.')
mswb54a5f9c2015-07-15 23:10:5928 parser.add_argument('--verbose', default=False, action='store_true')
sadrul14238f72015-07-24 22:58:3529 parser.add_argument('--apk', help='Name of the APK to run.',
30 default='MojoRunner.apk')
msw7e92ef9c2015-06-02 01:27:2231 runner_args, args = parser.parse_known_args()
32
33 logger = logging.getLogger()
mswb54a5f9c2015-07-15 23:10:5934 logging.basicConfig(stream=sys.stdout, format='%(levelname)s:%(message)s')
msw7e92ef9c2015-06-02 01:27:2235 logger.setLevel(logging.DEBUG if runner_args.verbose else logging.WARNING)
mswb54a5f9c2015-07-15 23:10:5936 logger.debug('Initialized logging: level=%s' % logger.level)
John Abd-El-Malekda4596e2015-04-02 19:16:5337
38 config = Config(target_os=Config.OS_ANDROID,
msw7e92ef9c2015-06-02 01:27:2239 target_cpu=runner_args.target_cpu,
40 is_debug=runner_args.debug,
sadrul74d653532015-07-28 22:56:2841 is_verbose=runner_args.verbose,
sadrul14238f72015-07-24 22:58:3542 apk_name=runner_args.apk)
msw7e92ef9c2015-06-02 01:27:2243 shell = AndroidShell(config)
sadrul2075cfb2015-07-30 07:18:1744 shell.InitShell(runner_args.device)
msw209e4b12015-04-23 20:31:3045 p = shell.ShowLogs()
ben05d2eea2015-06-11 23:38:0246 shell.StartActivity('MojoShellActivity', args, sys.stdout, p.terminate)
John Abd-El-Malekda4596e2015-04-02 19:16:5347 return 0
48
49
mswb54a5f9c2015-07-15 23:10:5950if __name__ == '__main__':
John Abd-El-Malekda4596e2015-04-02 19:16:5351 sys.exit(main())