[flutter_tools] remove globals from desktop configuration (#67146)

Refactors the desktop devices and workflow to remove unnecessary usage of global variables. This should make it easier to test and continue enhancing the desktop functionality of the tooling

#47161
This commit is contained in:
Jonah Williams
2020-10-02 21:52:53 -07:00
committed by GitHub
parent ddb01a0c81
commit ddb8177018
15 changed files with 518 additions and 341 deletions

View File

@@ -123,13 +123,13 @@ class _FakeProcess implements Process {
this._stderr,
this.stdin,
this._stdout,
Completer<void> completer,
this._completer,
) : exitCode = Future<void>.delayed(duration).then((void value) {
if (onRun != null) {
onRun();
}
if (completer != null) {
return completer.future.then((void _) => _exitCode);
if (_completer != null) {
return _completer.future.then((void _) => _exitCode);
}
return _exitCode;
}),
@@ -141,6 +141,7 @@ class _FakeProcess implements Process {
: Stream<List<int>>.value(utf8.encode(_stdout));
final int _exitCode;
final Completer<void> _completer;
@override
final Future<int> exitCode;
@@ -205,6 +206,8 @@ abstract class FakeProcessManager implements ProcessManager {
commands.forEach(addCommand);
}
final Map<int, _FakeProcess> _fakeRunningProcesses = <int, _FakeProcess>{};
/// Whether this fake has more [FakeCommand]s that are expected to run.
///
/// This is always `true` for [FakeProcessManager.any].
@@ -248,7 +251,16 @@ abstract class FakeProcessManager implements ProcessManager {
bool includeParentEnvironment = true, // ignored
bool runInShell = false, // ignored
ProcessStartMode mode = ProcessStartMode.normal, // ignored
}) async => _runCommand(command.cast<String>(), workingDirectory, environment, systemEncoding);
}) {
final _FakeProcess process = _runCommand(command.cast<String>(), workingDirectory, environment, systemEncoding);
if (process._completer != null) {
_fakeRunningProcesses[process.pid] = process;
process.exitCode.whenComplete(() {
_fakeRunningProcesses.remove(process.pid);
});
}
return Future<Process>.value(process);
}
@override
Future<ProcessResult> run(
@@ -294,8 +306,13 @@ abstract class FakeProcessManager implements ProcessManager {
@override
bool killPid(int pid, [io.ProcessSignal signal = io.ProcessSignal.sigterm]) {
// Killing a fake process has no effect.
return false;
// Killing a fake process has no effect unless it has an attached completer.
final _FakeProcess fakeProcess = _fakeRunningProcesses[pid];
if (fakeProcess == null) {
return false;
}
fakeProcess._completer.complete();
return true;
}
}