Fix --pid-file not working for --machine + add to attach command (#23242)

* Fix --pid-file not working for --machine + add to attach

Fixes #23201.

* Add tests for --pid-file in run+attach
This commit is contained in:
Danny Tuppeny
2018-10-24 07:21:36 +01:00
committed by GitHub
parent b21d0de0d6
commit aa83f77a49
6 changed files with 62 additions and 17 deletions

View File

@@ -398,6 +398,13 @@ String wrapText(String text, {int columnWidth, int hangingIndent, int indent}) {
return result.join('\n');
}
void writePidFile(String pidFile) {
if (pidFile != null) {
// Write our pid to the file.
fs.file(pidFile).writeAsStringSync(io.pid.toString());
}
}
// Used to represent a run of ANSI control sequences next to a visible
// character.
class _AnsiRun {

View File

@@ -7,6 +7,7 @@ import 'dart:async';
import '../base/common.dart';
import '../base/file_system.dart';
import '../base/io.dart';
import '../base/utils.dart';
import '../cache.dart';
import '../commands/daemon.dart';
import '../device.dart';
@@ -44,6 +45,10 @@ class AttachCommand extends FlutterCommand {
..addOption(
'debug-port',
help: 'Local port where the observatory is listening.',
)..addOption('pid-file',
help: 'Specify a file to write the process id to. '
'You can send SIGUSR1 to trigger a hot reload '
'and SIGUSR2 to trigger a hot restart.',
)..addOption(
'project-root',
hide: !verboseHelp,
@@ -90,6 +95,8 @@ class AttachCommand extends FlutterCommand {
await _validateArguments();
writePidFile(argResults['pid-file']);
final Device device = await findTargetDevice();
final int devicePort = observatoryPort;

View File

@@ -6,7 +6,6 @@ import 'dart:async';
import '../base/common.dart';
import '../base/file_system.dart';
import '../base/io.dart';
import '../base/utils.dart';
import '../build_info.dart';
import '../cache.dart';
@@ -276,6 +275,8 @@ class RunCommand extends RunCommandBase {
// debug mode.
final bool hotMode = shouldUseHotMode();
writePidFile(argResults['pid-file']);
if (argResults['machine']) {
if (devices.length > 1)
throwToolExit('--machine does not support -d all.');
@@ -340,12 +341,6 @@ class RunCommand extends RunCommandBase {
}
}
final String pidFile = argResults['pid-file'];
if (pidFile != null) {
// Write our pid to the file.
fs.file(pidFile).writeAsStringSync(pid.toString());
}
final List<FlutterDevice> flutterDevices = devices.map<FlutterDevice>((Device device) {
return FlutterDevice(
device,