Skip to content

Commit

Permalink
Reland: [fuchsia] Enable running from source packages (flutter#4634)
Browse files Browse the repository at this point in the history
This relands flutter#4629 with a
tonic roll to fix the build.
  • Loading branch information
zanderso authored Feb 6, 2018
1 parent 0f38a05 commit 76d4928
Show file tree
Hide file tree
Showing 9 changed files with 310 additions and 45 deletions.
2 changes: 1 addition & 1 deletion DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ deps = {
Var('fuchsia_git') + '/garnet' + '@' + 'b3ba6b6d6ab8ef658278cc43c9f839a8a8d1718e',

'src/topaz':
Var('fuchsia_git') + '/topaz' + '@' + '1eb2e77be92ed968223b0cea19fe2108e689dcd5',
Var('fuchsia_git') + '/topaz' + '@' + '201335048e32db217493141a3ab61137aea60d78',

'src/third_party/benchmark':
Var('fuchsia_git') + '/third_party/benchmark' + '@' + '296537bc48d380adf21567c5d736ab79f5363d22',
Expand Down
1 change: 1 addition & 0 deletions content_handler/application_controller_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ ApplicationControllerImpl::ApplicationControllerImpl(
fdio_ns_t* fdio_ns = SetupNamespace(startup_info->flat_namespace);
if (fdio_ns == nullptr) {
FXL_LOG(ERROR) << "Failed to initialize namespace";
return;
}

url_ = startup_info->launch_info->url;
Expand Down
20 changes: 17 additions & 3 deletions content_handler/runtime_holder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@
#include "flutter/runtime/runtime_init.h"
#include "lib/app/cpp/connect.h"
#include "lib/fsl/vmo/vector.h"
#include "lib/fxl/files/path.h"
#include "lib/fxl/files/unique_fd.h"
#include "lib/fxl/functional/make_copyable.h"
#include "lib/fxl/logging.h"
#include "lib/fxl/time/time_delta.h"
#include "lib/tonic/logging/dart_error.h"
#include "lib/zip/create_unzipper.h"
#include "third_party/dart/runtime/include/dart_api.h"
#include "third_party/rapidjson/rapidjson/document.h"
Expand Down Expand Up @@ -115,6 +117,11 @@ void RuntimeHolder::Init(
FXL_DCHECK(rasterizer_);

namespc_ = namespc;
dirfd_ = fdio_ns_opendir(namespc);
if (dirfd_ == -1) {
FXL_LOG(ERROR) << "Failed to get fd for namespace";
return;
}
context_ = std::move(context);
outgoing_services_ = std::move(outgoing_services);

Expand Down Expand Up @@ -196,11 +203,12 @@ void RuntimeHolder::CreateView(

std::vector<uint8_t> kernel;
std::vector<uint8_t> snapshot;
bool maybe_running_from_source = false;
if (!Dart_IsPrecompiledRuntime()) {
if (!GetAssetAsBuffer(kKernelKey, &kernel) &&
!GetAssetAsBuffer(kSnapshotKey, &snapshot)) {
FXL_LOG(ERROR) << "Unable to load kernel or snapshot from root bundle.";
return;
maybe_running_from_source = true;
FXL_LOG(INFO) << "No kernel or snapshot in root bundle.";
}
}

Expand Down Expand Up @@ -273,14 +281,20 @@ void RuntimeHolder::CreateView(
dlsym(dylib_handle_, "_kDartIsolateSnapshotInstructions"));
}
runtime_->CreateDartController(script_uri, isolate_snapshot_data,
isolate_snapshot_instr);
isolate_snapshot_instr, dirfd_);

runtime_->SetViewportMetrics(viewport_metrics_);

if (Dart_IsPrecompiledRuntime()) {
runtime_->dart_controller()->RunFromPrecompiledSnapshot();
} else if (!kernel.empty()) {
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 {
runtime_->dart_controller()->RunFromScriptSnapshot(snapshot.data(),
snapshot.size());
Expand Down
1 change: 1 addition & 0 deletions content_handler/runtime_holder.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ class RuntimeHolder : public blink::RuntimeDelegate,
void Invalidate();

fdio_ns_t* namespc_;
int dirfd_;
std::unique_ptr<app::ApplicationContext> context_;
fidl::InterfaceRequest<app::ServiceProvider> outgoing_services_;
std::vector<char> root_bundle_data_;
Expand Down
6 changes: 4 additions & 2 deletions lib/ui/ui_dart_state.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ namespace blink {
IsolateClient::~IsolateClient() {}

UIDartState::UIDartState(IsolateClient* isolate_client,
std::unique_ptr<Window> window)
: isolate_client_(isolate_client),
std::unique_ptr<Window> window,
int dirfd)
: tonic::DartState(dirfd),
isolate_client_(isolate_client),
main_port_(ILLEGAL_PORT),
window_(std::move(window)) {}

Expand Down
4 changes: 3 additions & 1 deletion lib/ui/ui_dart_state.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ class IsolateClient {

class UIDartState : public tonic::DartState {
public:
UIDartState(IsolateClient* isolate_client, std::unique_ptr<Window> window);
UIDartState(IsolateClient* isolate_client,
std::unique_ptr<Window> window,
int dirfd = -1);
~UIDartState() override;

static UIDartState* Current();
Expand Down
6 changes: 4 additions & 2 deletions runtime/runtime_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,15 @@ RuntimeController::~RuntimeController() {}
void RuntimeController::CreateDartController(
const std::string& script_uri,
const uint8_t* isolate_snapshot_data,
const uint8_t* isolate_snapshot_instr) {
const uint8_t* isolate_snapshot_instr,
int dirfd) {
FXL_DCHECK(!dart_controller_);

dart_controller_.reset(new DartController());
dart_controller_->CreateIsolateFor(
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();
DartState::Scope scope(dart_state);
Expand Down
3 changes: 2 additions & 1 deletion runtime/runtime_controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ class RuntimeController : public WindowClient, public IsolateClient {

void CreateDartController(const std::string& script_uri,
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(); }

void SetViewportMetrics(const ViewportMetrics& metrics);
Expand Down
Loading

0 comments on commit 76d4928

Please sign in to comment.