未验证 提交 76d4928b 编写于 作者: Z Zachary Anderson 提交者: GitHub

Reland: [fuchsia] Enable running from source packages (#4634)

This relands https://github.com/flutter/engine/pull/4629 with a
tonic roll to fix the build.
上级 0f38a059
...@@ -127,7 +127,7 @@ deps = { ...@@ -127,7 +127,7 @@ deps = {
Var('fuchsia_git') + '/garnet' + '@' + 'b3ba6b6d6ab8ef658278cc43c9f839a8a8d1718e', Var('fuchsia_git') + '/garnet' + '@' + 'b3ba6b6d6ab8ef658278cc43c9f839a8a8d1718e',
'src/topaz': 'src/topaz':
Var('fuchsia_git') + '/topaz' + '@' + '1eb2e77be92ed968223b0cea19fe2108e689dcd5', Var('fuchsia_git') + '/topaz' + '@' + '201335048e32db217493141a3ab61137aea60d78',
'src/third_party/benchmark': 'src/third_party/benchmark':
Var('fuchsia_git') + '/third_party/benchmark' + '@' + '296537bc48d380adf21567c5d736ab79f5363d22', Var('fuchsia_git') + '/third_party/benchmark' + '@' + '296537bc48d380adf21567c5d736ab79f5363d22',
......
...@@ -64,6 +64,7 @@ ApplicationControllerImpl::ApplicationControllerImpl( ...@@ -64,6 +64,7 @@ ApplicationControllerImpl::ApplicationControllerImpl(
fdio_ns_t* fdio_ns = SetupNamespace(startup_info->flat_namespace); fdio_ns_t* fdio_ns = SetupNamespace(startup_info->flat_namespace);
if (fdio_ns == nullptr) { if (fdio_ns == nullptr) {
FXL_LOG(ERROR) << "Failed to initialize namespace"; FXL_LOG(ERROR) << "Failed to initialize namespace";
return;
} }
url_ = startup_info->launch_info->url; url_ = startup_info->launch_info->url;
......
...@@ -24,10 +24,12 @@ ...@@ -24,10 +24,12 @@
#include "flutter/runtime/runtime_init.h" #include "flutter/runtime/runtime_init.h"
#include "lib/app/cpp/connect.h" #include "lib/app/cpp/connect.h"
#include "lib/fsl/vmo/vector.h" #include "lib/fsl/vmo/vector.h"
#include "lib/fxl/files/path.h"
#include "lib/fxl/files/unique_fd.h" #include "lib/fxl/files/unique_fd.h"
#include "lib/fxl/functional/make_copyable.h" #include "lib/fxl/functional/make_copyable.h"
#include "lib/fxl/logging.h" #include "lib/fxl/logging.h"
#include "lib/fxl/time/time_delta.h" #include "lib/fxl/time/time_delta.h"
#include "lib/tonic/logging/dart_error.h"
#include "lib/zip/create_unzipper.h" #include "lib/zip/create_unzipper.h"
#include "third_party/dart/runtime/include/dart_api.h" #include "third_party/dart/runtime/include/dart_api.h"
#include "third_party/rapidjson/rapidjson/document.h" #include "third_party/rapidjson/rapidjson/document.h"
...@@ -115,6 +117,11 @@ void RuntimeHolder::Init( ...@@ -115,6 +117,11 @@ void RuntimeHolder::Init(
FXL_DCHECK(rasterizer_); FXL_DCHECK(rasterizer_);
namespc_ = namespc; namespc_ = namespc;
dirfd_ = fdio_ns_opendir(namespc);
if (dirfd_ == -1) {
FXL_LOG(ERROR) << "Failed to get fd for namespace";
return;
}
context_ = std::move(context); context_ = std::move(context);
outgoing_services_ = std::move(outgoing_services); outgoing_services_ = std::move(outgoing_services);
...@@ -196,11 +203,12 @@ void RuntimeHolder::CreateView( ...@@ -196,11 +203,12 @@ void RuntimeHolder::CreateView(
std::vector<uint8_t> kernel; std::vector<uint8_t> kernel;
std::vector<uint8_t> snapshot; std::vector<uint8_t> snapshot;
bool maybe_running_from_source = false;
if (!Dart_IsPrecompiledRuntime()) { if (!Dart_IsPrecompiledRuntime()) {
if (!GetAssetAsBuffer(kKernelKey, &kernel) && if (!GetAssetAsBuffer(kKernelKey, &kernel) &&
!GetAssetAsBuffer(kSnapshotKey, &snapshot)) { !GetAssetAsBuffer(kSnapshotKey, &snapshot)) {
FXL_LOG(ERROR) << "Unable to load kernel or snapshot from root bundle."; maybe_running_from_source = true;
return; FXL_LOG(INFO) << "No kernel or snapshot in root bundle.";
} }
} }
...@@ -273,7 +281,7 @@ void RuntimeHolder::CreateView( ...@@ -273,7 +281,7 @@ void RuntimeHolder::CreateView(
dlsym(dylib_handle_, "_kDartIsolateSnapshotInstructions")); dlsym(dylib_handle_, "_kDartIsolateSnapshotInstructions"));
} }
runtime_->CreateDartController(script_uri, isolate_snapshot_data, runtime_->CreateDartController(script_uri, isolate_snapshot_data,
isolate_snapshot_instr); isolate_snapshot_instr, dirfd_);
runtime_->SetViewportMetrics(viewport_metrics_); runtime_->SetViewportMetrics(viewport_metrics_);
...@@ -281,6 +289,12 @@ void RuntimeHolder::CreateView( ...@@ -281,6 +289,12 @@ void RuntimeHolder::CreateView(
runtime_->dart_controller()->RunFromPrecompiledSnapshot(); runtime_->dart_controller()->RunFromPrecompiledSnapshot();
} else if (!kernel.empty()) { } else if (!kernel.empty()) {
runtime_->dart_controller()->RunFromKernel(std::move(kernel)); runtime_->dart_controller()->RunFromKernel(std::move(kernel));
} else if (maybe_running_from_source) {
std::string basename = files::GetBaseName(script_uri);
std::string main_dart = "pkg/data/" + basename + "/lib/main.dart";
FXL_LOG(INFO) << "Running from source with entrypoint: '" << main_dart
<< "'";
runtime_->dart_controller()->RunFromSource(main_dart, "pkg/data/.packages");
} else { } else {
runtime_->dart_controller()->RunFromScriptSnapshot(snapshot.data(), runtime_->dart_controller()->RunFromScriptSnapshot(snapshot.data(),
snapshot.size()); snapshot.size());
......
...@@ -109,6 +109,7 @@ class RuntimeHolder : public blink::RuntimeDelegate, ...@@ -109,6 +109,7 @@ class RuntimeHolder : public blink::RuntimeDelegate,
void Invalidate(); void Invalidate();
fdio_ns_t* namespc_; fdio_ns_t* namespc_;
int dirfd_;
std::unique_ptr<app::ApplicationContext> context_; std::unique_ptr<app::ApplicationContext> context_;
fidl::InterfaceRequest<app::ServiceProvider> outgoing_services_; fidl::InterfaceRequest<app::ServiceProvider> outgoing_services_;
std::vector<char> root_bundle_data_; std::vector<char> root_bundle_data_;
......
...@@ -15,8 +15,10 @@ namespace blink { ...@@ -15,8 +15,10 @@ namespace blink {
IsolateClient::~IsolateClient() {} IsolateClient::~IsolateClient() {}
UIDartState::UIDartState(IsolateClient* isolate_client, UIDartState::UIDartState(IsolateClient* isolate_client,
std::unique_ptr<Window> window) std::unique_ptr<Window> window,
: isolate_client_(isolate_client), int dirfd)
: tonic::DartState(dirfd),
isolate_client_(isolate_client),
main_port_(ILLEGAL_PORT), main_port_(ILLEGAL_PORT),
window_(std::move(window)) {} window_(std::move(window)) {}
......
...@@ -28,7 +28,9 @@ class IsolateClient { ...@@ -28,7 +28,9 @@ class IsolateClient {
class UIDartState : public tonic::DartState { class UIDartState : public tonic::DartState {
public: public:
UIDartState(IsolateClient* isolate_client, std::unique_ptr<Window> window); UIDartState(IsolateClient* isolate_client,
std::unique_ptr<Window> window,
int dirfd = -1);
~UIDartState() override; ~UIDartState() override;
static UIDartState* Current(); static UIDartState* Current();
......
...@@ -29,13 +29,15 @@ RuntimeController::~RuntimeController() {} ...@@ -29,13 +29,15 @@ RuntimeController::~RuntimeController() {}
void RuntimeController::CreateDartController( void RuntimeController::CreateDartController(
const std::string& script_uri, const std::string& script_uri,
const uint8_t* isolate_snapshot_data, const uint8_t* isolate_snapshot_data,
const uint8_t* isolate_snapshot_instr) { const uint8_t* isolate_snapshot_instr,
int dirfd) {
FXL_DCHECK(!dart_controller_); FXL_DCHECK(!dart_controller_);
dart_controller_.reset(new DartController()); dart_controller_.reset(new DartController());
dart_controller_->CreateIsolateFor( dart_controller_->CreateIsolateFor(
script_uri, isolate_snapshot_data, isolate_snapshot_instr, script_uri, isolate_snapshot_data, isolate_snapshot_instr,
std::make_unique<UIDartState>(this, std::make_unique<Window>(this))); std::make_unique<UIDartState>(this, std::make_unique<Window>(this),
dirfd));
UIDartState* dart_state = dart_controller_->dart_state(); UIDartState* dart_state = dart_controller_->dart_state();
DartState::Scope scope(dart_state); DartState::Scope scope(dart_state);
......
...@@ -28,7 +28,8 @@ class RuntimeController : public WindowClient, public IsolateClient { ...@@ -28,7 +28,8 @@ class RuntimeController : public WindowClient, public IsolateClient {
void CreateDartController(const std::string& script_uri, void CreateDartController(const std::string& script_uri,
const uint8_t* isolate_snapshot_data, const uint8_t* isolate_snapshot_data,
const uint8_t* isolate_snapshot_instr); const uint8_t* isolate_snapshot_instr,
int dirfd = -1);
DartController* dart_controller() const { return dart_controller_.get(); } DartController* dart_controller() const { return dart_controller_.get(); }
void SetViewportMetrics(const ViewportMetrics& metrics); void SetViewportMetrics(const ViewportMetrics& metrics);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册