new android port: fix android build and tests

This commit is contained in:
Paul Rouget 2018-07-31 22:38:54 +08:00
parent 76d394eca8
commit bef2fe83cd
9 changed files with 43 additions and 39 deletions

View file

@ -23,7 +23,7 @@ matrix:
script: script:
# see https://github.com/servo/servo/issues/20664 # see https://github.com/servo/servo/issues/20664
#- ./mach cargo check -p compositing --no-default-features #- ./mach cargo check -p compositing --no-default-features
- ./mach build -d --verbose - ./mach build -d --verbose -p servo
- ./mach test-unit - ./mach test-unit
- ./mach clean - ./mach clean
- bash etc/ci/lockfile_changed.sh - bash etc/ci/lockfile_changed.sh

View file

@ -76,14 +76,14 @@ linux-rel-intermittent:
- ./mach clean-nightlies --keep 3 --force - ./mach clean-nightlies --keep 3 --force
- ./mach clean-cargo-cache --keep 3 --force - ./mach clean-cargo-cache --keep 3 --force
- ./etc/ci/clean_build_artifacts.sh - ./etc/ci/clean_build_artifacts.sh
- ./mach build --release - ./mach build --release -p servo
- ./etc/ci/check_intermittents.sh --log-raw intermittents.log - ./etc/ci/check_intermittents.sh --log-raw intermittents.log
linux-rel-nogate: linux-rel-nogate:
- ./mach clean-nightlies --keep 3 --force - ./mach clean-nightlies --keep 3 --force
- ./mach clean-cargo-cache --keep 3 --force - ./mach clean-cargo-cache --keep 3 --force
- ./etc/ci/clean_build_artifacts.sh - ./etc/ci/clean_build_artifacts.sh
- ./mach build --release - ./mach build --release -p servo
- python ./etc/ci/chaos_monkey_test.py - python ./etc/ci/chaos_monkey_test.py
- env RUSTFLAGS= bash ./etc/ci/mutation_test.sh - env RUSTFLAGS= bash ./etc/ci/mutation_test.sh
@ -103,11 +103,11 @@ linux-dev:
- ./etc/ci/clean_build_artifacts.sh - ./etc/ci/clean_build_artifacts.sh
- ./mach test-tidy --no-progress --all - ./mach test-tidy --no-progress --all
- ./mach test-tidy --no-progress --self-test - ./mach test-tidy --no-progress --self-test
- ./mach build --dev - ./mach build --dev -p servo
- ./mach test-unit - ./mach test-unit
- python ./etc/memory_reports_over_time.py --test - python ./etc/memory_reports_over_time.py --test
- ./mach package --dev - ./mach package --dev
- ./mach build --dev --no-default-features --features default-except-unstable - ./mach build --dev --no-default-features --features default-except-unstable -p servo
- bash ./etc/ci/lockfile_changed.sh - bash ./etc/ci/lockfile_changed.sh
- bash ./etc/ci/check_no_panic.sh - bash ./etc/ci/check_no_panic.sh
- ./etc/ci/clean_build_artifacts.sh - ./etc/ci/clean_build_artifacts.sh
@ -120,7 +120,7 @@ linux-rel-wpt:
- ./mach clean-nightlies --keep 3 --force - ./mach clean-nightlies --keep 3 --force
- ./mach clean-cargo-cache --keep 3 --force - ./mach clean-cargo-cache --keep 3 --force
- ./etc/ci/clean_build_artifacts.sh - ./etc/ci/clean_build_artifacts.sh
- ./mach build --release --with-debug-assertions - ./mach build --release --with-debug-assertions -p servo
- ./mach test-wpt-failure - ./mach test-wpt-failure
- ./mach test-wpt --release --processes 24 --total-chunks 2 --this-chunk 1 --log-raw test-wpt.log --log-errorsummary wpt-errorsummary.log --always-succeed - ./mach test-wpt --release --processes 24 --total-chunks 2 --this-chunk 1 --log-raw test-wpt.log --log-errorsummary wpt-errorsummary.log --always-succeed
- ./mach filter-intermittents wpt-errorsummary.log --log-intermittents intermittents.log --log-filteredsummary filtered-wpt-errorsummary.log --tracker-api default --reporter-api default - ./mach filter-intermittents wpt-errorsummary.log --log-intermittents intermittents.log --log-filteredsummary filtered-wpt-errorsummary.log --tracker-api default --reporter-api default
@ -134,7 +134,7 @@ linux-rel-css:
- ./mach clean-nightlies --keep 3 --force - ./mach clean-nightlies --keep 3 --force
- ./mach clean-cargo-cache --keep 3 --force - ./mach clean-cargo-cache --keep 3 --force
- ./etc/ci/clean_build_artifacts.sh - ./etc/ci/clean_build_artifacts.sh
- ./mach build --release --with-debug-assertions - ./mach build --release --with-debug-assertions -p servo
- ./mach test-wpt --release --processes 24 --total-chunks 2 --this-chunk 2 --log-raw test-wpt.log --log-errorsummary wpt-errorsummary.log --always-succeed - ./mach test-wpt --release --processes 24 --total-chunks 2 --this-chunk 2 --log-raw test-wpt.log --log-errorsummary wpt-errorsummary.log --always-succeed
- ./mach filter-intermittents wpt-errorsummary.log --log-intermittents intermittents.log --log-filteredsummary filtered-wpt-errorsummary.log --tracker-api default --reporter-api default - ./mach filter-intermittents wpt-errorsummary.log --log-intermittents intermittents.log --log-filteredsummary filtered-wpt-errorsummary.log --tracker-api default --reporter-api default
- bash ./etc/ci/lockfile_changed.sh - bash ./etc/ci/lockfile_changed.sh
@ -144,7 +144,7 @@ linux-nightly:
- ./mach clean-nightlies --keep 3 --force - ./mach clean-nightlies --keep 3 --force
- ./mach clean-cargo-cache --keep 3 --force - ./mach clean-cargo-cache --keep 3 --force
- ./etc/ci/clean_build_artifacts.sh - ./etc/ci/clean_build_artifacts.sh
- ./mach build --release - ./mach build --release -p servo
- ./mach package --release - ./mach package --release
- ./mach upload-nightly linux - ./mach upload-nightly linux
- ./mach test-perf - ./mach test-perf

