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