Launch DDS using DartDevelopmentServiceLauncher (#154015)

`DartDevelopmentServiceLauncher` was created to share the DDS launch
logic from flutter_tools with other Dart tooling.

---------

Co-authored-by: Andrew Kolos <andrewrkolos@gmail.com>
This commit is contained in:
Ben Konyi
2024-08-29 16:16:27 -04:00
committed by GitHub
parent 055350f84a
commit 04595bc088
5 changed files with 104 additions and 245 deletions

View File

@@ -23,6 +23,7 @@ import 'package:test/fake.dart';
import '../src/context.dart';
import '../src/fake_process_manager.dart';
import '../src/fake_vm_services.dart';
import '../src/fakes.dart';
void main() {
late FakePlatform platform;
@@ -267,16 +268,18 @@ void main() {
]);
device = createDevice(enableVmService: true);
originalDdsLauncher = ddsLauncherCallback;
ddsLauncherCallback = (Uri remoteVmServiceUri, {
required bool enableAuthCodes,
required bool ipv6,
required bool enableDevTools,
required List<String> cachedUserTags,
ddsLauncherCallback = ({
required Uri remoteVmServiceUri,
Uri? serviceUri,
String? google3WorkspaceRoot,
bool enableAuthCodes = true,
bool serveDevTools = false,
Uri? devToolsServerAddress,
bool enableServicePortFallback = false,
List<String> cachedUserTags = const <String>[],
String? dartExecutable,
Uri? google3WorkspaceRoot,
}) async {
return (process: null, serviceUri: Uri.parse('http://localhost:1234'), devToolsUri: null, dtdUri: null);
return FakeDartDevelopmentServiceLauncher(uri: Uri.parse('http://localhost:1234'));
};
});

View File

@@ -138,13 +138,6 @@ const FakeVmServiceRequest evictShader = FakeVmServiceRequest(
}
);
const DartDevelopmentServiceInstance fakeDartDevelopmentServiceInstance = (
process: null,
serviceUri: null,
devToolsUri: null,
dtdUri: null,
);
final Uri testUri = Uri.parse('foo://bar');
class FakeDartDevelopmentService extends Fake with DartDevelopmentServiceLocalOperationsMixin implements DartDevelopmentService {
@@ -164,6 +157,11 @@ class FakeDartDevelopmentServiceException implements DartDevelopmentServiceExcep
@override
final String message;
static const String defaultMessage = 'A DDS instance is already connected at http://localhost:8181';
@override
Map<String, Object?> toJson() {
throw UnimplementedError();
}
}
class TestFlutterDevice extends FlutterDevice {

View File

@@ -1938,14 +1938,17 @@ flutter:
fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[]);
final FakeDevice device = FakeDevice()
..dds = DartDevelopmentService(logger: testLogger);
ddsLauncherCallback = (Uri uri,
{bool enableDevTools = false,
bool enableAuthCodes = true,
bool ipv6 = false, Uri? serviceUri,
List<String> cachedUserTags = const <String>[],
String? google3WorkspaceRoot,
Uri? devToolsServerAddress,
}) {
ddsLauncherCallback = ({
required Uri remoteVmServiceUri,
Uri? serviceUri,
bool enableAuthCodes = true,
bool serveDevTools = false,
Uri? devToolsServerAddress,
bool enableServicePortFallback = false,
List<String> cachedUserTags = const <String>[],
String? dartExecutable,
Uri? google3WorkspaceRoot,
}) {
throw DartDevelopmentServiceException.existingDdsInstance(
'Existing DDS at http://localhost/existingDdsInMessage.',
ddsUri: Uri.parse('http://localhost/existingDdsInField'),
@@ -1984,21 +1987,23 @@ flutter:
final FakeDevice device = FakeDevice()
..dds = DartDevelopmentService(logger: testLogger);
final Completer<void>done = Completer<void>();
ddsLauncherCallback = (Uri uri,
{bool enableDevTools = false,
bool enableAuthCodes = true,
bool ipv6 = false, Uri? serviceUri,
List<String> cachedUserTags = const <String>[],
String? google3WorkspaceRoot,
Uri? devToolsServerAddress,
}) async {
expect(uri, Uri(scheme: 'foo', host: 'bar'));
ddsLauncherCallback = ({
required Uri remoteVmServiceUri,
Uri? serviceUri,
bool enableAuthCodes = true,
bool serveDevTools = false,
Uri? devToolsServerAddress,
bool enableServicePortFallback = false,
List<String> cachedUserTags = const <String>[],
String? dartExecutable,
Uri? google3WorkspaceRoot,
}) async {
expect(remoteVmServiceUri, Uri(scheme: 'foo', host: 'bar'));
expect(enableAuthCodes, isFalse);
expect(ipv6, isTrue);
expect(serviceUri, Uri(scheme: 'http', host: '::1', port: 0));
expect(cachedUserTags, isEmpty);
done.complete();
return fakeDartDevelopmentServiceInstance;
return FakeDartDevelopmentServiceLauncher(uri: remoteVmServiceUri);
};
final TestFlutterDevice flutterDevice = TestFlutterDevice(
device,
@@ -2029,19 +2034,19 @@ flutter:
// See https://github.com/flutter/flutter/issues/72385 for context.
final FakeDevice device = FakeDevice()
..dds = DartDevelopmentService(logger: testLogger);
ddsLauncherCallback = (
Uri uri, {
bool enableDevTools = false,
bool enableAuthCodes = false,
bool ipv6 = false,
Uri? serviceUri,
List<String> cachedUserTags = const <String>[],
String? google3WorkspaceRoot,
Uri? devToolsServerAddress,
}) {
expect(uri, Uri(scheme: 'foo', host: 'bar'));
ddsLauncherCallback = ({
required Uri remoteVmServiceUri,
Uri? serviceUri,
bool enableAuthCodes = true,
bool serveDevTools = false,
Uri? devToolsServerAddress,
bool enableServicePortFallback = false,
List<String> cachedUserTags = const <String>[],
String? dartExecutable,
Uri? google3WorkspaceRoot,
}) {
expect(remoteVmServiceUri, Uri(scheme: 'foo', host: 'bar'));
expect(enableAuthCodes, isTrue);
expect(ipv6, isFalse);
expect(serviceUri, Uri(scheme: 'http', host: '127.0.0.1', port: 0));
expect(cachedUserTags, isEmpty);
throw FakeDartDevelopmentServiceException(message: 'No URI');

View File

@@ -5,6 +5,7 @@
import 'dart:async';
import 'dart:io' as io show IOSink, ProcessSignal, Stdout, StdoutException;
import 'package:dds/dds_launcher.dart';
import 'package:flutter_tools/src/android/android_sdk.dart';
import 'package:flutter_tools/src/android/android_studio.dart';
import 'package:flutter_tools/src/android/java.dart';
@@ -696,6 +697,32 @@ class FakeJava extends Fake implements Java {
}
}
class FakeDartDevelopmentServiceLauncher extends Fake
implements DartDevelopmentServiceLauncher {
FakeDartDevelopmentServiceLauncher({
required this.uri,
this.devToolsUri,
this.dtdUri,
});
@override
final Uri uri;
@override
final Uri? devToolsUri;
@override
final Uri? dtdUri;
@override
Future<void> get done => _completer.future;
@override
Future<void> shutdown() async => _completer.complete();
final Completer<void> _completer = Completer<void>();
}
class FakeDevtoolsLauncher extends Fake implements DevtoolsLauncher {
FakeDevtoolsLauncher({DevToolsServerAddress? serverAddress})
: _serverAddress = serverAddress;