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

Commit c74f25f

Browse files
authored
Reland build rules for scenario app (#27360)
* Revert "Revert "Build rules for scenario_app (#27302)" (#27358)" This reverts commit 99f8791. * Ignore *.*framework in copy_trees
1 parent 99f8791 commit c74f25f

20 files changed

+391
-409
lines changed

BUILD.gn

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,10 @@ group("flutter") {
116116
]
117117
}
118118

119+
if (is_ios || is_android) {
120+
public_deps += [ "//flutter/testing/scenario_app" ]
121+
}
122+
119123
# Compile all unittests targets if enabled.
120124
if (enable_unittests) {
121125
public_deps += [

build/dart/rules.gni

Lines changed: 163 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,171 @@
22
# Use of this source code is governed by a BSD-style license that can be
33
# found in the LICENSE file.
44

5-
# This file has rules for making Dart packages and Dart-based Mojo applications.
6-
# The entrypoint is the dart_pkg rule.
5+
# This file has rules for making Dart packages and snapshots.
76

7+
import("//build/compiled_action.gni")
88
import("//build/module_args/dart.gni")
9+
import("//flutter/common/config.gni")
10+
import("//third_party/dart/build/dart/dart_action.gni")
11+
12+
# Creates a dart kernel (dill) file suitable for use with gen_snapshot, as well
13+
# as the app-jit, aot-elf, or aot-assembly snapshot for Android or iOS.
14+
#
15+
# Invoker must supply dart_main and package_config. Invoker may optionally
16+
# supply aot as a boolean and product as a boolean.
17+
template("dart_snapshot") {
18+
assert(!is_fuchsia)
19+
assert(defined(invoker.main_dart), "main_dart is a required parameter.")
20+
assert(defined(invoker.package_config),
21+
"package_config is a required parameter.")
22+
23+
kernel_target = "_${target_name}_kernel"
24+
snapshot_target = "_${target_name}_snapshot"
25+
is_aot =
26+
flutter_runtime_mode == "profile" || flutter_runtime_mode == "release"
27+
28+
kernel_output = "$target_gen_dir/kernel_blob.bin"
29+
30+
prebuilt_dart_action(kernel_target) {
31+
script = "//flutter/flutter_frontend_server/bin/starter.dart"
32+
33+
main_dart = rebase_path(invoker.main_dart)
34+
package_config = rebase_path(invoker.package_config)
35+
flutter_patched_sdk = rebase_path("$root_out_dir/flutter_patched_sdk")
36+
37+
deps = [ "//flutter/lib/snapshot:strong_platform" ]
38+
39+
inputs = [
40+
main_dart,
41+
package_config,
42+
]
43+
44+
outputs = [ kernel_output ]
45+
46+
depfile = "$kernel_output.d"
47+
abs_depfile = rebase_path(depfile)
48+
rebased_output = rebase_path(kernel_output, root_build_dir)
49+
vm_args = [
50+
"--depfile=$abs_depfile",
51+
"--depfile_output_filename=$rebased_output",
52+
"--disable-dart-dev",
53+
]
54+
55+
args = [
56+
"--packages=" + rebase_path(package_config),
57+
"--target=flutter",
58+
"--sdk-root=" + flutter_patched_sdk,
59+
"--output-dill=" + rebase_path(kernel_output),
60+
]
61+
62+
if (is_aot) {
63+
args += [
64+
"--aot",
65+
"--tfa",
66+
]
67+
} else {
68+
# --no-link-platform is only valid when --aot isn't specified
69+
args += [ "--no-link-platform" ]
70+
}
71+
72+
if (defined(invoker.product) && invoker.product) {
73+
# Setting this flag in a non-product release build for AOT (a "profile"
74+
# build) causes the vm service isolate code to be tree-shaken from an app.
75+
# See the pragma on the entrypoint here:
76+
#
77+
# https://github.com/dart-lang/sdk/blob/master/sdk/lib/_internal/vm/bin/vmservice_io.dart#L240
78+
#
79+
# Also, this define excludes debugging and profiling code from Flutter.
80+
args += [ "-Ddart.vm.product=true" ]
81+
} else {
82+
if (!is_debug) {
83+
# The following define excludes debugging code from Flutter.
84+
args += [ "-Ddart.vm.profile=true" ]
85+
}
86+
}
87+
88+
args += [ rebase_path(main_dart) ]
89+
}
90+
91+
compiled_action(snapshot_target) {
92+
if (target_cpu == "x86" && host_os == "linux") {
93+
# By default Dart will create a 32-bit gen_snapshot host binary if the target
94+
# platform is 32-bit. Override this to create a 64-bit gen_snapshot for x86
95+
# targets because some host platforms may not support 32-bit binaries.
96+
tool = "//third_party/dart/runtime/bin:gen_snapshot_host_targeting_host"
97+
toolchain = "//build/toolchain/$host_os:clang_x64"
98+
} else {
99+
tool = "//third_party/dart/runtime/bin:gen_snapshot"
100+
}
101+
102+
inputs = [ kernel_output ]
103+
deps = [ ":$kernel_target" ]
104+
outputs = []
105+
106+
args = [ "--lazy_async_stacks" ]
107+
108+
if (is_debug && flutter_runtime_mode != "profile" &&
109+
flutter_runtime_mode != "release" &&
110+
flutter_runtime_mode != "jit_release") {
111+
args += [ "--enable_asserts" ]
112+
}
113+
114+
if (is_aot) {
115+
args += [ "--deterministic" ]
116+
if (is_ios) {
117+
snapshot_assembly = "$target_gen_dir/ios/snapshot_assembly.S"
118+
outputs += [ snapshot_assembly ]
119+
args += [
120+
"--snapshot_kind=app-aot-assembly",
121+
"--assembly=" + rebase_path(snapshot_assembly),
122+
]
123+
} else if (is_android) {
124+
libapp = "$target_gen_dir/android/libs/$android_app_abi/libapp.so"
125+
outputs += [ libapp ]
126+
args += [
127+
"--snapshot_kind=app-aot-elf",
128+
"--elf=" + rebase_path(libapp),
129+
]
130+
} else {
131+
assert(false)
132+
}
133+
} else {
134+
deps += [ "//flutter/lib/snapshot:generate_snapshot_bin" ]
135+
vm_snapshot_data =
136+
"$root_gen_dir/flutter/lib/snapshot/vm_isolate_snapshot.bin"
137+
snapshot_data = "$root_gen_dir/flutter/lib/snapshot/isolate_snapshot.bin"
138+
isolate_snapshot_data = "$target_gen_dir/isolate_snapshot_data"
139+
isolate_snapshot_instructions = "$target_gen_dir/isolate_snapshot_instr"
140+
141+
inputs += [
142+
vm_snapshot_data,
143+
snapshot_data,
144+
]
145+
146+
outputs += [
147+
isolate_snapshot_data,
148+
isolate_snapshot_instructions,
149+
]
150+
args += [
151+
"--snapshot_kind=app-jit",
152+
"--load_vm_snapshot_data=" + rebase_path(vm_snapshot_data),
153+
"--load_isolate_snapshot_data=" + rebase_path(snapshot_data),
154+
"--isolate_snapshot_data=" + rebase_path(isolate_snapshot_data),
155+
"--isolate_snapshot_instructions=" +
156+
rebase_path(isolate_snapshot_instructions),
157+
]
158+
}
159+
160+
args += [ rebase_path(kernel_output) ]
161+
}
162+
163+
group(target_name) {
164+
public_deps = [
165+
":$kernel_target",
166+
":$snapshot_target",
167+
]
168+
}
169+
}
9170

10171
template("dart_pkg_helper") {
11172
assert(defined(invoker.package_name))

testing/scenario_app/BUILD.gn

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Copyright 2013 The Flutter Authors. All rights reserved.
2+
# Use of this source code is governed by a BSD-style license that can be
3+
# found in the LICENSE file.
4+
5+
import("//flutter/build/dart/rules.gni")
6+
import("//flutter/testing/scenario_app/runtime_mode.gni")
7+
8+
dart_snapshot("scenario_app_snapshot") {
9+
main_dart = "lib/main.dart"
10+
package_config = ".dart_tool/package_config.json"
11+
}
12+
13+
if (!is_aot) {
14+
if (is_android) {
15+
_flutter_assets_dir = "$root_out_dir/scenario_app/app/assets/flutter_assets"
16+
} else if (is_ios) {
17+
_flutter_assets_dir =
18+
"$root_out_dir/scenario_app/Scenarios/App.framework/flutter_assets"
19+
} else {
20+
assert(false)
21+
}
22+
23+
copy("copy_jit_assets") {
24+
visibility = [ ":*" ]
25+
sources = [
26+
"$target_gen_dir/isolate_snapshot_data",
27+
"$target_gen_dir/isolate_snapshot_instr",
28+
"$target_gen_dir/kernel_blob.bin",
29+
]
30+
outputs = [ "$_flutter_assets_dir/{{source_file_part}}" ]
31+
deps = [ ":scenario_app_snapshot" ]
32+
}
33+
}
34+
35+
group("scenario_app") {
36+
deps = [ ":scenario_app_snapshot" ]
37+
38+
if (!is_aot) {
39+
deps += [ ":copy_jit_assets" ]
40+
}
41+
42+
if (is_android) {
43+
deps += [ "android" ]
44+
}
45+
46+
if (is_ios) {
47+
deps += [ "ios" ]
48+
}
49+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Copyright 2013 The Flutter Authors. All rights reserved.
2+
# Use of this source code is governed by a BSD-style license that can be
3+
# found in the LICENSE file.
4+
5+
import("//flutter/testing/scenario_app/runtime_mode.gni")
6+
7+
action("android") {
8+
script = "run_gradle.py"
9+
10+
inputs = [ "$root_out_dir/flutter.jar" ]
11+
sources = [
12+
"app/build.gradle",
13+
"app/src/androidTest/java/dev/flutter/TestRunner.java",
14+
"app/src/androidTest/java/dev/flutter/scenarios/EngineLaunchE2ETest.java",
15+
"app/src/androidTest/java/dev/flutter/scenarios/ExampleInstrumentedTest.java",
16+
"app/src/androidTest/java/dev/flutter/scenariosui/MemoryLeakTests.java",
17+
"app/src/androidTest/java/dev/flutter/scenariosui/PlatformTextureUiTests.java",
18+
"app/src/androidTest/java/dev/flutter/scenariosui/PlatformViewUiTests.java",
19+
"app/src/androidTest/java/dev/flutter/scenariosui/ScreenshotUtil.java",
20+
"app/src/androidTest/java/dev/flutter/scenariosui/SpawnEngineTests.java",
21+
"app/src/main/AndroidManifest.xml",
22+
"app/src/main/java/dev/flutter/scenarios/SpawnedEngineActivity.java",
23+
"app/src/main/java/dev/flutter/scenarios/StrictModeFlutterActivity.java",
24+
"app/src/main/java/dev/flutter/scenarios/TestActivity.java",
25+
"app/src/main/java/dev/flutter/scenarios/TestableFlutterActivity.java",
26+
"app/src/main/java/dev/flutter/scenarios/TextPlatformView.java",
27+
"app/src/main/java/dev/flutter/scenarios/TextPlatformViewActivity.java",
28+
"app/src/main/java/dev/flutter/scenarios/TextPlatformViewFactory.java",
29+
"app/src/main/java/io/flutter/plugins/GeneratedPluginRegistrant.java",
30+
"build.gradle",
31+
]
32+
outputs = [ "$root_out_dir/scenario_app/app/outputs/apk/debug/app-debug.apk" ]
33+
34+
args = [
35+
"assembleDebug",
36+
"--no-daemon",
37+
"-Pflutter_jar=" + rebase_path("$root_out_dir/flutter.jar"),
38+
"-Pout_dir=" + rebase_path("$root_out_dir/scenario_app"),
39+
]
40+
41+
if (is_aot) {
42+
args += [ "-Plibapp=" + rebase_path("$target_gen_dir/libs") ]
43+
inputs += [ "$target_gen_dir/libs/$android_app_abi/libapp.so" ]
44+
}
45+
46+
deps = [
47+
"//flutter/shell/platform/android:android_jar",
48+
"//flutter/testing/scenario_app:scenario_app_snapshot",
49+
]
50+
}

testing/scenario_app/android/app/build.gradle

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,18 @@ android {
3030
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
3131
}
3232
}
33-
sourceSets {
34-
main.assets.srcDirs += "${project.buildDir}/assets"
33+
sourceSets.main {
34+
assets.srcDirs += "${project.buildDir}/assets"
35+
if (project.hasProperty('libapp')) {
36+
jni.srcDirs = []
37+
jniLibs.srcDirs = [project.property('libapp')]
38+
}
3539
}
3640
}
3741

3842
dependencies {
43+
implementation files(project.property('flutter_jar'))
3944
compile 'com.facebook.testing.screenshot:layout-hierarchy-common:0.12.0'
40-
implementation fileTree(dir: 'libs', include: ['*.jar'])
4145
implementation 'androidx.appcompat:appcompat:1.1.0'
4246
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
4347
implementation 'com.google.android.material:material:1.0.0'

testing/scenario_app/android/build.gradle

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ allprojects {
2121
}
2222
}
2323

24-
rootProject.buildDir = '../build'
24+
rootProject.buildDir = project.hasProperty('out_dir')
25+
? project.property('out_dir')
26+
: '../build'
27+
2528
subprojects {
2629
project.buildDir = "${rootProject.buildDir}/${project.name}"
2730
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/usr/bin/env python
2+
# Copyright 2013 The Flutter Authors. All rights reserved.
3+
# Use of this source code is governed by a BSD-style license that can be
4+
# found in the LICENSE file.
5+
6+
"""
7+
Invokes gradlew for building the scenario_app from GN/Ninja.
8+
"""
9+
10+
import os
11+
import sys
12+
import subprocess
13+
14+
def main():
15+
BAT = '.bat' if sys.platform.startswith(('cygwin', 'win')) else ''
16+
android_dir = os.path.abspath(os.path.dirname(__file__))
17+
gradle_bin = os.path.join('.', 'gradlew%s' % BAT)
18+
result = subprocess.check_output(
19+
args=[gradle_bin] + sys.argv[1:],
20+
cwd=android_dir,
21+
)
22+
return 0
23+
24+
25+
if __name__ == '__main__':
26+
sys.exit(main())

testing/scenario_app/assemble_apk.sh

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,9 @@ SCRIPT_DIR=$(follow_links "$(dirname -- "${BASH_SOURCE[0]}")")
2727
SRC_DIR="$(cd "$SCRIPT_DIR/../../.."; pwd -P)"
2828
export ANDROID_HOME="$SRC_DIR/third_party/android_tools/sdk"
2929

30-
"$SRC_DIR/flutter/tools/gn" --unopt
31-
ninja -C "$SRC_DIR/out/host_debug_unopt" sky_engine -j 400
32-
33-
"$SCRIPT_DIR/compile_android_aot.sh" "$1" "$2"
34-
35-
(
36-
cd "$SCRIPT_DIR/android"
37-
./gradlew assembleDebug --no-daemon
38-
)
30+
# TODO(dnfield): Delete this whole file.
31+
DEVICE_OUT_DIR=${2%"clang_x64"}
3932

4033
# LUCI expects to find the APK here
4134
mkdir -p "$SCRIPT_DIR/android/app/build/outputs/apk/debug"
42-
cp "$SCRIPT_DIR/build/app/outputs/apk/debug/app-debug.apk" "$SCRIPT_DIR/android/app/build/outputs/apk/debug"
35+
cp "$DEVICE_OUT_DIR/scenario_app/app/outputs/apk/debug/app-debug.apk" "$SCRIPT_DIR/android/app/build/outputs/apk/debug"

testing/scenario_app/build_and_run_android_tests.sh

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,8 @@ fi
3939

4040
if [[ ! -d "$SRC_DIR/out/$FLUTTER_ENGINE" ]]; then
4141
"$GN" --android --unoptimized --android-cpu x64 --runtime-mode debug
42-
"$GN" --unoptimized --runtime-mode debug
4342
fi
4443

4544
autoninja -C "$SRC_DIR/out/$FLUTTER_ENGINE"
46-
autoninja -C "$SRC_DIR/out/host_debug_unopt"
4745

48-
"$SCRIPT_DIR/compile_android_jit.sh" "$SRC_DIR/out/host_debug_unopt" "$SRC_DIR/out/$FLUTTER_ENGINE/clang_x64"
4946
"$SCRIPT_DIR/run_android_tests.sh" "$FLUTTER_ENGINE"

testing/scenario_app/build_and_run_ios_tests.sh

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,5 @@ if [ ! -d "$SRC_DIR/out/$FLUTTER_ENGINE" ]; then
4242
fi
4343

4444
autoninja -C "$SRC_DIR/out/$FLUTTER_ENGINE"
45-
autoninja -C "$SRC_DIR/out/host_debug_unopt"
4645

47-
"$SCRIPT_DIR/compile_ios_jit.sh" "$SRC_DIR/out/host_debug_unopt" "$SRC_DIR/out/$FLUTTER_ENGINE/clang_x64"
4846
"$SCRIPT_DIR/run_ios_tests.sh" "$FLUTTER_ENGINE"

0 commit comments

Comments
 (0)