Unverified Commit 5555725f authored by Zachary Anderson's avatar Zachary Anderson Committed by GitHub

[flutter_tool] Fix 'q' for Fuchsia profile/debug mode (#33846)

parent 9114f445
...@@ -863,7 +863,7 @@ class AppInstance { ...@@ -863,7 +863,7 @@ class AppInstance {
return runner.restart(fullRestart: fullRestart, pauseAfterRestart: pauseAfterRestart, reason: reason); return runner.restart(fullRestart: fullRestart, pauseAfterRestart: pauseAfterRestart, reason: reason);
} }
Future<void> stop() => runner.stop(); Future<void> stop() => runner.exit();
Future<void> detach() => runner.detach(); Future<void> detach() => runner.detach();
void closeLogger() { void closeLogger() {
......
...@@ -307,7 +307,7 @@ abstract class Device { ...@@ -307,7 +307,7 @@ abstract class Device {
/// Whether flutter applications running on this device can be terminated /// Whether flutter applications running on this device can be terminated
/// from the vmservice. /// from the vmservice.
bool get supportsStopApp => true; bool get supportsFlutterExit => true;
/// Whether the device supports taking screenshots of a running flutter /// Whether the device supports taking screenshots of a running flutter
/// application. /// application.
......
...@@ -184,7 +184,7 @@ class FuchsiaDevice extends Device { ...@@ -184,7 +184,7 @@ class FuchsiaDevice extends Device {
bool get supportsHotRestart => false; bool get supportsHotRestart => false;
@override @override
bool get supportsStopApp => false; bool get supportsFlutterExit => false;
@override @override
final String name; final String name;
......
...@@ -11,7 +11,7 @@ import 'artifacts.dart'; ...@@ -11,7 +11,7 @@ import 'artifacts.dart';
import 'asset.dart'; import 'asset.dart';
import 'base/common.dart'; import 'base/common.dart';
import 'base/file_system.dart'; import 'base/file_system.dart';
import 'base/io.dart'; import 'base/io.dart' as io;
import 'base/logger.dart'; import 'base/logger.dart';
import 'base/terminal.dart'; import 'base/terminal.dart';
import 'base/utils.dart'; import 'base/utils.dart';
...@@ -166,8 +166,9 @@ class FlutterDevice { ...@@ -166,8 +166,9 @@ class FlutterDevice {
await service.getVM(); await service.getVM();
} }
Future<void> stopApps() async { Future<void> exitApps() async {
if (!device.supportsStopApp) { if (!device.supportsFlutterExit) {
await device.stopApp(package);
return; return;
} }
final List<FlutterView> flutterViews = views; final List<FlutterView> flutterViews = views;
...@@ -530,7 +531,7 @@ abstract class ResidentRunner { ...@@ -530,7 +531,7 @@ abstract class ResidentRunner {
final bool stayResident; final bool stayResident;
final bool ipv6; final bool ipv6;
final Completer<int> _finished = Completer<int>(); final Completer<int> _finished = Completer<int>();
bool _stopped = false; bool _exited = false;
String _packagesFilePath; String _packagesFilePath;
String get packagesFilePath => _packagesFilePath; String get packagesFilePath => _packagesFilePath;
String _projectRootPath; String _projectRootPath;
...@@ -582,18 +583,18 @@ abstract class ResidentRunner { ...@@ -582,18 +583,18 @@ abstract class ResidentRunner {
throw '${fullRestart ? 'Restart' : 'Reload'} is not supported in $mode mode'; throw '${fullRestart ? 'Restart' : 'Reload'} is not supported in $mode mode';
} }
Future<void> stop() async { Future<void> exit() async {
_stopped = true; _exited = true;
if (saveCompilationTrace) if (saveCompilationTrace)
await _debugSaveCompilationTrace(); await _debugSaveCompilationTrace();
await stopEchoingDeviceLog(); await stopEchoingDeviceLog();
await preStop(); await preExit();
await stopApp(); await exitApp();
} }
Future<void> detach() async { Future<void> detach() async {
await stopEchoingDeviceLog(); await stopEchoingDeviceLog();
await preStop(); await preExit();
appFinished(); appFinished();
} }
...@@ -743,29 +744,29 @@ abstract class ResidentRunner { ...@@ -743,29 +744,29 @@ abstract class ResidentRunner {
void registerSignalHandlers() { void registerSignalHandlers() {
assert(stayResident); assert(stayResident);
ProcessSignal.SIGINT.watch().listen(_cleanUpAndExit); io.ProcessSignal.SIGINT.watch().listen(_cleanUpAndExit);
ProcessSignal.SIGTERM.watch().listen(_cleanUpAndExit); io.ProcessSignal.SIGTERM.watch().listen(_cleanUpAndExit);
if (!supportsServiceProtocol || !supportsRestart) if (!supportsServiceProtocol || !supportsRestart)
return; return;
ProcessSignal.SIGUSR1.watch().listen(_handleSignal); io.ProcessSignal.SIGUSR1.watch().listen(_handleSignal);
ProcessSignal.SIGUSR2.watch().listen(_handleSignal); io.ProcessSignal.SIGUSR2.watch().listen(_handleSignal);
} }
Future<void> _cleanUpAndExit(ProcessSignal signal) async { Future<void> _cleanUpAndExit(io.ProcessSignal signal) async {
_resetTerminal(); _resetTerminal();
await cleanupAfterSignal(); await cleanupAfterSignal();
exit(0); io.exit(0);
} }
bool _processingUserRequest = false; bool _processingUserRequest = false;
Future<void> _handleSignal(ProcessSignal signal) async { Future<void> _handleSignal(io.ProcessSignal signal) async {
if (_processingUserRequest) { if (_processingUserRequest) {
printTrace('Ignoring signal: "$signal" because we are busy.'); printTrace('Ignoring signal: "$signal" because we are busy.');
return; return;
} }
_processingUserRequest = true; _processingUserRequest = true;
final bool fullRestart = signal == ProcessSignal.SIGUSR2; final bool fullRestart = signal == io.ProcessSignal.SIGUSR2;
try { try {
await restart(fullRestart: fullRestart); await restart(fullRestart: fullRestart);
...@@ -903,7 +904,7 @@ abstract class ResidentRunner { ...@@ -903,7 +904,7 @@ abstract class ResidentRunner {
} }
} else if (lower == 'q') { } else if (lower == 'q') {
// exit // exit
await stop(); await exit();
return true; return true;
} else if (lower == 'd') { } else if (lower == 'd') {
await detach(); await detach();
...@@ -937,7 +938,7 @@ abstract class ResidentRunner { ...@@ -937,7 +938,7 @@ abstract class ResidentRunner {
} }
void _serviceDisconnected() { void _serviceDisconnected() {
if (_stopped) { if (_exited) {
// User requested the application exit. // User requested the application exit.
return; return;
} }
...@@ -980,12 +981,12 @@ abstract class ResidentRunner { ...@@ -980,12 +981,12 @@ abstract class ResidentRunner {
return exitCode; return exitCode;
} }
Future<void> preStop() async { } Future<void> preExit() async { }
Future<void> stopApp() async { Future<void> exitApp() async {
final List<Future<void>> futures = <Future<void>>[]; final List<Future<void>> futures = <Future<void>>[];
for (FlutterDevice device in flutterDevices) for (FlutterDevice device in flutterDevices)
futures.add(device.stopApps()); futures.add(device.exitApps());
await Future.wait(futures); await Future.wait(futures);
appFinished(); appFinished();
} }
......
...@@ -160,10 +160,8 @@ class ColdRunner extends ResidentRunner { ...@@ -160,10 +160,8 @@ class ColdRunner extends ResidentRunner {
await stopEchoingDeviceLog(); await stopEchoingDeviceLog();
if (_didAttach) { if (_didAttach) {
appFinished(); appFinished();
} else {
await stopApp();
} }
await stopApp(); await exitApp();
} }
@override @override
...@@ -207,7 +205,7 @@ class ColdRunner extends ResidentRunner { ...@@ -207,7 +205,7 @@ class ColdRunner extends ResidentRunner {
} }
@override @override
Future<void> preStop() async { Future<void> preExit() async {
for (FlutterDevice device in flutterDevices) { for (FlutterDevice device in flutterDevices) {
// If we're running in release mode, stop the app using the device logic. // If we're running in release mode, stop the app using the device logic.
if (device.vmServices == null || device.vmServices.isEmpty) if (device.vmServices == null || device.vmServices.isEmpty)
......
...@@ -218,7 +218,7 @@ class HotRunner extends ResidentRunner { ...@@ -218,7 +218,7 @@ class HotRunner extends ResidentRunner {
printStatus('Benchmark completed. Exiting application.'); printStatus('Benchmark completed. Exiting application.');
await _cleanupDevFS(); await _cleanupDevFS();
await stopEchoingDeviceLog(); await stopEchoingDeviceLog();
await stopApp(); await exitApp();
} }
final File benchmarkOutput = fs.file('hot_benchmark.json'); final File benchmarkOutput = fs.file('hot_benchmark.json');
benchmarkOutput.writeAsStringSync(toPrettyJson(benchmarkData)); benchmarkOutput.writeAsStringSync(toPrettyJson(benchmarkData));
...@@ -922,12 +922,12 @@ class HotRunner extends ResidentRunner { ...@@ -922,12 +922,12 @@ class HotRunner extends ResidentRunner {
if (_didAttach) { if (_didAttach) {
appFinished(); appFinished();
} else { } else {
await stopApp(); await exitApp();
} }
} }
@override @override
Future<void> preStop() async { Future<void> preExit() async {
await _cleanupDevFS(); await _cleanupDevFS();
await hotRunnerConfig.runPreShutdownOperations(); await hotRunnerConfig.runPreShutdownOperations();
} }
......
...@@ -49,7 +49,7 @@ class WebDevice extends Device { ...@@ -49,7 +49,7 @@ class WebDevice extends Device {
bool get supportsStartPaused => true; bool get supportsStartPaused => true;
@override @override
bool get supportsStopApp => true; bool get supportsFlutterExit => true;
@override @override
bool get supportsScreenshot => false; bool get supportsScreenshot => false;
......
...@@ -72,7 +72,7 @@ void main() { ...@@ -72,7 +72,7 @@ void main() {
expect(device.supportsHotReload, true); expect(device.supportsHotReload, true);
expect(device.supportsHotRestart, false); expect(device.supportsHotRestart, false);
expect(device.supportsStopApp, false); expect(device.supportsFlutterExit, false);
expect(device.isSupportedForProject(FlutterProject.current()), true); expect(device.isSupportedForProject(FlutterProject.current()), true);
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
FileSystem: () => memoryFileSystem, FileSystem: () => memoryFileSystem,
......
...@@ -232,7 +232,7 @@ void main() { ...@@ -232,7 +232,7 @@ void main() {
final MockDevice mockDevice = MockDevice(); final MockDevice mockDevice = MockDevice();
when(mockDevice.supportsHotReload).thenReturn(true); when(mockDevice.supportsHotReload).thenReturn(true);
when(mockDevice.supportsHotRestart).thenReturn(true); when(mockDevice.supportsHotRestart).thenReturn(true);
when(mockDevice.supportsStopApp).thenReturn(false); when(mockDevice.supportsFlutterExit).thenReturn(false);
final List<FlutterDevice> devices = <FlutterDevice>[ final List<FlutterDevice> devices = <FlutterDevice>[
FlutterDevice(mockDevice, generator: residentCompiler, trackWidgetCreation: false, buildMode: BuildMode.debug), FlutterDevice(mockDevice, generator: residentCompiler, trackWidgetCreation: false, buildMode: BuildMode.debug),
]; ];
...@@ -247,11 +247,11 @@ void main() { ...@@ -247,11 +247,11 @@ void main() {
final MockDevice mockDevice = MockDevice(); final MockDevice mockDevice = MockDevice();
when(mockDevice.supportsHotReload).thenReturn(true); when(mockDevice.supportsHotReload).thenReturn(true);
when(mockDevice.supportsHotRestart).thenReturn(true); when(mockDevice.supportsHotRestart).thenReturn(true);
when(mockDevice.supportsStopApp).thenReturn(false); when(mockDevice.supportsFlutterExit).thenReturn(false);
final List<FlutterDevice> devices = <FlutterDevice>[ final List<FlutterDevice> devices = <FlutterDevice>[
FlutterDevice(mockDevice, generator: residentCompiler, trackWidgetCreation: false, buildMode: BuildMode.debug), FlutterDevice(mockDevice, generator: residentCompiler, trackWidgetCreation: false, buildMode: BuildMode.debug),
]; ];
await HotRunner(devices).preStop(); await HotRunner(devices).preExit();
expect(shutdownTestingConfig.shutdownHookCalled, true); expect(shutdownTestingConfig.shutdownHookCalled, true);
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
Artifacts: () => mockArtifacts, Artifacts: () => mockArtifacts,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment