[Eraser strings] Remove unused Supervised User infobar and corresponding strings
[chromium-blink-merge.git] / mandoline / tools / android / run_mandoline.py
blob9e5255f74740d0b864b5aade2bcb9b855af50519
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('--build-dir', help='Build directory')
59 parser.add_argument('--target-cpu', help='CPU architecture to run for.',
60 choices=['x64', 'x86', 'arm'], default='arm')
61 parser.add_argument('--device', help='Serial number of the target device.')
62 parser.add_argument('--gdb', help='Run gdb',
63 default=False, action='store_true')
64 runner_args, args = parser.parse_known_args()
66 config = Config(build_dir=runner_args.build_dir,
67 target_os=Config.OS_ANDROID,
68 target_cpu=runner_args.target_cpu,
69 is_debug=runner_args.debug,
70 apk_name='Mandoline.apk')
71 shell = AndroidShell(config)
72 shell.InitShell(runner_args.device)
73 p = shell.ShowLogs()
75 temp_gdb_dir = None
76 if runner_args.gdb:
77 temp_gdb_dir = tempfile.mkdtemp()
78 atexit.register(shutil.rmtree, temp_gdb_dir, True)
79 _CreateSOLinks(temp_gdb_dir)
81 shell.StartActivity('MandolineActivity',
82 args,
83 sys.stdout,
84 p.terminate,
85 temp_gdb_dir)
86 return 0
89 if __name__ == '__main__':
90 sys.exit(main())