7#include <lib/async-loop/loop.h>
8#include <lib/async/default.h>
9#include <lib/vfs/cpp/pseudo_dir.h>
11#include <zircon/status.h>
12#include <zircon/syscalls.h>
20#include "flutter/fml/command_line.h"
21#include "flutter/fml/logging.h"
22#include "flutter/fml/trace_event.h"
26#include "third_party/dart/runtime/include/bin/dart_io_api.h"
30#if defined(AOT_RUNTIME)
31extern "C" uint8_t _kDartVmSnapshotData[];
32extern "C" uint8_t _kDartVmSnapshotInstructions[];
39const char* kDartVMArgs[] = {
42 "--timeline_recorder=systrace",
43 "--timeline_streams=Compiler,Dart,Debugger,Embedder,GC,Isolate,VM",
45#if defined(AOT_RUNTIME)
48 "--enable_mirrors=false",
54#if !defined(DART_PRODUCT) && (!defined(FLUTTER_PROFILE) || !defined(NDEBUG))
61 const char* package_root,
62 const char* package_config,
67#if defined(DART_PRODUCT)
68 *
error =
strdup(
"The service isolate is not implemented in product mode");
75 *
error =
strdup(
"Isolate spawning is not implemented in dart_runner");
79void IsolateShutdownCallback(
void* isolate_group_data,
void* isolate_data) {
82 auto dispatcher = async_get_default_dispatcher();
83 auto loop = async_loop_from_dispatcher(dispatcher);
91 async_loop_quit(loop);
95 static_cast<std::shared_ptr<tonic::DartState>*
>(isolate_group_data);
96 state->get()->SetIsShuttingDown();
99void IsolateGroupCleanupCallback(
void* isolate_group_data) {
100 delete static_cast<std::shared_ptr<tonic::DartState>*
>(isolate_group_data);
106 fuchsia::component::runner::ComponentStartInfo start_info,
107 std::shared_ptr<sys::ServiceDirectory> runner_incoming_services,
108 fidl::InterfaceRequest<fuchsia::component::runner::ComponentController>
112 DartComponentController
app(std::move(start_info), runner_incoming_services,
113 std::move(controller));
114 const bool success =
app.SetUp();
118 "DartComponentController::SetUp", start, end, 0,
nullptr,
129void RunTestApplication(
131 fuchsia::component::runner::ComponentStartInfo start_info,
132 std::shared_ptr<sys::ServiceDirectory> runner_incoming_services,
133 fidl::InterfaceRequest<fuchsia::component::runner::ComponentController>
135 fit::function<
void(std::shared_ptr<DartTestComponentController>)>
136 component_created_callback,
137 fit::function<
void(DartTestComponentController*)> done_callback) {
140 auto test_component = std::make_shared<DartTestComponentController>(
141 std::move(start_info), runner_incoming_services, std::move(controller),
142 std::move(done_callback));
144 component_created_callback(test_component);
147 test_component->SetUp();
151 "DartTestComponentController::SetUp", start, end, 0,
nullptr,
155bool EntropySource(uint8_t*
buffer, intptr_t
count) {
168 for (
const auto& entry : program_metadata.entries()) {
169 if (entry.key.compare(
kArgsKey) != 0 || entry.value ==
nullptr) {
172 auto args = entry.value->str_vec();
177 std::vector<std::string> command_line_args = {
""};
178 command_line_args.insert(command_line_args.end(),
args.begin(),
args.end());
180 command_line_args.begin(), command_line_args.end());
182 std::string is_test_str;
184 is_test_str ==
"true";
191 ->AddPublicService<fuchsia::component::runner::ComponentRunner>(
192 [
this](fidl::InterfaceRequest<
193 fuchsia::component::runner::ComponentRunner> request) {
194 component_runner_bindings_.AddBinding(
this, std::move(request));
197#if !defined(DART_PRODUCT)
201 context_->outgoing()->debug_dir()->AddEntry(
203 std::make_unique<dart_utils::VMServiceObject>());
217#if defined(AOT_RUNTIME)
218 params.vm_snapshot_data = ::_kDartVmSnapshotData;
219 params.vm_snapshot_instructions = ::_kDartVmSnapshotInstructions;
222 nullptr,
"/pkg/data/vm_snapshot_data.bin", vm_snapshot_data_)) {
227 params.create_group = IsolateGroupCreateCallback;
228 params.shutdown_isolate = IsolateShutdownCallback;
229 params.cleanup_group = IsolateGroupCleanupCallback;
230 params.entropy_source = EntropySource;
231#if !defined(DART_PRODUCT)
245void DartRunner::Start(
246 fuchsia::component::runner::ComponentStartInfo start_info,
247 fidl::InterfaceRequest<fuchsia::component::runner::ComponentController>
253 std::string url_copy = start_info.resolved_url();
256 RunTestApplication,
this, std::move(start_info), context_->svc(),
257 std::move(controller),
259 [
this](std::shared_ptr<DartTestComponentController> ptr) {
260 test_components_.emplace(ptr.get(), std::move(ptr));
264 auto it = test_components_.find(ptr);
265 if (it != test_components_.end()) {
266 test_components_.erase(it);
271 std::string url_copy = start_info.resolved_url();
273 std::thread thread(RunApplication,
this, std::move(start_info),
274 context_->svc(), std::move(controller));
DartRunner(sys::ComponentContext *context)
static bool LoadFromNamespace(fdio_ns_t *namespc, const std::string &path, MappedResource &resource, bool executable=false)
const uint8_t * address() const
static constexpr const char * kPortDirName
bool GetOptionValue(std::string_view name, std::string *value) const
static DartMicrotaskQueue * GetForCurrentThread()
#define DART_INITIALIZE_PARAMS_CURRENT_VERSION
DART_EXPORT void Dart_ShutdownIsolate(void)
struct _Dart_Isolate * Dart_Isolate
DART_EXPORT DART_WARN_UNUSED_RESULT char * Dart_Initialize(Dart_InitializeParams *params)
DART_EXPORT Dart_Isolate Dart_CurrentIsolate(void)
DART_EXPORT DART_WARN_UNUSED_RESULT char * Dart_Cleanup(void)
#define DART_VM_SERVICE_ISOLATE_NAME
DART_EXPORT DART_WARN_UNUSED_RESULT char * Dart_SetVMFlags(int argc, const char **argv)
const EmbeddedViewParams * params
FlutterSemanticsFlag flags
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
const uint8_t uint32_t uint32_t GError ** error
#define FML_LOG(severity)
Dart_NativeFunction function
constexpr char kArgsKey[]
bool IsTestProgram(const fuchsia::data::Dictionary &program_metadata)
Dart_Handle GetVMServiceAssetsArchiveCallback()
Dart_Isolate CreateServiceIsolate(const char *uri, Dart_IsolateFlags *flags_unused, char **error)
size_t ArraySize(T(&array)[SIZE])
sys::ComponentContext * ComponentContext()
DEF_SWITCHES_START aot vmservice shared library name
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified vm service A custom Dart VM Service port The default is to pick a randomly available open port disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode disable vm service Disable mDNS Dart VM Service publication Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set endless trace buffer
char * strdup(const char *str1)
CommandLine CommandLineFromIterators(InputIterator first, InputIterator last)
#define TRACE_EVENT1(category_group, name, arg1_name, arg1_val)