Skip to content

Commit

Permalink
[fuchsia] Hack to set inspect node for embedder.
Browse files Browse the repository at this point in the history
  • Loading branch information
akbiggs committed Sep 19, 2022
1 parent a1e7905 commit 3cbcbb2
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
22 changes: 22 additions & 0 deletions shell/platform/embedder/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import("//build/fuchsia/sdk.gni")
import("//build/toolchain/clang.gni")
import("//flutter/build/zip_bundle.gni")
import("//flutter/common/config.gni")
import("//flutter/shell/gpu/gpu.gni")
import("//flutter/shell/platform/embedder/embedder.gni")
import("//flutter/testing/testing.gni")
import("//flutter/tools/fuchsia/fuchsia_libs.gni")

declare_args() {
embedder_enable_software = shell_enable_software
Expand Down Expand Up @@ -95,6 +97,26 @@ template("embedder_source_set") {
"//third_party/skia",
]

if (is_fuchsia) {
deps += [
"$fuchsia_sdk_root/pkg:sys_cpp",
"$fuchsia_sdk_root/pkg:sys_inspect_cpp",
"//flutter/shell/platform/fuchsia/runtime/dart/utils",

# TODO(akbiggs): Why do I get this error without this? https://pastebin.com/07m66KWt
# This should already be included by //flutter/runtime:libdart.
"//third_party/dart/runtime:libdart_jit",
"//third_party/dart/runtime/platform:libdart_platform_jit",
]
} else {
# Needed to gn host_debug even though this dep is only used by fuchsia???
# and apparently I need to gn host_debug to run clang_tidy now????
# which I need to push my change???
# deps +=
# [ "//third_party/dart/runtime/platform:libdart_platform_precompiler" ]
deps += [ "//third_party/dart/runtime/platform:libdart_platform_jit" ]
}

if (embedder_enable_metal) {
sources += [
"embedder_external_texture_metal.h",
Expand Down
28 changes: 28 additions & 0 deletions shell/platform/embedder/embedder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ extern const intptr_t kPlatformStrongDillSize;
#include "rapidjson/rapidjson.h"
#include "rapidjson/writer.h"

#if OS_FUCHSIA
#include "flutter/shell/platform/fuchsia/runtime/dart/utils/build_info.h"
#include "flutter/shell/platform/fuchsia/runtime/dart/utils/root_inspect_node.h"
#include "platform/utils.h"
#endif

#ifdef SHELL_ENABLE_GL
#include "flutter/shell/platform/embedder/embedder_external_texture_gl.h"
#endif
Expand Down Expand Up @@ -1538,6 +1544,28 @@ FlutterEngineResult FlutterEngineInitialize(size_t version,
// Release the ownership of the embedder engine to the caller.
*engine_out = reinterpret_cast<FLUTTER_API_SYMBOL(FlutterEngine)>(
embedder_engine.release());

#if OS_FUCHSIA
// Terrible hack to get the component context.
struct FuchsiaEmbedderData {
std::unique_ptr<sys::ComponentContext> component_context;
};
auto fuchsia_user_data = reinterpret_cast<FuchsiaEmbedderData*>(user_data);

// We inject the 'vm' node into the dart vm so that it can add any inspect
// data that it needs to the inspect tree.
//
// NOTE: IF YOU DON'T DO THIS, THE DART VM WILL SERVE OUTGOING PERMISSIONS
// ON BEHALF OF YOUR APP AND YOU WILL NEVER BE ABLE TO SERVE OUTGOING
// PERMISSIONS. SEE fxb/75282.
dart_utils::RootInspectNode::Initialize(
fuchsia_user_data->component_context.get());
auto build_info = dart_utils::RootInspectNode::CreateRootChild("build_info");
dart_utils::BuildInfo::Dump(build_info);
dart::SetDartVmNode(std::make_unique<inspect::Node>(
dart_utils::RootInspectNode::CreateRootChild("vm")));
#endif

return kSuccess;
}

Expand Down

0 comments on commit 3cbcbb2

Please sign in to comment.