mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
179 lines
7.0 KiB
Python
Executable File
179 lines
7.0 KiB
Python
Executable File
#!/usr/bin/env python
|
|
# Copyright 2014 The Chromium Authors. All rights reserved.
|
|
# Use of this source code is governed by a BSD-style license that can be
|
|
# found in the LICENSE file.
|
|
|
|
import argparse
|
|
import logging
|
|
import sys
|
|
|
|
from devtoolslib.android_shell import AndroidShell
|
|
from devtoolslib.linux_shell import LinuxShell
|
|
from devtoolslib import paths
|
|
from devtoolslib import shell_arguments
|
|
|
|
USAGE = ("mojo_run "
|
|
"[--args-for=<mojo-app>] "
|
|
"[--content-handlers=<handlers>] "
|
|
"[--enable-external-applications] "
|
|
"[--disable-cache] "
|
|
"[--enable-multiprocess] "
|
|
"[<mojo-app>] "
|
|
"""
|
|
|
|
A <mojo-app> is a Mojo URL or a Mojo URL and arguments within quotes.
|
|
Example: mojo_run "mojo:js_standalone test.js".
|
|
<url-lib-path> is searched for shared libraries named by mojo URLs.
|
|
The value of <handlers> is a comma separated list like:
|
|
text/html,mojo:html_viewer,application/javascript,mojo:js_content_handler
|
|
""")
|
|
|
|
_DEFAULT_WINDOW_MANAGER = "mojo:kiosk_wm"
|
|
|
|
|
|
def main():
|
|
logging.basicConfig()
|
|
|
|
parser = argparse.ArgumentParser(usage=USAGE)
|
|
|
|
# Arguments indicating the configuration we are targeting.
|
|
parser.add_argument('--android', help='Run on Android',
|
|
action='store_true')
|
|
debug_group = parser.add_mutually_exclusive_group()
|
|
debug_group.add_argument('--debug', help='Debug build (default)',
|
|
default=True, action='store_true')
|
|
debug_group.add_argument('--release', help='Release build', default=False,
|
|
dest='debug', action='store_false')
|
|
parser.add_argument('--target-cpu', help='CPU architecture to run for.',
|
|
choices=['x64', 'x86', 'arm'])
|
|
|
|
# Arguments indicating paths to binaries and tools.
|
|
parser.add_argument('--adb-path', help='Path of the adb binary.')
|
|
parser.add_argument('--shell-path', help='Path of the Mojo shell binary.')
|
|
parser.add_argument('--origin-path', help='Path of a directory to be set as '
|
|
'the origin for mojo: urls')
|
|
|
|
# Arguments configuring the shell run.
|
|
parser.add_argument('--origin', help='Origin for mojo: URLs.')
|
|
parser.add_argument('--map-url', action='append',
|
|
help='Define a mapping for a url in the format '
|
|
'<url>=<url-or-local-file-path>')
|
|
parser.add_argument('--map-origin', action='append',
|
|
help='Define a mapping for a url origin in the format '
|
|
'<origin>=<url-or-local-file-path>')
|
|
parser.add_argument('--window-manager', default=_DEFAULT_WINDOW_MANAGER,
|
|
help='Window manager app to be mapped as '
|
|
'mojo:window_manager. By default it is ' +
|
|
_DEFAULT_WINDOW_MANAGER)
|
|
parser.add_argument('--no-debugger', action="store_true",
|
|
help='Do not spawn mojo:debugger.')
|
|
parser.add_argument('--sky',
|
|
help='Loads the given Sky file.')
|
|
parser.add_argument('-v', '--verbose', action="store_true",
|
|
help="Increase output verbosity")
|
|
|
|
# Android-only arguments.
|
|
parser.add_argument('--target-device',
|
|
help='(android-only) Device to run on.')
|
|
parser.add_argument('--logcat-tags',
|
|
help='(android-only) Comma-separated list of additional '
|
|
'logcat tags to display on the console.')
|
|
|
|
# Desktop-only arguments.
|
|
parser.add_argument('--use-osmesa', action='store_true',
|
|
help='(linux-only) Configure the native viewport service '
|
|
'for off-screen rendering.')
|
|
|
|
launcher_args, args = parser.parse_known_args()
|
|
|
|
# |mojo_paths| is a hack that allows to automagically get the correct
|
|
# configuration when running within the Mojo repository. This will go away
|
|
# once we have devtools config files, see
|
|
# https://github.com/domokit/devtools/issues/28.
|
|
mojo_paths, _ = paths.infer_mojo_paths(launcher_args.android,
|
|
launcher_args.debug,
|
|
launcher_args.target_cpu)
|
|
if mojo_paths:
|
|
if launcher_args.android:
|
|
adb_path = mojo_paths['adb']
|
|
shell_binary_path = mojo_paths['shell']
|
|
local_origin_path = mojo_paths['build']
|
|
if launcher_args.verbose:
|
|
print 'Running within a Chromium-style checkout.'
|
|
else:
|
|
if launcher_args.android:
|
|
adb_path = 'adb'
|
|
shell_binary_path = None
|
|
local_origin_path = '.'
|
|
if launcher_args.verbose:
|
|
print 'Running outside a Chromium-style checkout:'
|
|
else:
|
|
print 'Running outside a Mojo checkout is not supported on Linux yet.'
|
|
return 1
|
|
|
|
if launcher_args.adb_path:
|
|
adb_path = launcher_args.adb_path
|
|
if launcher_args.shell_path:
|
|
shell_binary_path = launcher_args.shell_path
|
|
if launcher_args.origin_path:
|
|
local_origin_path = launcher_args.origin_path
|
|
|
|
if launcher_args.verbose:
|
|
if shell_binary_path:
|
|
print 'Using the locally built shell at ' + shell_binary_path
|
|
if local_origin_path:
|
|
print 'Using the local origin of ' + local_origin_path
|
|
|
|
if launcher_args.android:
|
|
verbose_pipe = sys.stdout if launcher_args.verbose else None
|
|
|
|
shell = AndroidShell(adb_path, launcher_args.target_device,
|
|
logcat_tags=launcher_args.logcat_tags,
|
|
verbose_pipe=verbose_pipe)
|
|
device_status, error = shell.CheckDevice()
|
|
if not device_status:
|
|
print 'Device check failed: ' + error
|
|
return 1
|
|
if shell_binary_path:
|
|
shell.InstallApk(shell_binary_path)
|
|
|
|
args = shell_arguments.ApplyMappings(shell, args, launcher_args.map_url,
|
|
launcher_args.map_origin)
|
|
if not launcher_args.origin:
|
|
args.extend(shell_arguments.ConfigureLocalOrigin(shell,
|
|
local_origin_path))
|
|
else:
|
|
if not shell_binary_path:
|
|
print 'Can not run without a shell binary. Please pass --shell-path.'
|
|
return 1
|
|
shell = LinuxShell(shell_binary_path)
|
|
if launcher_args.use_osmesa:
|
|
args.append('--args-for=mojo:native_viewport_service --use-osmesa')
|
|
|
|
if launcher_args.origin:
|
|
args.append('--origin=' + launcher_args.origin)
|
|
args = shell_arguments.AppendToArgument(args, '--url-mappings=',
|
|
'mojo:window_manager=%s' %
|
|
launcher_args.window_manager)
|
|
if not launcher_args.no_debugger:
|
|
args.extend(shell_arguments.ConfigureDebugger(shell))
|
|
|
|
if launcher_args.sky:
|
|
if not mojo_paths:
|
|
print 'Running with --sky is not supported outside of the Mojo checkout.'
|
|
# See https://github.com/domokit/devtools/issues/27.
|
|
return 1
|
|
args.extend(shell_arguments.ConfigureSky(shell, mojo_paths['root'],
|
|
mojo_paths['sky_packages'],
|
|
launcher_args.sky))
|
|
|
|
if launcher_args.verbose:
|
|
print "Shell arguments: " + str(args)
|
|
|
|
shell.Run(args)
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
sys.exit(main())
|