From 15df8436d173616e12a2e42417de07f8266dd977 Mon Sep 17 00:00:00 2001 From: Jason Simmons Date: Wed, 25 Jan 2017 12:06:23 -0800 Subject: [PATCH] Add a flag to sky_shell that keeps the process alive after the Dart script completes (flutter/engine#3363) --- engine/src/flutter/shell/common/switches.h | 4 ++++ .../src/flutter/shell/platform/linux/main_linux.cc | 14 +++++++++----- .../shell/testing/observatory/launcher.dart | 1 + 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/engine/src/flutter/shell/common/switches.h b/engine/src/flutter/shell/common/switches.h index 5924c402a4..4b133e5b38 100644 --- a/engine/src/flutter/shell/common/switches.h +++ b/engine/src/flutter/shell/common/switches.h @@ -82,6 +82,10 @@ DEF_SWITCH(UseTestFonts, "will make font resolution default to the Ahem test font on all " "platforms (See https://www.w3.org/Style/CSS/Test/Fonts/Ahem/). " "This option is only available on the desktop test shells.") +DEF_SWITCH(RunForever, + "run-forever", + "In non-interactive mode, keep the shell running after the Dart " + "script has completed.") DEF_SWITCHES_END void PrintUsage(const std::string& executable_name); diff --git a/engine/src/flutter/shell/platform/linux/main_linux.cc b/engine/src/flutter/shell/platform/linux/main_linux.cc index fc0d1b7d63..4756b9c04c 100644 --- a/engine/src/flutter/shell/platform/linux/main_linux.cc +++ b/engine/src/flutter/shell/platform/linux/main_linux.cc @@ -43,7 +43,7 @@ class ScriptCompletionTaskObserver : public base::MessageLoop::TaskObserver { bool prev_live_; }; -void RunNonInteractive() { +void RunNonInteractive(bool run_forever) { base::MessageLoop message_loop; shell::Shell::InitStandalone(); @@ -51,9 +51,11 @@ void RunNonInteractive() { // 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 (!run_forever) { + blink::Threads::UI()->PostTask([&task_observer] { + base::MessageLoop::current()->AddTaskObserver(&task_observer); + }); + } if (!shell::InitForTesting()) { shell::PrintUsage("sky_shell"); @@ -133,7 +135,9 @@ int main(int argc, const char* argv[]) { if (command_line.HasSwitch( shell::FlagForSwitch(shell::Switch::NonInteractive))) { - RunNonInteractive(); + bool run_forever = command_line.HasSwitch( + shell::FlagForSwitch(shell::Switch::RunForever)); + RunNonInteractive(run_forever); return 0; } diff --git a/engine/src/flutter/shell/testing/observatory/launcher.dart b/engine/src/flutter/shell/testing/observatory/launcher.dart index b2df0664b3..e3f6671cac 100644 --- a/engine/src/flutter/shell/testing/observatory/launcher.dart +++ b/engine/src/flutter/shell/testing/observatory/launcher.dart @@ -42,6 +42,7 @@ class ShellLauncher { final List args = [ '--observatory-port=0', '--non-interactive', + '--run-forever', ]; final String shellExecutablePath; final String mainDartPath;