[dart_runner,flutter_runner] Expose debug ports as a regular directory.
This usage of inspect was unfortunately blocking a migration away from
VFS for libinspect. This change modifies the dart debug port use case to
instead use LazyDir directly rather than inspect.
TEST=fx run-test run_vmservice_object_tests
CF-255: #comment
Change-Id: If4bd5fc8f35bf8c7ab9a64a31cf1e1c1c97bfb4a
diff --git a/runtime/dart/utils/BUILD.gn b/runtime/dart/utils/BUILD.gn
index 7d17da3..742becb 100644
--- a/runtime/dart/utils/BUILD.gn
+++ b/runtime/dart/utils/BUILD.gn
@@ -15,7 +15,7 @@
]
public_deps = [
- "//garnet/public/lib/component/cpp",
+ "//zircon/public/lib/fs",
"//zircon/public/lib/zx",
]
diff --git a/runtime/dart/utils/run_vmservice_object_tests.sh b/runtime/dart/utils/run_vmservice_object_tests.sh
index 5a8316c..209e008 100644
--- a/runtime/dart/utils/run_vmservice_object_tests.sh
+++ b/runtime/dart/utils/run_vmservice_object_tests.sh
@@ -7,7 +7,7 @@
# Start up a dart runner app that is guaranteed to be JIT, non-product, and
# won't terminate.
-run hello_dart_jit &
+run -d hello_dart_jit
# Wait for it to come up.
sleep 2
diff --git a/runtime/dart/utils/vmservice_object.cc b/runtime/dart/utils/vmservice_object.cc
index 2c1fd21..6cbcd24 100644
--- a/runtime/dart/utils/vmservice_object.cc
+++ b/runtime/dart/utils/vmservice_object.cc
@@ -7,41 +7,34 @@
#include <errno.h>
#include <zircon/status.h>
-#include "lib/component/cpp/exposed_object.h"
#include "lib/fxl/files/directory.h"
#include "lib/fxl/files/file.h"
+#include <string>
+
namespace fuchsia {
namespace dart {
-VMServiceObject::VMServiceObject() : ExposedObject(kDirName) {
- // This code exposes the contents of /${kPortDir} in the hub for the
- // dart_runner at /hub/.../out/objects/${kDirName}/${kPortDirName}.
- object_dir().set_children_callback(component::ObjectPath{kPortDirName},
- [](component::Object::ObjectVector* out_children){
- // List /tmp/dart.services if it exists, and push its contents as
- // component::Objects onto out_children.
- std::vector<std::string> files;
- if (!files::ReadDirContents(kPortDir, &files)) {
- FXL_LOG(ERROR) << "Failed to read Dart VM Service port directory '"
- << kPortDir << "':"
- << strerror(errno);
- return;
+void VMServiceObject::GetContents(LazyEntryVector* out_vector) {
+ // List /tmp/dart.services if it exists, and push its contents as
+ // as the conrtents of this directory.
+ std::vector<std::string> files;
+ if (!files::ReadDirContents(kPortDir, &files)) {
+ FXL_LOG(ERROR) << "Failed to read Dart VM Service port directory '"
+ << kPortDir << "':" << strerror(errno);
+ return;
+ }
+ for (const auto& file : files) {
+ if ((file == ".") || (file == "..")) {
+ continue;
}
- for (const auto& file : files) {
- if ((file == ".") || (file == "..")) {
- continue;
- }
- out_children->push_back(component::ObjectDir::Make(file).object());
- }
- });
+ out_vector->push_back({std::stoul(file), file, V_TYPE_FILE});
+ }
}
-std::unique_ptr<VMServiceObject> VMServiceObject::Create(
- component::ObjectDir* object_dir) {
- auto vmservice = std::make_unique<VMServiceObject>();
- vmservice->set_parent(*object_dir);
- return vmservice;
+zx_status_t VMServiceObject::GetFile(fbl::RefPtr<fs::Vnode>* out, uint64_t id,
+ fbl::String name) {
+ return ZX_ERR_NOT_FOUND;
}
} // namespace dart
diff --git a/runtime/dart/utils/vmservice_object.h b/runtime/dart/utils/vmservice_object.h
index 68c3124..2580106 100644
--- a/runtime/dart/utils/vmservice_object.h
+++ b/runtime/dart/utils/vmservice_object.h
@@ -5,24 +5,23 @@
#ifndef TOPAZ_RUNTIME_DART_UTILS_VMSERVICE_OBJECT_H_
#define TOPAZ_RUNTIME_DART_UTILS_VMSERVICE_OBJECT_H_
-#include "lib/component/cpp/exposed_object.h"
+#include <fs/lazy-dir.h>
namespace fuchsia {
namespace dart {
-class VMServiceObject : public component::ExposedObject {
+class VMServiceObject : public fs::LazyDir {
public:
static constexpr const char* kDirName = "DartVM";
static constexpr const char* kPortDirName = "vmservice-port";
static constexpr const char* kPortDir = "/tmp/dart.services";
- VMServiceObject();
-
- static std::unique_ptr<VMServiceObject> Create(
- component::ObjectDir* object_dir);
+ void GetContents(LazyEntryVector* out_vector) override;
+ zx_status_t GetFile(fbl::RefPtr<Vnode>* out, uint64_t id,
+ fbl::String name) override;
};
} // namespace dart
} // namespace fuchsia
-#endif // TOPAZ_RUNTIME_UTILS_VMSERVICE_OBJECT_H_
+#endif // TOPAZ_RUNTIME_DART_UTILS_VMSERVICE_OBJECT_H_
diff --git a/runtime/dart_runner/dart_runner.cc b/runtime/dart_runner/dart_runner.cc
index f2ccc14..2a3254a 100644
--- a/runtime/dart_runner/dart_runner.cc
+++ b/runtime/dart_runner/dart_runner.cc
@@ -6,20 +6,20 @@
#include <errno.h>
#include <sys/stat.h>
-#include <thread>
#include <trace/event.h>
-#include <utility>
#include <zircon/status.h>
#include <zircon/syscalls.h>
+#include <thread>
+#include <utility>
#include "lib/fxl/arraysize.h"
+#include "third_party/dart/runtime/include/bin/dart_io_api.h"
#include "third_party/tonic/dart_microtask_queue.h"
#include "third_party/tonic/dart_state.h"
-#include "third_party/dart/runtime/include/bin/dart_io_api.h"
#include "topaz/lib/deprecated_loop/message_loop.h"
+#include "topaz/runtime/dart/utils/vmservice_object.h"
#include "topaz/runtime/dart_runner/dart_component_controller.h"
#include "topaz/runtime/dart_runner/service_isolate.h"
-#include "topaz/runtime/dart/utils/vmservice_object.h"
#if defined(AOT_RUNTIME)
extern "C" uint8_t _kDartVmSnapshotData[];
@@ -72,7 +72,8 @@
void IsolateShutdownCallback(void* callback_data) {
// The service isolate (and maybe later the kernel isolate) doesn't have an
// deprecated_loop::MessageLoop.
- deprecated_loop::MessageLoop* loop = deprecated_loop::MessageLoop::GetCurrent();
+ deprecated_loop::MessageLoop* loop =
+ deprecated_loop::MessageLoop::GetCurrent();
if (loop) {
loop->SetAfterTaskCallback(nullptr);
tonic::DartMicrotaskQueue::GetForCurrentThread()->Destroy();
@@ -150,8 +151,9 @@
// The VM service isolate uses the process-wide namespace. It writes the
// vm service protocol port under /tmp. The VMServiceObject exposes that
// port number to The Hub.
- vmservice_object_ = fuchsia::dart::VMServiceObject::Create(
- context_->outgoing().object_dir());
+ context_->outgoing().debug_dir()->AddEntry(
+ fuchsia::dart::VMServiceObject::kPortDirName,
+ fbl::AdoptRef(new fuchsia::dart::VMServiceObject()));
#endif // !defined(DART_PRODUCT)
diff --git a/runtime/dart_runner/dart_runner.h b/runtime/dart_runner/dart_runner.h
index 38cbf60..5a4b24c 100644
--- a/runtime/dart_runner/dart_runner.h
+++ b/runtime/dart_runner/dart_runner.h
@@ -12,7 +12,6 @@
#include "lib/fxl/macros.h"
#include "topaz/lib/deprecated_loop/message_loop.h"
#include "topaz/runtime/dart_runner/mapped_resource.h"
-#include "topaz/runtime/dart/utils/vmservice_object.h"
namespace dart_runner {
@@ -36,10 +35,10 @@
private:
// |fuchsia::sys::Runner| implementation:
- void StartComponent(fuchsia::sys::Package package,
- fuchsia::sys::StartupInfo startup_info,
- ::fidl::InterfaceRequest<fuchsia::sys::ComponentController>
- controller) override;
+ void StartComponent(
+ fuchsia::sys::Package package, fuchsia::sys::StartupInfo startup_info,
+ ::fidl::InterfaceRequest<fuchsia::sys::ComponentController> controller)
+ override;
ControllerToken* AddController(std::string label);
void RemoveController(ControllerToken* token);
@@ -50,11 +49,6 @@
fidl::BindingSet<fuchsia::sys::Runner> bindings_;
std::vector<ControllerToken*> controllers_;
-#if !defined(DART_PRODUCT)
- // The connection between the Dart VM service and The Hub.
- std::unique_ptr<fuchsia::dart::VMServiceObject> vmservice_object_;
-#endif // !defined(DART_PRODUCT)
-
#if !defined(AOT_RUNTIME)
MappedResource vm_snapshot_data_;
MappedResource vm_snapshot_instructions_;
diff --git a/runtime/flutter_runner/runner.cc b/runtime/flutter_runner/runner.cc
index d25f167..7f529d0 100644
--- a/runtime/flutter_runner/runner.cc
+++ b/runtime/flutter_runner/runner.cc
@@ -43,8 +43,9 @@
// The VM service isolate uses the process-wide namespace. It writes the
// vm service protocol port under /tmp. The VMServiceObject exposes that
// port number to The Hub.
- vmservice_object_ = fuchsia::dart::VMServiceObject::Create(
- host_context_->outgoing().object_dir());
+ host_context_->outgoing().debug_dir()->AddEntry(
+ fuchsia::dart::VMServiceObject::kPortDirName,
+ fbl::AdoptRef(new fuchsia::dart::VMServiceObject()));
#endif // !defined(DART_PRODUCT)
SkGraphics::Init();
@@ -55,12 +56,16 @@
SetThreadName("io.flutter.runner.main");
- host_context_->outgoing().deprecated_services()->AddService<fuchsia::sys::Runner>(
- std::bind(&Runner::RegisterApplication, this, std::placeholders::_1));
+ host_context_->outgoing()
+ .deprecated_services()
+ ->AddService<fuchsia::sys::Runner>(
+ std::bind(&Runner::RegisterApplication, this, std::placeholders::_1));
}
Runner::~Runner() {
- host_context_->outgoing().deprecated_services()->RemoveService<fuchsia::sys::Runner>();
+ host_context_->outgoing()
+ .deprecated_services()
+ ->RemoveService<fuchsia::sys::Runner>();
}
void Runner::RegisterApplication(