Add P2PDatagramSocket and P2PStreamSocket interfaces.
[chromium-blink-merge.git] / mandoline / tools / android / run_mandoline.py
blobc06e008b52f174d4d1c32af9ad09dd33bdbb43f4
1 #!/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.
6 import argparse
7 import atexit
8 import logging
9 import os
10 import shutil
11 import sys
12 import tempfile
14 sys.path.append(os.path.join(os.path.dirname(__file__), os.pardir, os.pardir,
15 os.pardir, 'build', 'android'))
16 from pylib import constants
18 sys.path.insert(0, os.path.join(os.path.abspath(os.path.dirname(__file__)),
19 os.pardir, os.pardir, os.pardir, 'mojo',
20 'tools'))
22 from mopy.android import AndroidShell
23 from mopy.config import Config
25 USAGE = ('run_mandoline.py [<shell-and-app-args>] [<start-page-url>]')
27 def _CreateSOLinks(dest_dir):
28 '''Creates links from files (eg. *.mojo) to the real .so for gdb to find.'''
29 # The files to create links for. The key is the name as seen on the device,
30 # and the target an array of path elements as to where the .so lives (relative
31 # to the output directory).
32 # TODO(sky): come up with some way to automate this.
33 files_to_link = {
34 'html_viewer.mojo': ['libhtml_viewer_library.so'],
35 'libmandoline_runner.so': ['mandoline_runner'],
37 build_dir = constants.GetOutDirectory()
38 print build_dir
39 for android_name, so_path in files_to_link.iteritems():
40 src = os.path.join(build_dir, *so_path)
41 if not os.path.isfile(src):
42 print '*** Expected file not found', src
43 print '*** Aborting launch.'
44 sys.exit(-1)
45 os.symlink(src, os.path.join(dest_dir, android_name))
48 def main():
49 logging.basicConfig()
51 parser = argparse.ArgumentParser(usage=USAGE)
53 debug_group = parser.add_mutually_exclusive_group()
54 debug_group.add_argument('--debug', help='Debug build (default)',
55 default=True, action='store_true')
56 debug_group.add_argument('--release', help='Release build', default=False,
57 dest='debug', action='store_false')
58 parser.add_argument('--target-cpu', help='CPU architecture to run for.',
59 choices=['x64', 'x86', 'arm'], default='arm')
60 parser.add_argument('--device', help='Serial number of the target device.')
61 parser.add_argument('--gdb', help='Run gdb',
62 default=False, action='store_true')
63 runner_args, args = parser.parse_known_args()
65 config = Config(target_os=Config.OS_ANDROID,
66 target_cpu=runner_args.target_cpu,
67 is_debug=runner_args.debug,
68 apk_name='Mandoline.apk')
69 shell = AndroidShell(config)
70 shell.InitShell(None, runner_args.device)
71 p = shell.ShowLogs()
73 temp_gdb_dir = None
74 if runner_args.gdb:
75 temp_gdb_dir = tempfile.mkdtemp()
76 atexit.register(shutil.rmtree, temp_gdb_dir, True)
77 _CreateSOLinks(temp_gdb_dir)
79 shell.StartActivity('MandolineActivity',
80 args,
81 sys.stdout,
82 p.terminate,
83 temp_gdb_dir)
84 return 0
87 if __name__ == '__main__':
88 sys.exit(main())