Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit d1e9017

Browse files
authored
Clean up scenario app scripts (#20641)
I just made a pass on the scenario scripts so that they can be more easily run from the scenario directory, set the ANDROID_HOME correctly, and generally fixed lint errors. Also compile_android_aot.sh didn't appear to work, and I think I fixed it (it builds now).
1 parent 4dc8662 commit d1e9017

11 files changed

+358
-143
lines changed

testing/scenario_app/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ compared against golden reside.
4242

4343
## Running for Android
4444

45-
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:
45+
The test is run on a x86 emulator. To run the test locally, you must create an emulator running API level 28, using an x86_64 ABI, and set the following screen settings in the avd's `config.ini` file:
4646

4747
```
4848
hw.lcd.density = 480

testing/scenario_app/assemble_apk.sh

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,37 @@
22

33
set -e
44

5-
pushd "${BASH_SOURCE%/*}/../../.."
6-
./flutter/tools/gn --unopt
7-
ninja -C out/host_debug_unopt sky_engine sky_services
8-
popd
5+
# Needed because if it is set, cd may print the path it changed to.
6+
unset CDPATH
97

10-
pushd "${BASH_SOURCE%/*}"
11-
./compile_android_aot.sh "$1" "$2"
12-
popd
8+
# On Mac OS, readlink -f doesn't work, so follow_links traverses the path one
9+
# link at a time, and then cds into the link destination and find out where it
10+
# ends up.
11+
#
12+
# The function is enclosed in a subshell to avoid changing the working directory
13+
# of the caller.
14+
function follow_links() (
15+
cd -P "$(dirname -- "$1")"
16+
file="$PWD/$(basename -- "$1")"
17+
while [[ -L "$file" ]]; do
18+
cd -P "$(dirname -- "$file")"
19+
file="$(readlink -- "$file")"
20+
cd -P "$(dirname -- "$file")"
21+
file="$PWD/$(basename -- "$file")"
22+
done
23+
echo "$file"
24+
)
1325

14-
pushd "${BASH_SOURCE%/*}/android"
15-
./gradlew assembleDebug --no-daemon
16-
popd
26+
SCRIPT_DIR=$(follow_links "$(dirname -- "${BASH_SOURCE[0]}")")
27+
SRC_DIR="$(cd "$SCRIPT_DIR/../../.."; pwd -P)"
28+
export ANDROID_HOME="$SRC_DIR/third_party/android_tools/sdk"
29+
30+
"$SRC_DIR/flutter/tools/gn" --unopt
31+
autoninja -C "$SRC_DIR/out/host_debug_unopt" sky_engine sky_services
32+
33+
"$SCRIPT_DIR/compile_android_aot.sh" "$1" "$2"
34+
35+
(
36+
cd "$SCRIPT_DIR/android"
37+
./gradlew assembleDebug --no-daemon
38+
)

testing/scenario_app/build_and_run_android_tests.sh

Lines changed: 34 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,29 +5,44 @@
55

66
set -e
77

8+
# Needed because if it is set, cd may print the path it changed to.
9+
unset CDPATH
10+
11+
# On Mac OS, readlink -f doesn't work, so follow_links traverses the path one
12+
# link at a time, and then cds into the link destination and find out where it
13+
# ends up.
14+
#
15+
# The function is enclosed in a subshell to avoid changing the working directory
16+
# of the caller.
17+
function follow_links() (
18+
cd -P "$(dirname -- "$1")"
19+
file="$PWD/$(basename -- "$1")"
20+
while [[ -h "$file" ]]; do
21+
cd -P "$(dirname -- "$file")"
22+
file="$(readlink -- "$file")"
23+
cd -P "$(dirname -- "$file")"
24+
file="$PWD/$(basename -- "$file")"
25+
done
26+
echo "$file"
27+
)
28+
29+
SCRIPT_DIR=$(follow_links "$(dirname -- "${BASH_SOURCE[0]}")")
30+
SRC_DIR="$(cd "$SCRIPT_DIR/../../.."; pwd -P)"
31+
GN="$SRC_DIR/flutter/tools/gn"
32+
833
FLUTTER_ENGINE=android_debug_unopt_x64
34+
export ANDROID_HOME="$SRC_DIR/third_party/android_tools/sdk"
935

10-
if [ $# -eq 1 ]; then
11-
FLUTTER_ENGINE=$1
36+
if [[ $# -eq 1 ]]; then
37+
FLUTTER_ENGINE="$1"
1238
fi
1339

14-
cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd
15-
16-
pushd ../../..
17-
18-
if [ ! -d "out/$FLUTTER_ENGINE" ]; then
19-
echo "You must GN to generate out/$FLUTTER_ENGINE and its host engine."
20-
echo "Example: "
21-
echo " ./tools/gn --android --unoptimized --android-cpu x64 --runtime-mode debug"
22-
echo " ./tools/gn --unoptimized --runtime-mode debug"
23-
echo "to create out/android_debug_unopt_x64 and out/host_debug_unopt."
24-
exit 1
40+
if [[ ! -d "$SRC_DIR/out/$FLUTTER_ENGINE" ]]; then
41+
"$GN" --android --unoptimized --android-cpu x64 --runtime-mode debug
42+
"$GN" --unoptimized --runtime-mode debug
2543
fi
2644

27-
autoninja -C out/$FLUTTER_ENGINE
28-
29-
popd
30-
31-
./compile_android_jit.sh ../../../out/host_debug_unopt ../../../out/$FLUTTER_ENGINE/clang_x64
45+
autoninja -C "$SRC_DIR/out/$FLUTTER_ENGINE"
3246

33-
./run_android_tests.sh $FLUTTER_ENGINE
47+
"$SCRIPT_DIR/compile_android_jit.sh" "$SRC_DIR/out/host_debug_unopt" "$SRC_DIR/out/$FLUTTER_ENGINE/clang_x64"
48+
"$SCRIPT_DIR/run_android_tests.sh" "$FLUTTER_ENGINE"
Lines changed: 34 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,47 @@
1-
#!/bin/sh
1+
#!/bin/bash
22
# Copyright 2013 The Flutter Authors. All rights reserved.
33
# Use of this source code is governed by a BSD-style license that can be
44
# found in the LICENSE file.
55

66
set -e
77

8+
# Needed because if it is set, cd may print the path it changed to.
9+
unset CDPATH
10+
11+
# On Mac OS, readlink -f doesn't work, so follow_links traverses the path one
12+
# link at a time, and then cds into the link destination and find out where it
13+
# ends up.
14+
#
15+
# The function is enclosed in a subshell to avoid changing the working directory
16+
# of the caller.
17+
function follow_links() (
18+
cd -P "$(dirname -- "$1")"
19+
file="$PWD/$(basename -- "$1")"
20+
while [[ -h "$file" ]]; do
21+
cd -P "$(dirname -- "$file")"
22+
file="$(readlink -- "$file")"
23+
cd -P "$(dirname -- "$file")"
24+
file="$PWD/$(basename -- "$file")"
25+
done
26+
echo "$file"
27+
)
28+
29+
SCRIPT_DIR=$(follow_links "$(dirname -- "${BASH_SOURCE[0]}")")
30+
SRC_DIR="$(cd "$SCRIPT_DIR/../../.."; pwd -P)"
31+
GN="$SRC_DIR/flutter/tools/gn"
32+
833
FLUTTER_ENGINE=ios_debug_sim_unopt
934

10-
if [ $# -eq 1 ]; then
11-
FLUTTER_ENGINE=$1
35+
if [[ $# -eq 1 ]]; then
36+
FLUTTER_ENGINE="$1"
1237
fi
1338

14-
cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd
15-
16-
pushd ../../..
17-
18-
if [ ! -d "out/$FLUTTER_ENGINE" ]; then
19-
echo "You must GN to generate out/$FLUTTER_ENGINE"
20-
echo "Example: "
21-
echo " ./flutter/tools/gn --ios --simulator --unoptimized"
22-
echo " ./flutter/tools/gn --unoptimized"
23-
echo "to create out/ios_debug_sim_unopt and out/host_debug_unopt."
24-
exit 1
39+
if [ ! -d "$SRC_DIR/out/$FLUTTER_ENGINE" ]; then
40+
"$GN" --ios --simulator --unoptimized
41+
"$GN" --unoptimized
2542
fi
2643

27-
autoninja -C out/$FLUTTER_ENGINE
28-
29-
popd
30-
31-
./compile_ios_jit.sh ../../../out/host_debug_unopt ../../../out/$FLUTTER_ENGINE/clang_x64
44+
autoninja -C "$SRC_DIR/out/$FLUTTER_ENGINE"
3245

33-
./run_ios_tests.sh $FLUTTER_ENGINE
46+
"$SCRIPT_DIR/compile_ios_jit.sh" "$SRC_DIR/out/host_debug_unopt" "$SRC_DIR/out/$FLUTTER_ENGINE/clang_x64"
47+
"$SCRIPT_DIR/run_ios_tests.sh" "$FLUTTER_ENGINE"

testing/scenario_app/compile_android_aot.sh

Lines changed: 41 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,31 +7,57 @@
77

88
set -e
99

10-
HOST_TOOLS=$1
11-
DEVICE_TOOLS=$2
10+
# Needed because if it is set, cd may print the path it changed to.
11+
unset CDPATH
12+
13+
# On Mac OS, readlink -f doesn't work, so follow_links traverses the path one
14+
# link at a time, and then cds into the link destination and find out where it
15+
# ends up.
16+
#
17+
# The function is enclosed in a subshell to avoid changing the working directory
18+
# of the caller.
19+
function follow_links() (
20+
cd -P "$(dirname -- "$1")"
21+
file="$PWD/$(basename -- "$1")"
22+
while [[ -h "$file" ]]; do
23+
cd -P "$(dirname -- "$file")"
24+
file="$(readlink -- "$file")"
25+
cd -P "$(dirname -- "$file")"
26+
file="$PWD/$(basename -- "$file")"
27+
done
28+
echo "$file"
29+
)
30+
31+
SCRIPT_DIR=$(follow_links "$(dirname -- "${BASH_SOURCE[0]}")")
32+
33+
HOST_TOOLS="$1"
34+
DEVICE_TOOLS="$2"
1235

1336
if [[ ! -d "$HOST_TOOLS" ]]; then
14-
echo "Must specify the host out directory containing dart."
37+
echo "Directory $HOST_TOOLS not found."
38+
echo "First argument must specify the host out directory containing dart (e.g. out/host_debug_unopt)."
1539
exit 1
1640
fi
1741

1842
if [[ ! -d "$DEVICE_TOOLS" ]]; then
19-
echo "Must specify the device out directory containing gen_snapshot."
43+
echo "Directory $DEVICE_TOOLS not found."
44+
ehco "Second argument must specify the device out directory containing gen_snapshot (e.g. out/android_debug_unopt_x64/clang_x64)."
2045
exit 1
2146
fi
2247

23-
PUB_VERSION=$($HOST_TOOLS/dart-sdk/bin/pub --version)
24-
echo "Using Pub ${PUB_VERSION} from $HOST_TOOLS/dart-sdk/bin/pub"
48+
PUB="$HOST_TOOLS/dart-sdk/bin/pub"
49+
PUB_VERSION="$("$PUB" --version)"
50+
echo "Using Pub ${PUB_VERSION} from $PUB"
2551

26-
$HOST_TOOLS/dart-sdk/bin/pub get
52+
(cd "$SCRIPT_DIR"; "$PUB" get)
2753

2854
echo "Using dart from $HOST_TOOLS, gen_snapshot from $DEVICE_TOOLS."
2955

30-
OUTDIR="${BASH_SOURCE%/*}/build/android"
56+
OUTDIR="$SCRIPT_DIR/build/android"
3157

3258
echo "Creating $OUTDIR..."
3359

34-
mkdir -p $OUTDIR
60+
mkdir -p "$OUTDIR"
3561

3662
echo "Compiling kernel..."
3763

@@ -40,15 +66,15 @@ echo "Compiling kernel..."
4066
--sdk-root "$HOST_TOOLS/flutter_patched_sdk" \
4167
--aot --tfa --target=flutter \
4268
--output-dill "$OUTDIR/app.dill" \
43-
"${BASH_SOURCE%/*}/lib/main.dart"
69+
"$SCRIPT_DIR/lib/main.dart"
4470

4571
echo "Compiling ELF Shared Library..."
4672

47-
"$DEVICE_TOOLS/gen_snapshot" --deterministic --snapshot_kind=app-aot-elf --elf="$OUTDIR/libapp.so" --strip "$OUTDIR/app.dill"
73+
"$HOST_TOOLS/gen_snapshot" --deterministic --snapshot_kind=app-aot-elf --elf="$OUTDIR/libapp.so" --strip "$OUTDIR/app.dill"
4874

49-
mkdir -p "${BASH_SOURCE%/*}/android/app/src/main/jniLibs/arm64-v8a"
50-
mkdir -p "${BASH_SOURCE%/*}/android/app/libs"
51-
cp "$OUTDIR/libapp.so" "${BASH_SOURCE%/*}/android/app/src/main/jniLibs/arm64-v8a/"
52-
cp "$DEVICE_TOOLS/../flutter.jar" "${BASH_SOURCE%/*}/android/app/libs/"
75+
mkdir -p "$SCRIPT_DIR/android/app/src/main/jniLibs/arm64-v8a"
76+
mkdir -p "$SCRIPT_DIR/android/app/libs"
77+
cp "$OUTDIR/libapp.so" "$SCRIPT_DIR/android/app/src/main/jniLibs/arm64-v8a/"
78+
cp "$DEVICE_TOOLS/../flutter.jar" "$SCRIPT_DIR/android/app/libs/"
5379

5480
echo "Created $OUTDIR/libapp.so."

testing/scenario_app/compile_android_jit.sh

Lines changed: 42 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,33 +5,59 @@
55

66
set -e
77

8-
HOST_TOOLS=$1
9-
DEVICE_TOOLS=$2
8+
# Needed because if it is set, cd may print the path it changed to.
9+
unset CDPATH
10+
11+
# On Mac OS, readlink -f doesn't work, so follow_links traverses the path one
12+
# link at a time, and then cds into the link destination and find out where it
13+
# ends up.
14+
#
15+
# The function is enclosed in a subshell to avoid changing the working directory
16+
# of the caller.
17+
function follow_links() (
18+
cd -P "$(dirname -- "$1")"
19+
file="$PWD/$(basename -- "$1")"
20+
while [[ -h "$file" ]]; do
21+
cd -P "$(dirname -- "$file")"
22+
file="$(readlink -- "$file")"
23+
cd -P "$(dirname -- "$file")"
24+
file="$PWD/$(basename -- "$file")"
25+
done
26+
echo "$file"
27+
)
28+
29+
SCRIPT_DIR=$(follow_links "$(dirname -- "${BASH_SOURCE[0]}")")
30+
31+
HOST_TOOLS="$1"
32+
DEVICE_TOOLS="$2"
1033

1134
if [[ ! -d "$HOST_TOOLS" ]]; then
12-
echo "Must specify the host out directory containing dart."
35+
echo "Directory $HOST_TOOLS not found."
36+
echo "First argument must specify the host out directory containing dart (e.g. host_debug_unopt)."
1337
exit 1
1438
fi
1539

1640
if [[ ! -d "$DEVICE_TOOLS" ]]; then
17-
echo "Must specify the device out directory containing gen_snapshot."
41+
echo "Directory $DEVICE_TOOLS not found."
42+
ehco "Second argument must specify the device out directory containing gen_snapshot (e.g. android_debug_unopt_x64)."
1843
exit 1
1944
fi
2045

21-
PUB_VERSION=$($HOST_TOOLS/dart-sdk/bin/pub --version)
22-
echo "Using Pub ${PUB_VERSION} from $HOST_TOOLS/dart-sdk/bin/pub"
46+
PUB="$HOST_TOOLS/dart-sdk/bin/pub"
47+
PUB_VERSION="$("$PUB" --version)"
48+
echo "Using Pub $PUB_VERSION from $PUB"
2349

24-
$HOST_TOOLS/dart-sdk/bin/pub get
50+
"$PUB" get
2551

2652
echo "Using dart from $HOST_TOOLS, gen_snapshot from $DEVICE_TOOLS."
2753

28-
OUTDIR="${BASH_SOURCE%/*}/build/app"
29-
FLUTTER_ASSETS_DIR=$OUTDIR/assets/flutter_assets
30-
LIBS_DIR="${BASH_SOURCE%/*}/android/app/libs"
31-
GEN_SNAPSHOT=$DEVICE_TOOLS/gen_snapshot
54+
OUTDIR="$SCRIPT_DIR/build/app"
55+
FLUTTER_ASSETS_DIR="$OUTDIR/assets/flutter_assets"
56+
LIBS_DIR="$SCRIPT_DIR/android/app/libs"
57+
GEN_SNAPSHOT="$DEVICE_TOOLS/gen_snapshot"
3258

3359
if [[ ! -f "$GEN_SNAPSHOT" ]]; then
34-
GEN_SNAPSHOT=$DEVICE_TOOLS/gen_snapshot_host_targeting_host
60+
GEN_SNAPSHOT="$DEVICE_TOOLS/gen_snapshot_host_targeting_host"
3561
fi
3662

3763
if [[ ! -f "$GEN_SNAPSHOT" ]]; then
@@ -41,9 +67,9 @@ fi
4167

4268
echo "Creating directories..."
4369

44-
mkdir -p $OUTDIR
45-
mkdir -p $FLUTTER_ASSETS_DIR
46-
mkdir -p $LIBS_DIR
70+
mkdir -p "$OUTDIR"
71+
mkdir -p "$FLUTTER_ASSETS_DIR"
72+
mkdir -p "$LIBS_DIR"
4773

4874
echo "Compiling kernel..."
4975

@@ -53,7 +79,7 @@ echo "Compiling kernel..."
5379
--target=flutter \
5480
--no-link-platform \
5581
--output-dill "$FLUTTER_ASSETS_DIR/kernel_blob.bin" \
56-
"${BASH_SOURCE%/*}/lib/main.dart"
82+
"$SCRIPT_DIR/lib/main.dart"
5783

5884
echo "Compiling JIT Snapshot..."
5985

0 commit comments

Comments
 (0)