Unverified Commit 15ba3956 authored by Jonah Williams's avatar Jonah Williams Committed by GitHub

replace no-op log reader with real implementation (#31526)

parent fee1d3db
......@@ -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<bool> killProcess(String executable) async {
}
return succeeded;
}
class DesktopLogReader extends DeviceLogReader {
final StreamController<String> _inputController = StreamController<String>.broadcast();
void initializeProcess(Process process) {
_inputController.addStream(process.stdout
.transform(utf8.decoder)
.transform(const LineSplitter()));
}
@override
Stream<String> get logLines {
return _inputController.stream;
}
@override
String get name => 'desktop';
}
......@@ -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<List<String>> getDiagnostics() async => const <String>[];
}
class LinuxLogReader extends DeviceLogReader {
LinuxLogReader(this.linuxApp, this.process);
final LinuxApp linuxApp;
final Process process;
@override
Stream<String> get logLines {
return process.stdout.transform(utf8.decoder);
}
@override
String get name => linuxApp.displayName;
}
......@@ -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<List<String>> getDiagnostics() async => const <String>[];
}
class MacOSLogReader extends DeviceLogReader {
MacOSLogReader(this.macOSApp, this.process);
final MacOSApp macOSApp;
final Process process;
@override
Stream<String> get logLines {
return process.stdout.transform(utf8.decoder);
}
@override
String get name => macOSApp.displayName;
}
......@@ -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<String> runningProcess(String processName) {
}
return null;
}
class WindowsLogReader extends DeviceLogReader {
WindowsLogReader(this.windowsApp, this.process);
final WindowsApp windowsApp;
final Process process;
@override
Stream<String> get logLines {
return process.stdout.transform(utf8.decoder);
}
@override
String get name => windowsApp.displayName;
}
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