Skip to content

Commit

Permalink
Reland "[ package:dds ] Add null safety support"
Browse files Browse the repository at this point in the history
This reverts commit b8c5ecd.

TEST=N/A

Change-Id: I38bbebe1e38bc9dbfdde764eff847aafb3e39353
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/200926
Reviewed-by: Siva Annamalai <asiva@google.com>
  • Loading branch information
bkonyi committed May 24, 2021
1 parent 3db3b93 commit 7250fd6
Show file tree
Hide file tree
Showing 43 changed files with 298 additions and 348 deletions.
10 changes: 2 additions & 8 deletions .dart_tool/package_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"constraint, update this by running tools/generate_package_config.dart."
],
"configVersion": 2,
"generated": "2021-05-21T16:08:02.444059",
"generated": "2021-05-24T09:58:37.618570",
"generator": "tools/generate_package_config.dart",
"packages": [
{
Expand Down Expand Up @@ -252,17 +252,11 @@
"packageUri": "lib/",
"languageVersion": "2.3"
},
{
"name": "devtools_server",
"rootUri": "../third_party/devtools/devtools_server",
"packageUri": "lib/",
"languageVersion": "2.6"
},
{
"name": "devtools_shared",
"rootUri": "../third_party/devtools/devtools_shared",
"packageUri": "lib/",
"languageVersion": "2.3"
"languageVersion": "2.12"
},
{
"name": "diagnostic",
Expand Down
2 changes: 1 addition & 1 deletion DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ vars = {

"chromedriver_tag": "83.0.4103.39",
"dartdoc_rev" : "e6a9b7c536a85e49233c97bb892bbb0ab778e425",
"devtools_rev" : "12ad5341ae0a275042c84a4e7be9a6c98db65612",
"devtools_rev" : "e138d55437a59838607415ef21f20bd6c4955dbc",
"jsshell_tag": "version:88.0",
"ffi_rev": "f3346299c55669cc0db48afae85b8110088bf8da",
"fixnum_rev": "16d3890c6dc82ca629659da1934e412292508bba",
Expand Down
4 changes: 4 additions & 0 deletions pkg/dds/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 2.0.0
- **Breaking change:** add null safety support.
- **Breaking change:** minimum Dart SDK revision bumped to 2.12.0.

# 1.8.0
- Add support for launching DevTools from DDS.
- Fixed issue where two clients subscribing to the same stream in close succession
Expand Down
8 changes: 3 additions & 5 deletions pkg/dds/bin/dds.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

// @dart=2.10

import 'dart:convert';
import 'dart:io';

Expand All @@ -28,7 +26,7 @@ Future<void> main(List<String> args) async {
final remoteVmServiceUri = Uri.parse(args.first);

// Resolve the address which is potentially provided by the user.
InternetAddress address;
late InternetAddress address;
final addresses = await InternetAddress.lookup(args[1]);
// Prefer IPv4 addresses.
for (int i = 0; i < addresses.length; i++) {
Expand All @@ -43,7 +41,7 @@ Future<void> main(List<String> args) async {
final disableServiceAuthCodes = args[3] == 'true';

final startDevTools = args[4] == 'true';
Uri devToolsBuildDirectory;
Uri? devToolsBuildDirectory;
if (args[5].isNotEmpty) {
devToolsBuildDirectory = Uri.file(args[5]);
}
Expand All @@ -55,7 +53,7 @@ Future<void> main(List<String> args) async {
remoteVmServiceUri,
serviceUri: serviceUri,
enableAuthCodes: !disableServiceAuthCodes,
devToolsConfiguration: startDevTools
devToolsConfiguration: startDevTools && devToolsBuildDirectory != null
? DevToolsConfiguration(
enable: startDevTools,
customBuildDirectoryPath: devToolsBuildDirectory,
Expand Down
2 changes: 0 additions & 2 deletions pkg/dds/example/example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

// @dart=2.10

import 'package:dds/dds.dart';
import 'package:vm_service/vm_service_io.dart';

Expand Down
34 changes: 16 additions & 18 deletions pkg/dds/lib/dds.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

// @dart=2.10

/// A library used to spawn the Dart Developer Service, used to communicate
/// with a Dart VM Service instance.
library dds;
Expand Down Expand Up @@ -41,15 +39,12 @@ abstract class DartDevelopmentService {
/// default.
static Future<DartDevelopmentService> startDartDevelopmentService(
Uri remoteVmServiceUri, {
Uri serviceUri,
Uri? serviceUri,
bool enableAuthCodes = true,
bool ipv6 = false,
DevToolsConfiguration devToolsConfiguration = const DevToolsConfiguration(),
DevToolsConfiguration? devToolsConfiguration,
bool logRequests = false,
}) async {
if (remoteVmServiceUri == null) {
throw ArgumentError.notNull('remoteVmServiceUri');
}
if (remoteVmServiceUri.scheme != 'http') {
throw ArgumentError(
'remoteVmServiceUri must have an HTTP scheme. Actual: ${remoteVmServiceUri.scheme}',
Expand All @@ -65,12 +60,15 @@ abstract class DartDevelopmentService {
// If provided an address to bind to, ensure it uses a protocol consistent
// with that used to spawn DDS.
final addresses = await InternetAddress.lookup(serviceUri.host);
final address = addresses.firstWhere(
(a) => (a.type ==
(ipv6 ? InternetAddressType.IPv6 : InternetAddressType.IPv4)),
orElse: () => null,
);
if (address == null) {

try {
// Check to see if there's a valid address.
addresses.firstWhere(
(a) => (a.type ==
(ipv6 ? InternetAddressType.IPv6 : InternetAddressType.IPv4)),
);
} on StateError {
// Could not find a valid address.
throw ArgumentError(
"serviceUri '$serviceUri' is not an IPv${ipv6 ? "6" : "4"} address.",
);
Expand Down Expand Up @@ -115,24 +113,24 @@ abstract class DartDevelopmentService {
/// [DartDevelopmentService] via HTTP.
///
/// Returns `null` if the service is not running.
Uri get uri;
Uri? get uri;

/// The [Uri] VM service clients can use to communicate with this
/// [DartDevelopmentService] via server-sent events (SSE).
///
/// Returns `null` if the service is not running.
Uri get sseUri;
Uri? get sseUri;

/// The [Uri] VM service clients can use to communicate with this
/// [DartDevelopmentService] via a [WebSocket].
///
/// Returns `null` if the service is not running.
Uri get wsUri;
Uri? get wsUri;

/// The HTTP [Uri] of the hosted DevTools instance.
///
/// Returns `null` if DevTools is not running.
Uri get devToolsUri;
Uri? get devToolsUri;

/// Set to `true` if this instance of [DartDevelopmentService] is accepting
/// requests.
Expand Down Expand Up @@ -180,8 +178,8 @@ class DartDevelopmentServiceException implements Exception {

class DevToolsConfiguration {
const DevToolsConfiguration({
required this.customBuildDirectoryPath,
this.enable = false,
this.customBuildDirectoryPath,
});

final bool enable;
Expand Down
2 changes: 0 additions & 2 deletions pkg/dds/lib/src/binary_compatible_peer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

// @dart=2.10

import 'dart:async';
import 'dart:convert';
import 'dart:typed_data';
Expand Down
23 changes: 11 additions & 12 deletions pkg/dds/lib/src/client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

// @dart=2.10

import 'dart:async';

import 'package:json_rpc_2/json_rpc_2.dart' as json_rpc;
Expand All @@ -26,7 +24,7 @@ class DartDevelopmentServiceClient {
WebSocketChannel ws,
json_rpc.Peer vmServicePeer,
) : this._(
dds,
dds as DartDevelopmentServiceImpl,
ws,
vmServicePeer,
);
Expand All @@ -36,7 +34,7 @@ class DartDevelopmentServiceClient {
SseConnection sse,
json_rpc.Peer vmServicePeer,
) : this._(
dds,
dds as DartDevelopmentServiceImpl,
sse,
vmServicePeer,
);
Expand Down Expand Up @@ -167,7 +165,8 @@ class DartDevelopmentServiceClient {
(parameters) => {
'type': 'Size',
'size': StreamManager
.loggingRepositories[StreamManager.kLoggingStream].bufferSize,
.loggingRepositories[StreamManager.kLoggingStream]!
.bufferSize,
});

_clientPeer.registerMethod('setLogHistorySize', (parameters) {
Expand All @@ -177,7 +176,7 @@ class DartDevelopmentServiceClient {
"'size' must be greater or equal to zero",
);
}
StreamManager.loggingRepositories[StreamManager.kLoggingStream]
StreamManager.loggingRepositories[StreamManager.kLoggingStream]!
.resize(size);
return RPCResponses.success;
});
Expand All @@ -193,8 +192,8 @@ class DartDevelopmentServiceClient {
});

_clientPeer.registerMethod('getSupportedProtocols', (parameters) async {
final Map<String, dynamic> supportedProtocols =
await _vmServicePeer.sendRequest('getSupportedProtocols');
final Map<String, dynamic> supportedProtocols = (await _vmServicePeer
.sendRequest('getSupportedProtocols')) as Map<String, dynamic>;
final ddsVersion = DartDevelopmentService.protocolVersion.split('.');
final ddsProtocol = {
'protocolName': 'DDS',
Expand Down Expand Up @@ -289,17 +288,17 @@ class DartDevelopmentServiceClient {
String get defaultClientName => 'client$_id';

/// The current name associated with this client.
String get name => _name;
String? get name => _name;

// NOTE: this should not be called directly except from:
// - `ClientManager._clearClientName`
// - `ClientManager._setClientNameHelper`
set name(String n) => _name = n ?? defaultClientName;
String _name;
set name(String? n) => _name = n ?? defaultClientName;
String? _name;

final DartDevelopmentServiceImpl dds;
final StreamChannel connection;
final Map<String, String> services = {};
final json_rpc.Peer _vmServicePeer;
json_rpc.Peer _clientPeer;
late json_rpc.Peer _clientPeer;
}
12 changes: 5 additions & 7 deletions pkg/dds/lib/src/client_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

// @dart=2.10

import 'package:json_rpc_2/json_rpc_2.dart' as json_rpc;

import 'client.dart';
Expand Down Expand Up @@ -98,7 +96,7 @@ class ClientManager {
pauseTypeMask |= PauseTypeMasks.pauseOnExitMask;
}

clientResumePermissions[client.name].permissionsMask = pauseTypeMask;
clientResumePermissions[client.name!]!.permissionsMask = pauseTypeMask;
return RPCResponses.success;
}

Expand All @@ -111,10 +109,10 @@ class ClientManager {
_clearClientName(client);
client.name = name.isEmpty ? client.defaultClientName : name;
clientResumePermissions.putIfAbsent(
client.name,
client.name!,
() => _ClientResumePermissions(),
);
clientResumePermissions[client.name].clients.add(client);
clientResumePermissions[client.name!]!.clients.add(client);
}

/// Resets the client's name while also cleaning up resume permissions and
Expand Down Expand Up @@ -155,7 +153,7 @@ class ClientManager {
}
}

DartDevelopmentServiceClient findFirstClientThatHandlesService(
DartDevelopmentServiceClient? findFirstClientThatHandlesService(
String service) {
for (final client in clients) {
if (client.services.containsKey(service)) {
Expand All @@ -173,7 +171,7 @@ class ClientManager {

/// Mapping of client names to all clients of that name and their resume
/// permissions.
final Map<String, _ClientResumePermissions> clientResumePermissions = {};
final Map<String?, _ClientResumePermissions> clientResumePermissions = {};

final DartDevelopmentServiceImpl dds;
}
2 changes: 0 additions & 2 deletions pkg/dds/lib/src/constants.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

// @dart=2.10

abstract class RPCResponses {
static const success = <String, dynamic>{
'type': 'Success',
Expand Down
Loading

0 comments on commit 7250fd6

Please sign in to comment.