View file

@ -23,7 +23,7 @@ objdump_output = subprocess.check_output([
'android-toolchains', 'ndk', 'toolchains', 'arm-linux-androideabi-4.9', 'android-toolchains', 'ndk', 'toolchains', 'arm-linux-androideabi-4.9',
'prebuilt', 'linux-x86_64', 'bin', 'arm-linux-androideabi-objdump'), 'prebuilt', 'linux-x86_64', 'bin', 'arm-linux-androideabi-objdump'),
'-T', '-T',
'target/armv7-linux-androideabi/debug/libservo.so'] 'target/armv7-linux-androideabi/debug/libsimpleservo.so']
).split(b'\n') ).split(b'\n')
for line in objdump_output: for line in objdump_output:

View file

@ -10,6 +10,7 @@
# except according to those terms. # except according to those terms.
import contextlib import contextlib
import json
import os import os
import signal import signal
import subprocess import subprocess
@ -55,16 +56,17 @@ def main(avd_name, apk_path, *args):
args = list(args) args = list(args)
write_user_stylesheets(adb, args) write_user_stylesheets(adb, args)
write_hosts_file(adb) write_hosts_file(adb)
write_args(adb, args)
check_call(adb + ["shell", "am start com.mozilla.servo/com.mozilla.servo.MainActivity"], json_params = shell_quote(json.dumps(args))
stdout=sys.stderr) extra = "-e servoargs " + json_params
cmd = "am start " + extra + " com.mozilla.servo/com.mozilla.servo.MainActivity"
check_call(adb + ["shell", cmd], stdout=sys.stderr)
# Start showing logs as soon as the application starts, # Start showing logs as soon as the application starts,
# in case they say something useful while we wait in subsequent steps. # in case they say something useful while we wait in subsequent steps.
logcat_args = [ logcat_args = [
"--format=raw", # Print no metadata, only log messages "--format=raw", # Print no metadata, only log messages
"RustAndroidGlueStdouterr:D", # Show (debug level) Rust stdio "simpleservo:D", # Show (debug level) Rust stdio
"*:S", # Hide everything else "*:S", # Hide everything else
] ]
with terminate_on_exit(adb + ["logcat"] + logcat_args) as logcat: with terminate_on_exit(adb + ["logcat"] + logcat_args) as logcat:
@ -125,16 +127,6 @@ def check_call(*args, **kwargs):
sys.exit(exit_code) sys.exit(exit_code)
def write_args(adb, args):
data_dir = "/sdcard/Android/data/com.mozilla.servo/files"
params_file = data_dir + "/android_params"
check_call(adb + ["shell", "mkdir -p %s" % data_dir])
check_call(adb + ["shell", "echo 'servo' > %s" % params_file])
for arg in args:
check_call(adb + ["shell", "echo %s >> %s" % (shell_quote(arg), params_file)])
def write_user_stylesheets(adb, args): def write_user_stylesheets(adb, args):
data_dir = "/sdcard/Android/data/com.mozilla.servo/files" data_dir = "/sdcard/Android/data/com.mozilla.servo/files"
check_call(adb + ["shell", "mkdir -p %s" % data_dir]) check_call(adb + ["shell", "mkdir -p %s" % data_dir])

