Reverts "Launch DDS from Dart SDK and prepare to serve DevTools from DDS (#146593)" (#151781)

Reverts: flutter/flutter#146593
Initiated by: zanderso
Reason for reverting: Consistently failing `Windows_android native_assets_android` as in https://ci.chromium.org/ui/p/flutter/builders/prod/Windows_android%20native_assets_android/2533/overview 
Original PR Author: bkonyi

Reviewed By: {christopherfujino, kenzieschmoll}

This change reverts the following previous change:
This change is a major step towards moving away from shipping DDS via Pub.

The first component of this PR is the move away from importing package:dds to launch DDS. Instead, DDS is launched out of process using the `dart development-service` command shipped with the Dart SDK. This makes Flutter's handling of DDS consistent with the standalone Dart VM.

The second component of this PR is 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 PR also includes some refactoring around `DebuggingOptions` to reduce the number of debugging related arguments being passed as parameters adjacent to a `DebuggingOptions` instance.
This commit is contained in:
auto-submit[bot]
2024-07-15 19:55:18 +00:00
committed by GitHub
parent f023430859
commit 7cdc23b3e1
57 changed files with 752 additions and 925 deletions

View File

@@ -59,7 +59,7 @@ class AndroidDevice extends Device {
this.productID,
required this.modelID,
this.deviceCodeName,
required super.logger,
required Logger logger,
required ProcessManager processManager,
required Platform platform,
required AndroidSdk androidSdk,

View File

@@ -4,333 +4,112 @@
import 'dart:async';
import 'package:dds/dds.dart' as dds;
import 'package:meta/meta.dart';
import '../artifacts.dart';
import '../convert.dart';
import '../device.dart';
import '../globals.dart' as globals;
import 'common.dart';
import 'context.dart';
import 'io.dart' as io;
import 'logger.dart';
/// A representation of the current DDS state including:
///
/// - The process the external DDS instance is running in
/// - The service URI DDS is being served on
/// - The URI DevTools is being served on, if applicable
/// - The URI DTD is being served on, if applicable
typedef DartDevelopmentServiceInstance = ({
io.Process? process,
Uri? serviceUri,
Uri? devToolsUri,
Uri? dtdUri,
});
/// The default DDSLauncherCallback used to spawn DDS.
Future<DartDevelopmentServiceInstance> defaultStartDartDevelopmentService(
Uri remoteVmServiceUri, {
required bool enableAuthCodes,
required bool ipv6,
required bool enableDevTools,
required List<String> cachedUserTags,
Uri? serviceUri,
String? google3WorkspaceRoot,
Uri? devToolsServerAddress,
}) async {
final String exe = globals.artifacts!.getArtifactPath(
Artifact.engineDartBinary,
);
final io.Process process = await io.Process.start(
exe,
<String>[
'development-service',
'--vm-service-uri=$remoteVmServiceUri',
if (serviceUri != null) ...<String>[
'--bind-address=${serviceUri.host}',
'--bind-port=${serviceUri.port}',
],
if (!enableAuthCodes) '--disable-service-auth-codes',
// TODO(bkonyi): uncomment when ready to serve DevTools from DDS.
// if (enableDevTools) '--serve-devtools',
if (google3WorkspaceRoot != null)
'--google3-workspace-root=$google3WorkspaceRoot',
// TODO(bkonyi): uncomment when ready to serve DevTools from DDS.
// if (devToolsServerAddress != null)
// '--devtools-server-address=$devToolsServerAddress',
for (final String tag in cachedUserTags) '--cached-user-tags=$tag',
],
);
final Completer<DartDevelopmentServiceInstance> completer =
Completer<DartDevelopmentServiceInstance>();
late StreamSubscription<Object?> stderrSub;
stderrSub = process.stderr
.transform(utf8.decoder)
.transform(json.decoder)
.listen((Object? result) {
if (result
case {
'state': 'started',
'ddsUri': final String ddsUriStr,
}) {
final Uri ddsUri = Uri.parse(ddsUriStr);
final String? devToolsUriStr = result['devToolsUri'] as String?;
final Uri? devToolsUri =
devToolsUriStr == null ? null : Uri.parse(devToolsUriStr);
final String? dtdUriStr =
(result['dtd'] as Map<String, Object?>?)?['uri'] as String?;
final Uri? dtdUri = dtdUriStr == null ? null : Uri.parse(dtdUriStr);
completer.complete((
process: process,
serviceUri: ddsUri,
devToolsUri: devToolsUri,
dtdUri: dtdUri,
));
} else if (result
case {
'state': 'error',
'error': final String error,
}) {
final Map<String, Object?>? exceptionDetails =
result['ddsExceptionDetails'] as Map<String, Object?>?;
completer.completeError(
exceptionDetails != null
? DartDevelopmentServiceException.fromJson(exceptionDetails)
: StateError(error),
);
} else {
throw StateError('Unexpected result from DDS: $result');
}
stderrSub.cancel();
});
return completer.future;
}
typedef DDSLauncherCallback = Future<DartDevelopmentServiceInstance> Function(
Uri remoteVmServiceUri, {
required bool enableAuthCodes,
required bool ipv6,
required bool enableDevTools,
required List<String> cachedUserTags,
Uri? serviceUri,
String? google3WorkspaceRoot,
Uri? devToolsServerAddress,
});
// TODO(fujino): This should be direct injected, rather than mutable global state.
/// Used by tests to override the DDS spawn behavior for mocking purposes.
@visibleForTesting
DDSLauncherCallback ddsLauncherCallback = defaultStartDartDevelopmentService;
/// Thrown by DDS during initialization failures, unexpected connection issues,
/// and when attempting to spawn DDS when an existing DDS instance exists.
class DartDevelopmentServiceException implements Exception {
factory DartDevelopmentServiceException.fromJson(Map<String, Object?> json) {
if (json
case {
'error_code': final int errorCode,
'message': final String message,
'uri': final String? uri
}) {
return switch (errorCode) {
existingDdsInstanceError =>
DartDevelopmentServiceException.existingDdsInstance(
message,
ddsUri: Uri.parse(uri!),
),
failedToStartError => DartDevelopmentServiceException.failedToStart(),
connectionError =>
DartDevelopmentServiceException.connectionIssue(message),
_ => throw StateError(
'Invalid DartDevelopmentServiceException error_code: $errorCode',
),
};
}
throw StateError('Invalid DartDevelopmentServiceException JSON: $json');
}
/// Thrown when `DartDeveloperService.startDartDevelopmentService` is called
/// and the target VM service already has a Dart Developer Service instance
/// connected.
factory DartDevelopmentServiceException.existingDdsInstance(
String message, {
Uri? ddsUri,
}) {
return ExistingDartDevelopmentServiceException._(
message,
ddsUri: ddsUri,
);
}
/// Thrown when the connection to the remote VM service terminates unexpectedly
/// during Dart Development Service startup.
factory DartDevelopmentServiceException.failedToStart() {
return DartDevelopmentServiceException._(
failedToStartError,
'Failed to start Dart Development Service',
);
}
/// Thrown when a connection error has occurred after startup.
factory DartDevelopmentServiceException.connectionIssue(String message) {
return DartDevelopmentServiceException._(connectionError, message);
}
DartDevelopmentServiceException._(this.errorCode, this.message);
/// Set when `DartDeveloperService.startDartDevelopmentService` is called and
/// the target VM service already has a Dart Developer Service instance
/// connected.
static const int existingDdsInstanceError = 1;
/// Set when the connection to the remote VM service terminates unexpectedly
/// during Dart Development Service startup.
static const int failedToStartError = 2;
/// Set when a connection error has occurred after startup.
static const int connectionError = 3;
@override
String toString() => 'DartDevelopmentServiceException: $message';
final int errorCode;
final String message;
}
/// Thrown when attempting to start a new DDS instance when one already exists.
class ExistingDartDevelopmentServiceException
extends DartDevelopmentServiceException {
ExistingDartDevelopmentServiceException._(
String message, {
this.ddsUri,
}) : super._(
DartDevelopmentServiceException.existingDdsInstanceError,
message,
);
/// The URI of the existing DDS instance, if available.
///
/// This URI is the base HTTP URI such as `http://127.0.0.1:1234/AbcDefg=/`,
/// not the WebSocket URI (which can be obtained by mapping the scheme to
/// `ws` (or `wss`) and appending `ws` to the path segments).
final Uri? ddsUri;
}
Future<dds.DartDevelopmentService> Function(
Uri remoteVmServiceUri, {
bool enableAuthCodes,
bool ipv6,
Uri? serviceUri,
List<String> cachedUserTags,
dds.UriConverter? uriConverter,
}) ddsLauncherCallback = dds.DartDevelopmentService.startDartDevelopmentService;
/// Helper class to launch a [dds.DartDevelopmentService]. Allows for us to
/// mock out this functionality for testing purposes.
class DartDevelopmentService with DartDevelopmentServiceLocalOperationsMixin {
DartDevelopmentService({required Logger logger}) : _logger = logger;
class DartDevelopmentService {
dds.DartDevelopmentService? _ddsInstance;
DartDevelopmentServiceInstance? _ddsInstance;
Uri? get uri => _ddsInstance?.serviceUri ?? _existingDdsUri;
Uri? get uri => _ddsInstance?.uri ?? _existingDdsUri;
Uri? _existingDdsUri;
Future<void> get done => _completer.future;
final Completer<void> _completer = Completer<void>();
final Logger _logger;
@override
Future<void> startDartDevelopmentService(
Uri vmServiceUri, {
int? ddsPort,
bool? disableServiceAuthCodes,
required Logger logger,
int? hostPort,
bool? ipv6,
bool enableDevTools = true,
bool? disableServiceAuthCodes,
bool cacheStartupProfile = false,
String? google3WorkspaceRoot,
Uri? devToolsServerAddress,
}) async {
assert(_ddsInstance == null);
final Uri ddsUri = Uri(
scheme: 'http',
host: ((ipv6 ?? false)
? io.InternetAddress.loopbackIPv6
: io.InternetAddress.loopbackIPv4)
.host,
port: ddsPort ?? 0,
host: ((ipv6 ?? false) ? io.InternetAddress.loopbackIPv6 : io.InternetAddress.loopbackIPv4).host,
port: hostPort ?? 0,
);
_logger.printTrace(
logger.printTrace(
'Launching a Dart Developer Service (DDS) instance at $ddsUri, '
'connecting to VM service at $vmServiceUri.',
);
void completeFuture() {
try {
_ddsInstance = await ddsLauncherCallback(
vmServiceUri,
serviceUri: ddsUri,
enableAuthCodes: disableServiceAuthCodes != true,
ipv6: ipv6 ?? false,
// Enables caching of CPU samples collected during application startup.
cachedUserTags: cacheStartupProfile ? const <String>['AppStartUp'] : const <String>[],
uriConverter: context.get<dds.UriConverter>(),
);
unawaited(_ddsInstance?.done.whenComplete(() {
if (!_completer.isCompleted) {
_completer.complete();
}
}));
logger.printTrace('DDS is listening at ${_ddsInstance?.uri}.');
} on dds.DartDevelopmentServiceException catch (e) {
logger.printTrace('Warning: Failed to start DDS: ${e.message}');
if (e.errorCode == dds.DartDevelopmentServiceException.existingDdsInstanceError) {
try {
// First try to use the new field to avoid parsing from the message.
_existingDdsUri = e is dds.ExistingDartDevelopmentServiceException ? e.ddsUri : null;
// Otherwise, fall back to parsing from the exception (old DDS).
// This is not completely reliable which is why the new field above
// was added.
if (_existingDdsUri == null) {
String parsedUrl = e.message.split(' ').firstWhere((String e) => e.startsWith('http'));
// Trim trailing full stops from the message.
// https://github.com/flutter/flutter/issues/118609.
if (parsedUrl.endsWith('.')) {
parsedUrl = parsedUrl.substring(0, parsedUrl.length - 1);
}
_existingDdsUri ??= Uri.parse(parsedUrl);
}
} on StateError {
if (e.message.contains('Existing VM service clients prevent DDS from taking control.')) {
throwToolExit('${e.message}. Please rebuild your application with a newer version of Flutter.');
}
logger.printError(
'DDS has failed to start and there is not an existing DDS instance '
'available to connect to. Please file an issue at https://github.com/flutter/flutter/issues '
'with the following error message:\n\n ${e.message}.'
);
// DDS was unable to start for an unknown reason. Raise a StateError
// so it can be reported by the crash reporter.
throw StateError(e.message);
}
}
if (!_completer.isCompleted) {
_completer.complete();
}
}
try {
_ddsInstance = await ddsLauncherCallback(
vmServiceUri,
serviceUri: ddsUri,
enableAuthCodes: disableServiceAuthCodes != true,
ipv6: ipv6 ?? false,
enableDevTools: enableDevTools,
// Enables caching of CPU samples collected during application startup.
cachedUserTags: cacheStartupProfile
? const <String>['AppStartUp']
: const <String>[],
google3WorkspaceRoot: google3WorkspaceRoot,
devToolsServerAddress: devToolsServerAddress,
);
final io.Process? process = _ddsInstance?.process;
// Complete the future if the DDS process is null, which happens in
// testing.
if (process != null) {
unawaited(process.exitCode.whenComplete(completeFuture));
}
} on DartDevelopmentServiceException catch (e) {
_logger.printTrace('Warning: Failed to start DDS: ${e.message}');
if (e is ExistingDartDevelopmentServiceException) {
_existingDdsUri = e.ddsUri;
} else {
_logger.printError(
'DDS has failed to start and there is not an existing DDS instance '
'available to connect to. Please file an issue at https://github.com/flutter/flutter/issues '
'with the following error message:\n\n ${e.message}.');
// DDS was unable to start for an unknown reason. Raise a StateError
// so it can be reported by the crash reporter.
throw StateError(e.message);
}
completeFuture();
rethrow;
}
}
void shutdown() => _ddsInstance?.process?.kill();
}
Future<void> shutdown() async => _ddsInstance?.shutdown();
/// Contains common functionality that can be used with any implementation of
/// [DartDevelopmentService].
mixin DartDevelopmentServiceLocalOperationsMixin {
Future<void> startDartDevelopmentService(
Uri vmServiceUri, {
int? ddsPort,
bool? disableServiceAuthCodes,
bool? ipv6,
bool enableDevTools = true,
bool cacheStartupProfile = false,
String? google3WorkspaceRoot,
Uri? devToolsServerAddress,
});
/// A convenience method used to create a [DartDevelopmentService] instance
/// from a [DebuggingOptions] instance.
Future<void> startDartDevelopmentServiceFromDebuggingOptions(
Uri vmServiceUri, {
required DebuggingOptions debuggingOptions,
}) =>
startDartDevelopmentService(
vmServiceUri,
ddsPort: debuggingOptions.ddsPort,
disableServiceAuthCodes: debuggingOptions.disableServiceAuthCodes,
ipv6: debuggingOptions.ipv6,
enableDevTools: debuggingOptions.enableDevTools,
cacheStartupProfile: debuggingOptions.cacheStartupProfile,
google3WorkspaceRoot: debuggingOptions.google3WorkspaceRoot,
devToolsServerAddress: debuggingOptions.devToolsServerAddress,
);
void setExternalDevToolsUri(Uri uri) {
_ddsInstance?.setExternalDevToolsUri(uri);
}
}

View File

@@ -361,6 +361,7 @@ known, it can be explicitly provided to attach via the command-line, e.g.
connectionInfoCompleter: connectionInfoCompleter,
appStartedCompleter: appStartedCompleter,
allowExistingDdsInstance: true,
enableDevTools: boolArg(FlutterCommand.kEnableDevTools),
);
},
device,
@@ -402,6 +403,7 @@ known, it can be explicitly provided to attach via the command-line, e.g.
result = await runner.attach(
appStartedCompleter: onAppStart,
allowExistingDdsInstance: true,
enableDevTools: boolArg(FlutterCommand.kEnableDevTools),
);
if (result != 0) {
throwToolExit(null, exitCode: result);
@@ -460,9 +462,6 @@ known, it can be explicitly provided to attach via the command-line, e.g.
serveObservatory: serveObservatory,
usingCISystem: usingCISystem,
debugLogsDirectoryPath: debugLogsDirectoryPath,
enableDevTools: boolArg(FlutterCommand.kEnableDevTools),
ipv6: usesIpv6,
printDtd: boolArg(FlutterGlobalOptions.kPrintDtd, global: true),
);
return buildInfo.isDebug
@@ -473,6 +472,7 @@ known, it can be explicitly provided to attach via the command-line, e.g.
packagesFilePath: globalResults![FlutterGlobalOptions.kPackagesOption] as String?,
projectRootPath: stringArg('project-root'),
dillOutputPath: stringArg('output-dill'),
ipv6: usesIpv6,
flutterProject: flutterProject,
nativeAssetsYamlFile: stringArg(FlutterOptions.kNativeAssetsYamlFile),
nativeAssetsBuilder: _nativeAssetsBuilder,
@@ -482,6 +482,7 @@ known, it can be explicitly provided to attach via the command-line, e.g.
flutterDevices,
target: targetFile,
debuggingOptions: debuggingOptions,
ipv6: usesIpv6,
);
}
@@ -505,6 +506,7 @@ class HotRunnerFactory {
String? packagesFilePath,
String? dillOutputPath,
bool stayResident = true,
bool ipv6 = false,
FlutterProject? flutterProject,
String? nativeAssetsYamlFile,
required HotRunnerNativeAssetsBuilder? nativeAssetsBuilder,
@@ -519,6 +521,7 @@ class HotRunnerFactory {
projectRootPath: projectRootPath,
dillOutputPath: dillOutputPath,
stayResident: stayResident,
ipv6: ipv6,
nativeAssetsYamlFile: nativeAssetsYamlFile,
nativeAssetsBuilder: nativeAssetsBuilder,
analytics: analytics,

View File

@@ -664,9 +664,11 @@ class AppDomain extends Domain {
String? projectRootPath,
String? packagesFilePath,
String? dillOutputPath,
bool ipv6 = false,
String? isolateFilter,
bool machine = true,
String? userIdentifier,
bool enableDevTools = true,
required HotRunnerNativeAssetsBuilder? nativeAssetsBuilder,
}) async {
if (!await device.supportsRuntimeMode(options.buildInfo.mode)) {
@@ -697,6 +699,7 @@ class AppDomain extends Domain {
flutterProject: flutterProject,
target: target,
debuggingOptions: options,
ipv6: ipv6,
stayResident: true,
urlTunneller: options.webEnableExposeUrl! ? daemon.daemonDomain.exposeUrl : null,
machine: machine,
@@ -714,6 +717,7 @@ class AppDomain extends Domain {
applicationBinary: applicationBinary,
projectRootPath: projectRootPath,
dillOutputPath: dillOutputPath,
ipv6: ipv6,
hostIsIde: true,
machine: machine,
analytics: globals.analytics,
@@ -725,6 +729,7 @@ class AppDomain extends Domain {
target: target,
debuggingOptions: options,
applicationBinary: applicationBinary,
ipv6: ipv6,
machine: machine,
);
}
@@ -738,6 +743,7 @@ class AppDomain extends Domain {
return runner.run(
connectionInfoCompleter: connectionInfoCompleter,
appStartedCompleter: appStartedCompleter,
enableDevTools: enableDevTools,
route: route,
);
},
@@ -1002,6 +1008,7 @@ class DeviceDomain extends Domain {
registerHandler('takeScreenshot', takeScreenshot);
registerHandler('startDartDevelopmentService', startDartDevelopmentService);
registerHandler('shutdownDartDevelopmentService', shutdownDartDevelopmentService);
registerHandler('setExternalDevToolsUriForDartDevelopmentService', setExternalDevToolsUriForDartDevelopmentService);
registerHandler('getDiagnostics', getDiagnostics);
registerHandler('startVMServiceDiscoveryForAttach', startVMServiceDiscoveryForAttach);
registerHandler('stopVMServiceDiscoveryForAttach', stopVMServiceDiscoveryForAttach);
@@ -1189,6 +1196,7 @@ class DeviceDomain extends Domain {
route: _getStringArg(args, 'route'),
platformArgs: castStringKeyedMap(args['platformArgs']) ?? const <String, Object>{},
prebuiltApplication: _getBoolArg(args, 'prebuiltApplication') ?? false,
ipv6: _getBoolArg(args, 'ipv6') ?? false,
userIdentifier: _getStringArg(args, 'userIdentifier'),
);
return <String, Object?>{
@@ -1236,36 +1244,23 @@ class DeviceDomain extends Domain {
}
/// Starts DDS for the device.
Future<Map<String, Object?>> startDartDevelopmentService(Map<String, Object?> args) async {
Future<String?> startDartDevelopmentService(Map<String, Object?> args) async {
final String? deviceId = _getStringArg(args, 'deviceId', required: true);
final bool? disableServiceAuthCodes = _getBoolArg(args, 'disableServiceAuthCodes');
final String vmServiceUriStr = _getStringArg(args, 'vmServiceUri', required: true)!;
final bool enableDevTools = _getBoolArg(args, 'enableDevTools') ?? false;
final String? devToolsServerAddressStr = _getStringArg(args, 'devToolsServerAddress');
final Device? device = await daemon.deviceDomain._getDevice(deviceId);
if (device == null) {
throw DaemonException("device '$deviceId' not found");
}
Uri? devToolsServerAddress;
if (devToolsServerAddressStr != null) {
devToolsServerAddress = Uri.parse(devToolsServerAddressStr);
}
await device.dds.startDartDevelopmentService(
Uri.parse(vmServiceUriStr),
logger: globals.logger,
disableServiceAuthCodes: disableServiceAuthCodes,
enableDevTools: enableDevTools,
devToolsServerAddress: devToolsServerAddress,
);
unawaited(device.dds.done.whenComplete(() => sendEvent('device.dds.done.$deviceId')));
return <String, Object?>{
'ddsUri': device.dds.uri?.toString(),
// TODO(bkonyi): uncomment when ready to serve DevTools from DDS.
// 'devToolsUri': device.dds.devToolsUri?.toString(),
// 'dtdUri': device.dds.dtdUri?.toString(),
};
return device.dds.uri?.toString();
}
/// Starts DDS for the device.
@@ -1277,7 +1272,19 @@ class DeviceDomain extends Domain {
throw DaemonException("device '$deviceId' not found");
}
device.dds.shutdown();
await device.dds.shutdown();
}
Future<void> setExternalDevToolsUriForDartDevelopmentService(Map<String, Object?> args) async {
final String? deviceId = _getStringArg(args, 'deviceId', required: true);
final String uri = _getStringArg(args, 'uri', required: true)!;
final Device? device = await daemon.deviceDomain._getDevice(deviceId);
if (device == null) {
throw DaemonException("device '$deviceId' not found");
}
device.dds.setExternalDevToolsUri(Uri.parse(uri));
}
@override

View File

@@ -274,6 +274,7 @@ class DriveCommand extends RunCommandBase {
buildInfo,
device,
debuggingOptions,
ipv6 ?? false,
applicationBinary: applicationBinary,
route: route,
userIdentifier: userIdentifier,
@@ -294,6 +295,7 @@ class DriveCommand extends RunCommandBase {
uri,
device,
debuggingOptions,
ipv6 ?? false,
);
}

View File

@@ -354,9 +354,6 @@ abstract class RunCommandBase extends FlutterCommand with DeviceBasedDevelopment
enableEmbedderApi: enableEmbedderApi,
usingCISystem: usingCISystem,
debugLogsDirectoryPath: debugLogsDirectoryPath,
enableDevTools: boolArg(FlutterCommand.kEnableDevTools),
ipv6: boolArg(FlutterCommand.ipv6Flag),
printDtd: boolArg(FlutterGlobalOptions.kPrintDtd, global: true),
);
}
}
@@ -705,6 +702,7 @@ class RunCommand extends RunCommandBase {
projectRootPath: stringArg('project-root'),
dillOutputPath: stringArg('output-dill'),
stayResident: stayResident,
ipv6: ipv6 ?? false,
analytics: globals.analytics,
nativeAssetsYamlFile: stringArg(FlutterOptions.kNativeAssetsYamlFile),
nativeAssetsBuilder: _nativeAssetsBuilder,
@@ -714,6 +712,7 @@ class RunCommand extends RunCommandBase {
flutterDevices.single,
target: targetFile,
flutterProject: flutterProject,
ipv6: ipv6,
debuggingOptions: await createDebuggingOptions(webMode),
stayResident: stayResident,
fileSystem: globals.fs,
@@ -732,6 +731,7 @@ class RunCommand extends RunCommandBase {
applicationBinary: applicationBinaryPath == null
? null
: globals.fs.file(applicationBinaryPath),
ipv6: ipv6 ?? false,
stayResident: stayResident,
);
}
@@ -776,7 +776,9 @@ class RunCommand extends RunCommandBase {
projectRootPath: stringArg('project-root'),
packagesFilePath: globalResults![FlutterGlobalOptions.kPackagesOption] as String?,
dillOutputPath: stringArg('output-dill'),
ipv6: ipv6 ?? false,
userIdentifier: userIdentifier,
enableDevTools: boolArg(FlutterCommand.kEnableDevTools),
nativeAssetsBuilder: _nativeAssetsBuilder,
);
} on Exception catch (error) {
@@ -864,6 +866,7 @@ class RunCommand extends RunCommandBase {
try {
final int? result = await runner.run(
appStartedCompleter: appStartedTimeRecorder,
enableDevTools: stayResident && boolArg(FlutterCommand.kEnableDevTools),
route: route,
);
handler?.stop();

View File

@@ -16,7 +16,6 @@ import '../globals.dart' as globals;
import '../native_assets.dart';
import '../project.dart';
import '../runner/flutter_command.dart';
import '../runner/flutter_command_runner.dart';
import '../test/coverage_collector.dart';
import '../test/event_printer.dart';
import '../test/runner.dart';
@@ -412,7 +411,6 @@ class TestCommand extends FlutterCommand with DeviceBasedDevelopmentArtifacts {
enableImpeller: ImpellerStatus.fromBool(argResults!['enable-impeller'] as bool?),
debugLogsDirectoryPath: debugLogsDirectoryPath,
webRenderer: webRenderer,
printDtd: boolArg(FlutterGlobalOptions.kPrintDtd, global: true),
webUseWasm: useWasm,
webUseLocalCanvaskit: true,
);
@@ -601,6 +599,7 @@ class TestCommand extends FlutterCommand with DeviceBasedDevelopmentArtifacts {
excludeTags: excludeTags,
watcher: watcher,
enableVmService: collector != null || startPaused || enableVmService,
ipv6: ipv6,
machine: machine,
updateGoldens: boolArg('update-goldens'),
concurrency: jobs,

View File

@@ -352,6 +352,7 @@ class CustomDeviceAppSession {
required DebuggingOptions debuggingOptions,
Map<String, Object?> platformArgs = const <String, Object>{},
bool prebuiltApplication = false,
bool ipv6 = false,
String? userIdentifier
}) async {
final bool traceStartup = platformArgs['trace-startup'] as bool? ?? false;
@@ -376,7 +377,7 @@ class CustomDeviceAppSession {
logReader,
portForwarder: _device._config.usesPortForwarding ? _device.portForwarder : null,
logger: _logger,
ipv6: debuggingOptions.ipv6,
ipv6: ipv6,
);
// We need to make the discovery listen to the logReader before the logReader
@@ -438,7 +439,7 @@ class CustomDeviceAppSession {
class CustomDevice extends Device {
CustomDevice({
required CustomDeviceConfig config,
required super.logger,
required Logger logger,
required ProcessManager processManager,
}) : _config = config,
_logger = logger,
@@ -788,6 +789,7 @@ class CustomDevice extends Device {
debuggingOptions: debuggingOptions,
platformArgs: platformArgs,
prebuiltApplication: prebuiltApplication,
ipv6: ipv6,
userIdentifier: userIdentifier,
);
}

View File

@@ -26,7 +26,7 @@ abstract class DesktopDevice extends Device {
DesktopDevice(super.id, {
required PlatformType super.platformType,
required super.ephemeral,
required super.logger,
required Logger logger,
required ProcessManager processManager,
required FileSystem fileSystem,
required OperatingSystemUtils operatingSystemUtils,
@@ -114,6 +114,7 @@ abstract class DesktopDevice extends Device {
required DebuggingOptions debuggingOptions,
Map<String, dynamic> platformArgs = const <String, dynamic>{},
bool prebuiltApplication = false,
bool ipv6 = false,
String? userIdentifier,
}) async {
if (!prebuiltApplication) {
@@ -157,7 +158,7 @@ abstract class DesktopDevice extends Device {
final ProtocolDiscovery vmServiceDiscovery = ProtocolDiscovery.vmService(_deviceLogReader,
devicePort: debuggingOptions.deviceVmServicePort,
hostPort: debuggingOptions.hostVmServicePort,
ipv6: debuggingOptions.ipv6,
ipv6: ipv6,
logger: _logger,
);
try {

View File

@@ -603,11 +603,10 @@ String getNameForDeviceConnectionInterface(DeviceConnectionInterface connectionI
/// the host operating system in the case of Flutter Desktop.
abstract class Device {
Device(this.id, {
required Logger logger,
required this.category,
required this.platformType,
required this.ephemeral,
}) : dds = DartDevelopmentService(logger: logger);
});
final String id;
@@ -734,7 +733,7 @@ abstract class Device {
DevicePortForwarder? get portForwarder;
/// Get the DDS instance for this device.
final DartDevelopmentService dds;
final DartDevelopmentService dds = DartDevelopmentService();
/// Clear the device's logs.
void clearLogs();
@@ -779,6 +778,7 @@ abstract class Device {
required DebuggingOptions debuggingOptions,
Map<String, Object?> platformArgs,
bool prebuiltApplication = false,
bool ipv6 = false,
String? userIdentifier,
});
@@ -1007,11 +1007,7 @@ class DebuggingOptions {
this.enableEmbedderApi = false,
this.usingCISystem = false,
this.debugLogsDirectoryPath,
this.enableDevTools = true,
this.ipv6 = false,
this.google3WorkspaceRoot,
this.printDtd = false,
}) : debuggingEnabled = true,
}) : debuggingEnabled = true,
webRenderer = webRenderer ?? WebRendererMode.getDefault(useWasm: webUseWasm);
DebuggingOptions.disabled(this.buildInfo, {
@@ -1069,10 +1065,6 @@ class DebuggingOptions {
nullAssertions = false,
nativeNullAssertions = false,
serveObservatory = false,
enableDevTools = false,
ipv6 = false,
google3WorkspaceRoot = null,
printDtd = false,
webRenderer = webRenderer ?? WebRendererMode.getDefault(useWasm: webUseWasm);
DebuggingOptions._({
@@ -1131,10 +1123,6 @@ class DebuggingOptions {
required this.enableEmbedderApi,
required this.usingCISystem,
required this.debugLogsDirectoryPath,
required this.enableDevTools,
required this.ipv6,
required this.google3WorkspaceRoot,
required this.printDtd,
});
final bool debuggingEnabled;
@@ -1179,10 +1167,6 @@ class DebuggingOptions {
final bool enableEmbedderApi;
final bool usingCISystem;
final String? debugLogsDirectoryPath;
final bool enableDevTools;
final bool ipv6;
final String? google3WorkspaceRoot;
final bool printDtd;
/// Whether the tool should try to uninstall a previously installed version of the app.
///
@@ -1236,6 +1220,7 @@ class DebuggingOptions {
EnvironmentType environmentType,
String? route,
Map<String, Object?> platformArgs, {
bool ipv6 = false,
DeviceConnectionInterface interfaceType = DeviceConnectionInterface.attached,
bool isCoreDevice = false,
}) {
@@ -1341,10 +1326,6 @@ class DebuggingOptions {
'enableEmbedderApi': enableEmbedderApi,
'usingCISystem': usingCISystem,
'debugLogsDirectoryPath': debugLogsDirectoryPath,
'enableDevTools': enableDevTools,
'ipv6': ipv6,
'google3WorkspaceRoot': google3WorkspaceRoot,
'printDtd': printDtd,
};
static DebuggingOptions fromJson(Map<String, Object?> json, BuildInfo buildInfo) =>
@@ -1404,10 +1385,6 @@ class DebuggingOptions {
enableEmbedderApi: (json['enableEmbedderApi'] as bool?) ?? false,
usingCISystem: (json['usingCISystem'] as bool?) ?? false,
debugLogsDirectoryPath: json['debugLogsDirectoryPath'] as String?,
enableDevTools: (json['enableDevTools'] as bool?) ?? true,
ipv6: (json['ipv6'] as bool?) ?? false,
google3WorkspaceRoot: json['google3WorkspaceRoot'] as String?,
printDtd: (json['printDtd'] as bool?) ?? false,
);
}

View File

@@ -4,6 +4,7 @@
import 'dart:async';
import 'package:dds/dds.dart' as dds;
import 'package:file/file.dart';
import 'package:meta/meta.dart';
import 'package:package_config/package_config_types.dart';
@@ -11,7 +12,6 @@ import 'package:vm_service/vm_service.dart' as vm_service;
import '../application_package.dart';
import '../base/common.dart';
import '../base/dds.dart';
import '../base/logger.dart';
import '../base/process.dart';
import '../build_info.dart';
@@ -65,7 +65,8 @@ abstract class DriverService {
Future<void> start(
BuildInfo buildInfo,
Device device,
DebuggingOptions debuggingOptions, {
DebuggingOptions debuggingOptions,
bool ipv6, {
File? applicationBinary,
String? route,
String? userIdentifier,
@@ -78,6 +79,7 @@ abstract class DriverService {
Uri vmServiceUri,
Device device,
DebuggingOptions debuggingOptions,
bool ipv6,
);
/// Start the test file with the provided [arguments] and [environment], returning
@@ -146,7 +148,8 @@ class FlutterDriverService extends DriverService {
Future<void> start(
BuildInfo buildInfo,
Device device,
DebuggingOptions debuggingOptions, {
DebuggingOptions debuggingOptions,
bool ipv6, {
File? applicationBinary,
String? route,
String? userIdentifier,
@@ -196,6 +199,7 @@ class FlutterDriverService extends DriverService {
result.vmServiceUri!,
device,
debuggingOptions,
ipv6,
);
}
@@ -204,6 +208,7 @@ class FlutterDriverService extends DriverService {
Uri vmServiceUri,
Device device,
DebuggingOptions debuggingOptions,
bool ipv6,
) async {
Uri uri;
if (vmServiceUri.scheme == 'ws') {
@@ -217,12 +222,15 @@ class FlutterDriverService extends DriverService {
_device = device;
if (debuggingOptions.enableDds) {
try {
await device.dds.startDartDevelopmentServiceFromDebuggingOptions(
await device.dds.startDartDevelopmentService(
uri,
debuggingOptions: debuggingOptions,
hostPort: debuggingOptions.ddsPort,
ipv6: ipv6,
disableServiceAuthCodes: debuggingOptions.disableServiceAuthCodes,
logger: _logger,
);
_vmServiceUri = device.dds.uri.toString();
} on DartDevelopmentServiceException {
} on dds.DartDevelopmentServiceException {
// If there's another flutter_tools instance still connected to the target
// application, DDS will already be running remotely and this call will fail.
// This can be ignored to continue to use the existing remote DDS instance.

View File

@@ -55,7 +55,8 @@ class WebDriverService extends DriverService {
Future<void> start(
BuildInfo buildInfo,
Device device,
DebuggingOptions debuggingOptions, {
DebuggingOptions debuggingOptions,
bool ipv6, {
File? applicationBinary,
String? route,
String? userIdentifier,
@@ -71,6 +72,7 @@ class WebDriverService extends DriverService {
_residentRunner = webRunnerFactory!.createWebRunner(
flutterDevice,
target: mainPath,
ipv6: ipv6,
debuggingOptions: buildInfo.isRelease ?
DebuggingOptions.disabled(
buildInfo,
@@ -232,7 +234,7 @@ class WebDriverService extends DriverService {
}
@override
Future<void> reuseApplication(Uri vmServiceUri, Device device, DebuggingOptions debuggingOptions) async {
Future<void> reuseApplication(Uri vmServiceUri, Device device, DebuggingOptions debuggingOptions, bool ipv6) async {
throwToolExit('--use-existing-app is not supported with flutter web driver');
}
}

View File

@@ -58,9 +58,10 @@ Future<void> _kDefaultDartDevelopmentServiceStarter(
) async {
await device.dds.startDartDevelopmentService(
vmServiceUri,
ddsPort: 0,
disableServiceAuthCodes: disableServiceAuthCodes,
hostPort: 0,
ipv6: true,
disableServiceAuthCodes: disableServiceAuthCodes,
logger: globals.logger,
);
}
@@ -211,7 +212,7 @@ class FuchsiaDevices extends PollingDeviceDiscovery {
_logger.printError('Failed to resolve host for Fuchsia device `$name`');
return null;
}
return FuchsiaDevice(resolvedHost, name: name, logger: _logger);
return FuchsiaDevice(resolvedHost, name: name);
}
@override
@@ -219,7 +220,7 @@ class FuchsiaDevices extends PollingDeviceDiscovery {
}
class FuchsiaDevice extends Device {
FuchsiaDevice(super.id, {required this.name, required super.logger})
FuchsiaDevice(super.id, {required this.name})
: super(
platformType: PlatformType.fuchsia,
category: null,
@@ -294,6 +295,7 @@ class FuchsiaDevice extends Device {
required DebuggingOptions debuggingOptions,
Map<String, Object?> platformArgs = const <String, Object?>{},
bool prebuiltApplication = false,
bool ipv6 = false,
String? userIdentifier,
}) async {
if (await isSession) {

View File

@@ -272,7 +272,7 @@ class IOSDevice extends Device {
required IOSCoreDeviceControl coreDeviceControl,
required XcodeDebug xcodeDebug,
required IProxy iProxy,
required super.logger,
required Logger logger,
})
: _sdkVersion = sdkVersion,
_iosDeploy = iosDeploy,
@@ -470,6 +470,7 @@ class IOSDevice extends Device {
required DebuggingOptions debuggingOptions,
Map<String, Object?> platformArgs = const <String, Object?>{},
bool prebuiltApplication = false,
bool ipv6 = false,
String? userIdentifier,
@visibleForTesting Duration? discoveryTimeout,
@visibleForTesting ShutdownHooks? shutdownHooks,
@@ -523,6 +524,7 @@ class IOSDevice extends Device {
EnvironmentType.physical,
route,
platformArgs,
ipv6: ipv6,
interfaceType: connectionInterface,
isCoreDevice: isCoreDevice,
);
@@ -539,6 +541,7 @@ class IOSDevice extends Device {
bundle: bundle,
debuggingOptions: debuggingOptions,
launchArguments: launchArguments,
ipv6: ipv6,
uninstallFirst: debuggingOptions.uninstallFirst,
);
}
@@ -616,6 +619,7 @@ class IOSDevice extends Device {
localUri = await _discoverDartVMForCoreDevice(
debuggingOptions: debuggingOptions,
packageId: packageId,
ipv6: ipv6,
vmServiceDiscovery: vmServiceDiscovery,
);
} else if (isWirelesslyConnected) {
@@ -647,7 +651,7 @@ class IOSDevice extends Device {
localUri = await MDnsVmServiceDiscovery.instance!.getVMServiceUriForLaunch(
packageId,
this,
usesIpv6: debuggingOptions.ipv6,
usesIpv6: ipv6,
deviceVmservicePort: serviceURL.port,
useDeviceIPAsHost: true,
);
@@ -669,6 +673,7 @@ class IOSDevice extends Device {
bundle: bundle,
debuggingOptions: debuggingOptions,
launchArguments: launchArguments,
ipv6: ipv6,
uninstallFirst: false,
skipInstall: true,
);
@@ -723,6 +728,7 @@ class IOSDevice extends Device {
/// Wireless devices require using the device IP as the host.
Future<Uri?> _discoverDartVMForCoreDevice({
required String packageId,
required bool ipv6,
required DebuggingOptions debuggingOptions,
ProtocolDiscovery? vmServiceDiscovery,
}) async {
@@ -769,7 +775,7 @@ class IOSDevice extends Device {
final Future<Uri?> vmUrlFromMDns = MDnsVmServiceDiscovery.instance!.getVMServiceUriForLaunch(
packageId,
this,
usesIpv6: debuggingOptions.ipv6,
usesIpv6: ipv6,
useDeviceIPAsHost: isWirelesslyConnected,
);
@@ -808,6 +814,7 @@ class IOSDevice extends Device {
required Directory bundle,
required DebuggingOptions debuggingOptions,
required List<String> launchArguments,
required bool ipv6,
required bool uninstallFirst,
bool skipInstall = false,
}) {
@@ -838,7 +845,7 @@ class IOSDevice extends Device {
portForwarder: isWirelesslyConnected ? null : portForwarder,
hostPort: debuggingOptions.hostVmServicePort,
devicePort: debuggingOptions.deviceVmServicePort,
ipv6: debuggingOptions.ipv6,
ipv6: ipv6,
logger: _logger,
);
}

View File

@@ -90,7 +90,6 @@ class IOSSimulatorUtils {
name: name,
simControl: _simControl,
simulatorCategory: device.category,
logger: _simControl._logger,
);
}).whereType<IOSSimulator>().toList();
}
@@ -357,7 +356,6 @@ class IOSSimulator extends Device {
required this.name,
required this.simulatorCategory,
required SimControl simControl,
required super.logger,
}) : _simControl = simControl,
super(
category: Category.mobile,
@@ -474,6 +472,7 @@ class IOSSimulator extends Device {
required DebuggingOptions debuggingOptions,
Map<String, Object?> platformArgs = const <String, Object?>{},
bool prebuiltApplication = false,
bool ipv6 = false,
String? userIdentifier,
}) async {
if (!prebuiltApplication && package is BuildableIOSApp) {
@@ -502,7 +501,7 @@ class IOSSimulator extends Device {
if (debuggingOptions.debuggingEnabled) {
vmServiceDiscovery = ProtocolDiscovery.vmService(
getLogReader(app: package),
ipv6: debuggingOptions.ipv6,
ipv6: ipv6,
hostPort: debuggingOptions.hostVmServicePort,
devicePort: debuggingOptions.deviceVmServicePort,
logger: globals.logger,

View File

@@ -50,6 +50,7 @@ class DwdsWebRunnerFactory extends WebRunnerFactory {
String? target,
required bool stayResident,
required FlutterProject flutterProject,
required bool? ipv6,
required DebuggingOptions debuggingOptions,
UrlTunneller? urlTunneller,
required Logger logger,
@@ -64,6 +65,7 @@ class DwdsWebRunnerFactory extends WebRunnerFactory {
target: target,
flutterProject: flutterProject,
debuggingOptions: debuggingOptions,
ipv6: ipv6,
stayResident: stayResident,
urlTunneller: urlTunneller,
machine: machine,
@@ -87,6 +89,7 @@ class ResidentWebRunner extends ResidentRunner {
bool stayResident = true,
bool machine = false,
required this.flutterProject,
required bool? ipv6,
required DebuggingOptions debuggingOptions,
required FileSystem fileSystem,
required Logger logger,
@@ -94,7 +97,6 @@ class ResidentWebRunner extends ResidentRunner {
required Usage usage,
required Analytics analytics,
UrlTunneller? urlTunneller,
// TODO(bkonyi): remove when ready to serve DevTools from DDS.
ResidentDevtoolsHandlerFactory devtoolsHandler = createDefaultHandler,
}) : _fileSystem = fileSystem,
_logger = logger,
@@ -106,6 +108,7 @@ class ResidentWebRunner extends ResidentRunner {
<FlutterDevice>[device],
target: target ?? fileSystem.path.join('lib', 'main.dart'),
debuggingOptions: debuggingOptions,
ipv6: ipv6,
stayResident: stayResident,
machine: machine,
devtoolsHandler: devtoolsHandler,
@@ -192,7 +195,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();
@@ -245,6 +247,7 @@ class ResidentWebRunner extends ResidentRunner {
Future<int> run({
Completer<DebugConnectionInfo>? connectionInfoCompleter,
Completer<void>? appStartedCompleter,
bool enableDevTools = false, // ignored, we don't yet support devtools for web
String? route,
}) async {
final ApplicationPackage? package = await ApplicationPackageFactory.instance!.getPackageForPlatform(
@@ -365,6 +368,7 @@ Please provide a valid TCP port (an integer between 0 and 65535, inclusive).
return attach(
connectionInfoCompleter: connectionInfoCompleter,
appStartedCompleter: appStartedCompleter,
enableDevTools: enableDevTools,
);
});
} on WebSocketException catch (error, stackTrace) {
@@ -472,14 +476,7 @@ Please provide a valid TCP port (an integer between 0 and 65535, inclusive).
final Duration elapsed = _systemClock.now().difference(start);
final String elapsedMS = getElapsedAsMilliseconds(elapsed);
_logger.printStatus('Restarted application in $elapsedMS.');
// TODO(bkonyi): replace with code below when ready to serve DevTools from DDS.
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.
if (debuggingOptions.buildInfo.isDebug && deviceIsDebuggable) {
@@ -606,6 +603,7 @@ Please provide a valid TCP port (an integer between 0 and 65535, inclusive).
Completer<DebugConnectionInfo>? connectionInfoCompleter,
Completer<void>? appStartedCompleter,
bool allowExistingDdsInstance = false,
bool enableDevTools = false, // ignored, we don't yet support devtools for web
bool needsFullRestart = true,
}) async {
if (_chromiumLauncher != null) {
@@ -684,14 +682,13 @@ Please provide a valid TCP port (an integer between 0 and 65535, inclusive).
}
});
}
}
// 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,
));
if (enableDevTools) {
// The method below is guaranteed never to return a failing future.
unawaited(residentDevtoolsHandler!.serveAndAnnounceDevTools(
devToolsServerAddress: debuggingOptions.devToolsServerAddress,
flutterDevices: flutterDevices,
));
}
}
if (websocketUri != null) {
if (debuggingOptions.vmserviceOutFile != null) {

View File

@@ -99,6 +99,7 @@ class MacOSDesignedForIPadDevice extends DesktopDevice {
required DebuggingOptions debuggingOptions,
Map<String, Object?> platformArgs = const <String, Object>{},
bool prebuiltApplication = false,
bool ipv6 = false,
String? userIdentifier,
}) async {
// Only attaching to a running app launched from Xcode is supported.

View File

@@ -95,7 +95,7 @@ class PreviewDeviceDiscovery extends PollingDeviceDiscovery {
class PreviewDevice extends Device {
PreviewDevice({
required ProcessManager processManager,
required super.logger,
required Logger logger,
required FileSystem fileSystem,
required Artifacts artifacts,
required File previewBinary,
@@ -170,6 +170,7 @@ class PreviewDevice extends Device {
required DebuggingOptions debuggingOptions,
Map<String, dynamic> platformArgs = const <String, dynamic>{},
bool prebuiltApplication = false,
bool ipv6 = false,
String? userIdentifier,
}) async {
final Directory assetDirectory = _fileSystem.systemTempDirectory
@@ -213,7 +214,7 @@ class PreviewDevice extends Device {
final ProtocolDiscovery vmServiceDiscovery = ProtocolDiscovery.vmService(_logReader,
devicePort: debuggingOptions.deviceVmServicePort,
hostPort: debuggingOptions.hostVmServicePort,
ipv6: debuggingOptions.ipv6,
ipv6: ipv6,
logger: _logger,
);
try {

View File

@@ -19,7 +19,6 @@ import '../device.dart';
import '../device_port_forwarder.dart';
import '../device_vm_service_discovery_for_attach.dart';
import '../project.dart';
import '../resident_runner.dart';
import 'debounce_data_stream.dart';
import 'file_transfer.dart';
@@ -176,7 +175,7 @@ class ProxiedDevice extends Device {
required this.supportsScreenshot,
required this.supportsFastStart,
required bool supportsHardwareRendering,
required super.logger,
required Logger logger,
FileTransfer fileTransfer = const FileTransfer(),
}): _deltaFileTransfer = deltaFileTransfer,
_enableDdsProxy = enableDdsProxy,
@@ -335,6 +334,7 @@ class ProxiedDevice extends Device {
required DebuggingOptions debuggingOptions,
Map<String, Object?> platformArgs = const <String, Object?>{},
bool prebuiltApplication = false,
bool ipv6 = false,
String? userIdentifier,
}) async {
final Map<String, Object?> result = _cast<Map<String, Object?>>(await connection.sendRequest('device.startApp', <String, Object?>{
@@ -345,7 +345,7 @@ class ProxiedDevice extends Device {
'debuggingOptions': debuggingOptions.toJson(),
'platformArgs': platformArgs,
'prebuiltApplication': prebuiltApplication,
'ipv6': debuggingOptions.ipv6,
'ipv6': ipv6,
'userIdentifier': userIdentifier,
}));
final bool started = _cast<bool>(result['started']);
@@ -748,7 +748,7 @@ Future<ServerSocket> _defaultCreateServerSocket(Logger logger, int? hostPort, bo
/// There are a lot of communications between DDS and the VM service on the
/// device. When using proxied device, starting DDS remotely helps reduces the
/// amount of data transferred with the remote daemon, hence improving latency.
class ProxiedDartDevelopmentService with DartDevelopmentServiceLocalOperationsMixin implements DartDevelopmentService {
class ProxiedDartDevelopmentService implements DartDevelopmentService {
ProxiedDartDevelopmentService(
this.connection,
this.deviceId, {
@@ -756,11 +756,10 @@ class ProxiedDartDevelopmentService with DartDevelopmentServiceLocalOperationsMi
required ProxiedPortForwarder proxiedPortForwarder,
required ProxiedPortForwarder devicePortForwarder,
@visibleForTesting DartDevelopmentService? localDds,
}) :
_logger = logger,
}) : _logger = logger,
_proxiedPortForwarder = proxiedPortForwarder,
_devicePortForwarder = devicePortForwarder,
_localDds = localDds ?? DartDevelopmentService(logger: logger);
_localDds = localDds ?? DartDevelopmentService();
final String deviceId;
@@ -777,9 +776,10 @@ class ProxiedDartDevelopmentService with DartDevelopmentServiceLocalOperationsMi
/// It forwards a port on the remotely connected device, to the remote host, then to the local host.
final ProxiedPortForwarder _devicePortForwarder;
Uri? _localUri;
@override
Uri? get uri => _ddsStartedLocally ? _localDds.uri : _localUri;
Uri? _localUri;
@override
Future<void> get done => _completer.future;
@@ -792,14 +792,11 @@ class ProxiedDartDevelopmentService with DartDevelopmentServiceLocalOperationsMi
@override
Future<void> startDartDevelopmentService(
Uri vmServiceUri, {
FlutterDevice? device,
int? ddsPort,
required Logger logger,
int? hostPort,
bool? ipv6,
bool? disableServiceAuthCodes,
bool enableDevTools = false,
bool cacheStartupProfile = false,
String? google3WorkspaceRoot,
Uri? devToolsServerAddress,
}) async {
// Locate the original VM service port on the remote daemon.
// A proxied device has two PortForwarder. Check both to determine which
@@ -808,26 +805,18 @@ class ProxiedDartDevelopmentService with DartDevelopmentServiceLocalOperationsMi
_proxiedPortForwarder.originalRemotePort(vmServiceUri.port) ??
_devicePortForwarder.originalRemotePort(vmServiceUri.port);
Future<void> startLocalDds() async {
if (remoteVMServicePort == null) {
_logger.printTrace('VM service port is not a forwarded port. Start DDS locally.');
_ddsStartedLocally = true;
await _localDds.startDartDevelopmentService(
vmServiceUri,
ddsPort: ddsPort,
logger: logger,
hostPort: hostPort,
ipv6: ipv6,
disableServiceAuthCodes: disableServiceAuthCodes,
cacheStartupProfile: cacheStartupProfile,
enableDevTools: enableDevTools,
google3WorkspaceRoot: google3WorkspaceRoot,
devToolsServerAddress: devToolsServerAddress,
);
// TODO(bkonyi): uncomment when ready to serve DevTools from DDS.
// unawaited(_localDds.invokeServiceExtensions(device));
unawaited(_localDds.done.then(_completer.complete));
}
if (remoteVMServicePort == null) {
_logger.printTrace('VM service port is not a forwarded port. Start DDS locally.');
await startLocalDds();
return;
}
@@ -846,33 +835,11 @@ class ProxiedDartDevelopmentService with DartDevelopmentServiceLocalOperationsMi
// Ignore if we did not receive any event from the server.
},
));
final Object? response = await connection.sendRequest(method, <String, Object?>{
'deviceId': deviceId,
'vmServiceUri': remoteVMServiceUri.toString(),
'disableServiceAuthCodes': disableServiceAuthCodes,
// TODO(bkonyi): uncomment when ready to serve DevTools from DDS.
// 'enableDevTools': enableDevTools,
// if (devToolsServerAddress != null) 'devToolsServerAddress': devToolsServerAddress.toString(),
});
if (response is Map<String, Object?>) {
remoteUriStr = response['ddsUri'] as String?;
// TODO(bkonyi): uncomment when ready to serve DevTools from DDS.
/*
final String? devToolsUriStr = response['devToolsUri'] as String?;
if (devToolsUriStr != null) {
_remoteDevToolsUri = Uri.parse(devToolsUriStr);
}
final String? 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.
remoteUriStr = _cast<String?>(response);
}
remoteUriStr = _cast<String?>(await connection.sendRequest(method, <String, Object?>{
'deviceId': deviceId,
'vmServiceUri': remoteVMServiceUri.toString(),
'disableServiceAuthCodes': disableServiceAuthCodes,
}));
} on String catch (e) {
if (!e.contains(method)) {
rethrow;
@@ -883,7 +850,16 @@ class ProxiedDartDevelopmentService with DartDevelopmentServiceLocalOperationsMi
if (remoteUriStr == null) {
_logger.printTrace('Remote daemon cannot start DDS. Start a local DDS instead.');
await startLocalDds();
_ddsStartedLocally = true;
await _localDds.startDartDevelopmentService(
vmServiceUri,
logger: logger,
hostPort: hostPort,
ipv6: ipv6,
disableServiceAuthCodes: disableServiceAuthCodes,
cacheStartupProfile: cacheStartupProfile,
);
unawaited(_localDds.done.then(_completer.complete));
return;
}
@@ -893,7 +869,7 @@ class ProxiedDartDevelopmentService with DartDevelopmentServiceLocalOperationsMi
final Uri remoteUri = Uri.parse(remoteUriStr);
final int localPort = await _proxiedPortForwarder.forward(
remoteUri.port,
hostPort: ddsPort,
hostPort: hostPort,
ipv6: ipv6,
);
@@ -909,7 +885,7 @@ class ProxiedDartDevelopmentService with DartDevelopmentServiceLocalOperationsMi
@override
Future<void> shutdown() async {
if (_ddsStartedLocally) {
_localDds.shutdown();
await _localDds.shutdown();
_ddsStartedLocally = false;
} else {
await connection.sendRequest('device.shutdownDartDevelopmentService', <String, Object?>{
@@ -917,6 +893,14 @@ class ProxiedDartDevelopmentService with DartDevelopmentServiceLocalOperationsMi
});
}
}
@override
void setExternalDevToolsUri(Uri uri) {
connection.sendRequest('device.setExternalDevToolsUriForDartDevelopmentService', <String, Object?>{
'deviceId': deviceId,
'uri': uri.toString(),
});
}
}
class ProxiedVMServiceDiscoveryForAttach extends VMServiceDiscoveryForAttach {

View File

@@ -2,10 +2,6 @@
// 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:browser_launcher/browser_launcher.dart';
@@ -114,6 +110,18 @@ class FlutterResidentDevtoolsHandler implements ResidentDevtoolsHandler {
return;
}
final Uri? devToolsUrl = _devToolsLauncher.devToolsUrl;
if (devToolsUrl != null) {
for (final FlutterDevice? device in flutterDevices) {
if (device == null) {
continue;
}
// Notify the DDS instances that there's a DevTools instance available so they can correctly
// redirect DevTools related requests.
device.device?.dds.setExternalDevToolsUri(devToolsUrl);
}
}
Future<void> callServiceExtensions() async {
final List<FlutterDevice?> devicesWithExtension = await _devicesWithExtensions(flutterDevices);
await Future.wait(
@@ -206,12 +214,10 @@ class FlutterResidentDevtoolsHandler implements ResidentDevtoolsHandler {
},
);
} 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.',
);
}
_logger.printError(
'Failed to set DevTools server address: $e. Deep links to'
' DevTools will not show in Flutter errors.',
);
}
}
@@ -260,13 +266,11 @@ class FlutterResidentDevtoolsHandler implements ResidentDevtoolsHandler {
},
);
} 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.',
);
}
_logger.printError(e.toString());
_logger.printError(
'Failed to set vm service URI: $e. Deep links to DevTools'
' will not show in Flutter errors.',
);
}
}
@@ -304,10 +308,10 @@ class FlutterResidentDevtoolsHandler implements ResidentDevtoolsHandler {
@override
Future<void> shutdown() async {
_shutdown = true;
if (_devToolsLauncher == null || !_served) {
if (_devToolsLauncher == null || _shutdown || !_served) {
return;
}
_shutdown = true;
_readyToAnnounce = false;
await _devToolsLauncher.close();
}

View File

@@ -4,6 +4,7 @@
import 'dart:async';
import 'package:dds/dds.dart' as dds;
import 'package:meta/meta.dart';
import 'package:package_config/package_config.dart';
import 'package:vm_service/vm_service.dart' as vm_service;
@@ -14,7 +15,6 @@ import 'asset.dart';
import 'base/command_help.dart';
import 'base/common.dart';
import 'base/context.dart';
import 'base/dds.dart';
import 'base/file_system.dart';
import 'base/io.dart' as io;
import 'base/logger.dart';
@@ -252,9 +252,13 @@ class FlutterDevice {
CompileExpression? compileExpression,
GetSkSLMethod? getSkSLMethod,
PrintStructuredErrorLogMethod? printStructuredErrorLogMethod,
required DebuggingOptions debuggingOptions,
int? hostVmServicePort,
int? ddsPort,
bool disableServiceAuthCodes = false,
bool cacheStartupProfile = false,
bool enableDds = true,
required bool allowExistingDdsInstance,
bool ipv6 = false,
}) {
final Completer<void> completer = Completer<void>();
late StreamSubscription<void> subscription;
@@ -266,11 +270,11 @@ class FlutterDevice {
isWaitingForVm = true;
bool existingDds = false;
FlutterVmService? service;
if (debuggingOptions.enableDds) {
if (enableDds) {
void handleError(Exception e, StackTrace st) {
globals.printTrace('Fail to connect to service protocol: $vmServiceUri: $e');
if (!completer.isCompleted) {
completer.completeError('failed to connect to $vmServiceUri $e', st);
completer.completeError('failed to connect to $vmServiceUri', st);
}
}
// First check if the VM service is actually listening on vmServiceUri as
@@ -282,7 +286,7 @@ class FlutterDevice {
} on Exception catch (exception) {
globals.printTrace('Fail to connect to service protocol: $vmServiceUri: $exception');
if (!completer.isCompleted && !_isListeningForVmServiceUri!) {
completer.completeError('failed to connect to $vmServiceUri $exception');
completer.completeError('failed to connect to $vmServiceUri');
}
return;
}
@@ -291,13 +295,17 @@ class FlutterDevice {
// (e.g., failure to bind to a port, failure to connect to the VM service,
// attaching to a VM service with existing clients, etc.).
try {
await device!.dds.startDartDevelopmentServiceFromDebuggingOptions(
await device!.dds.startDartDevelopmentService(
vmServiceUri,
debuggingOptions: debuggingOptions,
hostPort: ddsPort,
ipv6: ipv6,
disableServiceAuthCodes: disableServiceAuthCodes,
logger: globals.logger,
cacheStartupProfile: cacheStartupProfile,
);
} on DartDevelopmentServiceException catch (e, st) {
} on dds.DartDevelopmentServiceException catch (e, st) {
if (!allowExistingDdsInstance ||
(e.errorCode != DartDevelopmentServiceException.existingDdsInstanceError)) {
(e.errorCode != dds.DartDevelopmentServiceException.existingDdsInstanceError)) {
handleError(e, st);
return;
} else {
@@ -318,7 +326,7 @@ class FlutterDevice {
service = await Future.any<dynamic>(
<Future<dynamic>>[
connectToVmService(
debuggingOptions.enableDds ? (device!.dds.uri ?? vmServiceUri!): vmServiceUri!,
enableDds ? (device!.dds.uri ?? vmServiceUri!): vmServiceUri!,
reloadSources: reloadSources,
restart: restart,
compileExpression: compileExpression,
@@ -335,7 +343,7 @@ class FlutterDevice {
} on Exception catch (exception) {
globals.printTrace('Fail to connect to service protocol: $vmServiceUri: $exception');
if (!completer.isCompleted && !_isListeningForVmServiceUri!) {
completer.completeError('failed to connect to $vmServiceUri $exception');
completer.completeError('failed to connect to $vmServiceUri');
}
return;
}
@@ -345,22 +353,6 @@ class FlutterDevice {
globals.printTrace('Successfully connected to service protocol: $vmServiceUri');
vmService = service;
// TODO(bkonyi): uncomment when ready to serve DevTools from DDS.
/*
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.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 device!.getLogReader(app: package)).connectedVMService = vmService;
completer.complete();
await subscription.cancel();
@@ -480,6 +472,7 @@ class FlutterDevice {
platformArgs: platformArgs,
route: route,
prebuiltApplication: prebuiltMode,
ipv6: hotRunner.ipv6!,
userIdentifier: userIdentifier,
);
@@ -545,6 +538,7 @@ class FlutterDevice {
platformArgs: platformArgs,
route: route,
prebuiltApplication: prebuiltMode,
ipv6: coldRunner.ipv6!,
userIdentifier: userIdentifier,
);
@@ -616,13 +610,6 @@ class FlutterDevice {
await generator?.reject();
}
}
// TODO(bkonyi): uncomment when ready to serve DevTools from DDS.
/*
Future<void> handleHotRestart() async {
await device?.dds.handleHotRestart(this);
}
*/
}
/// A subset of the [ResidentRunner] for delegating to attached flutter devices.
@@ -661,7 +648,6 @@ abstract class ResidentHandlers {
/// Whether all of the connected devices support hot reload.
bool get canHotReload;
// TODO(bkonyi): remove when ready to serve DevTools from DDS.
ResidentDevtoolsHandler? get residentDevtoolsHandler;
@protected
@@ -1110,6 +1096,7 @@ abstract class ResidentRunner extends ResidentHandlers {
required this.target,
required this.debuggingOptions,
String? projectRootPath,
this.ipv6,
this.stayResident = true,
this.hotMode = true,
String? dillOutputPath,
@@ -1132,7 +1119,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);
}
@@ -1150,6 +1136,7 @@ abstract class ResidentRunner extends ResidentHandlers {
@override
final bool stayResident;
final bool? ipv6;
final String? _dillOutputPath;
/// The parent location of the incremental artifacts.
final Directory artifactDirectory;
@@ -1161,7 +1148,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;
@@ -1242,6 +1228,7 @@ abstract class ResidentRunner extends ResidentHandlers {
Future<int?> run({
Completer<DebugConnectionInfo>? connectionInfoCompleter,
Completer<void>? appStartedCompleter,
bool enableDevTools = false,
String? route,
});
@@ -1253,6 +1240,7 @@ abstract class ResidentRunner extends ResidentHandlers {
Completer<DebugConnectionInfo>? connectionInfoCompleter,
Completer<void>? appStartedCompleter,
bool allowExistingDdsInstance = false,
bool enableDevTools = false,
bool needsFullRestart = true,
});
@@ -1318,21 +1306,19 @@ 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
shutdownDartDevelopmentService();
await shutdownDartDevelopmentService();
}
@override
Future<void> detach() async {
// TODO(bkonyi): remove when ready to serve DevTools from DDS.
await residentDevtoolsHandler!.shutdown();
await stopEchoingDeviceLog();
await preExit();
shutdownDartDevelopmentService();
await shutdownDartDevelopmentService();
appFinished();
}
@@ -1342,10 +1328,12 @@ abstract class ResidentRunner extends ResidentHandlers {
);
}
void shutdownDartDevelopmentService() {
for (final FlutterDevice device in flutterDevices) {
device.device?.dds.shutdown();
}
Future<void> shutdownDartDevelopmentService() async {
await Future.wait<void>(
flutterDevices.map<Future<void>>(
(FlutterDevice? device) => device?.device?.dds.shutdown() ?? Future<void>.value()
)
);
}
@protected
@@ -1414,14 +1402,18 @@ abstract class ResidentRunner extends ResidentHandlers {
// Listen for service protocol connection to close.
for (final FlutterDevice? device in flutterDevices) {
await device!.connect(
debuggingOptions: debuggingOptions,
reloadSources: reloadSources,
restart: restart,
compileExpression: compileExpression,
enableDds: debuggingOptions.enableDds,
ddsPort: debuggingOptions.ddsPort,
allowExistingDdsInstance: allowExistingDdsInstance,
hostVmServicePort: debuggingOptions.hostVmServicePort,
getSkSLMethod: getSkSLMethod,
printStructuredErrorLogMethod: printStructuredErrorLog,
ipv6: ipv6 ?? false,
disableServiceAuthCodes: debuggingOptions.disableServiceAuthCodes,
cacheStartupProfile: debuggingOptions.cacheStartupProfile,
);
await device.vmService!.getFlutterViews();
@@ -1511,8 +1503,7 @@ abstract class ResidentRunner extends ResidentHandlers {
bool get reportedDebuggers => _reportedDebuggers;
bool _reportedDebuggers = false;
void printDebuggerList({bool includeVmService = true, bool includeDevtools = true}) {
// TODO(bkonyi): update this logic when ready to serve DevTools from DDS.
void printDebuggerList({ bool includeVmService = true, bool includeDevtools = true }) {
final DevToolsServerAddress? devToolsServerAddress = residentDevtoolsHandler!.activeDevToolsServer;
if (!residentDevtoolsHandler!.readyToAnnounce) {
includeDevtools = false;
@@ -1825,13 +1816,6 @@ class TerminalHandler {
case 'v':
case 'V':
return residentRunner.residentDevtoolsHandler!.launchDevToolsInBrowser(flutterDevices: residentRunner.flutterDevices);
// TODO(bkonyi): uncomment and replace above line when ready to serve DevTools from DDS.
/*
return residentRunner.flutterDevices.fold<bool>(
true,
(bool s, FlutterDevice? device) => s && device!.device!.dds.launchDevToolsInBrowser(device),
);
*/
case 'w':
case 'W':
return residentRunner.debugDumpApp();
@@ -1972,7 +1956,6 @@ abstract class DevtoolsLauncher {
@protected
set dtdUri(Uri? value) => _dtdUri = value;
// TODO(bkonyi): remove when ready to serve DevTools from DDS.
/// Whether to print the Dart Tooling Daemon URI.
///
/// This will always return false when there is not a DTD instance being

View File

@@ -21,6 +21,7 @@ class ColdRunner extends ResidentRunner {
this.traceStartup = false,
this.awaitFirstFrameWhenTracing = true,
this.applicationBinary,
bool super.ipv6 = false,
super.stayResident,
super.machine,
super.devtoolsHandler,
@@ -46,6 +47,7 @@ class ColdRunner extends ResidentRunner {
Future<int> run({
Completer<DebugConnectionInfo>? connectionInfoCompleter,
Completer<void>? appStartedCompleter,
bool enableDevTools = false,
String? route,
}) async {
try {
@@ -76,18 +78,18 @@ class ColdRunner extends ResidentRunner {
}
}
if (debuggingEnabled && debuggingOptions.serveObservatory) {
await enableObservatory();
}
// 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 (debuggingEnabled) {
if (enableDevTools) {
// The method below is guaranteed never to return a failing future.
unawaited(residentDevtoolsHandler!.serveAndAnnounceDevTools(
devToolsServerAddress: debuggingOptions.devToolsServerAddress,
flutterDevices: flutterDevices,
isStartPaused: debuggingOptions.startPaused,
));
}
if (debuggingOptions.serveObservatory) {
await enableObservatory();
}
}
if (flutterDevices.first.vmServiceUris != null) {
@@ -140,6 +142,7 @@ class ColdRunner extends ResidentRunner {
Completer<DebugConnectionInfo>? connectionInfoCompleter,
Completer<void>? appStartedCompleter,
bool allowExistingDdsInstance = false,
bool enableDevTools = false,
bool needsFullRestart = true,
}) async {
_didAttach = true;
@@ -163,8 +166,18 @@ class ColdRunner extends ResidentRunner {
}
}
if (debuggingEnabled && debuggingOptions.serveObservatory) {
await enableObservatory();
if (debuggingEnabled) {
if (enableDevTools) {
// The method below is guaranteed never to return a failing future.
unawaited(residentDevtoolsHandler!.serveAndAnnounceDevTools(
devToolsServerAddress: debuggingOptions.devToolsServerAddress,
flutterDevices: flutterDevices,
isStartPaused: debuggingOptions.startPaused,
));
}
if (debuggingOptions.serveObservatory) {
await enableObservatory();
}
}
appStartedCompleter?.complete();
@@ -190,11 +203,12 @@ class ColdRunner extends ResidentRunner {
await flutterDevice!.device!.dispose();
}
await residentDevtoolsHandler!.shutdown();
await stopEchoingDeviceLog();
}
@override
void printHelp({required bool details}) {
void printHelp({ required bool details }) {
globals.printStatus('Flutter run key commands.');
if (details) {
printHelpDetails();

View File

@@ -86,6 +86,7 @@ class HotRunner extends ResidentRunner {
super.projectRootPath,
super.dillOutputPath,
super.stayResident,
bool super.ipv6 = false,
super.machine,
super.devtoolsHandler,
StopwatchFactory stopwatchFactory = const StopwatchFactory(),
@@ -227,6 +228,7 @@ class HotRunner extends ResidentRunner {
Completer<DebugConnectionInfo>? connectionInfoCompleter,
Completer<void>? appStartedCompleter,
bool allowExistingDdsInstance = false,
bool enableDevTools = false,
bool needsFullRestart = true,
}) async {
_didAttach = true;
@@ -251,8 +253,7 @@ class HotRunner extends ResidentRunner {
await enableObservatory();
}
// TODO(bkonyi): remove when ready to serve DevTools from DDS.
if (debuggingOptions.enableDevTools) {
if (enableDevTools) {
// The method below is guaranteed never to return a failing future.
unawaited(residentDevtoolsHandler!.serveAndAnnounceDevTools(
devToolsServerAddress: debuggingOptions.devToolsServerAddress,
@@ -361,6 +362,7 @@ class HotRunner extends ResidentRunner {
Future<int> run({
Completer<DebugConnectionInfo>? connectionInfoCompleter,
Completer<void>? appStartedCompleter,
bool enableDevTools = false,
String? route,
}) async {
await _calculateTargetPlatform();
@@ -468,6 +470,7 @@ class HotRunner extends ResidentRunner {
return attach(
connectionInfoCompleter: connectionInfoCompleter,
appStartedCompleter: appStartedCompleter,
enableDevTools: enableDevTools,
needsFullRestart: false,
);
}
@@ -787,11 +790,7 @@ 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());
// }
return result;
}
final OperationResult result = await _hotReloadHelper(

View File

@@ -489,7 +489,7 @@ abstract class FlutterCommand extends Command<void> {
defaultsTo: true,
help: 'Enable (or disable, with "--no-$kEnableDevTools") the launching of the '
'Flutter DevTools debugger and profiler. '
'If "--no-$kEnableDevTools" is specified, "--$kDevToolsServerAddress" is ignored.'
'If specified, "--$kDevToolsServerAddress" is ignored.'
);
argParser.addOption(
kDevToolsServerAddress,

View File

@@ -414,7 +414,6 @@ class FlutterCommandRunner extends CommandRunner<void> {
throwToolExit('The "--machine" flag is only valid with the "--version" flag or the "analyze --suggestions" command.', exitCode: 2);
}
// TODO(bkonyi): can this be removed and passed solely via DebuggingOptions?
final bool shouldPrintDtdUri = topLevelResults[FlutterGlobalOptions.kPrintDtd] as bool? ?? false;
DevtoolsLauncher.instance!.printDtdUri = shouldPrintDtdUri;

View File

@@ -6,6 +6,7 @@
import 'dart:async';
import 'package:dds/dds.dart';
import 'package:meta/meta.dart';
import 'package:package_config/package_config.dart';
import 'package:stream_channel/stream_channel.dart';
@@ -69,6 +70,7 @@ FlutterPlatform installHook({
Device? integrationTestDevice,
String? integrationTestUserIdentifier,
TestTimeRecorder? testTimeRecorder,
UriConverter? uriConverter,
TestCompilerNativeAssetsBuilder? nativeAssetsBuilder,
BuildInfo? buildInfo,
}) {
@@ -100,6 +102,7 @@ FlutterPlatform installHook({
integrationTestDevice: integrationTestDevice,
integrationTestUserIdentifier: integrationTestUserIdentifier,
testTimeRecorder: testTimeRecorder,
uriConverter: uriConverter,
nativeAssetsBuilder: nativeAssetsBuilder,
buildInfo: buildInfo,
);
@@ -306,6 +309,7 @@ class FlutterPlatform extends PlatformPlugin {
this.integrationTestDevice,
this.integrationTestUserIdentifier,
this.testTimeRecorder,
this.uriConverter,
this.nativeAssetsBuilder,
this.buildInfo,
});
@@ -327,6 +331,9 @@ class FlutterPlatform extends PlatformPlugin {
final TestCompilerNativeAssetsBuilder? nativeAssetsBuilder;
final BuildInfo? buildInfo;
// This can be used by internal projects that require custom logic for converting package: URIs to local paths.
final UriConverter? uriConverter;
/// The device to run the test on for Integration Tests.
///
/// If this is null, the test will run as a regular test with the Flutter
@@ -455,6 +462,7 @@ class FlutterPlatform extends PlatformPlugin {
icudtlPath: icudtlPath,
compileExpression: _compileExpressionService,
fontConfigManager: _fontConfigManager,
uriConverter: uriConverter,
);
}

View File

@@ -5,12 +5,12 @@
import 'dart:async';
import 'dart:io' as io; // flutter_ignore: dart_io_import;
import 'package:dds/dds.dart';
import 'package:meta/meta.dart';
import 'package:process/process.dart';
import 'package:stream_channel/stream_channel.dart';
import 'package:vm_service/vm_service.dart' as vm_service;
import '../base/dds.dart';
import '../base/file_system.dart';
import '../base/io.dart';
import '../base/logger.dart';
@@ -43,6 +43,7 @@ class FlutterTesterTestDevice extends TestDevice {
required this.icudtlPath,
required this.compileExpression,
required this.fontConfigManager,
required this.uriConverter,
}) : assert(!debuggingOptions.startPaused || enableVmService),
_gotProcessVmServiceUri = enableVmService
? Completer<Uri?>() : (Completer<Uri?>()..complete());
@@ -63,8 +64,8 @@ class FlutterTesterTestDevice extends TestDevice {
final String? icudtlPath;
final CompileExpression? compileExpression;
final FontConfigManager fontConfigManager;
final UriConverter? uriConverter;
late final DartDevelopmentService _ddsLauncher = DartDevelopmentService(logger: logger);
final Completer<Uri?> _gotProcessVmServiceUri;
final Completer<int> _exitCode = Completer<int>();
@@ -169,20 +170,16 @@ class FlutterTesterTestDevice extends TestDevice {
debuggingOptions.hostVmServicePort == detectedUri.port);
Uri? forwardingUri;
// TODO(bkonyi): uncomment when ready to serve DevTools from DDS.
// Uri? devToolsUri;
DartDevelopmentService? dds;
if (debuggingOptions.enableDds) {
logger.printTrace('test $id: Starting Dart Development Service');
await _ddsLauncher.startDartDevelopmentServiceFromDebuggingOptions(
dds = await startDds(
detectedUri,
debuggingOptions: debuggingOptions,
uriConverter: uriConverter,
);
forwardingUri = _ddsLauncher.uri;
// TODO(bkonyi): uncomment when ready to serve DevTools from DDS.
// devToolsUri = _ddsLauncher.devToolsUri;
logger.printTrace('test $id: Dart Development Service started at $forwardingUri, forwarding to VM service at $detectedUri.');
forwardingUri = dds.uri;
logger.printTrace('test $id: Dart Development Service started at ${dds.uri}, forwarding to VM service at ${dds.remoteVmServiceUri}.');
} else {
forwardingUri = detectedUri;
}
@@ -204,11 +201,7 @@ class FlutterTesterTestDevice extends TestDevice {
if (debuggingOptions.startPaused && !machine!) {
logger.printStatus('The Dart VM service is listening on $forwardingUri');
await _startDevTools(forwardingUri, _ddsLauncher);
// TODO(bkonyi): uncomment when ready to serve DevTools from DDS.
// if (devToolsUri != null) {
// logger.printStatus('The Flutter DevTools debugger and profiler is available at: $devToolsUri');
// }
await _startDevTools(forwardingUri, dds);
logger.printStatus('');
logger.printStatus('The test process has been started. Set any relevant breakpoints and then resume the test in the debugger.');
}
@@ -255,6 +248,28 @@ class FlutterTesterTestDevice extends TestDevice {
throw TestDeviceException(_getExitCodeMessage(exitCode), StackTrace.current);
}
Uri get _ddsServiceUri {
return Uri(
scheme: 'http',
host: (host!.type == InternetAddressType.IPv6 ?
InternetAddress.loopbackIPv6 :
InternetAddress.loopbackIPv4
).host,
port: debuggingOptions.hostVmServicePort ?? 0,
);
}
@visibleForTesting
@protected
Future<DartDevelopmentService> startDds(Uri uri, {UriConverter? uriConverter}) {
return DartDevelopmentService.startDartDevelopmentService(
uri,
serviceUri: _ddsServiceUri,
enableAuthCodes: !debuggingOptions.disableServiceAuthCodes,
ipv6: host!.type == InternetAddressType.IPv6,
uriConverter: uriConverter,
);
}
@visibleForTesting
@protected
@@ -270,7 +285,6 @@ class FlutterTesterTestDevice extends TestDevice {
);
}
// 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...');
@@ -283,6 +297,10 @@ class FlutterTesterTestDevice extends TestDevice {
await _devToolsLauncher?.ready;
logger.printTrace('test $id: DevTools is being served at ${devToolsServerAddress.uri}');
// Notify the DDS instance that there's a DevTools instance available so it can correctly
// redirect DevTools related requests.
dds?.setExternalDevToolsUri(devToolsServerAddress.uri!);
final Uri devToolsUri = devToolsServerAddress.uri!.replace(
// Use query instead of queryParameters to avoid unnecessary encoding.
query: 'uri=$forwardingUri',

View File

@@ -40,6 +40,7 @@ abstract class FlutterTestRunner {
String? tags,
String? excludeTags,
bool enableVmService = false,
bool ipv6 = false,
bool machine = false,
String? precompiledDillPath,
Map<String, String>? precompiledDillFiles,
@@ -107,6 +108,7 @@ class _FlutterTestRunnerImpl implements FlutterTestRunner {
String? tags,
String? excludeTags,
bool enableVmService = false,
bool ipv6 = false,
bool machine = false,
String? precompiledDillPath,
Map<String, String>? precompiledDillFiles,
@@ -237,7 +239,7 @@ class _FlutterTestRunnerImpl implements FlutterTestRunner {
..addAll(testFiles.map((Uri uri) => uri.toString()));
final InternetAddressType serverType =
debuggingOptions.ipv6 ? InternetAddressType.IPv6 : InternetAddressType.IPv4;
ipv6 ? InternetAddressType.IPv6 : InternetAddressType.IPv4;
final loader.FlutterPlatform platform = loader.installHook(
testWrapper: testWrapper,

View File

@@ -46,7 +46,7 @@ class FlutterTesterDevice extends Device {
FlutterTesterDevice(super.id, {
required ProcessManager processManager,
required FlutterVersion flutterVersion,
required super.logger,
required Logger logger,
required FileSystem fileSystem,
required Artifacts artifacts,
}) : _processManager = processManager,
@@ -135,6 +135,7 @@ class FlutterTesterDevice extends Device {
required DebuggingOptions debuggingOptions,
Map<String, Object?> platformArgs = const <String, Object>{},
bool prebuiltApplication = false,
bool ipv6 = false,
String? userIdentifier,
}) async {
final BuildInfo buildInfo = debuggingOptions.buildInfo;
@@ -192,7 +193,7 @@ class FlutterTesterDevice extends Device {
getLogReader(),
hostPort: debuggingOptions.hostVmServicePort,
devicePort: debuggingOptions.deviceVmServicePort,
ipv6: debuggingOptions.ipv6,
ipv6: ipv6,
logger: _logger,
);
_logReader.initializeProcess(_process!);

View File

@@ -38,7 +38,7 @@ abstract class ChromiumDevice extends Device {
required String name,
required this.chromeLauncher,
required FileSystem fileSystem,
required super.logger,
required Logger logger,
}) : _fileSystem = fileSystem,
_logger = logger,
super(
@@ -124,6 +124,7 @@ abstract class ChromiumDevice extends Device {
required DebuggingOptions debuggingOptions,
Map<String, Object?> platformArgs = const <String, Object?>{},
bool prebuiltApplication = false,
bool ipv6 = false,
String? userIdentifier,
}) async {
// See [ResidentWebRunner.run] in flutter_tools/lib/src/resident_web_runner.dart
@@ -381,7 +382,7 @@ String parseVersionForWindows(String input) {
/// A special device type to allow serving for arbitrary browsers.
class WebServerDevice extends Device {
WebServerDevice({
required super.logger,
required Logger logger,
}) : _logger = logger,
super(
'web-server',
@@ -459,6 +460,7 @@ class WebServerDevice extends Device {
required DebuggingOptions debuggingOptions,
Map<String, Object?> platformArgs = const <String, Object?>{},
bool prebuiltApplication = false,
bool ipv6 = false,
String? userIdentifier,
}) async {
final String? url = platformArgs['uri'] as String?;

View File

@@ -26,6 +26,7 @@ abstract class WebRunnerFactory {
String? target,
required bool stayResident,
required FlutterProject flutterProject,
required bool? ipv6,
required DebuggingOptions debuggingOptions,
UrlTunneller? urlTunneller,
required Logger logger,