mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
[ Tool ] Serve DevTools from DDS, remove ResidentDevToolsHandler (#174580)
This PR contains the initial work to prepare for the removal of instances of DevTools being served manually by the flutter_tool, instead relying on DDS to serve DevTools. This will be consistent with how the standalone Dart VM serves DevTools, tying the DevTools lifecycle to a live DDS instance. This will allow for the removal of much of the logic needed to properly manage the lifecycle of the DevTools server in a future PR. Also, by serving DevTools from DDS, users will no longer need to forward a secondary port in remote workflows as DevTools will be available on the DDS port. There's two remaining circumstances that will prevent us from removing `DevtoolsRunner` completely: - The daemon's `devtools.serve` endpoint - `flutter drive`'s `--profile-memory` flag used for recording memory profiles
This commit is contained in:
parent
560a500380
commit
643c2e9410
@ -4,15 +4,20 @@
|
||||
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:browser_launcher/browser_launcher.dart';
|
||||
import 'package:dds/dds.dart';
|
||||
import 'package:dds/dds_launcher.dart';
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
import '../artifacts.dart';
|
||||
import '../build_info.dart';
|
||||
import '../device.dart';
|
||||
import '../globals.dart' as globals;
|
||||
import '../resident_runner.dart';
|
||||
import '../vmservice.dart';
|
||||
import 'io.dart' as io;
|
||||
import 'logger.dart';
|
||||
import 'utils.dart';
|
||||
|
||||
export 'package:dds/dds.dart'
|
||||
show DartDevelopmentServiceException, ExistingDartDevelopmentServiceException;
|
||||
@ -42,12 +47,19 @@ class DartDevelopmentService with DartDevelopmentServiceLocalOperationsMixin {
|
||||
|
||||
DartDevelopmentServiceLauncher? _ddsInstance;
|
||||
|
||||
@override
|
||||
Uri? get uri => _ddsInstance?.uri ?? _existingDdsUri;
|
||||
Uri? _existingDdsUri;
|
||||
|
||||
@override
|
||||
Uri? get devToolsUri => _ddsInstance?.devToolsUri;
|
||||
|
||||
Uri? get dtdUri => _ddsInstance?.dtdUri;
|
||||
|
||||
Future<void> get done => _completer.future;
|
||||
final _completer = Completer<void>();
|
||||
|
||||
@override
|
||||
final Logger _logger;
|
||||
|
||||
@override
|
||||
@ -85,6 +97,7 @@ class DartDevelopmentService with DartDevelopmentServiceLocalOperationsMixin {
|
||||
enableAuthCodes: disableServiceAuthCodes != true,
|
||||
// Enables caching of CPU samples collected during application startup.
|
||||
cachedUserTags: cacheStartupProfile ? const <String>['AppStartUp'] : const <String>[],
|
||||
serveDevTools: enableDevTools,
|
||||
devToolsServerAddress: devToolsServerAddress,
|
||||
google3WorkspaceRoot: google3WorkspaceRoot,
|
||||
dartExecutable: globals.artifacts!.getArtifactPath(Artifact.engineDartBinary),
|
||||
@ -106,6 +119,15 @@ class DartDevelopmentService with DartDevelopmentServiceLocalOperationsMixin {
|
||||
/// Contains common functionality that can be used with any implementation of
|
||||
/// [DartDevelopmentService].
|
||||
mixin DartDevelopmentServiceLocalOperationsMixin {
|
||||
Uri? get uri;
|
||||
Uri? get devToolsUri;
|
||||
Logger get _logger;
|
||||
|
||||
/// Used to confirm `launchDevToolsInBrowser` is called in tests.
|
||||
@visibleForTesting
|
||||
bool get calledLaunchDevToolsInBrowser => _calledLaunchDevToolsInBrowser;
|
||||
var _calledLaunchDevToolsInBrowser = false;
|
||||
|
||||
Future<void> startDartDevelopmentService(
|
||||
Uri vmServiceUri, {
|
||||
int? ddsPort,
|
||||
@ -132,4 +154,118 @@ mixin DartDevelopmentServiceLocalOperationsMixin {
|
||||
google3WorkspaceRoot: debuggingOptions.google3WorkspaceRoot,
|
||||
devToolsServerAddress: debuggingOptions.devToolsServerAddress,
|
||||
);
|
||||
|
||||
/// Launches a DevTools instance connected to the DDS instance connected to
|
||||
/// [device] in Chrome.
|
||||
bool launchDevToolsInBrowser(FlutterDevice device) {
|
||||
_calledLaunchDevToolsInBrowser = true;
|
||||
if (devToolsUri == null) {
|
||||
return false;
|
||||
}
|
||||
assert(devToolsUri != null);
|
||||
_logger.printStatus('Launching Flutter DevTools for ${device.device!.name} at $devToolsUri');
|
||||
unawaited(Chrome.start(<String>[devToolsUri!.toString()]));
|
||||
return true;
|
||||
}
|
||||
|
||||
/// Re-initializes Flutter framework service extension state after a hot
|
||||
/// restart.
|
||||
Future<void> handleHotRestart(FlutterDevice? device) => invokeServiceExtensions(device);
|
||||
|
||||
/// Initializes Flutter framework service extension state related to DevTools
|
||||
/// and VM service connection information.
|
||||
Future<void> invokeServiceExtensions(FlutterDevice? device) async {
|
||||
await Future.wait(<Future<void>>[
|
||||
maybeCallDevToolsUriServiceExtension(device: device, uri: devToolsUri),
|
||||
_callConnectedVmServiceUriExtension(device),
|
||||
]);
|
||||
}
|
||||
|
||||
/// Returns null if the service extension cannot be found on the device.
|
||||
Future<bool> _waitForExtensionsForDevice(FlutterDevice flutterDevice, String extension) async {
|
||||
try {
|
||||
await flutterDevice.vmService?.findExtensionIsolate(extension);
|
||||
return true;
|
||||
} on VmServiceDisappearedException {
|
||||
_logger.printTrace(
|
||||
'The VM Service for ${flutterDevice.device} disappeared while trying to'
|
||||
' find the $extension service extension. Skipping subsequent DevTools '
|
||||
'setup for this device.',
|
||||
);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// Sets the DevTools URI in the Flutter framework, used for deep linking
|
||||
/// support.
|
||||
Future<void> maybeCallDevToolsUriServiceExtension({
|
||||
required FlutterDevice? device,
|
||||
required Uri? uri,
|
||||
}) async {
|
||||
if (uri != null && device?.vmService != null) {
|
||||
// We're only setting the URI pointing to where DevTools is being served from. Don't include
|
||||
// any query parameters, including those used to automatically connect to the application.
|
||||
if (uri.hasQuery) {
|
||||
uri = uri.withoutQueryParameters();
|
||||
}
|
||||
await _callDevToolsUriExtension(device!, uri);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _callDevToolsUriExtension(FlutterDevice device, Uri uri) async {
|
||||
try {
|
||||
await _invokeRpcOnFirstView(
|
||||
'ext.flutter.activeDevToolsServerAddress',
|
||||
device: device,
|
||||
params: <String, dynamic>{'value': uri.toString()},
|
||||
);
|
||||
} on Exception catch (e) {
|
||||
_logger.printError(
|
||||
'Failed to set DevTools server address: $e. Deep links to'
|
||||
' DevTools will not show in Flutter errors.',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _callConnectedVmServiceUriExtension(FlutterDevice? device) async {
|
||||
if (device == null || uri == null) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
await _invokeRpcOnFirstView(
|
||||
'ext.flutter.connectedVmServiceUri',
|
||||
device: device,
|
||||
params: <String, dynamic>{'value': uri.toString()},
|
||||
);
|
||||
} on Exception catch (e) {
|
||||
_logger.printError(e.toString());
|
||||
_logger.printError(
|
||||
'Failed to set vm service URI: $e. Deep links to DevTools'
|
||||
' will not show in Flutter errors.',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _invokeRpcOnFirstView(
|
||||
String method, {
|
||||
required FlutterDevice device,
|
||||
required Map<String, dynamic> params,
|
||||
}) async {
|
||||
if (!(await _waitForExtensionsForDevice(device, method))) {
|
||||
return;
|
||||
}
|
||||
if (device.targetPlatform == TargetPlatform.web_javascript) {
|
||||
await device.vmService!.callMethodWrapper(method, args: params);
|
||||
return;
|
||||
}
|
||||
final List<FlutterView> views = await device.vmService!.getFlutterViews();
|
||||
if (views.isEmpty) {
|
||||
return;
|
||||
}
|
||||
await device.vmService!.invokeFlutterExtensionRpcRaw(
|
||||
method,
|
||||
args: params,
|
||||
isolateId: views.first.uiIsolate!.id,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ -573,3 +573,10 @@ extension DurationAgo on Duration {
|
||||
return '$inMinutes minutes ago';
|
||||
}
|
||||
}
|
||||
|
||||
extension UriExtension on Uri {
|
||||
/// Returns this [Uri] with its query parameters removed.
|
||||
Uri withoutQueryParameters() {
|
||||
return Uri(scheme: scheme, userInfo: userInfo, host: host, port: port, path: this.path);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1280,7 +1280,11 @@ class DeviceDomain extends Domain {
|
||||
devToolsServerAddress: devToolsServerAddress,
|
||||
);
|
||||
unawaited(device.dds.done.whenComplete(() => sendEvent('device.dds.done.$deviceId')));
|
||||
return <String, Object?>{'ddsUri': device.dds.uri?.toString()};
|
||||
return <String, Object?>{
|
||||
'ddsUri': device.dds.uri?.toString(),
|
||||
'devToolsUri': device.dds.devToolsUri?.toString(),
|
||||
'dtdUri': device.dds.dtdUri?.toString(),
|
||||
};
|
||||
}
|
||||
|
||||
/// Starts DDS for the device.
|
||||
|
||||
@ -709,6 +709,9 @@ abstract class Device {
|
||||
/// Get the DDS instance for this device.
|
||||
final DartDevelopmentService dds;
|
||||
|
||||
/// Get the DevTools URI for the application instance.
|
||||
Uri? get devToolsUri => dds.devToolsUri;
|
||||
|
||||
/// Clear the device's logs.
|
||||
void clearLogs();
|
||||
|
||||
|
||||
@ -67,8 +67,7 @@ class WebDevFS implements DevFS {
|
||||
required this.useSseForInjectedClient,
|
||||
required this.buildInfo,
|
||||
required this.enableDwds,
|
||||
required this.enableDds,
|
||||
this.ddsPort,
|
||||
required this.ddsConfig,
|
||||
required this.entrypoint,
|
||||
required this.expressionCompiler,
|
||||
required this.chromiumLauncher,
|
||||
@ -101,8 +100,7 @@ class WebDevFS implements DevFS {
|
||||
final bool useSseForInjectedClient;
|
||||
final BuildInfo buildInfo;
|
||||
final bool enableDwds;
|
||||
final bool enableDds;
|
||||
final int? ddsPort;
|
||||
final DartDevelopmentServiceConfiguration ddsConfig;
|
||||
final bool testMode;
|
||||
final bool ddcModuleSystem;
|
||||
final bool canaryFeatures;
|
||||
@ -208,8 +206,7 @@ class WebDevFS implements DevFS {
|
||||
useSseForInjectedClient,
|
||||
buildInfo,
|
||||
enableDwds,
|
||||
enableDds,
|
||||
ddsPort,
|
||||
ddsConfig,
|
||||
entrypoint,
|
||||
expressionCompiler,
|
||||
webRenderer: webRenderer,
|
||||
|
||||
@ -32,7 +32,6 @@ import '../globals.dart' as globals;
|
||||
import '../hook_runner.dart' show hookRunner;
|
||||
import '../project.dart';
|
||||
import '../reporting/reporting.dart';
|
||||
import '../resident_devtools_handler.dart';
|
||||
import '../resident_runner.dart';
|
||||
import '../run_hot.dart';
|
||||
import '../vmservice.dart';
|
||||
@ -105,8 +104,6 @@ class ResidentWebRunner extends ResidentRunner {
|
||||
required SystemClock systemClock,
|
||||
required Analytics analytics,
|
||||
UrlTunneller? urlTunneller,
|
||||
// TODO(bkonyi): remove when ready to serve DevTools from DDS.
|
||||
ResidentDevtoolsHandlerFactory devtoolsHandler = createDefaultHandler,
|
||||
}) : _fileSystem = fileSystem,
|
||||
_logger = logger,
|
||||
_platform = platform,
|
||||
@ -119,7 +116,6 @@ class ResidentWebRunner extends ResidentRunner {
|
||||
debuggingOptions: debuggingOptions,
|
||||
stayResident: stayResident,
|
||||
machine: machine,
|
||||
devtoolsHandler: devtoolsHandler,
|
||||
commandHelp: CommandHelp(
|
||||
logger: logger,
|
||||
terminal: terminal,
|
||||
@ -218,8 +214,6 @@ class ResidentWebRunner extends ResidentRunner {
|
||||
if (_exited) {
|
||||
return;
|
||||
}
|
||||
// TODO(bkonyi): remove when ready to serve DevTools from DDS.
|
||||
await residentDevtoolsHandler!.shutdown();
|
||||
await _stdOutSub?.cancel();
|
||||
await _stdErrSub?.cancel();
|
||||
await _serviceSub?.cancel();
|
||||
@ -298,8 +292,12 @@ class ResidentWebRunner extends ResidentRunner {
|
||||
useSseForInjectedClient: debuggingOptions.webUseSseForInjectedClient,
|
||||
buildInfo: debuggingOptions.buildInfo,
|
||||
enableDwds: supportsServiceProtocol,
|
||||
enableDds: debuggingOptions.enableDds,
|
||||
ddsPort: debuggingOptions.ddsPort,
|
||||
ddsConfig: DartDevelopmentServiceConfiguration(
|
||||
enable: debuggingOptions.enableDds,
|
||||
port: debuggingOptions.ddsPort,
|
||||
serveDevTools: debuggingOptions.enableDevTools,
|
||||
devToolsServerAddress: debuggingOptions.devToolsServerAddress,
|
||||
),
|
||||
entrypoint: _fileSystem.file(target).uri,
|
||||
expressionCompiler: expressionCompiler,
|
||||
chromiumLauncher: _chromiumLauncher,
|
||||
@ -563,7 +561,9 @@ class ResidentWebRunner extends ResidentRunner {
|
||||
_logger.printStatus('${fullRestart ? 'Restarted' : 'Reloaded'} application in $elapsedMS.');
|
||||
|
||||
if (fullRestart) {
|
||||
unawaited(residentDevtoolsHandler!.hotRestart(flutterDevices));
|
||||
for (final FlutterDevice? device in flutterDevices) {
|
||||
unawaited(device?.handleHotRestart());
|
||||
}
|
||||
}
|
||||
|
||||
// Don't track restart times for dart2js builds or web-server devices.
|
||||
@ -788,7 +788,8 @@ class ResidentWebRunner extends ResidentRunner {
|
||||
unawaited(
|
||||
connectDebug!.then((connectionResult) async {
|
||||
_connectionResult = connectionResult;
|
||||
unawaited(_connectionResult!.debugConnection!.onDone.whenComplete(_cleanupAndExit));
|
||||
final DebugConnection debugConnection = connectionResult!.debugConnection!;
|
||||
unawaited(debugConnection.onDone.whenComplete(_cleanupAndExit));
|
||||
|
||||
void onLogEvent(vmservice.Event event) {
|
||||
final String message = processVmServiceMessage(event);
|
||||
@ -850,8 +851,11 @@ class ResidentWebRunner extends ResidentRunner {
|
||||
vmService: _vmService.service,
|
||||
);
|
||||
|
||||
final Uri websocketUri = Uri.parse(_connectionResult!.debugConnection!.uri);
|
||||
final Uri websocketUri = Uri.parse(debugConnection.uri);
|
||||
device!.vmService = _vmService;
|
||||
if (debugConnection.devToolsUri != null) {
|
||||
(device!.device! as WebDevice).devToolsUri = Uri.parse(debugConnection.devToolsUri!);
|
||||
}
|
||||
|
||||
// Run main immediately if the app is not started paused or if there
|
||||
// is no debugger attached. Otherwise, runMain when a resume event
|
||||
@ -883,16 +887,6 @@ class ResidentWebRunner extends ResidentRunner {
|
||||
} else {
|
||||
connectionInfoCompleter?.complete(DebugConnectionInfo());
|
||||
}
|
||||
// TODO(bkonyi): remove when ready to serve DevTools from DDS.
|
||||
if (debuggingOptions.enableDevTools) {
|
||||
// The method below is guaranteed never to return a failing future.
|
||||
unawaited(
|
||||
residentDevtoolsHandler!.serveAndAnnounceDevTools(
|
||||
devToolsServerAddress: debuggingOptions.devToolsServerAddress,
|
||||
flutterDevices: flutterDevices,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
appStartedCompleter?.complete();
|
||||
if (stayResident) {
|
||||
|
||||
@ -177,8 +177,7 @@ class WebAssetServer implements AssetReader {
|
||||
bool useSseForInjectedClient,
|
||||
BuildInfo buildInfo,
|
||||
bool enableDwds,
|
||||
bool enableDds,
|
||||
int? ddsPort,
|
||||
DartDevelopmentServiceConfiguration ddsConfig,
|
||||
Uri entrypoint,
|
||||
ExpressionCompiler? expressionCompiler, {
|
||||
required WebDevServerConfig webDevServerConfig,
|
||||
@ -362,8 +361,7 @@ class WebAssetServer implements AssetReader {
|
||||
useSseForDebugBackend: useSseForDebugBackend,
|
||||
useSseForInjectedClient: useSseForInjectedClient,
|
||||
expressionCompiler: expressionCompiler,
|
||||
spawnDds: enableDds,
|
||||
ddsPort: ddsPort,
|
||||
ddsConfiguration: ddsConfig,
|
||||
),
|
||||
appMetadata: AppMetadata(hostname: hostname),
|
||||
),
|
||||
|
||||
@ -828,6 +828,14 @@ class ProxiedDartDevelopmentService
|
||||
Uri? get uri => _ddsStartedLocally ? _localDds.uri : _localUri;
|
||||
Uri? _localUri;
|
||||
|
||||
@override
|
||||
Uri? get devToolsUri => _ddsStartedLocally ? _localDds.devToolsUri : _remoteDevToolsUri;
|
||||
Uri? _remoteDevToolsUri;
|
||||
|
||||
@override
|
||||
Uri? get dtdUri => _ddsStartedLocally ? _localDds.dtdUri : _remoteDtdUri;
|
||||
Uri? _remoteDtdUri;
|
||||
|
||||
@override
|
||||
Future<void> get done => _completer.future;
|
||||
final _completer = Completer<void>();
|
||||
@ -867,6 +875,7 @@ class ProxiedDartDevelopmentService
|
||||
google3WorkspaceRoot: google3WorkspaceRoot,
|
||||
devToolsServerAddress: devToolsServerAddress,
|
||||
);
|
||||
unawaited(_localDds.invokeServiceExtensions(device));
|
||||
unawaited(_localDds.done.then(_completer.complete));
|
||||
}
|
||||
|
||||
@ -897,10 +906,21 @@ class ProxiedDartDevelopmentService
|
||||
'deviceId': deviceId,
|
||||
'vmServiceUri': remoteVMServiceUri.toString(),
|
||||
'disableServiceAuthCodes': disableServiceAuthCodes,
|
||||
'enableDevTools': enableDevTools,
|
||||
if (devToolsServerAddress != null)
|
||||
'devToolsServerAddress': devToolsServerAddress.toString(),
|
||||
});
|
||||
|
||||
if (response is Map<String, Object?>) {
|
||||
remoteUriStr = response['ddsUri'] as String?;
|
||||
final devToolsUriStr = response['devToolsUri'] as String?;
|
||||
if (devToolsUriStr != null) {
|
||||
_remoteDevToolsUri = Uri.parse(devToolsUriStr);
|
||||
}
|
||||
final dtdUriStr = response['dtdUri'] as String?;
|
||||
if (dtdUriStr != null) {
|
||||
_remoteDtdUri = Uri.parse(dtdUriStr);
|
||||
}
|
||||
} else {
|
||||
// For backwards compatibility in google3.
|
||||
// TODO(bkonyi): remove once a newer version of the flutter_tool is rolled out.
|
||||
|
||||
@ -1,382 +0,0 @@
|
||||
// Copyright 2014 The Flutter Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// TODO(bkonyi): remove this file when ready to serve DevTools from DDS.
|
||||
//
|
||||
// See https://github.com/flutter/flutter/issues/150044
|
||||
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
import 'base/io.dart';
|
||||
import 'base/logger.dart';
|
||||
import 'build_info.dart';
|
||||
import 'resident_runner.dart';
|
||||
import 'vmservice.dart';
|
||||
import 'web/chrome.dart';
|
||||
|
||||
typedef ResidentDevtoolsHandlerFactory =
|
||||
ResidentDevtoolsHandler Function(DevtoolsLauncher?, ResidentRunner, Logger, ChromiumLauncher);
|
||||
|
||||
ResidentDevtoolsHandler createDefaultHandler(
|
||||
DevtoolsLauncher? launcher,
|
||||
ResidentRunner runner,
|
||||
Logger logger,
|
||||
ChromiumLauncher chromiumLauncher,
|
||||
) {
|
||||
return FlutterResidentDevtoolsHandler(launcher, runner, logger, chromiumLauncher);
|
||||
}
|
||||
|
||||
/// Helper class to manage the life-cycle of devtools and its interaction with
|
||||
/// the resident runner.
|
||||
abstract class ResidentDevtoolsHandler {
|
||||
/// The current devtools server, or null if one is not running.
|
||||
DevToolsServerAddress? get activeDevToolsServer;
|
||||
|
||||
/// The Dart Tooling Daemon (DTD) URI for the DTD instance being hosted by
|
||||
/// DevTools server.
|
||||
///
|
||||
/// This will be null if the DevTools server is not served through Flutter
|
||||
/// tools (e.g. if it is served from an IDE).
|
||||
Uri? get dtdUri;
|
||||
|
||||
/// Whether to print the Dart Tooling Daemon URI.
|
||||
///
|
||||
/// This will always return false when there is not a DTD instance being
|
||||
/// served from the DevTools server.
|
||||
bool get printDtdUri;
|
||||
|
||||
/// Whether it's ok to announce the [activeDevToolsServer].
|
||||
///
|
||||
/// This should only return true once all the devices have been notified
|
||||
/// of the DevTools.
|
||||
bool get readyToAnnounce;
|
||||
|
||||
Future<void> hotRestart(List<FlutterDevice?> flutterDevices);
|
||||
|
||||
Future<void> serveAndAnnounceDevTools({
|
||||
Uri? devToolsServerAddress,
|
||||
required List<FlutterDevice?> flutterDevices,
|
||||
bool isStartPaused = false,
|
||||
});
|
||||
|
||||
bool launchDevToolsInBrowser({required List<FlutterDevice?> flutterDevices});
|
||||
|
||||
Future<void> shutdown();
|
||||
}
|
||||
|
||||
class FlutterResidentDevtoolsHandler implements ResidentDevtoolsHandler {
|
||||
FlutterResidentDevtoolsHandler(
|
||||
this._devToolsLauncher,
|
||||
this._residentRunner,
|
||||
this._logger,
|
||||
this._chromiumLauncher,
|
||||
);
|
||||
|
||||
static const launchInBrowserTimeout = Duration(seconds: 15);
|
||||
|
||||
final DevtoolsLauncher? _devToolsLauncher;
|
||||
final ResidentRunner _residentRunner;
|
||||
final ChromiumLauncher _chromiumLauncher;
|
||||
final Logger _logger;
|
||||
var _shutdown = false;
|
||||
|
||||
@visibleForTesting
|
||||
var launchedInBrowser = false;
|
||||
|
||||
@override
|
||||
DevToolsServerAddress? get activeDevToolsServer {
|
||||
assert(!_readyToAnnounce || _devToolsLauncher?.activeDevToolsServer != null);
|
||||
return _devToolsLauncher?.activeDevToolsServer;
|
||||
}
|
||||
|
||||
@override
|
||||
Uri? get dtdUri => _devToolsLauncher?.dtdUri;
|
||||
|
||||
@override
|
||||
bool get printDtdUri => _devToolsLauncher?.printDtdUri ?? false;
|
||||
|
||||
@override
|
||||
bool get readyToAnnounce => _readyToAnnounce;
|
||||
var _readyToAnnounce = false;
|
||||
|
||||
// This must be guaranteed not to return a Future that fails.
|
||||
@override
|
||||
Future<void> serveAndAnnounceDevTools({
|
||||
Uri? devToolsServerAddress,
|
||||
required List<FlutterDevice?> flutterDevices,
|
||||
bool isStartPaused = false,
|
||||
}) async {
|
||||
assert(!_readyToAnnounce);
|
||||
if (!_residentRunner.supportsServiceProtocol || _devToolsLauncher == null) {
|
||||
return;
|
||||
}
|
||||
if (devToolsServerAddress != null) {
|
||||
_devToolsLauncher.devToolsUrl = devToolsServerAddress;
|
||||
} else {
|
||||
await _devToolsLauncher.serve();
|
||||
}
|
||||
await _devToolsLauncher.ready;
|
||||
// Do not attempt to print debugger list if the connection has failed or if we're shutting down.
|
||||
if (_devToolsLauncher.activeDevToolsServer == null || _shutdown) {
|
||||
assert(!_readyToAnnounce);
|
||||
return;
|
||||
}
|
||||
|
||||
Future<void> callServiceExtensions() async {
|
||||
final List<FlutterDevice?> devicesWithExtension = await _devicesWithExtensions(
|
||||
flutterDevices,
|
||||
);
|
||||
await Future.wait(<Future<void>>[
|
||||
_maybeCallDevToolsUriServiceExtension(devicesWithExtension),
|
||||
_callConnectedVmServiceUriExtension(devicesWithExtension),
|
||||
]);
|
||||
}
|
||||
|
||||
// If the application is starting paused, we can't invoke service extensions
|
||||
// as they're handled on the target app's paused isolate. Since invoking
|
||||
// service extensions will block in this situation, we should wait to invoke
|
||||
// them until after we've output the DevTools connection details.
|
||||
if (!isStartPaused) {
|
||||
await callServiceExtensions();
|
||||
}
|
||||
|
||||
// This check needs to happen after the possible asynchronous call above,
|
||||
// otherwise a shutdown event might be missed and the DevTools launcher may
|
||||
// no longer be initialized.
|
||||
if (_shutdown) {
|
||||
// If we're shutting down, no point reporting the debugger list.
|
||||
return;
|
||||
}
|
||||
|
||||
_readyToAnnounce = true;
|
||||
assert(_devToolsLauncher.activeDevToolsServer != null);
|
||||
if (_residentRunner.reportedDebuggers) {
|
||||
// Since the DevTools only just became available, we haven't had a chance to
|
||||
// report their URLs yet. Do so now.
|
||||
_residentRunner.printDebuggerList(includeVmService: false);
|
||||
}
|
||||
|
||||
if (isStartPaused) {
|
||||
await callServiceExtensions();
|
||||
}
|
||||
}
|
||||
|
||||
// This must be guaranteed not to return a Future that fails.
|
||||
@override
|
||||
bool launchDevToolsInBrowser({required List<FlutterDevice?> flutterDevices}) {
|
||||
if (!_residentRunner.supportsServiceProtocol || _devToolsLauncher == null) {
|
||||
return false;
|
||||
}
|
||||
if (_devToolsLauncher.devToolsUrl == null) {
|
||||
_logger.startProgress('Waiting for Flutter DevTools to be served...');
|
||||
unawaited(
|
||||
_devToolsLauncher.ready.then((_) {
|
||||
_launchDevToolsForDevices(flutterDevices);
|
||||
}),
|
||||
);
|
||||
} else {
|
||||
_launchDevToolsForDevices(flutterDevices);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void _launchDevToolsForDevices(List<FlutterDevice?> flutterDevices) {
|
||||
assert(activeDevToolsServer != null);
|
||||
for (final device in flutterDevices) {
|
||||
final devToolsUrl = activeDevToolsServer!.uri!
|
||||
.replace(queryParameters: <String, dynamic>{'uri': '${device!.vmService!.httpAddress}'})
|
||||
.toString();
|
||||
_logger.printStatus('Launching Flutter DevTools for ${device.device!.name} at $devToolsUrl');
|
||||
|
||||
_chromiumLauncher.launch(devToolsUrl).catchError((Object e) {
|
||||
_logger.printError('Failed to launch web browser: $e');
|
||||
throw ProcessException('Chrome', <String>[
|
||||
devToolsUrl,
|
||||
], 'Failed to launch browser for dev tools');
|
||||
}).ignore();
|
||||
}
|
||||
launchedInBrowser = true;
|
||||
}
|
||||
|
||||
Future<void> _maybeCallDevToolsUriServiceExtension(List<FlutterDevice?> flutterDevices) async {
|
||||
if (_devToolsLauncher?.activeDevToolsServer == null) {
|
||||
return;
|
||||
}
|
||||
await Future.wait(<Future<void>>[
|
||||
for (final FlutterDevice? device in flutterDevices)
|
||||
if (device?.vmService != null) _callDevToolsUriExtension(device!),
|
||||
]);
|
||||
}
|
||||
|
||||
Future<void> _callDevToolsUriExtension(FlutterDevice device) async {
|
||||
try {
|
||||
await _invokeRpcOnFirstView(
|
||||
'ext.flutter.activeDevToolsServerAddress',
|
||||
device: device,
|
||||
params: <String, dynamic>{'value': _devToolsLauncher!.activeDevToolsServer!.uri.toString()},
|
||||
);
|
||||
} on Exception catch (e) {
|
||||
if (!_shutdown) {
|
||||
_logger.printError(
|
||||
'Failed to set DevTools server address: $e. Deep links to'
|
||||
' DevTools will not show in Flutter errors.',
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Future<List<FlutterDevice?>> _devicesWithExtensions(List<FlutterDevice?> flutterDevices) async {
|
||||
return Future.wait(<Future<FlutterDevice?>>[
|
||||
for (final FlutterDevice? device in flutterDevices) _waitForExtensionsForDevice(device!),
|
||||
]);
|
||||
}
|
||||
|
||||
/// Returns null if the service extension cannot be found on the device.
|
||||
Future<FlutterDevice?> _waitForExtensionsForDevice(FlutterDevice flutterDevice) async {
|
||||
const extension = 'ext.flutter.connectedVmServiceUri';
|
||||
try {
|
||||
await flutterDevice.vmService?.findExtensionIsolate(extension);
|
||||
return flutterDevice;
|
||||
} on VmServiceDisappearedException {
|
||||
_logger.printTrace(
|
||||
'The VM Service for ${flutterDevice.device} disappeared while trying to'
|
||||
' find the $extension service extension. Skipping subsequent DevTools '
|
||||
'setup for this device.',
|
||||
);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _callConnectedVmServiceUriExtension(List<FlutterDevice?> flutterDevices) async {
|
||||
await Future.wait(<Future<void>>[
|
||||
for (final FlutterDevice? device in flutterDevices)
|
||||
if (device?.vmService != null) _callConnectedVmServiceExtension(device!),
|
||||
]);
|
||||
}
|
||||
|
||||
Future<void> _callConnectedVmServiceExtension(FlutterDevice device) async {
|
||||
final Uri? uri = device.vmService!.httpAddress ?? device.vmService!.wsAddress;
|
||||
if (uri == null) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
await _invokeRpcOnFirstView(
|
||||
'ext.flutter.connectedVmServiceUri',
|
||||
device: device,
|
||||
params: <String, dynamic>{'value': uri.toString()},
|
||||
);
|
||||
} on Exception catch (e) {
|
||||
if (!_shutdown) {
|
||||
_logger.printError(e.toString());
|
||||
_logger.printError(
|
||||
'Failed to set vm service URI: $e. Deep links to DevTools'
|
||||
' will not show in Flutter errors.',
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _invokeRpcOnFirstView(
|
||||
String method, {
|
||||
required FlutterDevice device,
|
||||
required Map<String, dynamic> params,
|
||||
}) async {
|
||||
if (device.targetPlatform == TargetPlatform.web_javascript) {
|
||||
await device.vmService!.callMethodWrapper(method, args: params);
|
||||
return;
|
||||
}
|
||||
final List<FlutterView> views = await device.vmService!.getFlutterViews();
|
||||
if (views.isEmpty) {
|
||||
return;
|
||||
}
|
||||
await device.vmService!.invokeFlutterExtensionRpcRaw(
|
||||
method,
|
||||
args: params,
|
||||
isolateId: views.first.uiIsolate!.id,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> hotRestart(List<FlutterDevice?> flutterDevices) async {
|
||||
final List<FlutterDevice?> devicesWithExtension = await _devicesWithExtensions(flutterDevices);
|
||||
await Future.wait(<Future<void>>[
|
||||
_maybeCallDevToolsUriServiceExtension(devicesWithExtension),
|
||||
_callConnectedVmServiceUriExtension(devicesWithExtension),
|
||||
]);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> shutdown() async {
|
||||
_shutdown = true;
|
||||
if (_devToolsLauncher == null) {
|
||||
return;
|
||||
}
|
||||
_readyToAnnounce = false;
|
||||
await _devToolsLauncher.close();
|
||||
}
|
||||
}
|
||||
|
||||
@visibleForTesting
|
||||
NoOpDevtoolsHandler createNoOpHandler(
|
||||
DevtoolsLauncher? launcher,
|
||||
ResidentRunner runner,
|
||||
Logger logger,
|
||||
ChromiumLauncher? chromiumLauncher,
|
||||
) {
|
||||
return NoOpDevtoolsHandler();
|
||||
}
|
||||
|
||||
@visibleForTesting
|
||||
class NoOpDevtoolsHandler implements ResidentDevtoolsHandler {
|
||||
var wasShutdown = false;
|
||||
|
||||
@override
|
||||
DevToolsServerAddress? get activeDevToolsServer => null;
|
||||
|
||||
@override
|
||||
bool get readyToAnnounce => false;
|
||||
|
||||
@override
|
||||
Future<void> hotRestart(List<FlutterDevice?> flutterDevices) async {
|
||||
return;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> serveAndAnnounceDevTools({
|
||||
Uri? devToolsServerAddress,
|
||||
List<FlutterDevice?>? flutterDevices,
|
||||
bool isStartPaused = false,
|
||||
}) async {
|
||||
return;
|
||||
}
|
||||
|
||||
@override
|
||||
bool launchDevToolsInBrowser({List<FlutterDevice?>? flutterDevices}) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> shutdown() async {
|
||||
wasShutdown = true;
|
||||
return;
|
||||
}
|
||||
|
||||
@override
|
||||
Uri? get dtdUri => null;
|
||||
|
||||
@override
|
||||
bool get printDtdUri => false;
|
||||
}
|
||||
|
||||
/// Convert the [uri] with query parameters into a display format instead
|
||||
/// of the default URI encoding.
|
||||
String urlToDisplayString(Uri uri) {
|
||||
final base = StringBuffer(uri.replace(queryParameters: <String, String>{}).toString());
|
||||
base.write(
|
||||
uri.queryParameters.keys.map((String key) => '$key=${uri.queryParameters[key]}').join('&'),
|
||||
);
|
||||
return base.toString();
|
||||
}
|
||||
@ -36,11 +36,9 @@ import 'hook_runner.dart' show FlutterHookRunner;
|
||||
import 'ios/application_package.dart';
|
||||
import 'ios/devices.dart';
|
||||
import 'project.dart';
|
||||
import 'resident_devtools_handler.dart';
|
||||
import 'run_cold.dart';
|
||||
import 'run_hot.dart';
|
||||
import 'vmservice.dart';
|
||||
import 'web/chrome.dart';
|
||||
|
||||
class FlutterDevice {
|
||||
FlutterDevice(
|
||||
@ -274,6 +272,7 @@ class FlutterDevice {
|
||||
try {
|
||||
service = await connectToVmService(vmServiceUri!, logger: globals.logger);
|
||||
await service.dispose();
|
||||
break;
|
||||
} on vm_service.RPCError catch (e, st) {
|
||||
if (!e.isConnectionDisposedException) {
|
||||
handleVmServiceCheckException(e);
|
||||
@ -392,6 +391,23 @@ class FlutterDevice {
|
||||
globals.printTrace('Successfully connected to service protocol: $vmServiceUri');
|
||||
|
||||
vmService = service;
|
||||
if (debuggingOptions.enableDds && !existingDds) {
|
||||
// Don't await this as service extensions won't return if the target
|
||||
// isolate is paused on start.
|
||||
unawaited(device!.dds.invokeServiceExtensions(this));
|
||||
}
|
||||
if ((existingDds || !debuggingOptions.enableDds) &&
|
||||
debuggingOptions.devToolsServerAddress != null) {
|
||||
// Don't await this as service extensions won't return if the target
|
||||
// isolate is paused on start.
|
||||
unawaited(
|
||||
device!.dds.maybeCallDevToolsUriServiceExtension(
|
||||
device: this,
|
||||
uri: debuggingOptions.devToolsServerAddress,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
await (await device!.getLogReader(app: package)).provideVmService(vmService!);
|
||||
completer.complete();
|
||||
await subscription.cancel();
|
||||
@ -626,6 +642,10 @@ class FlutterDevice {
|
||||
await generator?.reject();
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> handleHotRestart() async {
|
||||
await device?.dds.handleHotRestart(this);
|
||||
}
|
||||
}
|
||||
|
||||
/// A subset of the [ResidentRunner] for delegating to attached flutter devices.
|
||||
@ -664,9 +684,6 @@ abstract class ResidentHandlers {
|
||||
/// Whether an application can be detached without being stopped.
|
||||
bool get supportsDetach;
|
||||
|
||||
// TODO(bkonyi): remove when ready to serve DevTools from DDS.
|
||||
ResidentDevtoolsHandler? get residentDevtoolsHandler;
|
||||
|
||||
@protected
|
||||
Logger get logger;
|
||||
|
||||
@ -1042,7 +1059,6 @@ abstract class ResidentRunner extends ResidentHandlers {
|
||||
this.hotMode = true,
|
||||
String? dillOutputPath,
|
||||
this.machine = false,
|
||||
ResidentDevtoolsHandlerFactory devtoolsHandler = createDefaultHandler,
|
||||
CommandHelp? commandHelp,
|
||||
this.dartBuilder,
|
||||
}) : mainPath = globals.fs.file(target).absolute.path,
|
||||
@ -1064,20 +1080,6 @@ abstract class ResidentRunner extends ResidentHandlers {
|
||||
if (!artifactDirectory.existsSync()) {
|
||||
artifactDirectory.createSync(recursive: true);
|
||||
}
|
||||
// TODO(bkonyi): remove when ready to serve DevTools from DDS.
|
||||
_residentDevtoolsHandler = devtoolsHandler(
|
||||
DevtoolsLauncher.instance,
|
||||
this,
|
||||
globals.logger,
|
||||
ChromiumLauncher(
|
||||
fileSystem: globals.fs,
|
||||
platform: globals.platform,
|
||||
processManager: globals.processManager,
|
||||
operatingSystemUtils: globals.os,
|
||||
browserFinder: findChromeExecutable,
|
||||
logger: globals.logger,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
@ -1106,11 +1108,6 @@ abstract class ResidentRunner extends ResidentHandlers {
|
||||
final CommandHelp commandHelp;
|
||||
final bool machine;
|
||||
|
||||
// TODO(bkonyi): remove when ready to serve DevTools from DDS.
|
||||
@override
|
||||
ResidentDevtoolsHandler? get residentDevtoolsHandler => _residentDevtoolsHandler;
|
||||
ResidentDevtoolsHandler? _residentDevtoolsHandler;
|
||||
|
||||
var _exited = false;
|
||||
var _finished = Completer<int>();
|
||||
BuildResult? _lastBuild;
|
||||
@ -1276,8 +1273,6 @@ abstract class ResidentRunner extends ResidentHandlers {
|
||||
@override
|
||||
Future<void> exit() async {
|
||||
_exited = true;
|
||||
// TODO(bkonyi): remove when ready to serve DevTools from DDS.
|
||||
await residentDevtoolsHandler!.shutdown();
|
||||
await stopEchoingDeviceLog();
|
||||
await preExit();
|
||||
await exitApp(); // calls appFinished
|
||||
@ -1289,8 +1284,6 @@ abstract class ResidentRunner extends ResidentHandlers {
|
||||
Future<void> detach() async {
|
||||
stopAppDuringCleanup = false;
|
||||
|
||||
// TODO(bkonyi): remove when ready to serve DevTools from DDS.
|
||||
await residentDevtoolsHandler!.shutdown();
|
||||
await stopEchoingDeviceLog();
|
||||
await preExit();
|
||||
appFinished();
|
||||
@ -1453,42 +1446,40 @@ abstract class ResidentRunner extends ResidentHandlers {
|
||||
bool get reportedDebuggers => _reportedDebuggers;
|
||||
var _reportedDebuggers = false;
|
||||
|
||||
void printDebuggerList({bool includeVmService = true, bool includeDevtools = true}) {
|
||||
// TODO(bkonyi): update this logic when ready to serve DevTools from DDS.
|
||||
final DevToolsServerAddress? devToolsServerAddress =
|
||||
residentDevtoolsHandler!.activeDevToolsServer;
|
||||
if (!residentDevtoolsHandler!.readyToAnnounce) {
|
||||
includeDevtools = false;
|
||||
}
|
||||
assert(!includeDevtools || devToolsServerAddress != null);
|
||||
void printDebuggerList() {
|
||||
for (final FlutterDevice? device in flutterDevices) {
|
||||
if (device!.vmService == null) {
|
||||
continue;
|
||||
}
|
||||
if (includeVmService) {
|
||||
// Caution: This log line is parsed by device lab tests.
|
||||
logger.printStatus(
|
||||
'A Dart VM Service on ${device.device!.displayName} '
|
||||
'is available at: ${device.vmService!.httpAddress}',
|
||||
);
|
||||
// Caution: This log line is parsed by device lab tests.
|
||||
globals.printStatus(
|
||||
'A Dart VM Service on ${device.device!.name} is available at: '
|
||||
'${device.vmService!.httpAddress}',
|
||||
);
|
||||
|
||||
final DartDevelopmentService dds = device.device!.dds;
|
||||
final Uri? dtdUri = dds.dtdUri;
|
||||
if (debuggingOptions.printDtd && dtdUri != null) {
|
||||
globals.printStatus('The Dart Tooling Daemon is available at: $dtdUri');
|
||||
}
|
||||
if (includeDevtools) {
|
||||
if (_residentDevtoolsHandler!.printDtdUri) {
|
||||
final Uri? dtdUri = residentDevtoolsHandler!.dtdUri;
|
||||
if (dtdUri != null) {
|
||||
logger.printStatus('The Dart Tooling Daemon is available at: $dtdUri\n');
|
||||
}
|
||||
}
|
||||
final Uri? uri = devToolsServerAddress!.uri?.replace(
|
||||
queryParameters: <String, dynamic>{'uri': '${device.vmService!.httpAddress}'},
|
||||
);
|
||||
if (uri != null) {
|
||||
logger.printStatus(
|
||||
'The Flutter DevTools debugger and profiler '
|
||||
'on ${device.device!.displayName} '
|
||||
'is available at: ${urlToDisplayString(uri)}',
|
||||
final Uri? devToolsUri = device.device!.devToolsUri;
|
||||
if (devToolsUri != null) {
|
||||
/// Convert a [URI] with query parameters into a display format instead
|
||||
/// of the default URI encoding.
|
||||
String urlToDisplayString(Uri uri) {
|
||||
final base = StringBuffer(uri.withoutQueryParameters().toString());
|
||||
base.write(
|
||||
uri.queryParameters.keys
|
||||
.map((String key) => '$key=${uri.queryParameters[key]}')
|
||||
.join('&'),
|
||||
);
|
||||
return base.toString();
|
||||
}
|
||||
|
||||
globals.printStatus(
|
||||
'The Flutter DevTools debugger and profiler '
|
||||
'on ${device.device!.name} is available at: ${urlToDisplayString(devToolsUri)}',
|
||||
);
|
||||
}
|
||||
}
|
||||
_reportedDebuggers = true;
|
||||
@ -1805,14 +1796,18 @@ class TerminalHandler {
|
||||
) {
|
||||
return flutterDevice?.targetPlatform == TargetPlatform.web_javascript;
|
||||
});
|
||||
|
||||
if (residentRunner.isRunningDebug || !isRunningOnWeb) {
|
||||
// DevTools are only supported in debug mode for web, see https://docs.flutter.dev/testing/build-modes#profile
|
||||
return residentRunner.residentDevtoolsHandler!.launchDevToolsInBrowser(
|
||||
flutterDevices: residentRunner.flutterDevices,
|
||||
);
|
||||
return residentRunner.flutterDevices
|
||||
.where(
|
||||
(FlutterDevice? device) => device?.targetPlatform != TargetPlatform.web_javascript,
|
||||
)
|
||||
.fold<bool>(
|
||||
true,
|
||||
(bool s, FlutterDevice? device) =>
|
||||
s && device!.device!.dds.launchDevToolsInBrowser(device),
|
||||
);
|
||||
}
|
||||
|
||||
return false;
|
||||
case 'w':
|
||||
case 'W':
|
||||
|
||||
@ -24,7 +24,6 @@ class ColdRunner extends ResidentRunner {
|
||||
this.applicationBinary,
|
||||
super.stayResident,
|
||||
super.machine,
|
||||
super.devtoolsHandler,
|
||||
super.dartBuilder,
|
||||
}) : super(hotMode: false);
|
||||
|
||||
@ -76,18 +75,6 @@ class ColdRunner extends ResidentRunner {
|
||||
}
|
||||
}
|
||||
|
||||
// TODO(bkonyi): remove when ready to serve DevTools from DDS.
|
||||
if (debuggingEnabled && debuggingOptions.enableDevTools) {
|
||||
// The method below is guaranteed never to return a failing future.
|
||||
unawaited(
|
||||
residentDevtoolsHandler!.serveAndAnnounceDevTools(
|
||||
devToolsServerAddress: debuggingOptions.devToolsServerAddress,
|
||||
flutterDevices: flutterDevices,
|
||||
isStartPaused: debuggingOptions.startPaused,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
if (flutterDevices.first.vmServiceUris != null) {
|
||||
// For now, only support one debugger connection.
|
||||
connectionInfoCompleter?.complete(
|
||||
@ -178,7 +165,6 @@ class ColdRunner extends ResidentRunner {
|
||||
for (final FlutterDevice? flutterDevice in flutterDevices) {
|
||||
await flutterDevice!.device!.dispose();
|
||||
}
|
||||
await residentDevtoolsHandler!.shutdown();
|
||||
await stopEchoingDeviceLog();
|
||||
}
|
||||
|
||||
|
||||
@ -89,7 +89,6 @@ class HotRunner extends ResidentRunner {
|
||||
super.dillOutputPath,
|
||||
super.stayResident,
|
||||
super.machine,
|
||||
super.devtoolsHandler,
|
||||
StopwatchFactory stopwatchFactory = const StopwatchFactory(),
|
||||
ReloadSourcesHelper reloadSourcesHelper = defaultReloadSourcesHelper,
|
||||
ReassembleHelper reassembleHelper = _defaultReassembleHelper,
|
||||
@ -272,17 +271,6 @@ class HotRunner extends ResidentRunner {
|
||||
globals.printError('Error connecting to the service protocol: $error');
|
||||
return 2;
|
||||
}
|
||||
// TODO(bkonyi): remove when ready to serve DevTools from DDS.
|
||||
if (debuggingOptions.enableDevTools) {
|
||||
// The method below is guaranteed never to return a failing future.
|
||||
unawaited(
|
||||
residentDevtoolsHandler!.serveAndAnnounceDevTools(
|
||||
devToolsServerAddress: debuggingOptions.devToolsServerAddress,
|
||||
flutterDevices: flutterDevices,
|
||||
isStartPaused: debuggingOptions.startPaused,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
for (final FlutterDevice? device in flutterDevices) {
|
||||
device!.developmentShaderCompiler.configureCompiler(device.targetPlatform);
|
||||
@ -805,11 +793,9 @@ class HotRunner extends ResidentRunner {
|
||||
if (!silent) {
|
||||
globals.printStatus('Restarted application in ${getElapsedAsMilliseconds(timer.elapsed)}.');
|
||||
}
|
||||
// TODO(bkonyi): remove when ready to serve DevTools from DDS.
|
||||
unawaited(residentDevtoolsHandler!.hotRestart(flutterDevices));
|
||||
// for (final FlutterDevice? device in flutterDevices) {
|
||||
// unawaited(device?.handleHotRestart());
|
||||
// }
|
||||
for (final FlutterDevice? device in flutterDevices) {
|
||||
unawaited(device?.handleHotRestart());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
final OperationResult result = await _hotReloadHelper(
|
||||
@ -1242,7 +1228,6 @@ class HotRunner extends ResidentRunner {
|
||||
|
||||
@override
|
||||
Future<void> cleanupAfterSignal() async {
|
||||
await residentDevtoolsHandler!.shutdown();
|
||||
await stopEchoingDeviceLog();
|
||||
await hotRunnerConfig!.runPreShutdownOperations();
|
||||
shutdownDartDevelopmentService();
|
||||
@ -1265,7 +1250,6 @@ class HotRunner extends ResidentRunner {
|
||||
await flutterDevice!.device!.dispose();
|
||||
}
|
||||
await _cleanupDevFS();
|
||||
await residentDevtoolsHandler!.shutdown();
|
||||
await stopEchoingDeviceLog();
|
||||
}
|
||||
}
|
||||
|
||||
@ -173,6 +173,7 @@ class FlutterTesterTestDevice extends TestDevice {
|
||||
);
|
||||
|
||||
Uri? forwardingUri;
|
||||
Uri? devToolsUri;
|
||||
|
||||
if (debuggingOptions.enableDds) {
|
||||
logger.printTrace('test $id: Starting Dart Development Service');
|
||||
@ -181,6 +182,7 @@ class FlutterTesterTestDevice extends TestDevice {
|
||||
debuggingOptions: debuggingOptions,
|
||||
);
|
||||
forwardingUri = _ddsLauncher.uri;
|
||||
devToolsUri = _ddsLauncher.devToolsUri;
|
||||
logger.printTrace(
|
||||
'test $id: Dart Development Service started at $forwardingUri, forwarding to VM service at $detectedUri.',
|
||||
);
|
||||
@ -197,7 +199,11 @@ class FlutterTesterTestDevice extends TestDevice {
|
||||
logger.printTrace('test $id: Successfully connected to service protocol: $forwardingUri');
|
||||
if (debuggingOptions.startPaused && !machine!) {
|
||||
logger.printStatus('The Dart VM service is listening on $forwardingUri');
|
||||
await _startDevTools(forwardingUri, _ddsLauncher);
|
||||
if (devToolsUri != null) {
|
||||
logger.printStatus(
|
||||
'The Flutter DevTools debugger and profiler is available at: $devToolsUri',
|
||||
);
|
||||
}
|
||||
logger.printStatus('');
|
||||
logger.printStatus(
|
||||
'The test process has been started. Set any relevant breakpoints and then resume the test in the debugger.',
|
||||
@ -256,26 +262,6 @@ class FlutterTesterTestDevice extends TestDevice {
|
||||
return connectToVmService(httpUri, compileExpression: compileExpression, logger: logger);
|
||||
}
|
||||
|
||||
// TODO(bkonyi): remove when ready to serve DevTools from DDS.
|
||||
Future<void> _startDevTools(Uri forwardingUri, DartDevelopmentService? dds) async {
|
||||
_devToolsLauncher = DevtoolsLauncher.instance;
|
||||
logger.printTrace('test $id: Serving DevTools...');
|
||||
final DevToolsServerAddress? devToolsServerAddress = await _devToolsLauncher?.serve();
|
||||
|
||||
if (devToolsServerAddress == null) {
|
||||
logger.printTrace('test $id: Failed to start DevTools');
|
||||
return;
|
||||
}
|
||||
await _devToolsLauncher?.ready;
|
||||
logger.printTrace('test $id: DevTools is being served at ${devToolsServerAddress.uri}');
|
||||
|
||||
final Uri devToolsUri = devToolsServerAddress.uri!.replace(
|
||||
// Use query instead of queryParameters to avoid unnecessary encoding.
|
||||
query: 'uri=$forwardingUri',
|
||||
);
|
||||
logger.printStatus('The Flutter DevTools debugger and profiler is available at: $devToolsUri');
|
||||
}
|
||||
|
||||
/// Binds an [HttpServer] serving from `host` on `port`.
|
||||
///
|
||||
/// Only intended to be overridden in tests.
|
||||
|
||||
@ -32,8 +32,19 @@ class WebApplicationPackage extends ApplicationPackage {
|
||||
Directory get webSourcePath => flutterProject.directory.childDirectory('web');
|
||||
}
|
||||
|
||||
abstract class WebDevice extends Device {
|
||||
WebDevice(super.id, {required super.logger})
|
||||
: super(category: Category.web, platformType: PlatformType.web, ephemeral: false);
|
||||
|
||||
@override
|
||||
Uri? get devToolsUri => _devToolsUri;
|
||||
Uri? _devToolsUri;
|
||||
|
||||
set devToolsUri(Uri? uri) => _devToolsUri = uri;
|
||||
}
|
||||
|
||||
/// A web device that supports a chromium browser.
|
||||
abstract class ChromiumDevice extends Device {
|
||||
abstract class ChromiumDevice extends WebDevice {
|
||||
ChromiumDevice({
|
||||
required String name,
|
||||
required this.chromeLauncher,
|
||||
@ -41,7 +52,7 @@ abstract class ChromiumDevice extends Device {
|
||||
required super.logger,
|
||||
}) : _fileSystem = fileSystem,
|
||||
_logger = logger,
|
||||
super(name, category: Category.web, platformType: PlatformType.web, ephemeral: false);
|
||||
super(name);
|
||||
|
||||
final ChromiumLauncher chromeLauncher;
|
||||
|
||||
@ -364,10 +375,8 @@ String parseVersionForWindows(String input) {
|
||||
}
|
||||
|
||||
/// A special device type to allow serving for arbitrary browsers.
|
||||
class WebServerDevice extends Device {
|
||||
WebServerDevice({required super.logger})
|
||||
: _logger = logger,
|
||||
super('web-server', platformType: PlatformType.web, category: Category.web, ephemeral: false);
|
||||
class WebServerDevice extends WebDevice {
|
||||
WebServerDevice({required super.logger}) : _logger = logger, super('web-server');
|
||||
|
||||
static const kWebServerDeviceId = 'web-server';
|
||||
static var showWebServerDevice = false;
|
||||
|
||||
@ -662,6 +662,7 @@ void main() {
|
||||
'deviceId': 'device',
|
||||
'disableServiceAuthCodes': false,
|
||||
'vmServiceUri': 'http://fake_uri/auth_code',
|
||||
'enableDevTools': true,
|
||||
},
|
||||
}),
|
||||
);
|
||||
@ -676,6 +677,7 @@ void main() {
|
||||
expect(device.dds.startCalled, true);
|
||||
expect(device.dds.startDisableServiceAuthCodes, false);
|
||||
expect(device.dds.startVMServiceUri, Uri.parse('http://fake_uri/auth_code'));
|
||||
expect(device.dds.enableDevTools, true);
|
||||
|
||||
// dds.done event should be sent to the client.
|
||||
ddsDoneCompleter.complete();
|
||||
@ -1229,6 +1231,7 @@ class FakeDartDevelopmentService extends Fake implements DartDevelopmentService
|
||||
bool? startDisableServiceAuthCodes;
|
||||
|
||||
var shutdownCalled = false;
|
||||
var enableDevTools = false;
|
||||
|
||||
@override
|
||||
late Future<void> done;
|
||||
@ -1236,6 +1239,12 @@ class FakeDartDevelopmentService extends Fake implements DartDevelopmentService
|
||||
@override
|
||||
Uri? uri;
|
||||
|
||||
@override
|
||||
Uri? devToolsUri;
|
||||
|
||||
@override
|
||||
Uri? dtdUri;
|
||||
|
||||
@override
|
||||
Future<void> startDartDevelopmentService(
|
||||
Uri vmServiceUri, {
|
||||
@ -1251,6 +1260,7 @@ class FakeDartDevelopmentService extends Fake implements DartDevelopmentService
|
||||
startCalled = true;
|
||||
startVMServiceUri = vmServiceUri;
|
||||
startDisableServiceAuthCodes = disableServiceAuthCodes;
|
||||
this.enableDevTools = enableDevTools;
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
@ -134,6 +134,9 @@ class FakeFlutterDevice extends Fake implements FlutterDevice {
|
||||
required PackageConfig packageConfig,
|
||||
}) => updateDevFSReportCallback();
|
||||
|
||||
@override
|
||||
Future<void> handleHotRestart() async {}
|
||||
|
||||
@override
|
||||
TargetPlatform? get targetPlatform => device._targetPlatform;
|
||||
}
|
||||
|
||||
@ -12,7 +12,6 @@ import 'package:flutter_tools/src/dart/pub.dart';
|
||||
import 'package:flutter_tools/src/devfs.dart';
|
||||
import 'package:flutter_tools/src/device.dart';
|
||||
import 'package:flutter_tools/src/reporting/reporting.dart';
|
||||
import 'package:flutter_tools/src/resident_devtools_handler.dart';
|
||||
import 'package:flutter_tools/src/resident_runner.dart';
|
||||
import 'package:flutter_tools/src/run_hot.dart';
|
||||
import 'package:flutter_tools/src/vmservice.dart';
|
||||
@ -184,7 +183,6 @@ name: my_app
|
||||
devices,
|
||||
debuggingOptions: DebuggingOptions.disabled(BuildInfo.debug),
|
||||
target: 'main.dart',
|
||||
devtoolsHandler: createNoOpHandler,
|
||||
analytics: fakeAnalytics,
|
||||
).restart(fullRestart: true);
|
||||
expect(result.isOk, false);
|
||||
@ -215,7 +213,6 @@ name: my_app
|
||||
devices,
|
||||
debuggingOptions: DebuggingOptions.disabled(BuildInfo.debug),
|
||||
target: 'main.dart',
|
||||
devtoolsHandler: createNoOpHandler,
|
||||
reassembleHelper:
|
||||
(
|
||||
List<FlutterDevice?> flutterDevices,
|
||||
@ -343,7 +340,6 @@ name: my_app
|
||||
devices,
|
||||
debuggingOptions: DebuggingOptions.disabled(BuildInfo.debug),
|
||||
target: 'main.dart',
|
||||
devtoolsHandler: createNoOpHandler,
|
||||
stopwatchFactory: fakeStopwatchFactory,
|
||||
analytics: fakeAnalytics,
|
||||
).restart(fullRestart: true);
|
||||
@ -437,7 +433,6 @@ name: my_app
|
||||
devices,
|
||||
debuggingOptions: DebuggingOptions.disabled(BuildInfo.debug),
|
||||
target: 'main.dart',
|
||||
devtoolsHandler: createNoOpHandler,
|
||||
stopwatchFactory: fakeStopwatchFactory,
|
||||
analytics: fakeAnalytics,
|
||||
reloadSourcesHelper:
|
||||
@ -550,7 +545,6 @@ name: my_app
|
||||
devices,
|
||||
debuggingOptions: DebuggingOptions.disabled(BuildInfo.debug),
|
||||
target: 'main.dart',
|
||||
devtoolsHandler: createNoOpHandler,
|
||||
analytics: fakeAnalytics,
|
||||
);
|
||||
|
||||
@ -595,7 +589,6 @@ name: my_app
|
||||
devices,
|
||||
debuggingOptions: DebuggingOptions.disabled(BuildInfo.debug),
|
||||
target: 'main.dart',
|
||||
devtoolsHandler: createNoOpHandler,
|
||||
analytics: fakeAnalytics,
|
||||
);
|
||||
|
||||
|
||||
@ -7,7 +7,6 @@ import 'package:flutter_tools/src/build_info.dart';
|
||||
import 'package:flutter_tools/src/device.dart';
|
||||
import 'package:flutter_tools/src/features.dart';
|
||||
import 'package:flutter_tools/src/globals.dart' as globals;
|
||||
import 'package:flutter_tools/src/resident_devtools_handler.dart';
|
||||
import 'package:flutter_tools/src/resident_runner.dart';
|
||||
import 'package:flutter_tools/src/run_hot.dart';
|
||||
|
||||
@ -62,7 +61,6 @@ void main() {
|
||||
),
|
||||
),
|
||||
target: 'main.dart',
|
||||
devtoolsHandler: createNoOpHandler,
|
||||
analytics: getInitializedFakeAnalyticsInstance(
|
||||
fs: MemoryFileSystem.test(),
|
||||
fakeFlutterVersion: FakeFlutterVersion(),
|
||||
|
||||
@ -661,6 +661,7 @@ void main() {
|
||||
'deviceId': 'test_id',
|
||||
'vmServiceUri': 'http://127.0.0.1:200/fake',
|
||||
'disableServiceAuthCodes': true,
|
||||
'enableDevTools': false,
|
||||
});
|
||||
|
||||
serverDaemonConnection.sendResponse(startMessage.data['id']!, const <String, Object?>{
|
||||
@ -720,6 +721,7 @@ void main() {
|
||||
'deviceId': 'test_id',
|
||||
'vmServiceUri': 'http://127.0.0.1:200/fake',
|
||||
'disableServiceAuthCodes': true,
|
||||
'enableDevTools': false,
|
||||
});
|
||||
|
||||
serverDaemonConnection.sendResponse(startMessage.data['id']!, <String, Object?>{
|
||||
@ -822,6 +824,7 @@ void main() {
|
||||
'deviceId': 'test_id',
|
||||
'vmServiceUri': 'http://127.0.0.1:200/fake',
|
||||
'disableServiceAuthCodes': true,
|
||||
'enableDevTools': false,
|
||||
});
|
||||
|
||||
serverDaemonConnection.sendErrorResponse(
|
||||
@ -1243,6 +1246,9 @@ class FakeDartDevelopmentService extends Fake implements DartDevelopmentService
|
||||
|
||||
@override
|
||||
Future<void> shutdown() async => shutdownCalled = true;
|
||||
|
||||
@override
|
||||
Future<void> invokeServiceExtensions(FlutterDevice? device) async {}
|
||||
}
|
||||
|
||||
class FakePrebuiltApplicationPackage extends Fake implements PrebuiltApplicationPackage {
|
||||
|
||||
@ -1,488 +0,0 @@
|
||||
// Copyright 2014 The Flutter Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter_tools/src/artifacts.dart';
|
||||
import 'package:flutter_tools/src/base/dds.dart';
|
||||
import 'package:flutter_tools/src/base/file_system.dart';
|
||||
import 'package:flutter_tools/src/base/io.dart';
|
||||
import 'package:flutter_tools/src/base/logger.dart';
|
||||
import 'package:flutter_tools/src/build_info.dart';
|
||||
import 'package:flutter_tools/src/cache.dart';
|
||||
import 'package:flutter_tools/src/device.dart';
|
||||
import 'package:flutter_tools/src/devtools_launcher.dart';
|
||||
import 'package:flutter_tools/src/resident_devtools_handler.dart';
|
||||
import 'package:flutter_tools/src/resident_runner.dart';
|
||||
import 'package:flutter_tools/src/vmservice.dart';
|
||||
import 'package:flutter_tools/src/web/chrome.dart';
|
||||
import 'package:test/fake.dart';
|
||||
import 'package:vm_service/vm_service.dart' as vm_service;
|
||||
import 'package:vm_service/vm_service.dart';
|
||||
|
||||
import '../src/common.dart';
|
||||
import '../src/fake_process_manager.dart';
|
||||
import '../src/fake_vm_services.dart';
|
||||
import '../src/fakes.dart';
|
||||
|
||||
final isolate = vm_service.Isolate(
|
||||
id: '1',
|
||||
pauseEvent: vm_service.Event(kind: vm_service.EventKind.kResume, timestamp: 0),
|
||||
breakpoints: <vm_service.Breakpoint>[],
|
||||
libraries: <vm_service.LibraryRef>[
|
||||
vm_service.LibraryRef(id: '1', uri: 'file:///hello_world/main.dart', name: ''),
|
||||
],
|
||||
livePorts: 0,
|
||||
name: 'test',
|
||||
number: '1',
|
||||
pauseOnExit: false,
|
||||
runnable: true,
|
||||
startTime: 0,
|
||||
isSystemIsolate: false,
|
||||
isolateFlags: <vm_service.IsolateFlag>[],
|
||||
extensionRPCs: <String>['ext.flutter.connectedVmServiceUri'],
|
||||
);
|
||||
|
||||
final listViews = FakeVmServiceRequest(
|
||||
method: kListViewsMethod,
|
||||
jsonResponse: <String, Object>{
|
||||
'views': <Object>[FlutterView(id: 'a', uiIsolate: isolate).toJson()],
|
||||
},
|
||||
);
|
||||
|
||||
void main() {
|
||||
Cache.flutterRoot = '';
|
||||
|
||||
(BufferLogger, Artifacts) getTestState() => (BufferLogger.test(), Artifacts.test());
|
||||
|
||||
testWithoutContext('Does not serve devtools if launcher is null', () async {
|
||||
final ResidentDevtoolsHandler handler = FlutterResidentDevtoolsHandler(
|
||||
null,
|
||||
FakeResidentRunner(),
|
||||
BufferLogger.test(),
|
||||
_FakeChromiumLauncher(),
|
||||
);
|
||||
|
||||
await handler.serveAndAnnounceDevTools(flutterDevices: <FlutterDevice>[]);
|
||||
|
||||
expect(handler.activeDevToolsServer, null);
|
||||
});
|
||||
|
||||
testWithoutContext(
|
||||
'Does not serve devtools if ResidentRunner does not support the service protocol',
|
||||
() async {
|
||||
final ResidentDevtoolsHandler handler = FlutterResidentDevtoolsHandler(
|
||||
FakeDevtoolsLauncher(),
|
||||
FakeResidentRunner()..supportsServiceProtocol = false,
|
||||
BufferLogger.test(),
|
||||
_FakeChromiumLauncher(),
|
||||
);
|
||||
await handler.serveAndAnnounceDevTools(flutterDevices: <FlutterDevice>[]);
|
||||
|
||||
expect(handler.activeDevToolsServer, null);
|
||||
},
|
||||
);
|
||||
|
||||
testWithoutContext('Can use devtools with existing devtools URI', () async {
|
||||
final (BufferLogger logger, Artifacts artifacts) = getTestState();
|
||||
final launcher = DevtoolsServerLauncher(
|
||||
processManager: FakeProcessManager.empty(),
|
||||
artifacts: artifacts,
|
||||
logger: logger,
|
||||
botDetector: const FakeBotDetector(false),
|
||||
);
|
||||
final ResidentDevtoolsHandler handler = FlutterResidentDevtoolsHandler(
|
||||
// Uses real devtools instance which should be a no-op if
|
||||
// URI is already set.
|
||||
launcher,
|
||||
FakeResidentRunner(),
|
||||
BufferLogger.test(),
|
||||
_FakeChromiumLauncher(),
|
||||
);
|
||||
|
||||
await handler.serveAndAnnounceDevTools(
|
||||
devToolsServerAddress: Uri.parse('http://localhost:8181'),
|
||||
flutterDevices: <FlutterDevice>[],
|
||||
);
|
||||
|
||||
expect(handler.activeDevToolsServer!.host, 'localhost');
|
||||
expect(handler.activeDevToolsServer!.port, 8181);
|
||||
});
|
||||
|
||||
testWithoutContext(
|
||||
'serveAndAnnounceDevTools with attached device does not fail on null vm service',
|
||||
() async {
|
||||
final ResidentDevtoolsHandler handler = FlutterResidentDevtoolsHandler(
|
||||
FakeDevtoolsLauncher()
|
||||
..activeDevToolsServer = DevToolsServerAddress('localhost', 8080)
|
||||
..devToolsUrl = Uri.parse('http://localhost:8080'),
|
||||
FakeResidentRunner(),
|
||||
BufferLogger.test(),
|
||||
_FakeChromiumLauncher(),
|
||||
);
|
||||
|
||||
// VM Service is intentionally null
|
||||
final device = FakeFlutterDevice();
|
||||
|
||||
await handler.serveAndAnnounceDevTools(flutterDevices: <FlutterDevice>[device]);
|
||||
},
|
||||
);
|
||||
|
||||
testWithoutContext(
|
||||
'serveAndAnnounceDevTools with invokes devtools and vm_service setter',
|
||||
() async {
|
||||
final ResidentDevtoolsHandler handler = FlutterResidentDevtoolsHandler(
|
||||
FakeDevtoolsLauncher()
|
||||
..activeDevToolsServer = DevToolsServerAddress('localhost', 8080)
|
||||
..devToolsUrl = Uri.parse('http://localhost:8080'),
|
||||
FakeResidentRunner(),
|
||||
BufferLogger.test(),
|
||||
_FakeChromiumLauncher(),
|
||||
);
|
||||
final fakeVmServiceHost = FakeVmServiceHost(
|
||||
requests: <VmServiceExpectation>[
|
||||
const FakeVmServiceRequest(
|
||||
method: 'streamListen',
|
||||
args: <String, Object>{'streamId': 'Isolate'},
|
||||
),
|
||||
listViews,
|
||||
FakeVmServiceRequest(
|
||||
method: 'getIsolate',
|
||||
jsonResponse: isolate.toJson(),
|
||||
args: <String, Object>{'isolateId': '1'},
|
||||
),
|
||||
listViews,
|
||||
listViews,
|
||||
const FakeVmServiceRequest(
|
||||
method: 'ext.flutter.activeDevToolsServerAddress',
|
||||
args: <String, Object>{'isolateId': '1', 'value': 'http://localhost:8080'},
|
||||
),
|
||||
const FakeVmServiceRequest(
|
||||
method: 'ext.flutter.connectedVmServiceUri',
|
||||
args: <String, Object>{'isolateId': '1', 'value': 'http://localhost:1234'},
|
||||
),
|
||||
],
|
||||
httpAddress: Uri.parse('http://localhost:1234'),
|
||||
);
|
||||
|
||||
final device = FakeFlutterDevice()..vmService = fakeVmServiceHost.vmService;
|
||||
|
||||
await handler.serveAndAnnounceDevTools(flutterDevices: <FlutterDevice>[device]);
|
||||
},
|
||||
);
|
||||
|
||||
testWithoutContext('serveAndAnnounceDevTools will bail if launching devtools fails', () async {
|
||||
final ResidentDevtoolsHandler handler = FlutterResidentDevtoolsHandler(
|
||||
FakeDevtoolsLauncher()..activeDevToolsServer = null,
|
||||
FakeResidentRunner(),
|
||||
BufferLogger.test(),
|
||||
_FakeChromiumLauncher(),
|
||||
);
|
||||
final fakeVmServiceHost = FakeVmServiceHost(
|
||||
requests: <VmServiceExpectation>[],
|
||||
httpAddress: Uri.parse('http://localhost:1234'),
|
||||
);
|
||||
|
||||
final device = FakeFlutterDevice()..vmService = fakeVmServiceHost.vmService;
|
||||
|
||||
await handler.serveAndAnnounceDevTools(flutterDevices: <FlutterDevice>[device]);
|
||||
});
|
||||
|
||||
testWithoutContext('serveAndAnnounceDevTools with web device', () async {
|
||||
final ResidentDevtoolsHandler handler = FlutterResidentDevtoolsHandler(
|
||||
FakeDevtoolsLauncher()
|
||||
..activeDevToolsServer = DevToolsServerAddress('localhost', 8080)
|
||||
..devToolsUrl = Uri.parse('http://localhost:8080'),
|
||||
FakeResidentRunner(),
|
||||
BufferLogger.test(),
|
||||
_FakeChromiumLauncher(),
|
||||
);
|
||||
final fakeVmServiceHost = FakeVmServiceHost(
|
||||
requests: <VmServiceExpectation>[
|
||||
const FakeVmServiceRequest(
|
||||
method: 'streamListen',
|
||||
args: <String, Object>{'streamId': 'Isolate'},
|
||||
),
|
||||
listViews,
|
||||
FakeVmServiceRequest(
|
||||
method: 'getIsolate',
|
||||
jsonResponse: isolate.toJson(),
|
||||
args: <String, Object>{'isolateId': '1'},
|
||||
),
|
||||
const FakeVmServiceRequest(
|
||||
method: 'ext.flutter.activeDevToolsServerAddress',
|
||||
args: <String, Object>{'value': 'http://localhost:8080'},
|
||||
),
|
||||
const FakeVmServiceRequest(
|
||||
method: 'ext.flutter.connectedVmServiceUri',
|
||||
args: <String, Object>{'value': 'http://localhost:1234'},
|
||||
),
|
||||
],
|
||||
httpAddress: Uri.parse('http://localhost:1234'),
|
||||
);
|
||||
|
||||
final device = FakeFlutterDevice()
|
||||
..vmService = fakeVmServiceHost.vmService
|
||||
..targetPlatform = TargetPlatform.web_javascript;
|
||||
|
||||
await handler.serveAndAnnounceDevTools(flutterDevices: <FlutterDevice>[device]);
|
||||
});
|
||||
|
||||
testWithoutContext(
|
||||
'serveAndAnnounceDevTools with skips calling service extensions when VM service disappears',
|
||||
() async {
|
||||
final ResidentDevtoolsHandler handler = FlutterResidentDevtoolsHandler(
|
||||
FakeDevtoolsLauncher()..activeDevToolsServer = DevToolsServerAddress('localhost', 8080),
|
||||
FakeResidentRunner(),
|
||||
BufferLogger.test(),
|
||||
_FakeChromiumLauncher(),
|
||||
);
|
||||
final fakeVmServiceHost = FakeVmServiceHost(
|
||||
requests: <VmServiceExpectation>[
|
||||
const FakeVmServiceRequest(
|
||||
method: 'streamListen',
|
||||
args: <String, Object>{'streamId': 'Isolate'},
|
||||
),
|
||||
FakeVmServiceRequest(
|
||||
method: kListViewsMethod,
|
||||
error: FakeRPCError(code: RPCErrorKind.kServiceDisappeared.code),
|
||||
),
|
||||
],
|
||||
httpAddress: Uri.parse('http://localhost:1234'),
|
||||
);
|
||||
|
||||
final device = FakeFlutterDevice()..vmService = fakeVmServiceHost.vmService;
|
||||
|
||||
await handler.serveAndAnnounceDevTools(flutterDevices: <FlutterDevice>[device]);
|
||||
},
|
||||
);
|
||||
|
||||
testWithoutContext(
|
||||
'serveAndAnnounceDevTools with multiple devices and VM service disappears on one',
|
||||
() async {
|
||||
final ResidentDevtoolsHandler handler = FlutterResidentDevtoolsHandler(
|
||||
FakeDevtoolsLauncher()
|
||||
..activeDevToolsServer = DevToolsServerAddress('localhost', 8080)
|
||||
..devToolsUrl = Uri.parse('http://localhost:8080'),
|
||||
FakeResidentRunner(),
|
||||
BufferLogger.test(),
|
||||
_FakeChromiumLauncher(),
|
||||
);
|
||||
|
||||
final vmServiceHost = FakeVmServiceHost(
|
||||
requests: <VmServiceExpectation>[
|
||||
const FakeVmServiceRequest(
|
||||
method: 'streamListen',
|
||||
args: <String, Object>{'streamId': 'Isolate'},
|
||||
),
|
||||
listViews,
|
||||
FakeVmServiceRequest(
|
||||
method: 'getIsolate',
|
||||
jsonResponse: isolate.toJson(),
|
||||
args: <String, Object>{'isolateId': '1'},
|
||||
),
|
||||
listViews,
|
||||
listViews,
|
||||
const FakeVmServiceRequest(
|
||||
method: 'ext.flutter.activeDevToolsServerAddress',
|
||||
args: <String, Object>{'isolateId': '1', 'value': 'http://localhost:8080'},
|
||||
),
|
||||
const FakeVmServiceRequest(
|
||||
method: 'ext.flutter.connectedVmServiceUri',
|
||||
args: <String, Object>{'isolateId': '1', 'value': 'http://localhost:1234'},
|
||||
),
|
||||
],
|
||||
httpAddress: Uri.parse('http://localhost:1234'),
|
||||
);
|
||||
|
||||
final vmServiceHostThatDisappears = FakeVmServiceHost(
|
||||
requests: <VmServiceExpectation>[
|
||||
const FakeVmServiceRequest(
|
||||
method: 'streamListen',
|
||||
args: <String, Object>{'streamId': 'Isolate'},
|
||||
),
|
||||
FakeVmServiceRequest(
|
||||
method: kListViewsMethod,
|
||||
error: FakeRPCError(code: RPCErrorKind.kServiceDisappeared.code),
|
||||
),
|
||||
],
|
||||
httpAddress: Uri.parse('http://localhost:5678'),
|
||||
);
|
||||
|
||||
await handler.serveAndAnnounceDevTools(
|
||||
flutterDevices: <FlutterDevice>[
|
||||
FakeFlutterDevice()..vmService = vmServiceHostThatDisappears.vmService,
|
||||
FakeFlutterDevice()..vmService = vmServiceHost.vmService,
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
testWithoutContext('Does not launch devtools in browser if launcher is null', () async {
|
||||
final handler = FlutterResidentDevtoolsHandler(
|
||||
null,
|
||||
FakeResidentRunner(),
|
||||
BufferLogger.test(),
|
||||
_FakeChromiumLauncher(),
|
||||
);
|
||||
|
||||
handler.launchDevToolsInBrowser(flutterDevices: <FlutterDevice>[]);
|
||||
expect(handler.launchedInBrowser, isFalse);
|
||||
expect(handler.activeDevToolsServer, null);
|
||||
});
|
||||
|
||||
testWithoutContext(
|
||||
'Does not launch devtools in browser if ResidentRunner does not support the service protocol',
|
||||
() async {
|
||||
final handler = FlutterResidentDevtoolsHandler(
|
||||
FakeDevtoolsLauncher(),
|
||||
FakeResidentRunner()..supportsServiceProtocol = false,
|
||||
BufferLogger.test(),
|
||||
_FakeChromiumLauncher(),
|
||||
);
|
||||
|
||||
handler.launchDevToolsInBrowser(flutterDevices: <FlutterDevice>[]);
|
||||
expect(handler.launchedInBrowser, isFalse);
|
||||
expect(handler.activeDevToolsServer, null);
|
||||
},
|
||||
);
|
||||
|
||||
testWithoutContext(
|
||||
'launchDevToolsInBrowser launches after _devToolsLauncher.ready completes',
|
||||
() async {
|
||||
final completer = Completer<void>();
|
||||
final handler = FlutterResidentDevtoolsHandler(
|
||||
FakeDevtoolsLauncher()
|
||||
..devToolsUrl = null
|
||||
// We need to set [activeDevToolsServer] to simulate the state we would
|
||||
// be in after serving devtools completes.
|
||||
..activeDevToolsServer = DevToolsServerAddress('localhost', 8080)
|
||||
..readyCompleter = completer,
|
||||
FakeResidentRunner(),
|
||||
BufferLogger.test(),
|
||||
_FakeChromiumLauncher(),
|
||||
);
|
||||
|
||||
expect(handler.launchDevToolsInBrowser(flutterDevices: <FlutterDevice>[]), isTrue);
|
||||
expect(handler.launchedInBrowser, isFalse);
|
||||
|
||||
completer.complete();
|
||||
// Await a short delay to give DevTools time to launch.
|
||||
await Future<void>.delayed(const Duration(microseconds: 100));
|
||||
|
||||
expect(handler.launchedInBrowser, isTrue);
|
||||
},
|
||||
);
|
||||
|
||||
testWithoutContext('launchDevToolsInBrowser launches successfully', () async {
|
||||
final handler = FlutterResidentDevtoolsHandler(
|
||||
FakeDevtoolsLauncher()
|
||||
..devToolsUrl = Uri(host: 'localhost', port: 8080)
|
||||
..activeDevToolsServer = DevToolsServerAddress('localhost', 8080),
|
||||
FakeResidentRunner(),
|
||||
BufferLogger.test(),
|
||||
_FakeChromiumLauncher(),
|
||||
);
|
||||
|
||||
expect(handler.launchDevToolsInBrowser(flutterDevices: <FlutterDevice>[]), isTrue);
|
||||
expect(handler.launchedInBrowser, isTrue);
|
||||
});
|
||||
|
||||
testWithoutContext('launchDevToolsInBrowser fails without Chrome installed', () async {
|
||||
final handler = FlutterResidentDevtoolsHandler(
|
||||
FakeDevtoolsLauncher()
|
||||
..devToolsUrl = Uri(host: 'localhost', port: 8080)
|
||||
..activeDevToolsServer = DevToolsServerAddress('localhost', 8080),
|
||||
FakeResidentRunner(),
|
||||
BufferLogger.test(),
|
||||
_ThrowingChromiumLauncher(),
|
||||
);
|
||||
|
||||
expect(handler.launchedInBrowser, isFalse);
|
||||
expect(handler.launchDevToolsInBrowser(flutterDevices: <FlutterDevice>[]), isTrue);
|
||||
});
|
||||
|
||||
testWithoutContext(
|
||||
'Converts a VM Service URI with a query parameter to a pretty display string',
|
||||
() {
|
||||
const value = 'http://127.0.0.1:9100?uri=http%3A%2F%2F127.0.0.1%3A57922%2F_MXpzytpH20%3D%2F';
|
||||
final Uri uri = Uri.parse(value);
|
||||
|
||||
expect(
|
||||
urlToDisplayString(uri),
|
||||
'http://127.0.0.1:9100?uri=http://127.0.0.1:57922/_MXpzytpH20=/',
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
class FakeResidentRunner extends Fake implements ResidentRunner {
|
||||
@override
|
||||
var supportsServiceProtocol = true;
|
||||
|
||||
@override
|
||||
var reportedDebuggers = false;
|
||||
|
||||
@override
|
||||
var debuggingOptions = DebuggingOptions.disabled(BuildInfo.debug);
|
||||
}
|
||||
|
||||
class FakeFlutterDevice extends Fake implements FlutterDevice {
|
||||
@override
|
||||
final Device device = FakeDevice();
|
||||
|
||||
@override
|
||||
FlutterVmService? vmService;
|
||||
|
||||
@override
|
||||
TargetPlatform targetPlatform = TargetPlatform.android_arm;
|
||||
}
|
||||
|
||||
class FakeDevice extends Fake implements Device {
|
||||
@override
|
||||
DartDevelopmentService get dds => FakeDartDevelopmentService();
|
||||
}
|
||||
|
||||
class FakeDartDevelopmentService extends Fake implements DartDevelopmentService {
|
||||
var started = false;
|
||||
var disposed = false;
|
||||
|
||||
@override
|
||||
final Uri uri = Uri.parse('http://127.0.0.1:1234/');
|
||||
|
||||
@override
|
||||
Future<void> startDartDevelopmentService(
|
||||
Uri vmServiceUri, {
|
||||
int? ddsPort,
|
||||
bool? disableServiceAuthCodes,
|
||||
bool? ipv6,
|
||||
bool enableDevTools = true,
|
||||
bool cacheStartupProfile = false,
|
||||
String? google3WorkspaceRoot,
|
||||
Uri? devToolsServerAddress,
|
||||
}) async {
|
||||
started = true;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> shutdown() async {
|
||||
disposed = true;
|
||||
}
|
||||
}
|
||||
|
||||
class _ThrowingChromiumLauncher extends Fake implements ChromiumLauncher {
|
||||
@override
|
||||
Future<Chromium> launch(
|
||||
String url, {
|
||||
bool headless = false,
|
||||
int? debugPort,
|
||||
bool skipCheck = false,
|
||||
Directory? cacheDir,
|
||||
List<String> webBrowserFlags = const <String>[],
|
||||
}) async {
|
||||
throw ProcessException('ChromiumLauncher', <String>[url]);
|
||||
}
|
||||
}
|
||||
|
||||
class _FakeChromiumLauncher extends Fake implements ChromiumLauncher {}
|
||||
@ -123,6 +123,15 @@ class FakeDartDevelopmentService extends Fake
|
||||
@override
|
||||
Uri? get uri => null;
|
||||
|
||||
@override
|
||||
Uri? get devToolsUri => null;
|
||||
|
||||
@override
|
||||
Uri? get dtdUri => null;
|
||||
|
||||
@override
|
||||
Future<void> handleHotRestart(FlutterDevice? device) async {}
|
||||
|
||||
@override
|
||||
void shutdown() {}
|
||||
}
|
||||
@ -256,6 +265,9 @@ class FakeFlutterDevice extends Fake implements FlutterDevice {
|
||||
|
||||
@override
|
||||
Future<void> updateReloadStatus(bool wasReloadSuccessful) async {}
|
||||
|
||||
@override
|
||||
Future<void> handleHotRestart() async {}
|
||||
}
|
||||
|
||||
class FakeDelegateFlutterDevice extends FlutterDevice {
|
||||
@ -388,6 +400,9 @@ class FakeDevice extends Fake implements Device {
|
||||
@override
|
||||
String get displayName => name;
|
||||
|
||||
@override
|
||||
Uri? devToolsUri;
|
||||
|
||||
@override
|
||||
late DartDevelopmentService dds = FakeDartDevelopmentService();
|
||||
|
||||
|
||||
@ -22,7 +22,6 @@ import 'package:flutter_tools/src/features.dart';
|
||||
import 'package:flutter_tools/src/globals.dart' as globals;
|
||||
import 'package:flutter_tools/src/project.dart';
|
||||
import 'package:flutter_tools/src/reporting/reporting.dart';
|
||||
import 'package:flutter_tools/src/resident_devtools_handler.dart';
|
||||
import 'package:flutter_tools/src/resident_runner.dart';
|
||||
import 'package:flutter_tools/src/run_cold.dart';
|
||||
import 'package:flutter_tools/src/run_hot.dart';
|
||||
@ -61,7 +60,6 @@ void main() {
|
||||
debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug),
|
||||
target: 'main.dart',
|
||||
analytics: fakeAnalytics,
|
||||
devtoolsHandler: createNoOpHandler,
|
||||
);
|
||||
},
|
||||
overrides: <Type, Generator>{
|
||||
@ -121,7 +119,6 @@ void main() {
|
||||
stayResident: false,
|
||||
debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug),
|
||||
target: 'main.dart',
|
||||
devtoolsHandler: createNoOpHandler,
|
||||
analytics: globals.analytics,
|
||||
);
|
||||
flutterDevice.generator = residentCompiler;
|
||||
@ -145,7 +142,6 @@ void main() {
|
||||
stayResident: false,
|
||||
debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug),
|
||||
target: 'main.dart',
|
||||
devtoolsHandler: createNoOpHandler,
|
||||
analytics: globals.analytics,
|
||||
);
|
||||
flutterDevice.generator = residentCompiler;
|
||||
@ -167,7 +163,6 @@ void main() {
|
||||
stayResident: false,
|
||||
debuggingOptions: DebuggingOptions.enabled(BuildInfo.release),
|
||||
target: 'main.dart',
|
||||
devtoolsHandler: createNoOpHandler,
|
||||
);
|
||||
flutterDevice.runColdCode = 1;
|
||||
|
||||
@ -188,7 +183,6 @@ void main() {
|
||||
stayResident: false,
|
||||
debuggingOptions: DebuggingOptions.enabled(BuildInfo.release),
|
||||
target: 'main.dart',
|
||||
devtoolsHandler: createNoOpHandler,
|
||||
);
|
||||
flutterDevice.runColdError = Exception('BAD STUFF');
|
||||
|
||||
@ -211,7 +205,6 @@ void main() {
|
||||
stayResident: false,
|
||||
debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug),
|
||||
target: 'main.dart',
|
||||
devtoolsHandler: createNoOpHandler,
|
||||
analytics: globals.analytics,
|
||||
);
|
||||
flutterDevice.generator = residentCompiler;
|
||||
@ -403,7 +396,6 @@ void main() {
|
||||
stayResident: false,
|
||||
debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug),
|
||||
target: 'main.dart',
|
||||
devtoolsHandler: createNoOpHandler,
|
||||
analytics: fakeAnalytics,
|
||||
);
|
||||
final futureConnectionInfo = Completer<DebugConnectionInfo>.sync();
|
||||
@ -654,7 +646,6 @@ void main() {
|
||||
stayResident: false,
|
||||
debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug),
|
||||
target: 'main.dart',
|
||||
devtoolsHandler: createNoOpHandler,
|
||||
analytics: fakeAnalytics,
|
||||
);
|
||||
devFS.nextUpdateReport = UpdateFSReport(success: true, invalidatedSourcesCount: 1);
|
||||
@ -1012,7 +1003,6 @@ void main() {
|
||||
debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug),
|
||||
dillOutputPath: globals.fs.path.join('foobar', 'app.dill'),
|
||||
target: 'main.dart',
|
||||
devtoolsHandler: createNoOpHandler,
|
||||
analytics: fakeAnalytics,
|
||||
);
|
||||
expect(otherRunner.artifactDirectory.path, contains('foobar'));
|
||||
@ -1120,7 +1110,6 @@ flutter:
|
||||
stayResident: false,
|
||||
debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug),
|
||||
target: 'custom_main.dart',
|
||||
devtoolsHandler: createNoOpHandler,
|
||||
analytics: fakeAnalytics,
|
||||
);
|
||||
await residentRunner.runSourceGenerators();
|
||||
@ -1184,7 +1173,6 @@ flutter:
|
||||
stayResident: false,
|
||||
debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug),
|
||||
target: 'main.dart',
|
||||
devtoolsHandler: createNoOpHandler,
|
||||
analytics: fakeAnalytics,
|
||||
);
|
||||
flutterDevice.generator = residentCompiler;
|
||||
@ -1295,7 +1283,6 @@ flutter:
|
||||
stayResident: false,
|
||||
debuggingOptions: DebuggingOptions.disabled(BuildInfo.release),
|
||||
target: 'main.dart',
|
||||
devtoolsHandler: createNoOpHandler,
|
||||
);
|
||||
residentRunner.printHelp(details: true);
|
||||
|
||||
@ -1331,7 +1318,6 @@ flutter:
|
||||
stayResident: false,
|
||||
debuggingOptions: DebuggingOptions.disabled(BuildInfo.release),
|
||||
target: 'main.dart',
|
||||
devtoolsHandler: createNoOpHandler,
|
||||
);
|
||||
residentRunner.printHelp(details: false);
|
||||
|
||||
@ -1396,7 +1382,6 @@ flutter:
|
||||
enableDevTools: false,
|
||||
),
|
||||
target: 'main.dart',
|
||||
devtoolsHandler: createNoOpHandler,
|
||||
);
|
||||
|
||||
final Future<int?> result = residentRunner.attach();
|
||||
@ -1443,7 +1428,6 @@ flutter:
|
||||
stayResident: false,
|
||||
debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug, vmserviceOutFile: 'foo'),
|
||||
target: 'main.dart',
|
||||
devtoolsHandler: createNoOpHandler,
|
||||
analytics: fakeAnalytics,
|
||||
);
|
||||
|
||||
@ -1474,7 +1458,6 @@ flutter:
|
||||
),
|
||||
),
|
||||
target: 'main.dart',
|
||||
devtoolsHandler: createNoOpHandler,
|
||||
analytics: fakeAnalytics,
|
||||
);
|
||||
residentRunner.artifactDirectory.childFile('app.dill').writeAsStringSync('ABC');
|
||||
@ -1509,7 +1492,6 @@ flutter:
|
||||
),
|
||||
),
|
||||
target: 'main.dart',
|
||||
devtoolsHandler: createNoOpHandler,
|
||||
analytics: fakeAnalytics,
|
||||
);
|
||||
residentRunner.artifactDirectory.childFile('app.dill').writeAsStringSync('ABC');
|
||||
@ -1546,7 +1528,6 @@ flutter:
|
||||
),
|
||||
),
|
||||
target: 'main.dart',
|
||||
devtoolsHandler: createNoOpHandler,
|
||||
analytics: fakeAnalytics,
|
||||
);
|
||||
residentRunner.artifactDirectory.childFile('app.dill').writeAsStringSync('ABC');
|
||||
@ -1573,7 +1554,6 @@ flutter:
|
||||
stayResident: false,
|
||||
debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug),
|
||||
target: 'main.dart',
|
||||
devtoolsHandler: createNoOpHandler,
|
||||
analytics: fakeAnalytics,
|
||||
);
|
||||
residentRunner.artifactDirectory.childFile('app.dill').writeAsStringSync('ABC');
|
||||
@ -1603,7 +1583,6 @@ flutter:
|
||||
dillOutputPath: 'test',
|
||||
debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug),
|
||||
target: 'main.dart',
|
||||
devtoolsHandler: createNoOpHandler,
|
||||
analytics: fakeAnalytics,
|
||||
);
|
||||
residentRunner.artifactDirectory.childFile('app.dill').writeAsStringSync('ABC');
|
||||
@ -1635,7 +1614,6 @@ flutter:
|
||||
),
|
||||
),
|
||||
target: 'main.dart',
|
||||
devtoolsHandler: createNoOpHandler,
|
||||
analytics: fakeAnalytics,
|
||||
);
|
||||
residentRunner.artifactDirectory.childFile('app.dill').writeAsStringSync('ABC');
|
||||
@ -1664,7 +1642,6 @@ flutter:
|
||||
stayResident: false,
|
||||
debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug),
|
||||
target: 'main.dart',
|
||||
devtoolsHandler: createNoOpHandler,
|
||||
analytics: fakeAnalytics,
|
||||
);
|
||||
|
||||
@ -1686,7 +1663,6 @@ flutter:
|
||||
stayResident: false,
|
||||
debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug, vmserviceOutFile: 'foo'),
|
||||
target: 'main.dart',
|
||||
devtoolsHandler: createNoOpHandler,
|
||||
analytics: fakeAnalytics,
|
||||
);
|
||||
|
||||
@ -1713,7 +1689,6 @@ flutter:
|
||||
<FlutterDevice>[flutterDevice],
|
||||
stayResident: false,
|
||||
debuggingOptions: DebuggingOptions.enabled(BuildInfo.profile, vmserviceOutFile: 'foo'),
|
||||
devtoolsHandler: createNoOpHandler,
|
||||
target: 'main.dart',
|
||||
);
|
||||
|
||||
@ -2003,7 +1978,22 @@ flutter:
|
||||
'Host VM service ipv6 defaults',
|
||||
() => testbed.run(
|
||||
() async {
|
||||
fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[]);
|
||||
fakeVmServiceHost = FakeVmServiceHost(
|
||||
requests: <VmServiceExpectation>[
|
||||
const FakeVmServiceRequest(
|
||||
method: 'streamListen',
|
||||
args: <String, Object>{'streamId': 'Isolate'},
|
||||
),
|
||||
const FakeVmServiceRequest(
|
||||
method: 'streamListen',
|
||||
args: <String, Object>{'streamId': 'Isolate'},
|
||||
),
|
||||
const FakeVmServiceRequest(
|
||||
method: 'streamListen',
|
||||
args: <String, Object>{'streamId': 'Isolate'},
|
||||
),
|
||||
],
|
||||
);
|
||||
final device = FakeDevice()..dds = DartDevelopmentService(logger: testLogger);
|
||||
final done = Completer<void>();
|
||||
ddsLauncherCallback =
|
||||
@ -2047,7 +2037,7 @@ flutter:
|
||||
io.CompressionOptions? compression,
|
||||
Device? device,
|
||||
required Logger logger,
|
||||
}) async => FakeVmServiceHost(requests: <VmServiceExpectation>[]).vmService,
|
||||
}) async => fakeVmServiceHost!.vmService,
|
||||
},
|
||||
),
|
||||
);
|
||||
@ -2062,24 +2052,6 @@ flutter:
|
||||
expect(() => nextPlatform('unknown'), throwsAssertionError);
|
||||
});
|
||||
|
||||
// TODO(bkonyi): remove when ready to serve DevTools from DDS.
|
||||
testUsingContext(
|
||||
'cleanupAtFinish shuts down resident devtools handler',
|
||||
() => testbed.run(() async {
|
||||
residentRunner = HotRunner(
|
||||
<FlutterDevice>[flutterDevice],
|
||||
stayResident: false,
|
||||
debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug, vmserviceOutFile: 'foo'),
|
||||
target: 'main.dart',
|
||||
devtoolsHandler: createNoOpHandler,
|
||||
analytics: fakeAnalytics,
|
||||
);
|
||||
await residentRunner.cleanupAtFinish();
|
||||
|
||||
expect((residentRunner.residentDevtoolsHandler! as NoOpDevtoolsHandler).wasShutdown, true);
|
||||
}),
|
||||
);
|
||||
|
||||
testUsingContext(
|
||||
'HotRunner sets asset directory when first evict assets',
|
||||
() => testbed.run(() async {
|
||||
@ -2091,7 +2063,6 @@ flutter:
|
||||
stayResident: false,
|
||||
debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug),
|
||||
target: 'main.dart',
|
||||
devtoolsHandler: createNoOpHandler,
|
||||
analytics: fakeAnalytics,
|
||||
);
|
||||
|
||||
@ -2115,7 +2086,6 @@ flutter:
|
||||
stayResident: false,
|
||||
debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug),
|
||||
target: 'main.dart',
|
||||
devtoolsHandler: createNoOpHandler,
|
||||
analytics: fakeAnalytics,
|
||||
);
|
||||
|
||||
@ -2137,7 +2107,6 @@ flutter:
|
||||
stayResident: false,
|
||||
debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug),
|
||||
target: 'main.dart',
|
||||
devtoolsHandler: createNoOpHandler,
|
||||
analytics: fakeAnalytics,
|
||||
);
|
||||
|
||||
@ -2157,7 +2126,6 @@ flutter:
|
||||
stayResident: false,
|
||||
debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug),
|
||||
target: 'main.dart',
|
||||
devtoolsHandler: createNoOpHandler,
|
||||
analytics: fakeAnalytics,
|
||||
);
|
||||
|
||||
@ -2198,7 +2166,6 @@ flutter:
|
||||
),
|
||||
),
|
||||
target: 'main.dart',
|
||||
devtoolsHandler: createNoOpHandler,
|
||||
analytics: globals.analytics,
|
||||
nativeAssetsYamlFile: 'foo.yaml',
|
||||
);
|
||||
|
||||
@ -280,4 +280,7 @@ class FakeFlutterDevice extends Fake implements FlutterDevice {
|
||||
|
||||
@override
|
||||
FlutterVmService? vmService;
|
||||
|
||||
@override
|
||||
Future<void> handleHotRestart() async {}
|
||||
}
|
||||
|
||||
@ -28,7 +28,6 @@ import 'package:flutter_tools/src/globals.dart' as globals;
|
||||
import 'package:flutter_tools/src/isolated/devfs_web.dart';
|
||||
import 'package:flutter_tools/src/isolated/resident_web_runner.dart';
|
||||
import 'package:flutter_tools/src/project.dart';
|
||||
import 'package:flutter_tools/src/resident_devtools_handler.dart';
|
||||
import 'package:flutter_tools/src/resident_runner.dart';
|
||||
import 'package:flutter_tools/src/vmservice.dart';
|
||||
import 'package:flutter_tools/src/web/chrome.dart';
|
||||
@ -144,6 +143,7 @@ name: my_app
|
||||
debugConnection.fakeVmServiceHost = () => fakeVmServiceHost;
|
||||
webDevFS.result = ConnectionResult(appConnection, debugConnection, debugConnection.vmService);
|
||||
debugConnection.uri = 'ws://127.0.0.1/abcd/';
|
||||
debugConnection.devToolsUri = 'http://127.0.0.1/abcd/';
|
||||
chromeConnection.tabs.add(chromeTab);
|
||||
}
|
||||
|
||||
@ -369,7 +369,6 @@ name: my_app
|
||||
outputPreferences: OutputPreferences.test(),
|
||||
analytics: globals.analytics,
|
||||
systemClock: globals.systemClock,
|
||||
devtoolsHandler: createNoOpHandler,
|
||||
);
|
||||
|
||||
expect(await residentWebRunner.run(), 0);
|
||||
@ -399,7 +398,6 @@ name: my_app
|
||||
outputPreferences: OutputPreferences.test(),
|
||||
analytics: globals.analytics,
|
||||
systemClock: globals.systemClock,
|
||||
devtoolsHandler: createNoOpHandler,
|
||||
);
|
||||
|
||||
expect(await residentWebRunner.run(), 0);
|
||||
@ -429,11 +427,8 @@ name: my_app
|
||||
outputPreferences: OutputPreferences.test(),
|
||||
analytics: globals.analytics,
|
||||
systemClock: globals.systemClock,
|
||||
devtoolsHandler: createNoOpHandler,
|
||||
);
|
||||
|
||||
mockDevice.dds = DartDevelopmentService(logger: logger);
|
||||
|
||||
expect(mockDevice.isRunning, false);
|
||||
final connectionInfoCompleter = Completer<DebugConnectionInfo>();
|
||||
unawaited(residentWebRunner.run(connectionInfoCompleter: connectionInfoCompleter));
|
||||
@ -470,11 +465,8 @@ name: my_app
|
||||
outputPreferences: OutputPreferences.test(),
|
||||
analytics: globals.analytics,
|
||||
systemClock: globals.systemClock,
|
||||
devtoolsHandler: createNoOpHandler,
|
||||
);
|
||||
|
||||
mockDevice.dds = DartDevelopmentService(logger: logger);
|
||||
|
||||
expect(mockDevice.isRunning, false);
|
||||
final connectionInfoCompleter = Completer<DebugConnectionInfo>();
|
||||
unawaited(residentWebRunner.run(connectionInfoCompleter: connectionInfoCompleter));
|
||||
@ -654,6 +646,7 @@ name: my_app
|
||||
'Waiting for connection from debug service on FakeDevice...\n'
|
||||
'Debug service listening on ws://127.0.0.1/abcd/\n'
|
||||
'A Dart VM Service on FakeDevice is available at: http://127.0.0.1/abcd/\n'
|
||||
'The Flutter DevTools debugger and profiler on FakeDevice is available at: http://127.0.0.1/abcd/\n'
|
||||
'\n'
|
||||
'first\n'
|
||||
'\n'
|
||||
@ -693,7 +686,6 @@ name: my_app
|
||||
outputPreferences: OutputPreferences.test(),
|
||||
analytics: globals.analytics,
|
||||
systemClock: globals.systemClock,
|
||||
devtoolsHandler: createNoOpHandler,
|
||||
);
|
||||
fakeVmServiceHost = FakeVmServiceHost(requests: kStartPausedAndAttachExpectations.toList());
|
||||
setupMocks();
|
||||
@ -1487,7 +1479,6 @@ name: my_app
|
||||
'cleanup of resources is safe to call multiple times',
|
||||
() async {
|
||||
final ResidentRunner residentWebRunner = setUpResidentRunner(flutterDevice);
|
||||
mockDevice.dds = DartDevelopmentService(logger: test_fakes.FakeLogger());
|
||||
fakeVmServiceHost = FakeVmServiceHost(
|
||||
requests: <VmServiceExpectation>[...kAttachExpectations],
|
||||
);
|
||||
@ -1607,7 +1598,6 @@ name: my_app
|
||||
outputPreferences: OutputPreferences.test(),
|
||||
analytics: globals.analytics,
|
||||
systemClock: globals.systemClock,
|
||||
devtoolsHandler: createNoOpHandler,
|
||||
);
|
||||
|
||||
final connectionInfoCompleter = Completer<DebugConnectionInfo>();
|
||||
@ -1653,7 +1643,6 @@ name: my_app
|
||||
outputPreferences: OutputPreferences.test(),
|
||||
analytics: globals.analytics,
|
||||
systemClock: globals.systemClock,
|
||||
devtoolsHandler: createNoOpHandler,
|
||||
);
|
||||
|
||||
final connectionInfoCompleter = Completer<DebugConnectionInfo>();
|
||||
@ -1696,7 +1685,6 @@ name: my_app
|
||||
outputPreferences: OutputPreferences.test(),
|
||||
analytics: globals.analytics,
|
||||
systemClock: globals.systemClock,
|
||||
devtoolsHandler: createNoOpHandler,
|
||||
);
|
||||
|
||||
// Create necessary files.
|
||||
@ -1975,19 +1963,21 @@ ResidentRunner setUpResidentRunner(
|
||||
terminal: Terminal.test(),
|
||||
platform: FakePlatform(),
|
||||
outputPreferences: OutputPreferences.test(),
|
||||
devtoolsHandler: createNoOpHandler,
|
||||
);
|
||||
}
|
||||
|
||||
class FakeWebServerDevice extends FakeDevice implements WebServerDevice {}
|
||||
|
||||
class FakeDevice extends Fake implements Device {
|
||||
class FakeDevice extends Fake implements WebDevice {
|
||||
@override
|
||||
var name = 'FakeDevice';
|
||||
|
||||
@override
|
||||
String get displayName => name;
|
||||
|
||||
@override
|
||||
Uri? devToolsUri;
|
||||
|
||||
var count = 0;
|
||||
|
||||
var isRunning = false;
|
||||
@ -1996,7 +1986,7 @@ class FakeDevice extends Fake implements Device {
|
||||
Future<String> get sdkNameAndVersion async => 'SDK Name and Version';
|
||||
|
||||
@override
|
||||
late DartDevelopmentService dds;
|
||||
final dds = DartDevelopmentService(logger: test_fakes.FakeLogger());
|
||||
|
||||
@override
|
||||
bool get supportsHotRestart => true;
|
||||
@ -2036,6 +2026,9 @@ class FakeDebugConnection extends Fake implements DebugConnection {
|
||||
@override
|
||||
late String uri;
|
||||
|
||||
@override
|
||||
late String devToolsUri;
|
||||
|
||||
final completer = Completer<void>();
|
||||
var didClose = false;
|
||||
|
||||
@ -2328,6 +2321,9 @@ class FakeFlutterDevice extends Fake implements FlutterDevice {
|
||||
|
||||
@override
|
||||
Future<void> updateReloadStatus(bool wasReloadSuccessful) async {}
|
||||
|
||||
@override
|
||||
Future<void> handleHotRestart() async {}
|
||||
}
|
||||
|
||||
class FakeShaderCompiler implements DevelopmentShaderCompiler {
|
||||
|
||||
@ -8,7 +8,6 @@ import 'package:flutter_tools/src/build_info.dart';
|
||||
import 'package:flutter_tools/src/compile.dart';
|
||||
import 'package:flutter_tools/src/devfs.dart';
|
||||
import 'package:flutter_tools/src/device.dart';
|
||||
import 'package:flutter_tools/src/resident_devtools_handler.dart';
|
||||
import 'package:flutter_tools/src/resident_runner.dart';
|
||||
import 'package:flutter_tools/src/run_hot.dart';
|
||||
import 'package:flutter_tools/src/vmservice.dart';
|
||||
@ -52,14 +51,12 @@ void main() {
|
||||
target: 'main.dart',
|
||||
debuggingOptions: DebuggingOptions.disabled(BuildInfo.debug),
|
||||
analytics: _FakeAnalytics(),
|
||||
devtoolsHandler: createNoOpHandler,
|
||||
);
|
||||
|
||||
await runner.run();
|
||||
await runner.cleanupAfterSignal();
|
||||
expect(flutterDevice.wasExited, true);
|
||||
expect((flutterDevice.device.dds as FakeDartDevelopmentService).wasShutdown, true);
|
||||
expect((runner.residentDevtoolsHandler! as NoOpDevtoolsHandler).wasShutdown, true);
|
||||
},
|
||||
overrides: <Type, Generator>{
|
||||
FileSystem: () => fileSystem,
|
||||
|
||||
@ -18,7 +18,6 @@ import 'package:flutter_tools/src/compile.dart';
|
||||
import 'package:flutter_tools/src/convert.dart';
|
||||
import 'package:flutter_tools/src/devfs.dart';
|
||||
import 'package:flutter_tools/src/device.dart';
|
||||
import 'package:flutter_tools/src/resident_devtools_handler.dart';
|
||||
import 'package:flutter_tools/src/resident_runner.dart';
|
||||
import 'package:flutter_tools/src/vmservice.dart';
|
||||
import 'package:test/fake.dart';
|
||||
@ -744,11 +743,13 @@ void main() {
|
||||
testWithoutContext('v - launchDevToolsInBrowser', () async {
|
||||
final TerminalHandler terminalHandler = setUpTerminalHandler(<FakeVmServiceRequest>[]);
|
||||
final runner = terminalHandler.residentRunner as FakeResidentRunner;
|
||||
final devtoolsHandler = runner.residentDevtoolsHandler as FakeResidentDevtoolsHandler;
|
||||
|
||||
expect(devtoolsHandler.calledLaunchDevToolsInBrowser, isFalse);
|
||||
for (final FlutterDevice? device in runner.flutterDevices) {
|
||||
expect(device!.device!.dds.calledLaunchDevToolsInBrowser, isFalse);
|
||||
}
|
||||
await terminalHandler.processTerminalInput('v');
|
||||
expect(devtoolsHandler.calledLaunchDevToolsInBrowser, isTrue);
|
||||
for (final FlutterDevice? device in runner.flutterDevices) {
|
||||
expect(device!.device!.dds.calledLaunchDevToolsInBrowser, isTrue);
|
||||
}
|
||||
});
|
||||
|
||||
testWithoutContext('v - does not launchDevToolsInBrowser on web in profile mode', () async {
|
||||
@ -759,11 +760,11 @@ void main() {
|
||||
);
|
||||
|
||||
final runner = terminalHandler.residentRunner as FakeResidentRunner;
|
||||
final devtoolsHandler = runner.residentDevtoolsHandler as FakeResidentDevtoolsHandler;
|
||||
final DartDevelopmentService dds = runner.flutterDevices.single.device!.dds;
|
||||
|
||||
expect(devtoolsHandler.calledLaunchDevToolsInBrowser, isFalse);
|
||||
expect(dds.calledLaunchDevToolsInBrowser, isFalse);
|
||||
await terminalHandler.processTerminalInput('v');
|
||||
expect(devtoolsHandler.calledLaunchDevToolsInBrowser, isFalse);
|
||||
expect(dds.calledLaunchDevToolsInBrowser, isFalse);
|
||||
});
|
||||
|
||||
testWithoutContext('w,W - debugDumpApp without service protocol is skipped', () async {
|
||||
@ -1293,21 +1294,6 @@ class FakeResidentRunner extends ResidentHandlers {
|
||||
}
|
||||
return OperationResult(reloadExitCode, '', fatal: fatalReloadError);
|
||||
}
|
||||
|
||||
// TODO(bkonyi): remove when ready to serve DevTools from DDS.
|
||||
@override
|
||||
ResidentDevtoolsHandler get residentDevtoolsHandler => _residentDevtoolsHandler;
|
||||
final ResidentDevtoolsHandler _residentDevtoolsHandler = FakeResidentDevtoolsHandler();
|
||||
}
|
||||
|
||||
// TODO(bkonyi): remove when ready to serve DevTools from DDS.
|
||||
class FakeResidentDevtoolsHandler extends Fake implements ResidentDevtoolsHandler {
|
||||
var calledLaunchDevToolsInBrowser = false;
|
||||
|
||||
@override
|
||||
bool launchDevToolsInBrowser({List<FlutterDevice?>? flutterDevices}) {
|
||||
return calledLaunchDevToolsInBrowser = true;
|
||||
}
|
||||
}
|
||||
|
||||
class FakeDevice extends Fake implements Device {
|
||||
|
||||
@ -799,7 +799,7 @@ void main() {
|
||||
packageConfigPath: '.dart_tool/package_config.json',
|
||||
),
|
||||
enableDwds: false,
|
||||
enableDds: false,
|
||||
ddsConfig: const DartDevelopmentServiceConfiguration(enable: false),
|
||||
entrypoint: Uri.base,
|
||||
testMode: true,
|
||||
expressionCompiler: null,
|
||||
@ -905,7 +905,7 @@ void main() {
|
||||
packageConfigPath: '.dart_tool/package_config.json',
|
||||
),
|
||||
enableDwds: true,
|
||||
enableDds: false,
|
||||
ddsConfig: const DartDevelopmentServiceConfiguration(enable: false),
|
||||
entrypoint: Uri.base,
|
||||
testMode: true,
|
||||
expressionCompiler: null,
|
||||
@ -977,7 +977,7 @@ void main() {
|
||||
useSseForInjectedClient: true,
|
||||
buildInfo: BuildInfo.debug,
|
||||
enableDwds: false,
|
||||
enableDds: false,
|
||||
ddsConfig: const DartDevelopmentServiceConfiguration(enable: false),
|
||||
entrypoint: Uri.base,
|
||||
testMode: true,
|
||||
expressionCompiler: null,
|
||||
@ -1026,7 +1026,7 @@ void main() {
|
||||
packageConfigPath: '.dart_tool/package_config.json',
|
||||
),
|
||||
enableDwds: false,
|
||||
enableDds: false,
|
||||
ddsConfig: const DartDevelopmentServiceConfiguration(enable: false),
|
||||
entrypoint: Uri.base,
|
||||
testMode: true,
|
||||
expressionCompiler: null,
|
||||
@ -1077,7 +1077,7 @@ void main() {
|
||||
nativeNullAssertions: true,
|
||||
buildInfo: BuildInfo.debug,
|
||||
enableDwds: false,
|
||||
enableDds: false,
|
||||
ddsConfig: const DartDevelopmentServiceConfiguration(enable: false),
|
||||
entrypoint: Uri.base,
|
||||
testMode: true,
|
||||
expressionCompiler: null,
|
||||
@ -1121,8 +1121,7 @@ void main() {
|
||||
packageConfigPath: '.dart_tool/package_config.json',
|
||||
),
|
||||
false,
|
||||
false,
|
||||
null,
|
||||
const DartDevelopmentServiceConfiguration(enable: false),
|
||||
Uri.base,
|
||||
null,
|
||||
webRenderer: WebRendererMode.canvaskit,
|
||||
@ -1161,8 +1160,7 @@ void main() {
|
||||
packageConfigPath: '.dart_tool/package_config.json',
|
||||
),
|
||||
false,
|
||||
false,
|
||||
null,
|
||||
const DartDevelopmentServiceConfiguration(enable: false),
|
||||
Uri.base,
|
||||
null,
|
||||
webRenderer: WebRendererMode.canvaskit,
|
||||
@ -1245,7 +1243,7 @@ void main() {
|
||||
nativeNullAssertions: true,
|
||||
buildInfo: BuildInfo.debug,
|
||||
enableDwds: false,
|
||||
enableDds: false,
|
||||
ddsConfig: const DartDevelopmentServiceConfiguration(enable: false),
|
||||
entrypoint: Uri.base,
|
||||
testMode: true,
|
||||
expressionCompiler: null,
|
||||
|
||||
@ -924,7 +924,7 @@ void main() {
|
||||
packageConfigPath: '.dart_tool/package_config.json',
|
||||
),
|
||||
enableDwds: false,
|
||||
enableDds: false,
|
||||
ddsConfig: const DartDevelopmentServiceConfiguration(enable: false),
|
||||
entrypoint: Uri.base,
|
||||
testMode: true,
|
||||
expressionCompiler: null,
|
||||
@ -1031,7 +1031,7 @@ void main() {
|
||||
packageConfigPath: '.dart_tool/package_config.json',
|
||||
),
|
||||
enableDwds: false,
|
||||
enableDds: false,
|
||||
ddsConfig: const DartDevelopmentServiceConfiguration(enable: false),
|
||||
entrypoint: Uri.base,
|
||||
testMode: true,
|
||||
expressionCompiler: null,
|
||||
@ -1143,7 +1143,7 @@ void main() {
|
||||
packageConfigPath: '.dart_tool/package_config.json',
|
||||
),
|
||||
enableDwds: true,
|
||||
enableDds: false,
|
||||
ddsConfig: const DartDevelopmentServiceConfiguration(enable: false),
|
||||
entrypoint: Uri.base,
|
||||
testMode: true,
|
||||
expressionCompiler: null,
|
||||
@ -1217,7 +1217,7 @@ void main() {
|
||||
useSseForInjectedClient: true,
|
||||
buildInfo: BuildInfo.debug,
|
||||
enableDwds: false,
|
||||
enableDds: false,
|
||||
ddsConfig: const DartDevelopmentServiceConfiguration(enable: false),
|
||||
entrypoint: Uri.base,
|
||||
testMode: true,
|
||||
expressionCompiler: null,
|
||||
@ -1266,7 +1266,7 @@ void main() {
|
||||
packageConfigPath: '.dart_tool/package_config.json',
|
||||
),
|
||||
enableDwds: false,
|
||||
enableDds: false,
|
||||
ddsConfig: const DartDevelopmentServiceConfiguration(enable: false),
|
||||
entrypoint: Uri.base,
|
||||
testMode: true,
|
||||
expressionCompiler: null,
|
||||
@ -1319,7 +1319,7 @@ void main() {
|
||||
nativeNullAssertions: true,
|
||||
buildInfo: BuildInfo.debug,
|
||||
enableDwds: false,
|
||||
enableDds: false,
|
||||
ddsConfig: const DartDevelopmentServiceConfiguration(enable: false),
|
||||
entrypoint: Uri.base,
|
||||
testMode: true,
|
||||
expressionCompiler: null,
|
||||
@ -1365,8 +1365,7 @@ void main() {
|
||||
packageConfigPath: '.dart_tool/package_config.json',
|
||||
),
|
||||
false,
|
||||
false,
|
||||
null,
|
||||
const DartDevelopmentServiceConfiguration(enable: false),
|
||||
Uri.base,
|
||||
null,
|
||||
webRenderer: WebRendererMode.canvaskit,
|
||||
@ -1405,8 +1404,7 @@ void main() {
|
||||
packageConfigPath: '.dart_tool/package_config.json',
|
||||
),
|
||||
false,
|
||||
false,
|
||||
null,
|
||||
const DartDevelopmentServiceConfiguration(enable: false),
|
||||
Uri.base,
|
||||
null,
|
||||
webRenderer: WebRendererMode.canvaskit,
|
||||
@ -1496,7 +1494,7 @@ void main() {
|
||||
nativeNullAssertions: true,
|
||||
buildInfo: BuildInfo.debug,
|
||||
enableDwds: false,
|
||||
enableDds: false,
|
||||
ddsConfig: const DartDevelopmentServiceConfiguration(enable: false),
|
||||
entrypoint: Uri.base,
|
||||
testMode: true,
|
||||
expressionCompiler: null,
|
||||
|
||||
@ -63,8 +63,24 @@ abstract final class FlutterTestDriver {
|
||||
bool get hasExited => _hasExited;
|
||||
Uri? get vmServiceWsUri => _vmServiceWsUri;
|
||||
|
||||
/// Completes with the full method name for the 'reloadSources' service once
|
||||
/// it's registered (e.g., `s0.reloadSources`).
|
||||
late final Future<String> reloadSourcesService;
|
||||
|
||||
/// Completes with the full method name for the 'hotRestart' service once
|
||||
/// it's registered (e.g., `s0.hotRestart`).
|
||||
late final Future<String> hotRestartService;
|
||||
|
||||
/// Completes with the full method name for the 'flutterVersion' service once
|
||||
/// it's registered (e.g., `s0.hotRestart`).
|
||||
late final Future<String> flutterVersionService;
|
||||
|
||||
/// Completes with the full method name for the 'flutterMemoryInfo' service once
|
||||
/// it's registered (e.g., `s0.hotRestart`).
|
||||
late final Future<String> flutterMemoryInfoService;
|
||||
|
||||
var lastTime = '';
|
||||
void _debugPrint(String message, {String topic = ''}) {
|
||||
void debugPrint(String message, {String topic = ''}) {
|
||||
const maxLength = 2500;
|
||||
final truncatedMessage = message.length > maxLength
|
||||
? '${message.substring(0, maxLength)}...'
|
||||
@ -109,7 +125,7 @@ abstract final class FlutterTestDriver {
|
||||
if (script != null) {
|
||||
arguments.add(script);
|
||||
}
|
||||
_debugPrint('Spawning flutter $arguments in ${_projectFolder.path}');
|
||||
debugPrint('Spawning flutter $arguments in ${_projectFolder.path}');
|
||||
|
||||
const ProcessManager processManager = LocalProcessManager();
|
||||
_process = await processManager.start(
|
||||
@ -123,7 +139,7 @@ abstract final class FlutterTestDriver {
|
||||
// via a getter for external uses.
|
||||
unawaited(
|
||||
_process!.exitCode.then((int code) {
|
||||
_debugPrint('Process exited ($code)');
|
||||
debugPrint('Process exited ($code)');
|
||||
// The timing of this signal is important to the implementation of the
|
||||
// "quit" method, so only change how this is implemented by careful
|
||||
// testing of tests that use FlutterTestDriver.
|
||||
@ -137,8 +153,8 @@ abstract final class FlutterTestDriver {
|
||||
_stderr.stream.listen(_errorBuffer.writeln);
|
||||
|
||||
// This is just debug printing to aid running/debugging tests locally.
|
||||
_stdout.stream.listen((String message) => _debugPrint(message, topic: '<=stdout='));
|
||||
_stderr.stream.listen((String message) => _debugPrint(message, topic: '<=stderr='));
|
||||
_stdout.stream.listen((String message) => debugPrint(message, topic: '<=stdout='));
|
||||
_stderr.stream.listen((String message) => debugPrint(message, topic: '<=stderr='));
|
||||
}
|
||||
|
||||
/// Completes when process exits with the given exit code.
|
||||
@ -148,8 +164,8 @@ abstract final class FlutterTestDriver {
|
||||
|
||||
Future<void> connectToVmService({bool pauseOnExceptions = false}) async {
|
||||
_vmService = await vmServiceConnectUri('$_vmServiceWsUri');
|
||||
_vmService!.onSend.listen((String s) => _debugPrint(s, topic: '=vm=>'));
|
||||
_vmService!.onReceive.listen((String s) => _debugPrint(s, topic: '<=vm='));
|
||||
_vmService!.onSend.listen((String s) => debugPrint(s, topic: '=vm=>'));
|
||||
_vmService!.onReceive.listen((String s) => debugPrint(s, topic: '<=vm='));
|
||||
|
||||
final isolateStarted = Completer<void>();
|
||||
_vmService!.onIsolateEvent.listen((Event event) {
|
||||
@ -164,15 +180,20 @@ abstract final class FlutterTestDriver {
|
||||
}
|
||||
});
|
||||
|
||||
reloadSourcesService = subscribeToServiceRegisteredEvent('reloadSources');
|
||||
hotRestartService = subscribeToServiceRegisteredEvent('hotRestart');
|
||||
flutterVersionService = subscribeToServiceRegisteredEvent('flutterVersion');
|
||||
flutterMemoryInfoService = subscribeToServiceRegisteredEvent('flutterMemoryInfo');
|
||||
|
||||
await Future.wait(<Future<Success>>[
|
||||
_vmService!.streamListen('Isolate'),
|
||||
_vmService!.streamListen('Debug'),
|
||||
_vmService!.streamListen(EventStreams.kIsolate),
|
||||
_vmService!.streamListen(EventStreams.kDebug),
|
||||
_vmService!.streamListen(EventStreams.kService),
|
||||
]);
|
||||
|
||||
if ((await _vmService!.getVM()).isolates?.isEmpty ?? true) {
|
||||
await isolateStarted.future;
|
||||
}
|
||||
|
||||
await waitForPause();
|
||||
if (pauseOnExceptions) {
|
||||
await _vmService!.setIsolatePauseMode(
|
||||
@ -197,7 +218,7 @@ abstract final class FlutterTestDriver {
|
||||
Future<void> quit() async {
|
||||
final int result = await _killGracefully();
|
||||
if (result != 0) {
|
||||
_debugPrint('Expected process to terminate gracefully, got exit code $result.');
|
||||
debugPrint('Expected process to terminate gracefully, got exit code $result.');
|
||||
}
|
||||
|
||||
// The _hasExited signal could be on the microtask queue. Waiting for a
|
||||
@ -222,18 +243,18 @@ abstract final class FlutterTestDriver {
|
||||
.then(
|
||||
(Isolate? isolate) => isolate,
|
||||
onError: (Object e) {
|
||||
_debugPrint('Ignoring failure to resume during shutdown');
|
||||
debugPrint('Ignoring failure to resume during shutdown');
|
||||
return null;
|
||||
},
|
||||
);
|
||||
|
||||
_debugPrint('Sending SIGTERM to $_processPid..');
|
||||
debugPrint('Sending SIGTERM to $_processPid..');
|
||||
io.Process.killPid(_processPid!);
|
||||
return _process!.exitCode.timeout(quitTimeout, onTimeout: _killForcefully);
|
||||
}
|
||||
|
||||
Future<int> _killForcefully() {
|
||||
_debugPrint('Sending SIGKILL to $_processPid..');
|
||||
debugPrint('Sending SIGKILL to $_processPid..');
|
||||
ProcessSignal.sigkill.send(_processPid!);
|
||||
return _process!.exitCode;
|
||||
}
|
||||
@ -271,7 +292,7 @@ abstract final class FlutterTestDriver {
|
||||
}
|
||||
|
||||
Future<void> addBreakpoint(Uri uri, int line) async {
|
||||
_debugPrint('Sending breakpoint for: $uri:$line');
|
||||
debugPrint('Sending breakpoint for: $uri:$line');
|
||||
await _vmService!.addBreakpointWithScriptUri(
|
||||
await _getFlutterIsolateId(),
|
||||
uri.toString(),
|
||||
@ -312,13 +333,23 @@ abstract final class FlutterTestDriver {
|
||||
/// await waitForDebugEvent('Pause', id, event); // Isolate is paused now.
|
||||
/// ```
|
||||
Future<Event> subscribeToDebugEvent(String kind, String isolateId) {
|
||||
_debugPrint('Start listening for $kind events');
|
||||
debugPrint('Start listening for $kind events');
|
||||
|
||||
return _vmService!.onDebugEvent.where((Event event) {
|
||||
return event.isolate?.id == isolateId && (event.kind?.startsWith(kind) ?? false);
|
||||
}).first;
|
||||
}
|
||||
|
||||
Future<String> subscribeToServiceRegisteredEvent(String service) {
|
||||
debugPrint("Start listening for service '$service' to be registered");
|
||||
return _vmService!.onServiceEvent
|
||||
.where((Event event) {
|
||||
return event.service == service;
|
||||
})
|
||||
.first
|
||||
.then((e) => e.method!);
|
||||
}
|
||||
|
||||
/// Wait for the [event] if needed.
|
||||
///
|
||||
/// Return immediately if the isolate is already in the desired state.
|
||||
@ -330,10 +361,10 @@ abstract final class FlutterTestDriver {
|
||||
final VmService vmService = _vmService!;
|
||||
final Isolate isolate = await vmService.getIsolate(isolateId);
|
||||
if (isolate.pauseEvent?.kind?.startsWith(kind) ?? false) {
|
||||
_debugPrint('Isolate was already at "$kind" (${isolate.pauseEvent!.kind}).');
|
||||
debugPrint('Isolate was already at "$kind" (${isolate.pauseEvent!.kind}).');
|
||||
event.ignore();
|
||||
} else {
|
||||
_debugPrint('Waiting for "$kind" event to arrive...');
|
||||
debugPrint('Waiting for "$kind" event to arrive...');
|
||||
await event;
|
||||
}
|
||||
|
||||
@ -445,7 +476,7 @@ abstract final class FlutterTestDriver {
|
||||
}
|
||||
if ((event != null && json['event'] == event) || (id != null && json['id'] == id)) {
|
||||
await subscription?.cancel();
|
||||
_debugPrint('OK ($interestingOccurrence)');
|
||||
debugPrint('OK ($interestingOccurrence)');
|
||||
response.complete(json);
|
||||
} else if (!ignoreAppStopEvent && json['event'] == 'app.stop') {
|
||||
await subscription?.cancel();
|
||||
@ -477,8 +508,8 @@ abstract final class FlutterTestDriver {
|
||||
Duration timeout = defaultTimeout,
|
||||
}) {
|
||||
if (_printDebugOutputToStdOut) {
|
||||
_debugPrint('$task...');
|
||||
final longWarning = Timer(timeout, () => _debugPrint('$task is taking longer than usual...'));
|
||||
debugPrint('$task...');
|
||||
final longWarning = Timer(timeout, () => debugPrint('$task is taking longer than usual...'));
|
||||
return callback().whenComplete(longWarning.cancel);
|
||||
}
|
||||
|
||||
@ -497,9 +528,9 @@ abstract final class FlutterTestDriver {
|
||||
final StreamSubscription<String> subscription = _allMessages.stream.listen(logMessage);
|
||||
|
||||
final longWarning = Timer(timeout, () {
|
||||
_debugPrint(messages.toString());
|
||||
debugPrint(messages.toString());
|
||||
timeoutExpired = true;
|
||||
_debugPrint('$task is taking longer than usual...');
|
||||
debugPrint('$task is taking longer than usual...');
|
||||
});
|
||||
final Future<T> future = callback().whenComplete(longWarning.cancel);
|
||||
|
||||
@ -509,7 +540,7 @@ abstract final class FlutterTestDriver {
|
||||
onError: (Object error) {
|
||||
if (!timeoutExpired) {
|
||||
timeoutExpired = true;
|
||||
_debugPrint(messages.toString());
|
||||
debugPrint(messages.toString());
|
||||
}
|
||||
throw error; // ignore: only_throw_errors
|
||||
},
|
||||
@ -665,6 +696,7 @@ final class FlutterRunTestDriver extends FlutterTestDriver {
|
||||
if (withDebugger) {
|
||||
await connectToVmService(pauseOnExceptions: pauseOnExceptions);
|
||||
if (!startPaused) {
|
||||
await started;
|
||||
await resume();
|
||||
}
|
||||
}
|
||||
@ -718,7 +750,7 @@ final class FlutterRunTestDriver extends FlutterTestDriver {
|
||||
throw Exception('App has not started yet');
|
||||
}
|
||||
|
||||
_debugPrint(
|
||||
debugPrint(
|
||||
'Performing ${pause ? "paused " : ""}${fullRestart ? "hot restart" : "hot reload"}...',
|
||||
);
|
||||
final hotReloadResponse =
|
||||
@ -730,7 +762,7 @@ final class FlutterRunTestDriver extends FlutterTestDriver {
|
||||
'debounceDurationOverrideMs': debounceDurationOverrideMs,
|
||||
})
|
||||
as Map<String, Object?>?;
|
||||
_debugPrint('${fullRestart ? "Hot restart" : "Hot reload"} complete.');
|
||||
debugPrint('${fullRestart ? "Hot restart" : "Hot reload"} complete.');
|
||||
|
||||
if (hotReloadResponse == null || hotReloadResponse['code'] != 0) {
|
||||
_throwErrorResponse('Hot ${fullRestart ? 'restart' : 'reload'} request failed');
|
||||
@ -744,48 +776,48 @@ final class FlutterRunTestDriver extends FlutterTestDriver {
|
||||
}
|
||||
final VmService? vmService = _vmService;
|
||||
if (vmService != null) {
|
||||
_debugPrint('Closing VM service...');
|
||||
debugPrint('Closing VM service...');
|
||||
await vmService.dispose();
|
||||
}
|
||||
if (_currentRunningAppId != null) {
|
||||
_debugPrint('Detaching from app...');
|
||||
debugPrint('Detaching from app...');
|
||||
await Future.any<void>(<Future<void>>[
|
||||
process.exitCode,
|
||||
_sendRequest('app.detach', <String, Object?>{'appId': _currentRunningAppId}),
|
||||
]).timeout(
|
||||
quitTimeout,
|
||||
onTimeout: () {
|
||||
_debugPrint('app.detach did not return within $quitTimeout');
|
||||
debugPrint('app.detach did not return within $quitTimeout');
|
||||
},
|
||||
);
|
||||
_currentRunningAppId = null;
|
||||
}
|
||||
_debugPrint('Waiting for process to end...');
|
||||
debugPrint('Waiting for process to end...');
|
||||
return process.exitCode.timeout(quitTimeout, onTimeout: _killGracefully);
|
||||
}
|
||||
|
||||
Future<int> stop() async {
|
||||
final VmService? vmService = _vmService;
|
||||
if (vmService != null) {
|
||||
_debugPrint('Closing VM service...');
|
||||
debugPrint('Closing VM service...');
|
||||
await vmService.dispose();
|
||||
}
|
||||
final Process? process = _process;
|
||||
if (_currentRunningAppId != null) {
|
||||
_debugPrint('Stopping application...');
|
||||
debugPrint('Stopping application...');
|
||||
await Future.any<void>(<Future<void>>[
|
||||
process!.exitCode,
|
||||
_sendRequest('app.stop', <String, Object?>{'appId': _currentRunningAppId}),
|
||||
]).timeout(
|
||||
quitTimeout,
|
||||
onTimeout: () {
|
||||
_debugPrint('app.stop did not return within $quitTimeout');
|
||||
debugPrint('app.stop did not return within $quitTimeout');
|
||||
},
|
||||
);
|
||||
_currentRunningAppId = null;
|
||||
}
|
||||
if (process != null) {
|
||||
_debugPrint('Waiting for process to end...');
|
||||
debugPrint('Waiting for process to end...');
|
||||
return process.exitCode.timeout(quitTimeout, onTimeout: _killGracefully);
|
||||
}
|
||||
return 0;
|
||||
@ -796,7 +828,7 @@ final class FlutterRunTestDriver extends FlutterTestDriver {
|
||||
final int requestId = id++;
|
||||
final request = <String, Object?>{'id': requestId, 'method': method, 'params': params};
|
||||
final String jsonEncoded = json.encode(<Map<String, Object?>>[request]);
|
||||
_debugPrint(jsonEncoded, topic: '=stdin=>');
|
||||
debugPrint(jsonEncoded, topic: '=stdin=>');
|
||||
|
||||
// Set up the response future before we send the request to avoid any
|
||||
// races. If the method we're calling is app.stop then we tell _waitFor not
|
||||
|
||||
@ -32,6 +32,8 @@ void main() {
|
||||
final int? port = flutter.vmServicePort;
|
||||
expect(port != null, true);
|
||||
vmService = await vmServiceConnectUri('ws://localhost:$port/ws');
|
||||
vmService.onSend.listen((String s) => flutter.debugPrint(s, topic: '=vm=>'));
|
||||
vmService.onReceive.listen((String s) => flutter.debugPrint(s, topic: '<=vm='));
|
||||
});
|
||||
|
||||
tearDown(() async {
|
||||
@ -48,14 +50,18 @@ void main() {
|
||||
});
|
||||
|
||||
testWithoutContext('flutterVersion can be called', () async {
|
||||
final Response response = await vmService.callServiceExtension('s0.flutterVersion');
|
||||
final Response response = await vmService.callServiceExtension(
|
||||
await flutter.flutterVersionService,
|
||||
);
|
||||
expect(response.type, 'Success');
|
||||
expect(response.json, containsPair('frameworkRevisionShort', isNotNull));
|
||||
expect(response.json, containsPair('engineRevisionShort', isNotNull));
|
||||
});
|
||||
|
||||
testWithoutContext('flutterMemoryInfo can be called', () async {
|
||||
final Response response = await vmService.callServiceExtension('s0.flutterMemoryInfo');
|
||||
final Response response = await vmService.callServiceExtension(
|
||||
await flutter.flutterMemoryInfoService,
|
||||
);
|
||||
expect(response.type, 'Success');
|
||||
});
|
||||
|
||||
@ -64,14 +70,17 @@ void main() {
|
||||
final IsolateRef? isolateRef = vm.isolates?.first;
|
||||
expect(isolateRef != null, true);
|
||||
final Response response = await vmService.callMethod(
|
||||
's0.reloadSources',
|
||||
await flutter.reloadSourcesService,
|
||||
isolateId: isolateRef!.id,
|
||||
);
|
||||
expect(response.type, 'Success');
|
||||
});
|
||||
|
||||
testWithoutContext('reloadSources fails on bad params', () async {
|
||||
final Future<Response> response = vmService.callMethod('s0.reloadSources', isolateId: '');
|
||||
final Future<Response> response = vmService.callMethod(
|
||||
await flutter.reloadSourcesService,
|
||||
isolateId: '',
|
||||
);
|
||||
expect(response, throwsA(const TypeMatcher<RPCError>()));
|
||||
});
|
||||
|
||||
@ -80,7 +89,7 @@ void main() {
|
||||
final IsolateRef? isolateRef = vm.isolates?.first;
|
||||
expect(isolateRef != null, true);
|
||||
final Response response = await vmService.callMethod(
|
||||
's0.hotRestart',
|
||||
await flutter.hotRestartService,
|
||||
isolateId: isolateRef!.id,
|
||||
);
|
||||
expect(response.type, 'Success');
|
||||
@ -88,7 +97,7 @@ void main() {
|
||||
|
||||
testWithoutContext('hotRestart fails on bad params', () async {
|
||||
final Future<Response> response = vmService.callMethod(
|
||||
's0.hotRestart',
|
||||
await flutter.hotRestartService,
|
||||
args: <String, dynamic>{'pause': 'not_a_bool'},
|
||||
);
|
||||
expect(response, throwsA(const TypeMatcher<RPCError>()));
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user