Remove the Dart JIT snapshot data from AOT builds of the embedder library (flutter/engine#7806)
Also extend the embedder unit tests to cover AOT execution
This commit is contained in:
2
DEPS
2
DEPS
@@ -116,7 +116,7 @@ allowed_hosts = [
|
||||
]
|
||||
|
||||
deps = {
|
||||
'src': 'https://github.com/flutter/buildroot.git' + '@' + 'c82412bcdcd593f1385a478ae2c4b8eb9814f3b8',
|
||||
'src': 'https://github.com/flutter/buildroot.git' + '@' + '4d5aa40f7424aa6bfbe0b27af1067ffd2e6ec25a',
|
||||
|
||||
# Fuchsia compatibility
|
||||
#
|
||||
|
||||
@@ -38,7 +38,6 @@ source_set("embedder") {
|
||||
"$flutter_root/common",
|
||||
"$flutter_root/flow",
|
||||
"$flutter_root/fml",
|
||||
"$flutter_root/lib/snapshot",
|
||||
"$flutter_root/shell/common",
|
||||
"//third_party/dart/runtime/bin:dart_io_api",
|
||||
"//third_party/skia",
|
||||
@@ -48,7 +47,10 @@ source_set("embedder") {
|
||||
if (flutter_runtime_mode == "profile" || flutter_runtime_mode == "release") {
|
||||
deps += [ "//third_party/dart/runtime:libdart_precompiled_runtime" ]
|
||||
} else {
|
||||
deps += [ "//third_party/dart/runtime:libdart_jit" ]
|
||||
deps += [
|
||||
"$flutter_root/lib/snapshot",
|
||||
"//third_party/dart/runtime:libdart_jit",
|
||||
]
|
||||
}
|
||||
|
||||
public_configs = [ "$flutter_root:config" ]
|
||||
|
||||
@@ -4,8 +4,38 @@
|
||||
|
||||
#include <string>
|
||||
#include "embedder.h"
|
||||
#include "flutter/fml/file.h"
|
||||
#include "flutter/fml/mapping.h"
|
||||
#include "flutter/testing/testing.h"
|
||||
|
||||
namespace {
|
||||
|
||||
void MapAOTAsset(std::vector<std::unique_ptr<fml::FileMapping>>& aot_mappings,
|
||||
const fml::UniqueFD& fixtures_dir,
|
||||
const char* path,
|
||||
bool executable,
|
||||
const uint8_t** data,
|
||||
size_t* size) {
|
||||
fml::UniqueFD file =
|
||||
fml::OpenFile(fixtures_dir, path, false, fml::FilePermission::kRead);
|
||||
std::unique_ptr<fml::FileMapping> mapping;
|
||||
if (executable) {
|
||||
mapping = std::make_unique<fml::FileMapping>(
|
||||
file, std::initializer_list<fml::FileMapping::Protection>{
|
||||
fml::FileMapping::Protection::kRead,
|
||||
fml::FileMapping::Protection::kExecute});
|
||||
} else {
|
||||
mapping = std::make_unique<fml::FileMapping>(
|
||||
file, std::initializer_list<fml::FileMapping::Protection>{
|
||||
fml::FileMapping::Protection::kRead});
|
||||
}
|
||||
*data = mapping->GetMapping();
|
||||
*size = mapping->GetSize();
|
||||
aot_mappings.emplace_back(std::move(mapping));
|
||||
}
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
TEST(EmbedderTest, MustNotRunWithInvalidArgs) {
|
||||
FlutterEngine engine = nullptr;
|
||||
FlutterRendererConfig config = {};
|
||||
@@ -34,6 +64,22 @@ TEST(EmbedderTest, CanLaunchAndShutdownWithValidProjectArgs) {
|
||||
ASSERT_EQ(str_data, "Data");
|
||||
};
|
||||
|
||||
fml::UniqueFD fixtures_dir = fml::OpenDirectory(
|
||||
testing::GetFixturesPath(), false, fml::FilePermission::kRead);
|
||||
std::vector<std::unique_ptr<fml::FileMapping>> aot_mappings;
|
||||
if (fml::FileExists(fixtures_dir, "vm_snapshot_data")) {
|
||||
MapAOTAsset(aot_mappings, fixtures_dir, "vm_snapshot_data", false,
|
||||
&args.vm_snapshot_data, &args.vm_snapshot_data_size);
|
||||
MapAOTAsset(aot_mappings, fixtures_dir, "vm_snapshot_instr", true,
|
||||
&args.vm_snapshot_instructions,
|
||||
&args.vm_snapshot_instructions_size);
|
||||
MapAOTAsset(aot_mappings, fixtures_dir, "isolate_snapshot_data", false,
|
||||
&args.isolate_snapshot_data, &args.isolate_snapshot_data_size);
|
||||
MapAOTAsset(aot_mappings, fixtures_dir, "isolate_snapshot_instr", true,
|
||||
&args.isolate_snapshot_instructions,
|
||||
&args.isolate_snapshot_instructions_size);
|
||||
}
|
||||
|
||||
std::string str_data = "Data";
|
||||
void* user_data = const_cast<char*>(str_data.c_str());
|
||||
FlutterEngine engine = nullptr;
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
# Use of this source code is governed by a BSD-style license that can be
|
||||
# found in the LICENSE file.
|
||||
|
||||
import("$flutter_root/common/config.gni")
|
||||
import("//build/compiled_action.gni")
|
||||
import("//third_party/dart/build/dart/dart_action.gni")
|
||||
|
||||
# Builds test fixtures for a unit test.
|
||||
@@ -21,7 +23,11 @@ template("test_fixtures") {
|
||||
testonly = true
|
||||
|
||||
assert(defined(invoker.fixtures), "Test fixtures must be specified.")
|
||||
kernel_out = "kernel_blob.bin"
|
||||
if (flutter_runtime_mode == "profile" || flutter_runtime_mode == "release") {
|
||||
kernel_out = "kernel_snapshot.dill"
|
||||
} else {
|
||||
kernel_out = "kernel_blob.bin"
|
||||
}
|
||||
if (defined(invoker.kernel_out)) {
|
||||
kernel_out = invoker.kernel_out
|
||||
}
|
||||
@@ -69,21 +75,72 @@ template("test_fixtures") {
|
||||
inputs = fixture_paths
|
||||
outputs = ["$fixtures_location/$kernel_out"]
|
||||
|
||||
args = [
|
||||
"--sdk-root", rebase_path("$root_out_dir/flutter_patched_sdk"),
|
||||
"--target", "flutter",
|
||||
"--output-dill", rebase_path("$fixtures_location/$kernel_out"),
|
||||
] + fixture_paths
|
||||
deps = [
|
||||
"//third_party/dart/utils/kernel-service:frontend_server"
|
||||
]
|
||||
|
||||
if (flutter_runtime_mode == "profile" || flutter_runtime_mode == "release") {
|
||||
args = [
|
||||
"--sdk-root", rebase_path("$root_out_dir/flutter_patched_sdk"),
|
||||
"--strong",
|
||||
"--target=flutter",
|
||||
"--aot",
|
||||
"--tfa",
|
||||
"-Ddart.vm.product=true",
|
||||
"--output-dill", rebase_path("$fixtures_location/$kernel_out"),
|
||||
] + fixture_paths
|
||||
|
||||
deps += [ "//flutter/lib/snapshot:strong_platform" ]
|
||||
} else {
|
||||
args = [
|
||||
"--sdk-root", rebase_path("$root_out_dir/flutter_patched_sdk"),
|
||||
"--target", "flutter",
|
||||
"--output-dill", rebase_path("$fixtures_location/$kernel_out"),
|
||||
] + fixture_paths
|
||||
}
|
||||
}
|
||||
|
||||
fixtures_aot_target_name = target_name + "_aot"
|
||||
compiled_action(fixtures_aot_target_name) {
|
||||
testonly = true
|
||||
tool = "//third_party/dart/runtime/bin:gen_snapshot"
|
||||
|
||||
inputs = [
|
||||
"$fixtures_location/$kernel_out"
|
||||
]
|
||||
|
||||
outputs = [
|
||||
"$fixtures_location/vm_snapshot_data",
|
||||
"$fixtures_location/vm_snapshot_instr",
|
||||
"$fixtures_location/isolate_snapshot_data",
|
||||
"$fixtures_location/isolate_snapshot_instr",
|
||||
]
|
||||
|
||||
args = [
|
||||
"--causal_async_stacks",
|
||||
"--deterministic",
|
||||
"--snapshot_kind=app-aot-blobs",
|
||||
"--vm_snapshot_data=" + rebase_path("$fixtures_location/vm_snapshot_data"),
|
||||
"--vm_snapshot_instructions=" + rebase_path("$fixtures_location/vm_snapshot_instr"),
|
||||
"--isolate_snapshot_data=" + rebase_path("$fixtures_location/isolate_snapshot_data"),
|
||||
"--isolate_snapshot_instructions=" + rebase_path("$fixtures_location/isolate_snapshot_instr"),
|
||||
rebase_path("$fixtures_location/$kernel_out")
|
||||
]
|
||||
|
||||
deps = [
|
||||
":$fixtures_kernel_target_name",
|
||||
]
|
||||
}
|
||||
|
||||
group(target_name) {
|
||||
testonly = true
|
||||
deps = [
|
||||
":$fixtures_kernel_target_name",
|
||||
":$fixtures_source_set_target_name",
|
||||
]
|
||||
if (flutter_runtime_mode == "profile" || flutter_runtime_mode == "release") {
|
||||
deps += [ ":$fixtures_aot_target_name" ]
|
||||
} else {
|
||||
deps += [ ":$fixtures_kernel_target_name" ]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user