mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Exit the non-interactive sky_shell on Linux when the Dart script has completed (#3358)
The script will be finished when the microtask queue has been drained and Dart_HasLivePorts is returning false for the main isolate
This commit is contained in:
parent
16b2964f5c
commit
fdcd65eedd
@ -137,4 +137,16 @@ std::string RuntimeController::GetIsolateName() {
|
||||
return dart_controller_->dart_state()->debug_name();
|
||||
}
|
||||
|
||||
bool RuntimeController::HasLivePorts() {
|
||||
if (!dart_controller_) {
|
||||
return false;
|
||||
}
|
||||
UIDartState* dart_state = dart_controller_->dart_state();
|
||||
if (!dart_state) {
|
||||
return false;
|
||||
}
|
||||
DartState::Scope scope(dart_state);
|
||||
return Dart_HasLivePorts();
|
||||
}
|
||||
|
||||
} // namespace blink
|
||||
|
||||
@ -44,6 +44,8 @@ class RuntimeController : public WindowClient, public IsolateClient {
|
||||
|
||||
std::string GetIsolateName();
|
||||
|
||||
bool HasLivePorts();
|
||||
|
||||
private:
|
||||
explicit RuntimeController(RuntimeDelegate* client);
|
||||
|
||||
|
||||
@ -155,6 +155,12 @@ std::string Engine::GetUIIsolateName() {
|
||||
return runtime_->GetIsolateName();
|
||||
}
|
||||
|
||||
bool Engine::UIIsolateHasLivePorts() {
|
||||
if (!runtime_)
|
||||
return false;
|
||||
return runtime_->HasLivePorts();
|
||||
}
|
||||
|
||||
void Engine::OnOutputSurfaceCreated(const ftl::Closure& gpu_continuation) {
|
||||
blink::Threads::Gpu()->PostTask(gpu_continuation);
|
||||
have_surface_ = true;
|
||||
|
||||
@ -59,6 +59,8 @@ class Engine : public blink::RuntimeDelegate {
|
||||
|
||||
std::string GetUIIsolateName();
|
||||
|
||||
bool UIIsolateHasLivePorts();
|
||||
|
||||
void OnOutputSurfaceCreated(const ftl::Closure& gpu_continuation);
|
||||
void OnOutputSurfaceDestroyed(const ftl::Closure& gpu_continuation);
|
||||
void SetViewportMetrics(const blink::ViewportMetrics& metrics);
|
||||
|
||||
@ -14,22 +14,57 @@
|
||||
#include "flutter/shell/gpu/gpu_surface_gl.h"
|
||||
#include "flutter/shell/platform/linux/message_pump_glfw.h"
|
||||
#include "flutter/shell/platform/linux/platform_view_glfw.h"
|
||||
#include "flutter/shell/testing/test_runner.h"
|
||||
#include "flutter/shell/testing/testing.h"
|
||||
#include "flutter/sky/engine/public/web/Sky.h"
|
||||
|
||||
namespace {
|
||||
|
||||
int RunNonInteractive() {
|
||||
// Checks whether the engine's main Dart isolate has no pending work. If so,
|
||||
// then exit the given message loop.
|
||||
class ScriptCompletionTaskObserver : public base::MessageLoop::TaskObserver {
|
||||
public:
|
||||
ScriptCompletionTaskObserver(base::MessageLoop& main_message_loop)
|
||||
: main_message_loop_(main_message_loop), prev_live_(false) {}
|
||||
|
||||
void WillProcessTask(const base::PendingTask& pending_task) override {}
|
||||
|
||||
void DidProcessTask(const base::PendingTask& pending_task) override {
|
||||
shell::TestRunner& test_runner = shell::TestRunner::Shared();
|
||||
bool live = test_runner.platform_view().engine().UIIsolateHasLivePorts();
|
||||
if (prev_live_ && !live)
|
||||
main_message_loop_.PostTask(FROM_HERE,
|
||||
main_message_loop_.QuitWhenIdleClosure());
|
||||
prev_live_ = live;
|
||||
}
|
||||
|
||||
private:
|
||||
base::MessageLoop& main_message_loop_;
|
||||
bool prev_live_;
|
||||
};
|
||||
|
||||
void RunNonInteractive() {
|
||||
base::MessageLoop message_loop;
|
||||
|
||||
shell::Shell::InitStandalone();
|
||||
|
||||
// Note that this task observer must be added after the observer that drains
|
||||
// the microtask queue.
|
||||
ScriptCompletionTaskObserver task_observer(message_loop);
|
||||
blink::Threads::UI()->PostTask([&task_observer] {
|
||||
base::MessageLoop::current()->AddTaskObserver(&task_observer);
|
||||
});
|
||||
|
||||
if (!shell::InitForTesting()) {
|
||||
shell::PrintUsage("sky_shell");
|
||||
return 1;
|
||||
exit(1);
|
||||
}
|
||||
|
||||
message_loop.Run();
|
||||
return 0;
|
||||
|
||||
// The script has completed and the engine may not be in a clean state,
|
||||
// so just stop the process.
|
||||
exit(0);
|
||||
}
|
||||
|
||||
static bool IsDartFile(const std::string& path) {
|
||||
@ -98,7 +133,8 @@ int main(int argc, const char* argv[]) {
|
||||
|
||||
if (command_line.HasSwitch(
|
||||
shell::FlagForSwitch(shell::Switch::NonInteractive))) {
|
||||
return RunNonInteractive();
|
||||
RunNonInteractive();
|
||||
return 0;
|
||||
}
|
||||
|
||||
return RunInteractive();
|
||||
|
||||
@ -26,6 +26,8 @@ class TestRunner {
|
||||
|
||||
void Run(const TestDescriptor& test);
|
||||
|
||||
PlatformView& platform_view() { return *platform_view_; }
|
||||
|
||||
private:
|
||||
TestRunner();
|
||||
~TestRunner();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user