From 15ba39560a3a96ac5ac9541411ebd3228a1dedaa Mon Sep 17 00:00:00 2001 From: Jonah Williams Date: Tue, 23 Apr 2019 17:19:47 -0700 Subject: [PATCH] replace no-op log reader with real implementation (#31526) --- packages/flutter_tools/lib/src/desktop.dart | 22 ++++++++++++++++ .../lib/src/linux/linux_device.dart | 25 +++++------------- .../lib/src/macos/macos_device.dart | 25 +++++------------- .../lib/src/windows/windows_device.dart | 26 +++++-------------- 4 files changed, 41 insertions(+), 57 deletions(-) diff --git a/packages/flutter_tools/lib/src/desktop.dart b/packages/flutter_tools/lib/src/desktop.dart index e00342dd80..0929ea9f2a 100644 --- a/packages/flutter_tools/lib/src/desktop.dart +++ b/packages/flutter_tools/lib/src/desktop.dart @@ -2,9 +2,13 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +import 'dart:async'; + import 'base/io.dart'; import 'base/platform.dart'; import 'base/process_manager.dart'; +import 'convert.dart'; +import 'device.dart'; import 'version.dart'; // Only launch or display desktop embedding devices if @@ -47,3 +51,21 @@ Future killProcess(String executable) async { } return succeeded; } + +class DesktopLogReader extends DeviceLogReader { + final StreamController _inputController = StreamController.broadcast(); + + void initializeProcess(Process process) { + _inputController.addStream(process.stdout + .transform(utf8.decoder) + .transform(const LineSplitter())); + } + + @override + Stream get logLines { + return _inputController.stream; + } + + @override + String get name => 'desktop'; +} diff --git a/packages/flutter_tools/lib/src/linux/linux_device.dart b/packages/flutter_tools/lib/src/linux/linux_device.dart index 72fe802b62..9fa2065598 100644 --- a/packages/flutter_tools/lib/src/linux/linux_device.dart +++ b/packages/flutter_tools/lib/src/linux/linux_device.dart @@ -8,7 +8,6 @@ import '../base/os.dart'; import '../base/platform.dart'; import '../base/process_manager.dart'; import '../build_info.dart'; -import '../convert.dart'; import '../desktop.dart'; import '../device.dart'; import '../globals.dart'; @@ -26,7 +25,10 @@ class LinuxDevice extends Device { void clearLogs() { } @override - DeviceLogReader getLogReader({ ApplicationPackage app }) => NoOpDeviceLogReader('linux'); + DeviceLogReader getLogReader({ ApplicationPackage app }) { + return _logReader; + } + final DesktopLogReader _logReader = DesktopLogReader(); // Since the host and target devices are the same, no work needs to be done // to install the application. @@ -79,8 +81,8 @@ class LinuxDevice extends Device { if (debuggingOptions?.buildInfo?.isRelease == true) { return LaunchResult.succeeded(); } - final LinuxLogReader logReader = LinuxLogReader(package, process); - final ProtocolDiscovery observatoryDiscovery = ProtocolDiscovery.observatory(logReader); + _logReader.initializeProcess(process); + final ProtocolDiscovery observatoryDiscovery = ProtocolDiscovery.observatory(_logReader); try { final Uri observatoryUri = await observatoryDiscovery.uri; return LaunchResult.succeeded(observatoryUri: observatoryUri); @@ -129,18 +131,3 @@ class LinuxDevices extends PollingDeviceDiscovery { @override Future> getDiagnostics() async => const []; } - -class LinuxLogReader extends DeviceLogReader { - LinuxLogReader(this.linuxApp, this.process); - - final LinuxApp linuxApp; - final Process process; - - @override - Stream get logLines { - return process.stdout.transform(utf8.decoder); - } - - @override - String get name => linuxApp.displayName; -} diff --git a/packages/flutter_tools/lib/src/macos/macos_device.dart b/packages/flutter_tools/lib/src/macos/macos_device.dart index 1cc90281ce..b3309bbb00 100644 --- a/packages/flutter_tools/lib/src/macos/macos_device.dart +++ b/packages/flutter_tools/lib/src/macos/macos_device.dart @@ -9,7 +9,6 @@ import '../base/platform.dart'; import '../base/process_manager.dart'; import '../build_info.dart'; import '../cache.dart'; -import '../convert.dart'; import '../desktop.dart'; import '../device.dart'; import '../globals.dart'; @@ -27,7 +26,10 @@ class MacOSDevice extends Device { void clearLogs() { } @override - DeviceLogReader getLogReader({ ApplicationPackage app }) => NoOpDeviceLogReader('macos'); + DeviceLogReader getLogReader({ ApplicationPackage app }) { + return _deviceLogReader; + } + final DesktopLogReader _deviceLogReader = DesktopLogReader(); // Since the host and target devices are the same, no work needs to be done // to install the application. @@ -83,8 +85,8 @@ class MacOSDevice extends Device { if (debuggingOptions?.buildInfo?.isRelease == true) { return LaunchResult.succeeded(); } - final MacOSLogReader logReader = MacOSLogReader(package, process); - final ProtocolDiscovery observatoryDiscovery = ProtocolDiscovery.observatory(logReader); + _deviceLogReader.initializeProcess(process); + final ProtocolDiscovery observatoryDiscovery = ProtocolDiscovery.observatory(_deviceLogReader); try { final Uri observatoryUri = await observatoryDiscovery.uri; // Bring app to foreground. @@ -139,18 +141,3 @@ class MacOSDevices extends PollingDeviceDiscovery { @override Future> getDiagnostics() async => const []; } - -class MacOSLogReader extends DeviceLogReader { - MacOSLogReader(this.macOSApp, this.process); - - final MacOSApp macOSApp; - final Process process; - - @override - Stream get logLines { - return process.stdout.transform(utf8.decoder); - } - - @override - String get name => macOSApp.displayName; -} diff --git a/packages/flutter_tools/lib/src/windows/windows_device.dart b/packages/flutter_tools/lib/src/windows/windows_device.dart index 837e23d0dd..9843dea2f0 100644 --- a/packages/flutter_tools/lib/src/windows/windows_device.dart +++ b/packages/flutter_tools/lib/src/windows/windows_device.dart @@ -10,7 +10,7 @@ import '../base/os.dart'; import '../base/platform.dart'; import '../base/process_manager.dart'; import '../build_info.dart'; -import '../convert.dart'; +import '../desktop.dart'; import '../device.dart'; import '../globals.dart'; import '../project.dart'; @@ -27,7 +27,10 @@ class WindowsDevice extends Device { void clearLogs() { } @override - DeviceLogReader getLogReader({ ApplicationPackage app }) => NoOpDeviceLogReader('windows'); + DeviceLogReader getLogReader({ ApplicationPackage app }) { + return _logReader; + } + final DesktopLogReader _logReader = DesktopLogReader(); // Since the host and target devices are the same, no work needs to be done // to install the application. @@ -80,8 +83,8 @@ class WindowsDevice extends Device { if (debuggingOptions?.buildInfo?.isRelease == true) { return LaunchResult.succeeded(); } - final WindowsLogReader logReader = WindowsLogReader(package, process); - final ProtocolDiscovery observatoryDiscovery = ProtocolDiscovery.observatory(logReader); + _logReader.initializeProcess(process); + final ProtocolDiscovery observatoryDiscovery = ProtocolDiscovery.observatory(_logReader); try { final Uri observatoryUri = await observatoryDiscovery.uri; return LaunchResult.succeeded(observatoryUri: observatoryUri); @@ -162,18 +165,3 @@ List runningProcess(String processName) { } return null; } - -class WindowsLogReader extends DeviceLogReader { - WindowsLogReader(this.windowsApp, this.process); - - final WindowsApp windowsApp; - final Process process; - - @override - Stream get logLines { - return process.stdout.transform(utf8.decoder); - } - - @override - String get name => windowsApp.displayName; -}