View file

@ -185,7 +185,6 @@ class MachCommands(CommandBase):
debug_mozjs=False, params=None, with_debug_assertions=False): debug_mozjs=False, params=None, with_debug_assertions=False):
opts = params or [] opts = params or []
opts += ["--manifest-path", self.servo_manifest()]
if android is None: if android is None:
android = self.config["build"]["android"] android = self.config["build"]["android"]
@ -420,4 +419,4 @@ class MachCommands(CommandBase):
opts += ["-v"] opts += ["-v"]
opts += params opts += params
return check_call(["cargo", "clean"] + opts, return check_call(["cargo", "clean"] + opts,
env=self.build_env(), cwd=self.servo_crate(), verbose=verbose) env=self.build_env(), cwd=self.ports_servo_crate(), verbose=verbose)

View file

@ -330,15 +330,24 @@ class CommandBase(object):
else: else:
return path.join(self.context.topdir, "target") return path.join(self.context.topdir, "target")
def get_apk_path(self, release):
base_path = self.get_target_dir()
base_path = path.join(base_path, self.config["android"]["target"])
apk_name = "servo.apk"
build_type = "release" if release else "debug"
return path.join(base_path, build_type, apk_name)
def get_binary_path(self, release, dev, android=False): def get_binary_path(self, release, dev, android=False):
# TODO(autrilla): this function could still use work - it shouldn't # TODO(autrilla): this function could still use work - it shouldn't
# handle quitting, or printing. It should return the path, or an error. # handle quitting, or printing. It should return the path, or an error.
base_path = self.get_target_dir() base_path = self.get_target_dir()
binary_name = "servo" + BIN_SUFFIX
if android: if android:
base_path = path.join(base_path, self.config["android"]["target"]) base_path = path.join(base_path, self.config["android"]["target"])
binary_name = "libsimpleservo.so"
binary_name = "servo" + BIN_SUFFIX
release_path = path.join(base_path, "release", binary_name) release_path = path.join(base_path, "release", binary_name)
dev_path = path.join(base_path, "debug", binary_name) dev_path = path.join(base_path, "debug", binary_name)
@ -594,10 +603,10 @@ class CommandBase(object):
return env return env
def servo_crate(self): def ports_servo_crate(self):
return path.join(self.context.topdir, "ports", "servo") return path.join(self.context.topdir, "ports", "servo")
def servo_manifest(self): def ports_servo_manifest(self):
return path.join(self.context.topdir, "ports", "servo", "Cargo.toml") return path.join(self.context.topdir, "ports", "servo", "Cargo.toml")
def servo_features(self): def servo_features(self):

View file

@ -421,7 +421,7 @@ class PackageCommands(CommandBase):
return 1 return 1
if android: if android:
pkg_path = binary_path + ".apk" pkg_path = self.get_apk_path(release)
exec_command = [self.android_adb_path(env)] exec_command = [self.android_adb_path(env)]
if emulator and usb: if emulator and usb:
print("Cannot install to both emulator and USB at the same time.") print("Cannot install to both emulator and USB at the same time.")

View file

@ -9,6 +9,7 @@
from __future__ import print_function, unicode_literals from __future__ import print_function, unicode_literals
import json
import os import os
import os.path as path import os.path as path
import subprocess import subprocess
@ -34,6 +35,13 @@ def read_file(filename, if_exists=False):
return f.read() return f.read()
# Copied from Python 3.3+'s shlex.quote()
def shell_quote(arg):
# use single quotes, and put single quotes into double quotes
# the string $'b is then quoted as '$'"'"'b'
return "'" + arg.replace("'", "'\"'\"'") + "'"
@CommandProvider @CommandProvider
class PostBuildCommands(CommandBase): class PostBuildCommands(CommandBase):
@Command('run', @Command('run',
@ -88,15 +96,11 @@ class PostBuildCommands(CommandBase):
return return
script = [ script = [
"am force-stop com.mozilla.servo", "am force-stop com.mozilla.servo",
"echo servo >/sdcard/Android/data/com.mozilla.servo/files/android_params"
] ]
for param in params: json_params = shell_quote(json.dumps(params))
script += [ extra = "-e servoargs " + json_params
"echo '%s' >>/sdcard/Android/data/com.mozilla.servo/files/android_params"
% param.replace("'", "\\'")
]
script += [ script += [
"am start com.mozilla.servo/com.mozilla.servo.MainActivity", "am start " + extra + " com.mozilla.servo/com.mozilla.servo.MainActivity",
"sleep 0.5", "sleep 0.5",
"echo Servo PID: $(pidof com.mozilla.servo)", "echo Servo PID: $(pidof com.mozilla.servo)",
"exit" "exit"
@ -257,7 +261,7 @@ class PostBuildCommands(CommandBase):
copy2(full_name, destination) copy2(full_name, destination)
return self.call_rustup_run( return self.call_rustup_run(
["cargo", "doc", "--manifest-path", self.servo_manifest()] + params, ["cargo", "doc", "--manifest-path", self.ports_servo_manifest()] + params,
env=self.build_env() env=self.build_env()
) )

View file

@ -278,7 +278,7 @@ class MachCommands(CommandBase):
features = self.servo_features() features = self.servo_features()
if len(packages) > 0 or len(in_crate_packages) > 0: if len(packages) > 0 or len(in_crate_packages) > 0:
args = ["cargo", "bench" if bench else "test", "--manifest-path", self.servo_manifest()] args = ["cargo", "bench" if bench else "test", "--manifest-path", self.ports_servo_manifest()]
for crate in packages: for crate in packages:
args += ["-p", "%s_tests" % crate] args += ["-p", "%s_tests" % crate]
for crate in in_crate_packages: for crate in in_crate_packages:
@ -576,7 +576,7 @@ class MachCommands(CommandBase):
def test_android_startup(self, release, dev): def test_android_startup(self, release, dev):
html = """ html = """
<script> <script>
console.log("JavaScript is running!") window.alert("JavaScript is running!")
</script> </script>
""" """
url = "data:text/html;base64," + html.encode("base64").replace("\n", "") url = "data:text/html;base64," + html.encode("base64").replace("\n", "")