Sync dart_runner (flutter/engine#12375)
This commit is contained in:
@@ -53,9 +53,12 @@ template("runner") {
|
||||
"$flutter_root/shell/platform/fuchsia/dart-pkg/fuchsia",
|
||||
"$flutter_root/shell/platform/fuchsia/dart-pkg/zircon",
|
||||
"$flutter_root/shell/platform/fuchsia/runtime/dart/utils",
|
||||
"$fuchsia_sdk_root/pkg:async",
|
||||
"$fuchsia_sdk_root/pkg:async-cpp",
|
||||
"$fuchsia_sdk_root/pkg:async-default",
|
||||
"$fuchsia_sdk_root/pkg:async-loop",
|
||||
"$fuchsia_sdk_root/pkg:async-loop-cpp",
|
||||
"$fuchsia_sdk_root/pkg:async-loop-default",
|
||||
"$fuchsia_sdk_root/pkg:fidl_cpp",
|
||||
"$fuchsia_sdk_root/pkg:sys_cpp",
|
||||
"$fuchsia_sdk_root/pkg:syslog",
|
||||
|
||||
@@ -56,6 +56,11 @@ void AfterTask(async_loop_t*, void*) {
|
||||
}
|
||||
|
||||
constexpr async_loop_config_t kLoopConfig = {
|
||||
.default_accessors =
|
||||
{
|
||||
.getter = async_get_default_dispatcher,
|
||||
.setter = async_set_default_dispatcher,
|
||||
},
|
||||
.make_default_for_current_thread = true,
|
||||
.epilogue = &AfterTask,
|
||||
};
|
||||
@@ -157,7 +162,7 @@ bool DartComponentController::SetupNamespace() {
|
||||
return false;
|
||||
}
|
||||
|
||||
dart_utils::SetupComponentTemp(namespace_);
|
||||
dart_utils::RunnerTemp::SetupComponent(namespace_);
|
||||
|
||||
for (size_t i = 0; i < flat->paths.size(); ++i) {
|
||||
if (flat->paths.at(i) == kTmpPath) {
|
||||
|
||||
@@ -28,4 +28,4 @@ import 'package:lib.app.dart/app.dart';
|
||||
import 'package:fidl/fidl.dart';
|
||||
|
||||
// From //sdk/fidl/fuchsia.modular
|
||||
import 'package:fidl_fuchsia_modular/fidl.dart';
|
||||
import 'package:fidl_fuchsia_modular/fidl_async.dart';
|
||||
|
||||
@@ -40,16 +40,16 @@ void main(List<String> args) {
|
||||
|
||||
test('communicate with a fidl service (hello_app_dart)', () async {
|
||||
final HelloProxy service = HelloProxy();
|
||||
final dirProxy = DirectoryProxy();
|
||||
final incoming = Incoming();
|
||||
|
||||
final ComponentControllerProxy actl = ComponentControllerProxy();
|
||||
|
||||
final LaunchInfo info = LaunchInfo(
|
||||
url:
|
||||
'fuchsia-pkg://fuchsia.com/hello_app_dart_jit#meta/hello_app_dart_jit.cmx',
|
||||
directoryRequest: dirProxy.ctrl.request().passChannel());
|
||||
directoryRequest: incoming.request().passChannel());
|
||||
await launcher.createComponent(info, actl.ctrl.request());
|
||||
Incoming(dirProxy).connectToService(service);
|
||||
incoming.connectToService(service);
|
||||
|
||||
expect(await service.say('hello'), equals('hola from Dart!'));
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include <lib/async-loop/cpp/loop.h>
|
||||
#include <lib/async-loop/default.h>
|
||||
#include <lib/trace-provider/provider.h>
|
||||
#include <lib/trace/event.h>
|
||||
|
||||
@@ -33,7 +34,7 @@ static void RegisterProfilerSymbols(const char* symbols_path,
|
||||
#endif // !defined(DART_PRODUCT)
|
||||
|
||||
int main(int argc, const char** argv) {
|
||||
async::Loop loop(&kAsyncLoopConfigAttachToThread);
|
||||
async::Loop loop(&kAsyncLoopConfigAttachToCurrentThread);
|
||||
|
||||
#if !defined(FUCHSIA_SDK)
|
||||
syslog::InitLogger();
|
||||
@@ -61,8 +62,7 @@ int main(int argc, const char** argv) {
|
||||
#endif // defined(AOT_RUNTIME)
|
||||
#endif // !defined(DART_PRODUCT)
|
||||
|
||||
dart_utils::SetupRunnerTemp();
|
||||
|
||||
dart_utils::RunnerTemp runner_temp;
|
||||
dart_runner::DartRunner runner;
|
||||
loop.Run();
|
||||
return 0;
|
||||
|
||||
@@ -110,7 +110,7 @@ Application::Application(
|
||||
}
|
||||
|
||||
// Setup /tmp to be mapped to the process-local memfs.
|
||||
dart_utils::SetupComponentTemp(fdio_ns_.get());
|
||||
dart_utils::RunnerTemp::SetupComponent(fdio_ns_.get());
|
||||
|
||||
// LaunchInfo::flat_namespace optional.
|
||||
for (size_t i = 0; i < startup_info.flat_namespace.paths.size(); ++i) {
|
||||
|
||||
@@ -25,7 +25,7 @@ int main(int argc, char const* argv[]) {
|
||||
}
|
||||
|
||||
// Set up the process-wide /tmp memfs.
|
||||
dart_utils::SetupRunnerTemp();
|
||||
dart_utils::RunnerTemp runner_temp;
|
||||
|
||||
FML_DLOG(INFO) << "Flutter application services initialized.";
|
||||
|
||||
|
||||
@@ -31,6 +31,7 @@ source_set("utils") {
|
||||
"$fuchsia_sdk_root/fidl:fuchsia.mem",
|
||||
"$fuchsia_sdk_root/pkg:async-loop",
|
||||
"$fuchsia_sdk_root/pkg:async-loop-cpp",
|
||||
"$fuchsia_sdk_root/pkg:async-loop-default",
|
||||
"$fuchsia_sdk_root/pkg:fdio",
|
||||
"$fuchsia_sdk_root/pkg:memfs",
|
||||
"$fuchsia_sdk_root/pkg:syslog",
|
||||
|
||||
@@ -4,10 +4,13 @@
|
||||
|
||||
#include "runtime/dart/utils/tempfs.h"
|
||||
|
||||
#include <future>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
|
||||
#include <lib/async-loop/cpp/loop.h>
|
||||
#include <lib/async-loop/default.h>
|
||||
#include <lib/async/cpp/task.h>
|
||||
#include <lib/fdio/namespace.h>
|
||||
#include <lib/memfs/memfs.h>
|
||||
#include <lib/syslog/global.h>
|
||||
@@ -22,36 +25,41 @@ namespace {
|
||||
constexpr char kTmpPath[] = "/tmp";
|
||||
[[maybe_unused]] constexpr size_t kMaxTmpPages = 1024;
|
||||
|
||||
void DispatchTempMemFS() {
|
||||
async::Loop loop(&kAsyncLoopConfigAttachToThread);
|
||||
#if defined(DART_PRODUCT)
|
||||
zx_status_t status = memfs_install_at_with_page_limit(loop.dispatcher(),
|
||||
kMaxTmpPages, kTmpPath);
|
||||
#else
|
||||
// Hot reload uses /tmp to hold the updated dills and assets so do not
|
||||
// impose any size limitation in non product runners.
|
||||
zx_status_t status = memfs_install_at(loop.dispatcher(), kTmpPath);
|
||||
#endif
|
||||
if (status != ZX_OK) {
|
||||
FX_LOGF(ERROR, LOG_TAG, "Failed to install a /tmp memfs: %s",
|
||||
zx_status_get_string(status));
|
||||
return;
|
||||
}
|
||||
loop.Run();
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
namespace dart_utils {
|
||||
|
||||
// Set up a memfs bound to /tmp in the process-wide namespace that has the
|
||||
// lifetime of the process.
|
||||
void SetupRunnerTemp() {
|
||||
std::thread thread(DispatchTempMemFS);
|
||||
thread.detach();
|
||||
RunnerTemp::RunnerTemp()
|
||||
: loop_(std::make_unique<async::Loop>(
|
||||
&kAsyncLoopConfigNoAttachToCurrentThread)) {
|
||||
loop_->StartThread("RunnerTemp");
|
||||
Start();
|
||||
}
|
||||
|
||||
void SetupComponentTemp(fdio_ns_t* ns) {
|
||||
RunnerTemp::~RunnerTemp() = default;
|
||||
|
||||
void RunnerTemp::Start() {
|
||||
std::promise<void> finished;
|
||||
async::PostTask(loop_->dispatcher(), [this, &finished]() {
|
||||
#if defined(DART_PRODUCT)
|
||||
zx_status_t status = memfs_install_at_with_page_limit(
|
||||
loop_->dispatcher(), kMaxTmpPages, kTmpPath);
|
||||
#else
|
||||
// Hot reload uses /tmp to hold the updated dills and assets so do not
|
||||
// impose any size limitation in non product runners.
|
||||
zx_status_t status = memfs_install_at(loop_->dispatcher(), kTmpPath);
|
||||
#endif
|
||||
finished.set_value();
|
||||
if (status != ZX_OK) {
|
||||
FX_LOGF(ERROR, LOG_TAG, "Failed to install a /tmp memfs: %s",
|
||||
zx_status_get_string(status));
|
||||
return;
|
||||
}
|
||||
});
|
||||
finished.get_future().wait();
|
||||
}
|
||||
|
||||
void RunnerTemp::SetupComponent(fdio_ns_t* ns) {
|
||||
// TODO(zra): Should isolates share a /tmp file system within a process, or
|
||||
// should isolates each get their own private memfs for /tmp? For now,
|
||||
// sharing the process-wide /tmp simplifies hot reload since the hot reload
|
||||
|
||||
@@ -5,19 +5,34 @@
|
||||
#ifndef FLUTTER_SHELL_PLATFORM_FUCHSIA_RUNTIME_DART_UTILS_TEMPFS_H_
|
||||
#define FLUTTER_SHELL_PLATFORM_FUCHSIA_RUNTIME_DART_UTILS_TEMPFS_H_
|
||||
|
||||
#include <lib/fdio/namespace.h>
|
||||
#include <mutex>
|
||||
|
||||
// Utility functions that set up /tmp for the dart_runner and flutter_runner.
|
||||
#include <lib/async-loop/cpp/loop.h>
|
||||
#include <lib/fdio/namespace.h>
|
||||
|
||||
namespace dart_utils {
|
||||
|
||||
// Set up a memfs bound to /tmp in the process-wide namespace that has the
|
||||
// lifetime of the process.
|
||||
void SetupRunnerTemp();
|
||||
// Sets up /tmp for the dart_runner and flutter_runner.
|
||||
class RunnerTemp {
|
||||
public:
|
||||
// Sets up a memfs bound to /tmp in the process-wide namespace that has the
|
||||
// lifetime of this instance.
|
||||
RunnerTemp();
|
||||
~RunnerTemp();
|
||||
|
||||
// Take the memfs mapped into the process-wide namespace for /tmp, and map it to
|
||||
// /tmp in the given namespace.
|
||||
void SetupComponentTemp(fdio_ns_t* ns);
|
||||
// Take the memfs mapped into the process-wide namespace for /tmp, and map it
|
||||
// to /tmp in the given namespace.
|
||||
static void SetupComponent(fdio_ns_t* ns);
|
||||
|
||||
private:
|
||||
void Start();
|
||||
|
||||
std::unique_ptr<async::Loop> loop_;
|
||||
|
||||
// Disallow copy and assignment.
|
||||
RunnerTemp(const RunnerTemp&) = delete;
|
||||
RunnerTemp& operator=(const RunnerTemp&) = delete;
|
||||
};
|
||||
|
||||
} // namespace dart_utils
|
||||
|
||||
|
||||
Reference in New Issue
Block a user