Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove the Dart JIT snapshot data from AOT builds of the embedder library #7806

Merged
merged 1 commit into from
Feb 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -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
#
Expand Down
6 changes: 4 additions & 2 deletions shell/platform/embedder/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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" ]
Expand Down
46 changes: 46 additions & 0 deletions shell/platform/embedder/tests/embedder_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {};
Expand Down Expand Up @@ -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;
Expand Down
71 changes: 64 additions & 7 deletions testing/testing.gni
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
}
Expand Down Expand Up @@ -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
}
}

group(target_name) {
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_source_set_target_name",
]
if (flutter_runtime_mode == "profile" || flutter_runtime_mode == "release") {
deps += [ ":$fixtures_aot_target_name" ]
} else {
deps += [ ":$fixtures_kernel_target_name" ]
}
}
}