Commit d5c5a7e8 authored by msw's avatar msw Committed by Commit bot

Fix apptest builds and runner on Android.

Serve the build dir when origin is 'localhost'.
(so runners can access those output dir .mojos)
Build apptests and runner apk for mandoline:all.

BUG=486220
TEST=For Android: clobber, build mandoline:all; apptests can run.
R=sky@chromium.org

Review URL: https://codereview.chromium.org/1138933004

Cr-Commit-Position: refs/heads/master@{#329509}
parent d42d4b2b
......@@ -39,8 +39,7 @@ group("tests") {
"//third_party/mojo/src/mojo/edk/test:mojo_public_utility_unittests",
]
# TODO: get these working on android.
if (!is_android && !is_component_build) {
if (!is_component_build) {
deps += [
"//mojo/runner:apptests",
"//mojo/runner:tests",
......
......@@ -58,6 +58,6 @@ source_set("test_support") {
data_deps += [ "//mojo/android" ]
}
if (!is_component_build) {
data_deps += [ "//mojo/runner:mojo_runner" ]
data_deps += [ "//mojo/runner" ]
}
}
......@@ -25,7 +25,8 @@ def main():
dest='debug', action='store_false')
parser.add_argument('--target-cpu', help='CPU architecture to run for.',
choices=['x64', 'x86', 'arm'])
parser.add_argument('--origin', help='Origin for mojo: URLs.')
parser.add_argument('--origin', help='Origin for mojo: URLs.',
default='localhost')
parser.add_argument('--target-device', help='Device to run on.')
launcher_args, args = parser.parse_known_args()
......
......@@ -11,7 +11,6 @@ import sys
from mopy import dart_apptest
from mopy import gtest
# TODO(msw): Mojo's script pulls in android.py via mojo/devtools/common/pylib.
from mopy.android import AndroidShell
from mopy.config import Config
from mopy.gn import ConfigForGNArgs, ParseGNConfig
......@@ -48,7 +47,7 @@ def main():
paths = Paths(config)
shell = AndroidShell(paths.target_mojo_shell_path, paths.build_dir,
paths.adb_path)
extra_args.extend(shell.PrepareShellRun(fixed_port=False))
extra_args.extend(shell.PrepareShellRun('localhost'))
else:
shell = None
......
......@@ -37,8 +37,6 @@ MOJO_SHELL_PACKAGE_NAME = 'org.chromium.mojo.shell'
MAPPING_PREFIX = '--map-origin='
DEFAULT_BASE_PORT = 31337
ZERO = datetime.timedelta(0)
class UTC_TZINFO(datetime.tzinfo):
......@@ -272,7 +270,6 @@ class AndroidShell(object):
"""Starts an http server serving files from |path|. Returns the local
url."""
assert path
print 'starting http for', path
httpd = _SilentTCPServer(('127.0.0.1', 0), _GetHandlerClassForPath(path))
atexit.register(httpd.shutdown)
......@@ -280,7 +277,7 @@ class AndroidShell(object):
http_thread.daemon = True
http_thread.start()
print 'local port=%d' % httpd.server_address[1]
print 'Hosting %s at http://127.0.0.1:%d' % (path, httpd.server_address[1])
return 'http://127.0.0.1:%d/' % self._MapPort(port, httpd.server_address[1])
def _StartHttpServerForOriginMapping(self, mapping, port):
......@@ -301,7 +298,7 @@ class AndroidShell(object):
print 'started server at %s for %s' % (dest, localUrl)
return parts[0] + '=' + localUrl
def _StartHttpServerForOriginMappings(self, map_parameters, fixed_port):
def _StartHttpServerForOriginMappings(self, map_parameters):
"""Calls _StartHttpServerForOriginMapping for every --map-origin
argument."""
if not map_parameters:
......@@ -311,15 +308,14 @@ class AndroidShell(object):
*map(lambda x: x[len(MAPPING_PREFIX):].split(','), map_parameters)))
sorted(original_values)
result = []
for i, value in enumerate(original_values):
result.append(self._StartHttpServerForOriginMapping(
value, DEFAULT_BASE_PORT + 1 + i if fixed_port else 0))
for value in original_values:
result.append(self._StartHttpServerForOriginMapping(value, 0))
return [MAPPING_PREFIX + ','.join(result)]
def PrepareShellRun(self, origin=None, fixed_port=True):
""" Prepares for StartShell: runs adb as root and installs the apk. If no
--origin is specified, local http server will be set up to serve files from
the build directory along with port forwarding.
def PrepareShellRun(self, origin=None):
""" Prepares for StartShell: runs adb as root and installs the apk. If the
origin specified is 'localhost', a local http server will be set up to serve
files from the build directory along with port forwarding.
Returns arguments that should be appended to shell argument list."""
if 'cannot run as root' in subprocess.check_output(
......@@ -331,18 +327,16 @@ class AndroidShell(object):
atexit.register(self.StopShell)
extra_shell_args = []
if origin is 'localhost':
origin = self._StartHttpServerForDirectory(self.local_dir, 0)
if origin:
origin_url = origin if origin else self._StartHttpServerForDirectory(
self.local_dir, DEFAULT_BASE_PORT if fixed_port else 0)
extra_shell_args.append("--origin=" + origin_url)
extra_shell_args.append("--origin=" + origin)
return extra_shell_args
def StartShell(self,
arguments,
stdout=None,
on_application_stop=None,
fixed_port=True):
on_application_stop=None):
"""
Starts the mojo shell, passing it the given arguments.
......@@ -370,8 +364,7 @@ class AndroidShell(object):
# Extract map-origin arguments.
map_parameters, other_parameters = _Split(arguments, _IsMapOrigin)
parameters += other_parameters
parameters += self._StartHttpServerForOriginMappings(map_parameters,
fixed_port)
parameters += self._StartHttpServerForOriginMappings(map_parameters)
if parameters:
encodedParameters = json.dumps(parameters)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment