未验证 提交 ac9e521a 编写于 作者: C Chris Bracken 提交者: GitHub

Compile embedder unit test Dart to kernel (#7227)

Compile embedder unit test Dart to kernel

As of the migration to Dart 2, it has been necessary to compile Dart to
kernel prior to execution. The embedder currently requires that the
resulting kernel file be named `kernel_blob.bin` and be located at the
root of the assets directory passed to the embedder API.

This patch updates the test_fixtures build rule to perform a kernel
compile using frontend_server, outputting `kernel_blob.bin` to
`fixtures/test_target_name` directory, and updates the embedder
unittests to specify the kernel file rather than the Dart source file.

Since the kernel compiler requires a `main()` function to be defined, it
also updates `simple_main.dart` from runtime_unittests to define
`main()` rather than `simple_main()`.

This also updates all existing sub-targets to be testonly.
上级 828acc73
......@@ -2,6 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
void simple_main() {
void main() {
print("Hello");
}
void main() {}
\ No newline at end of file
void main() {}
......@@ -22,17 +22,14 @@ TEST(EmbedderTest, CanLaunchAndShutdownWithValidProjectArgs) {
return false;
};
std::string main =
std::string(testing::GetFixturesPath()) + "/simple_main.dart";
FlutterRendererConfig config = {};
config.type = FlutterRendererType::kSoftware;
config.software = renderer;
FlutterProjectArgs args = {};
args.struct_size = sizeof(FlutterProjectArgs);
args.assets_path = "";
args.main_path = main.c_str();
args.assets_path = testing::GetFixturesPath();
args.main_path = "";
args.packages_path = "";
FlutterEngine engine = nullptr;
......
......@@ -2,18 +2,21 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import("//third_party/dart/build/dart/dart_action.gni")
# Builds test fixtures for a unit test.
#
# Generates a directory structure containing an assets directory and the Dart
# code to execute compiled to kernel, emitted to assets/kernel_blob.bin.
template("test_fixtures") {
testonly = true
assert(defined(invoker.fixtures), "Test fixtures must be specified.")
fixtures_name_target_name = target_name + "_gen_fixtures_name"
fixtures_source_set_target_name = target_name + "_gen_fixtures_source_set"
fixtures_copy_target_name = target_name + "_copy_fixtures"
fixtures_location = "$target_gen_dir/fixtures"
fixtures_location_file = "$target_gen_dir/test_fixtures_location.cc"
fixtures_location = "$target_gen_dir/$target_name/assets"
fixtures_location_file = "$target_gen_dir/$target_name/test_fixtures_location.cc"
fixtures_name_target_name = target_name + "_gen_fixtures_name"
action(fixtures_name_target_name) {
script = "$flutter_root/testing/build/gen_fixtures_location_symbol.py"
......@@ -29,7 +32,9 @@ template("test_fixtures") {
]
}
fixtures_source_set_target_name = target_name + "_gen_fixtures_source_set"
source_set(fixtures_source_set_target_name) {
testonly = true
sources = [
fixtures_location_file,
]
......@@ -39,16 +44,33 @@ template("test_fixtures") {
]
}
copy(fixtures_copy_target_name) {
sources = invoker.fixtures
outputs = [
"$fixtures_location/{{source_file_part}}",
fixtures_kernel_target_name = target_name + "_kernel"
prebuilt_dart_action(fixtures_kernel_target_name) {
testonly = true
script = "$root_out_dir/frontend_server.dart.snapshot"
fixture_paths = []
foreach(fixture, invoker.fixtures) {
fixture_paths += [ rebase_path(fixture) ]
}
inputs = fixture_paths
outputs = ["$fixtures_location/kernel_blob.bin"]
args = [
"--sdk-root", rebase_path("$root_out_dir/flutter_patched_sdk"),
"--strong",
"--target", "flutter",
"--output-dill", rebase_path("$fixtures_location/kernel_blob.bin"),
] + fixture_paths
deps = [
"//third_party/dart/utils/kernel-service:frontend_server"
]
}
group(target_name) {
testonly = true
deps = [
":$fixtures_copy_target_name",
":$fixtures_kernel_target_name",
":$fixtures_source_set_target_name",
]
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册