Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Stream logging from attached debugger on iOS" #66397

Merged
merged 1 commit into from Sep 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
72 changes: 9 additions & 63 deletions packages/flutter_tools/lib/src/ios/devices.dart
Expand Up @@ -212,9 +212,6 @@ class IOSDevice extends Device {

DevicePortForwarder _portForwarder;

@visibleForTesting
IOSDeployDebugger iosDeployDebugger;

@override
Future<bool> get isLocalEmulator async => false;

Expand Down Expand Up @@ -398,38 +395,23 @@ class IOSDevice extends Device {
timeout: timeoutConfiguration.slowOperation);
try {
ProtocolDiscovery observatoryDiscovery;
int installationResult = 1;
if (debuggingOptions.debuggingEnabled) {
_logger.printTrace('Debugging is enabled, connecting to observatory');
iosDeployDebugger = _iosDeploy.prepareDebuggerForLaunch(
deviceId: id,
bundlePath: bundle.path,
launchArguments: launchArguments,
interfaceType: interfaceType,
);

final DeviceLogReader deviceLogReader = getLogReader(app: package);
if (deviceLogReader is IOSDeviceLogReader) {
deviceLogReader.debuggerStream = iosDeployDebugger;
}
observatoryDiscovery = ProtocolDiscovery.observatory(
deviceLogReader,
getLogReader(app: package),
portForwarder: portForwarder,
throttleDuration: fallbackPollingDelay,
throttleTimeout: fallbackThrottleTimeout ?? const Duration(seconds: 5),
hostPort: debuggingOptions.hostVmServicePort,
devicePort: debuggingOptions.deviceVmServicePort,
ipv6: ipv6,
);
installationResult = await iosDeployDebugger.launchAndAttach() ? 0 : 1;
} else {
installationResult = await _iosDeploy.launchApp(
deviceId: id,
bundlePath: bundle.path,
launchArguments: launchArguments,
interfaceType: interfaceType,
throttleTimeout: fallbackThrottleTimeout ?? const Duration(seconds: 1),
);
}
final int installationResult = await _iosDeploy.runApp(
deviceId: id,
bundlePath: bundle.path,
launchArguments: launchArguments,
interfaceType: interfaceType,
);
if (installationResult != 0) {
_logger.printError('Could not run ${bundle.path} on $id.');
_logger.printError('Try launching Xcode and selecting "Product > Run" to fix the problem:');
Expand Down Expand Up @@ -483,11 +465,7 @@ class IOSDevice extends Device {
IOSApp app, {
String userIdentifier,
}) async {
// If the debugger is not attached, killing the ios-deploy process won't stop the app.
if (iosDeployDebugger!= null && iosDeployDebugger.debuggerAttached) {
// Avoid null.
return iosDeployDebugger?.exit() == true;
}
// Currently we don't have a way to stop an app running on iOS.
return false;
}

Expand Down Expand Up @@ -677,13 +655,6 @@ class IOSDeviceLogReader extends DeviceLogReader {
// Matches a syslog line from any app.
RegExp _anyLineRegex;

// Logging from native code/Flutter engine is prefixed by timestamp and process metadata:
// 2020-09-15 19:15:10.931434-0700 Runner[541:226276] Did finish launching.
// 2020-09-15 19:15:10.931434-0700 Runner[541:226276] [Category] Did finish launching.
//
// Logging from the dart code has no prefixing metadata.
final RegExp _debuggerLoggingRegex = RegExp(r'^\S* \S* \S*\[[0-9:]*] (.*)');

StreamController<String> _linesController;
List<StreamSubscription<void>> _loggingSubscriptions;

Expand Down Expand Up @@ -716,10 +687,6 @@ class IOSDeviceLogReader extends DeviceLogReader {
}

void logMessage(vm_service.Event event) {
if (_iosDeployDebugger != null && _iosDeployDebugger.debuggerAttached) {
// Prefer the more complete logs from the attached debugger.
return;
}
final String message = processVmServiceMessage(event);
if (message.isNotEmpty) {
_linesController.add(message);
Expand All @@ -732,26 +699,6 @@ class IOSDeviceLogReader extends DeviceLogReader {
]);
}

/// Log reader will listen to [debugger.logLines] and will detach debugger on dispose.
set debuggerStream(IOSDeployDebugger debugger) {
// Logging is gathered from syslog on iOS 13 and earlier.
if (_majorSdkVersion < _minimumUniversalLoggingSdkVersion) {
return;
}
_iosDeployDebugger = debugger;
// Add the debugger logs to the controller created on initialization.
_loggingSubscriptions.add(debugger.logLines.listen(
(String line) => _linesController.add(_debuggerLineHandler(line)),
onError: _linesController.addError,
onDone: _linesController.close,
cancelOnError: true,
));
}
IOSDeployDebugger _iosDeployDebugger;

// Strip off the logging metadata (leave the category), or just echo the line.
String _debuggerLineHandler(String line) => _debuggerLoggingRegex?.firstMatch(line)?.group(1) ?? line;

void _listenToSysLog() {
// syslog is not written on iOS 13+.
if (_majorSdkVersion >= _minimumUniversalLoggingSdkVersion) {
Expand Down Expand Up @@ -811,7 +758,6 @@ class IOSDeviceLogReader extends DeviceLogReader {
loggingSubscription.cancel();
}
_idevicesyslogProcess?.kill();
_iosDeployDebugger?.detach();
}
}

Expand Down
34 changes: 17 additions & 17 deletions packages/flutter_tools/lib/src/ios/fallback_discovery.dart
Expand Up @@ -82,50 +82,50 @@ class FallbackDiscovery {
}

try {
final Uri result = await _protocolDiscovery.uri;
final Uri result = await _mDnsObservatoryDiscovery.getObservatoryUri(
packageId,
device,
usesIpv6: usesIpv6,
hostVmservicePort: hostVmservicePort,
);
if (result != null) {
UsageEvent(
_kEventName,
'log-success',
'mdns-success',
flutterUsage: _flutterUsage,
).send();
return result;
}
} on ArgumentError {
// In the event of an invalid InternetAddress, this code attempts to catch
// an ArgumentError from protocol_discovery.dart
} on Exception catch (err) {
_logger.printTrace(err.toString());
}
_logger.printTrace('Failed to connect with log scanning, falling back to mDNS');
_logger.printTrace('Failed to connect with mDNS, falling back to log scanning');
UsageEvent(
_kEventName,
'log-failure',
'mdns-failure',
flutterUsage: _flutterUsage,
).send();

try {
final Uri result = await _mDnsObservatoryDiscovery.getObservatoryUri(
packageId,
device,
usesIpv6: usesIpv6,
hostVmservicePort: hostVmservicePort,
);
final Uri result = await _protocolDiscovery.uri;
if (result != null) {
UsageEvent(
_kEventName,
'mdns-success',
'fallback-success',
flutterUsage: _flutterUsage,
).send();
return result;
}
} on ArgumentError {
// In the event of an invalid InternetAddress, this code attempts to catch
// an ArgumentError from protocol_discovery.dart
} on Exception catch (err) {
_logger.printTrace(err.toString());
}
_logger.printTrace('Failed to connect with mDNS');
_logger.printTrace('Failed to connect with log scanning');
UsageEvent(
_kEventName,
'mdns-failure',
'fallback-failure',
flutterUsage: _flutterUsage,
).send();
return null;
Expand All @@ -148,7 +148,7 @@ class FallbackDiscovery {
assumedWsUri = Uri.parse('ws://localhost:$hostPort/ws');
} on Exception catch (err) {
_logger.printTrace(err.toString());
_logger.printTrace('Failed to connect directly, falling back to log scanning');
_logger.printTrace('Failed to connect directly, falling back to mDNS');
_sendFailureEvent(err, assumedDevicePort);
return null;
}
Expand Down