Trigger a hot reload / full restart based on SIGUSR1 and SIGUSR2 (#5453)
This commit is contained in:
@@ -20,7 +20,6 @@ import '../runner/flutter_command.dart';
|
||||
import 'build_apk.dart';
|
||||
import 'install.dart';
|
||||
import 'trace.dart';
|
||||
import '../base/os.dart';
|
||||
|
||||
abstract class RunCommandBase extends FlutterCommand {
|
||||
RunCommandBase() {
|
||||
@@ -69,10 +68,9 @@ class RunCommand extends RunCommandBase {
|
||||
defaultsTo: false,
|
||||
help: 'Run with support for hot reloading.');
|
||||
|
||||
// Option to enable control over a named pipe.
|
||||
argParser.addOption('control-pipe',
|
||||
hide: true,
|
||||
help: 'Specify a named pipe to receive commands on.');
|
||||
// Option to write the pid to a file.
|
||||
argParser.addOption('pid-file',
|
||||
help: 'Specify a file to write the process id to.');
|
||||
|
||||
|
||||
// Hidden option to enable a benchmarking mode. This will run the given
|
||||
@@ -142,23 +140,13 @@ class RunCommand extends RunCommandBase {
|
||||
printError('Hot mode is not supported by this device.');
|
||||
return 1;
|
||||
}
|
||||
} else {
|
||||
if (argResults['control-pipe'] != null) {
|
||||
printError('--control-pipe requires --hot');
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
String pipePath = argResults['control-pipe'];
|
||||
File pipe;
|
||||
if (pipePath != null) {
|
||||
try {
|
||||
// Attempt to create the pipe.
|
||||
os.makePipe(pipePath);
|
||||
} catch (_) { /* ignore */ }
|
||||
pipe = new File(pipePath);
|
||||
String pidFile = argResults['pid-file'];
|
||||
if (pidFile != null) {
|
||||
// Write our pid to the file.
|
||||
new File(pidFile).writeAsStringSync(pid.toString());
|
||||
}
|
||||
|
||||
ResidentRunner runner;
|
||||
|
||||
if (argResults['hot']) {
|
||||
@@ -166,7 +154,6 @@ class RunCommand extends RunCommandBase {
|
||||
deviceForCommand,
|
||||
target: targetFile,
|
||||
debuggingOptions: options,
|
||||
pipe: pipe
|
||||
);
|
||||
} else {
|
||||
runner = new RunAndStayResident(
|
||||
|
||||
@@ -118,8 +118,7 @@ class HotRunner extends ResidentRunner {
|
||||
Device device, {
|
||||
String target,
|
||||
DebuggingOptions debuggingOptions,
|
||||
bool usesTerminalUI: true,
|
||||
this.pipe
|
||||
bool usesTerminalUI: true
|
||||
}) : super(device,
|
||||
target: target,
|
||||
debuggingOptions: debuggingOptions,
|
||||
@@ -132,33 +131,6 @@ class HotRunner extends ResidentRunner {
|
||||
String _projectRootPath;
|
||||
Set<String> _startupDependencies;
|
||||
final AssetBundle bundle = new AssetBundle();
|
||||
final File pipe;
|
||||
|
||||
Future<String> _readFromControlPipe() async {
|
||||
final Stream<List<int>> stream = pipe.openRead();
|
||||
final List<int> bytes = await stream.first;
|
||||
final String string = new String.fromCharCodes(bytes).trim();
|
||||
return string;
|
||||
}
|
||||
|
||||
Future<Null> _startReadingFromControlPipe() async {
|
||||
if (pipe == null)
|
||||
return;
|
||||
|
||||
while (true) {
|
||||
// This loop will only exit if _readFromControlPipe throws an exception.
|
||||
// If no exception is thrown this will keep the flutter command running
|
||||
// until it is explicitly stopped via some other mechanism, for example,
|
||||
// ctrl+c or sending "q" to the control pipe.
|
||||
String result = await _readFromControlPipe();
|
||||
printStatus('Control pipe received "$result"');
|
||||
await processTerminalInput(result);
|
||||
if (result.toLowerCase() == 'q') {
|
||||
printStatus("Finished reading from control pipe");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<int> run({
|
||||
@@ -300,8 +272,6 @@ class HotRunner extends ResidentRunner {
|
||||
_loaderShowMessage('Launching...');
|
||||
await _launchFromDevFS(_package, _mainPath);
|
||||
|
||||
_startReadingFromControlPipe();
|
||||
|
||||
printStatus('Application running.');
|
||||
|
||||
setupTerminal();
|
||||
|
||||
@@ -65,6 +65,14 @@ abstract class ResidentRunner {
|
||||
await cleanupAfterSignal();
|
||||
exit(0);
|
||||
});
|
||||
ProcessSignal.SIGUSR1.watch().listen((ProcessSignal signal) async {
|
||||
printStatus('Caught SIGUSR1');
|
||||
await restart(fullRestart: false);
|
||||
});
|
||||
ProcessSignal.SIGUSR2.watch().listen((ProcessSignal signal) async {
|
||||
printStatus('Caught SIGUSR2');
|
||||
await restart(fullRestart: true);
|
||||
});
|
||||
}
|
||||
|
||||
Future<Null> startEchoingDeviceLog() async {
|
||||
|
||||
Reference in New Issue
Block a user