From 954c3ec627a01b0509e3742b47f484aa675c389f Mon Sep 17 00:00:00 2001 From: Emmanuel Garcia Date: Fri, 7 Aug 2020 15:29:01 -0700 Subject: [PATCH] Add script to compile JIT on x86 (flutter/engine#20315) --- .../flutter/testing/scenario_app/README.md | 12 ++++ .../scenario_app/android/app/build.gradle | 3 + .../build_and_run_android_tests.sh | 14 ++-- .../scenario_app/compile_android_jit.sh | 64 +++++++++++++++++++ .../testing/scenario_app/run_android_tests.sh | 6 -- 5 files changed, 84 insertions(+), 15 deletions(-) create mode 100755 engine/src/flutter/testing/scenario_app/compile_android_jit.sh diff --git a/engine/src/flutter/testing/scenario_app/README.md b/engine/src/flutter/testing/scenario_app/README.md index 6f78ad9afd..628f402438 100644 --- a/engine/src/flutter/testing/scenario_app/README.md +++ b/engine/src/flutter/testing/scenario_app/README.md @@ -42,6 +42,18 @@ compared against golden reside. ## Running for Android +The test is run on a x86 emulator. To run the test locally, you must create an emulator running API level 28, and set the following screen settings in the avd's `config.ini` file: + +``` +hw.lcd.density = 480 +hw.lcd.height = 1920 +hw.lcd.width = 1080 +``` + +This file is typically located in your `$HOME/.android/avd/` folder. + +Once the emulator is up, you can run the test by running: + ```bash ./build_and_run_android_tests.sh ``` diff --git a/engine/src/flutter/testing/scenario_app/android/app/build.gradle b/engine/src/flutter/testing/scenario_app/android/app/build.gradle index 4438a32d79..fee812bdf1 100644 --- a/engine/src/flutter/testing/scenario_app/android/app/build.gradle +++ b/engine/src/flutter/testing/scenario_app/android/app/build.gradle @@ -26,6 +26,9 @@ android { proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' } } + sourceSets { + main.assets.srcDirs += "${project.buildDir}/assets" + } } dependencies { diff --git a/engine/src/flutter/testing/scenario_app/build_and_run_android_tests.sh b/engine/src/flutter/testing/scenario_app/build_and_run_android_tests.sh index 166662044e..509c3fd4e0 100755 --- a/engine/src/flutter/testing/scenario_app/build_and_run_android_tests.sh +++ b/engine/src/flutter/testing/scenario_app/build_and_run_android_tests.sh @@ -3,13 +3,9 @@ # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. -# Runs the Android scenario tests on a connected device. -# TODO(https://github.com/flutter/flutter/issues/55326): use Flutter tool and -# just build debug JIT for emulator. - set -e -FLUTTER_ENGINE=android_profile_unopt_arm64 +FLUTTER_ENGINE=android_debug_unopt_x64 if [ $# -eq 1 ]; then FLUTTER_ENGINE=$1 @@ -22,9 +18,9 @@ pushd ../../.. if [ ! -d "out/$FLUTTER_ENGINE" ]; then echo "You must GN to generate out/$FLUTTER_ENGINE and its host engine." echo "Example: " - echo " ./tools/gn --android --unoptimized --android-cpu arm64 --runtime-mode profile" - echo " ./tools/gn --unoptimized --runtime-mode profile" - echo "to create out/android_profile_unopt_arm64 and out/host_profile_unopt." + echo " ./tools/gn --android --unoptimized --android-cpu x64 --runtime-mode debug" + echo " ./tools/gn --unoptimized --runtime-mode debug" + echo "to create out/android_debug_unopt_x64 and out/host_debug_unopt." exit 1 fi @@ -32,6 +28,6 @@ autoninja -C out/$FLUTTER_ENGINE popd -./compile_android_aot.sh ../../../out/host_profile_unopt ../../../out/$FLUTTER_ENGINE/clang_x64 +./compile_android_jit.sh ../../../out/host_debug_unopt ../../../out/$FLUTTER_ENGINE/clang_x64 ./run_android_tests.sh $FLUTTER_ENGINE diff --git a/engine/src/flutter/testing/scenario_app/compile_android_jit.sh b/engine/src/flutter/testing/scenario_app/compile_android_jit.sh new file mode 100755 index 0000000000..88912a4fef --- /dev/null +++ b/engine/src/flutter/testing/scenario_app/compile_android_jit.sh @@ -0,0 +1,64 @@ +#!/bin/bash +# Copyright 2013 The Flutter Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +set -e + +HOST_TOOLS=$1 +DEVICE_TOOLS=$2 + +if [[ ! -d "$HOST_TOOLS" ]]; then + echo "Must specify the host out directory containing dart." + exit 1 +fi + +if [[ ! -d "$DEVICE_TOOLS" ]]; then + echo "Must specify the device out directory containing gen_snapshot." + exit 1 +fi + +PUB_VERSION=$($HOST_TOOLS/dart-sdk/bin/pub --version) +echo "Using Pub ${PUB_VERSION} from $HOST_TOOLS/dart-sdk/bin/pub" + +$HOST_TOOLS/dart-sdk/bin/pub get + +echo "Using dart from $HOST_TOOLS, gen_snapshot from $DEVICE_TOOLS." + +OUTDIR="${BASH_SOURCE%/*}/build/app" +FLUTTER_ASSETS_DIR=$OUTDIR/assets/flutter_assets +LIBS_DIR="${BASH_SOURCE%/*}/android/app/libs" + +echo "Creating directories..." + +mkdir -p $OUTDIR +mkdir -p $FLUTTER_ASSETS_DIR +mkdir -p $LIBS_DIR + +echo "Compiling kernel..." + +"$HOST_TOOLS/dart" \ + "$HOST_TOOLS/gen/frontend_server.dart.snapshot" \ + --sdk-root "$HOST_TOOLS/flutter_patched_sdk" \ + --target=flutter \ + --no-link-platform \ + --output-dill "$FLUTTER_ASSETS_DIR/kernel_blob.bin" \ + "${BASH_SOURCE%/*}/lib/main.dart" + +echo "Compiling JIT Snapshot..." + +"$DEVICE_TOOLS/gen_snapshot" --deterministic \ + --enable-asserts \ + --no-causal_async_stacks \ + --lazy_async_stacks \ + --isolate_snapshot_instructions="$OUTDIR/isolate_snapshot_instr" \ + --snapshot_kind=app-jit \ + --load_vm_snapshot_data="$DEVICE_TOOLS/../gen/flutter/lib/snapshot/vm_isolate_snapshot.bin" \ + --load_isolate_snapshot_data="$DEVICE_TOOLS/../gen/flutter/lib/snapshot/isolate_snapshot.bin" \ + --isolate_snapshot_data="$FLUTTER_ASSETS_DIR/isolate_snapshot_data" \ + --isolate_snapshot_instructions="$FLUTTER_ASSETS_DIR/isolate_snapshot_instr" \ + "$FLUTTER_ASSETS_DIR/kernel_blob.bin" + +cp "$DEVICE_TOOLS/../flutter.jar" "$LIBS_DIR" + +echo "Created $OUTDIR." diff --git a/engine/src/flutter/testing/scenario_app/run_android_tests.sh b/engine/src/flutter/testing/scenario_app/run_android_tests.sh index 7234b44caa..3aed749bf3 100755 --- a/engine/src/flutter/testing/scenario_app/run_android_tests.sh +++ b/engine/src/flutter/testing/scenario_app/run_android_tests.sh @@ -7,12 +7,6 @@ set -e -FLUTTER_ENGINE=android_profile_unopt_arm64 - -if [ $# -eq 1 ]; then - FLUTTER_ENGINE=$1 -fi - cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd pushd android