示例#1
0
def PrepareShellRun(config):
    """
  Returns a context allowing a shell to be run.

  This will start an internal http server to serve mojo applications, forward a
  local port on the device to this http server and install the current version
  of the mojo shell.
  """
    build_dir = Paths(config).build_dir
    constants.SetOutputDirectort(build_dir)

    httpd = _SilentTCPServer(('127.0.0.1', 0),
                             _GetHandlerClassForPath(build_dir))
    atexit.register(httpd.shutdown)
    host_port = httpd.server_address[1]

    http_thread = threading.Thread(target=httpd.serve_forever)
    http_thread.daemon = True
    http_thread.start()

    device = android_commands.AndroidCommands(
        android_commands.GetAttachedDevices()[0])
    device.EnableAdbRoot()

    device.ManagedInstall(os.path.join(build_dir, 'apks', 'MojoShell.apk'),
                          keep_data=True,
                          package_name=MOJO_SHELL_PACKAGE_NAME)

    atexit.register(forwarder.Forwarder.UnmapAllDevicePorts, device)
    forwarder.Forwarder.Map([(0, host_port)], device)
    context = Context(device,
                      forwarder.Forwarder.DevicePortForHostPort(host_port))

    atexit.register(StopShell, context)
    return context
def ProcessCommonOptions(args):
  """Processes and handles all common options."""
  run_tests_helper.SetLogLevel(args.verbose_count)
  constants.SetBuildType(args.build_type)
  if args.build_directory:
    constants.SetBuildDirectory(args.build_directory)
  if args.output_directory:
    constants.SetOutputDirectort(args.output_directory)
  if args.adb_path:
    constants.SetAdbPath(args.adb_path)
  # Some things such as Forwarder require ADB to be in the environment path.
  adb_dir = os.path.dirname(constants.GetAdbPath())
  if adb_dir and adb_dir not in os.environ['PATH'].split(os.pathsep):
    os.environ['PATH'] = adb_dir + os.pathsep + os.environ['PATH']
示例#3
0
def ProcessCommonOptions(options, error_func):
    """Processes and handles all common options."""
    run_tests_helper.SetLogLevel(options.verbose_count)
    constants.SetBuildType(options.build_type)
    if options.build_directory:
        constants.SetBuildDirectory(options.build_directory)
    if options.output_directory:
        constants.SetOutputDirectort(options.output_directory)
    if options.adb_path:
        constants.SetAdbPath(options.adb_path)
    # Some things such as Forwarder require ADB to be in the environment path.
    adb_dir = os.path.dirname(constants.GetAdbPath())
    if adb_dir and adb_dir not in os.environ['PATH'].split(os.pathsep):
        os.environ['PATH'] = adb_dir + os.pathsep + os.environ['PATH']
    if options.environment not in constants.VALID_ENVIRONMENTS:
        error_func('--environment must be one of: %s' %
                   ', '.join(constants.VALID_ENVIRONMENTS))
示例#4
0
def main():
    logging.basicConfig()

    parser = argparse.ArgumentParser(usage=USAGE)

    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('--no-url',
                        help='Allows not to provide a application URL',
                        action='store_true')
    launcher_args, args = parser.parse_known_args()

    paths = Paths(
        Config(target_os=Config.OS_ANDROID, is_debug=launcher_args.debug))
    constants.SetOutputDirectort(paths.build_dir)

    httpd = SocketServer.TCPServer(('127.0.0.1', 0),
                                   GetHandlerForPath(paths.build_dir))
    atexit.register(httpd.shutdown)
    port = httpd.server_address[1]

    http_thread = threading.Thread(target=httpd.serve_forever)
    http_thread.daemon = True
    http_thread.start()

    device = android_commands.AndroidCommands(
        android_commands.GetAttachedDevices()[0])
    device.EnableAdbRoot()

    atexit.register(forwarder.Forwarder.UnmapAllDevicePorts, device)
    forwarder.Forwarder.Map([(0, port)], device)
    device_port = forwarder.Forwarder.DevicePortForHostPort(port)

    cmd = ('am start'
           ' -W'
           ' -S'
           ' -a android.intent.action.VIEW'
           ' -n org.chromium.mojo_shell_apk/.MojoShellActivity')

    parameters = ['--origin=http://127.0.0.1:%d/' % device_port]

    url = None
    if launcher_args.no_url:
        parameters += args
    else:
        url = args[-1]
        parameters += args[:-1]

    cmd += ' --esa parameters \"%s\"' % ','.join(parameters)

    if url:
        cmd += ' -d %s' % url

    device.RunShellCommand('logcat -c')
    device.RunShellCommand(cmd)
    os.system("%s logcat -s %s" % (constants.GetAdbPath(), ' '.join(TAGS)))
    device.RunShellCommand("am force-stop org.chromium.mojo_shell_apk")
    return 0