Skip to content

Commit a527411

Browse files
bkonyicommit-bot@chromium.org
authored andcommitted
[ package:dds ] Add null safety support
Fixes #45756 TEST=service + DDS tests Change-Id: I6dd14d7f9fdee479a830c3b053dc3b00aa635202 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/199800 Commit-Queue: Ben Konyi <[email protected]> Reviewed-by: Devon Carew <[email protected]>
1 parent 15187a6 commit a527411

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+298
-348
lines changed

.dart_tool/package_config.json

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"constraint, update this by running tools/generate_package_config.dart."
1212
],
1313
"configVersion": 2,
14-
"generated": "2021-05-11T11:47:02.674706",
14+
"generated": "2021-05-13T13:57:59.578937",
1515
"generator": "tools/generate_package_config.dart",
1616
"packages": [
1717
{
@@ -252,17 +252,11 @@
252252
"packageUri": "lib/",
253253
"languageVersion": "2.3"
254254
},
255-
{
256-
"name": "devtools_server",
257-
"rootUri": "../third_party/devtools/devtools_server",
258-
"packageUri": "lib/",
259-
"languageVersion": "2.6"
260-
},
261255
{
262256
"name": "devtools_shared",
263257
"rootUri": "../third_party/devtools/devtools_shared",
264258
"packageUri": "lib/",
265-
"languageVersion": "2.3"
259+
"languageVersion": "2.12"
266260
},
267261
{
268262
"name": "diagnostic",

DEPS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ vars = {
107107

108108
"chromedriver_tag": "83.0.4103.39",
109109
"dartdoc_rev" : "e6a9b7c536a85e49233c97bb892bbb0ab778e425",
110-
"devtools_rev" : "12ad5341ae0a275042c84a4e7be9a6c98db65612",
110+
"devtools_rev" : "e138d55437a59838607415ef21f20bd6c4955dbc",
111111
"jsshell_tag": "version:88.0",
112112
"ffi_rev": "f3346299c55669cc0db48afae85b8110088bf8da",
113113
"fixnum_rev": "16d3890c6dc82ca629659da1934e412292508bba",

pkg/dds/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# 2.0.0
2+
- **Breaking change:** add null safety support.
3+
- **Breaking change:** minimum Dart SDK revision bumped to 2.12.0.
4+
15
# 1.8.0
26
- Add support for launching DevTools from DDS.
37
- Fixed issue where two clients subscribing to the same stream in close succession

pkg/dds/bin/dds.dart

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
// @dart=2.10
6-
75
import 'dart:convert';
86
import 'dart:io';
97

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

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

4543
final startDevTools = args[4] == 'true';
46-
Uri devToolsBuildDirectory;
44+
Uri? devToolsBuildDirectory;
4745
if (args[5].isNotEmpty) {
4846
devToolsBuildDirectory = Uri.file(args[5]);
4947
}
@@ -55,7 +53,7 @@ Future<void> main(List<String> args) async {
5553
remoteVmServiceUri,
5654
serviceUri: serviceUri,
5755
enableAuthCodes: !disableServiceAuthCodes,
58-
devToolsConfiguration: startDevTools
56+
devToolsConfiguration: startDevTools && devToolsBuildDirectory != null
5957
? DevToolsConfiguration(
6058
enable: startDevTools,
6159
customBuildDirectoryPath: devToolsBuildDirectory,

pkg/dds/example/example.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
// @dart=2.10
6-
75
import 'package:dds/dds.dart';
86
import 'package:vm_service/vm_service_io.dart';
97

pkg/dds/lib/dds.dart

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
// @dart=2.10
6-
75
/// A library used to spawn the Dart Developer Service, used to communicate
86
/// with a Dart VM Service instance.
97
library dds;
@@ -41,15 +39,12 @@ abstract class DartDevelopmentService {
4139
/// default.
4240
static Future<DartDevelopmentService> startDartDevelopmentService(
4341
Uri remoteVmServiceUri, {
44-
Uri serviceUri,
42+
Uri? serviceUri,
4543
bool enableAuthCodes = true,
4644
bool ipv6 = false,
47-
DevToolsConfiguration devToolsConfiguration = const DevToolsConfiguration(),
45+
DevToolsConfiguration? devToolsConfiguration,
4846
bool logRequests = false,
4947
}) async {
50-
if (remoteVmServiceUri == null) {
51-
throw ArgumentError.notNull('remoteVmServiceUri');
52-
}
5348
if (remoteVmServiceUri.scheme != 'http') {
5449
throw ArgumentError(
5550
'remoteVmServiceUri must have an HTTP scheme. Actual: ${remoteVmServiceUri.scheme}',
@@ -65,12 +60,15 @@ abstract class DartDevelopmentService {
6560
// If provided an address to bind to, ensure it uses a protocol consistent
6661
// with that used to spawn DDS.
6762
final addresses = await InternetAddress.lookup(serviceUri.host);
68-
final address = addresses.firstWhere(
69-
(a) => (a.type ==
70-
(ipv6 ? InternetAddressType.IPv6 : InternetAddressType.IPv4)),
71-
orElse: () => null,
72-
);
73-
if (address == null) {
63+
64+
try {
65+
// Check to see if there's a valid address.
66+
addresses.firstWhere(
67+
(a) => (a.type ==
68+
(ipv6 ? InternetAddressType.IPv6 : InternetAddressType.IPv4)),
69+
);
70+
} on StateError {
71+
// Could not find a valid address.
7472
throw ArgumentError(
7573
"serviceUri '$serviceUri' is not an IPv${ipv6 ? "6" : "4"} address.",
7674
);
@@ -115,24 +113,24 @@ abstract class DartDevelopmentService {
115113
/// [DartDevelopmentService] via HTTP.
116114
///
117115
/// Returns `null` if the service is not running.
118-
Uri get uri;
116+
Uri? get uri;
119117

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

126124
/// The [Uri] VM service clients can use to communicate with this
127125
/// [DartDevelopmentService] via a [WebSocket].
128126
///
129127
/// Returns `null` if the service is not running.
130-
Uri get wsUri;
128+
Uri? get wsUri;
131129

132130
/// The HTTP [Uri] of the hosted DevTools instance.
133131
///
134132
/// Returns `null` if DevTools is not running.
135-
Uri get devToolsUri;
133+
Uri? get devToolsUri;
136134

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

181179
class DevToolsConfiguration {
182180
const DevToolsConfiguration({
181+
required this.customBuildDirectoryPath,
183182
this.enable = false,
184-
this.customBuildDirectoryPath,
185183
});
186184

187185
final bool enable;

pkg/dds/lib/src/binary_compatible_peer.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
// @dart=2.10
6-
75
import 'dart:async';
86
import 'dart:convert';
97
import 'dart:typed_data';

pkg/dds/lib/src/client.dart

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
// @dart=2.10
6-
75
import 'dart:async';
86

97
import 'package:json_rpc_2/json_rpc_2.dart' as json_rpc;
@@ -26,7 +24,7 @@ class DartDevelopmentServiceClient {
2624
WebSocketChannel ws,
2725
json_rpc.Peer vmServicePeer,
2826
) : this._(
29-
dds,
27+
dds as DartDevelopmentServiceImpl,
3028
ws,
3129
vmServicePeer,
3230
);
@@ -36,7 +34,7 @@ class DartDevelopmentServiceClient {
3634
SseConnection sse,
3735
json_rpc.Peer vmServicePeer,
3836
) : this._(
39-
dds,
37+
dds as DartDevelopmentServiceImpl,
4038
sse,
4139
vmServicePeer,
4240
);
@@ -167,7 +165,8 @@ class DartDevelopmentServiceClient {
167165
(parameters) => {
168166
'type': 'Size',
169167
'size': StreamManager
170-
.loggingRepositories[StreamManager.kLoggingStream].bufferSize,
168+
.loggingRepositories[StreamManager.kLoggingStream]!
169+
.bufferSize,
171170
});
172171

173172
_clientPeer.registerMethod('setLogHistorySize', (parameters) {
@@ -177,7 +176,7 @@ class DartDevelopmentServiceClient {
177176
"'size' must be greater or equal to zero",
178177
);
179178
}
180-
StreamManager.loggingRepositories[StreamManager.kLoggingStream]
179+
StreamManager.loggingRepositories[StreamManager.kLoggingStream]!
181180
.resize(size);
182181
return RPCResponses.success;
183182
});
@@ -193,8 +192,8 @@ class DartDevelopmentServiceClient {
193192
});
194193

195194
_clientPeer.registerMethod('getSupportedProtocols', (parameters) async {
196-
final Map<String, dynamic> supportedProtocols =
197-
await _vmServicePeer.sendRequest('getSupportedProtocols');
195+
final Map<String, dynamic> supportedProtocols = (await _vmServicePeer
196+
.sendRequest('getSupportedProtocols')) as Map<String, dynamic>;
198197
final ddsVersion = DartDevelopmentService.protocolVersion.split('.');
199198
final ddsProtocol = {
200199
'protocolName': 'DDS',
@@ -289,17 +288,17 @@ class DartDevelopmentServiceClient {
289288
String get defaultClientName => 'client$_id';
290289

291290
/// The current name associated with this client.
292-
String get name => _name;
291+
String? get name => _name;
293292

294293
// NOTE: this should not be called directly except from:
295294
// - `ClientManager._clearClientName`
296295
// - `ClientManager._setClientNameHelper`
297-
set name(String n) => _name = n ?? defaultClientName;
298-
String _name;
296+
set name(String? n) => _name = n ?? defaultClientName;
297+
String? _name;
299298

300299
final DartDevelopmentServiceImpl dds;
301300
final StreamChannel connection;
302301
final Map<String, String> services = {};
303302
final json_rpc.Peer _vmServicePeer;
304-
json_rpc.Peer _clientPeer;
303+
late json_rpc.Peer _clientPeer;
305304
}

pkg/dds/lib/src/client_manager.dart

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
// @dart=2.10
6-
75
import 'package:json_rpc_2/json_rpc_2.dart' as json_rpc;
86

97
import 'client.dart';
@@ -98,7 +96,7 @@ class ClientManager {
9896
pauseTypeMask |= PauseTypeMasks.pauseOnExitMask;
9997
}
10098

101-
clientResumePermissions[client.name].permissionsMask = pauseTypeMask;
99+
clientResumePermissions[client.name!]!.permissionsMask = pauseTypeMask;
102100
return RPCResponses.success;
103101
}
104102

@@ -111,10 +109,10 @@ class ClientManager {
111109
_clearClientName(client);
112110
client.name = name.isEmpty ? client.defaultClientName : name;
113111
clientResumePermissions.putIfAbsent(
114-
client.name,
112+
client.name!,
115113
() => _ClientResumePermissions(),
116114
);
117-
clientResumePermissions[client.name].clients.add(client);
115+
clientResumePermissions[client.name!]!.clients.add(client);
118116
}
119117

120118
/// Resets the client's name while also cleaning up resume permissions and
@@ -155,7 +153,7 @@ class ClientManager {
155153
}
156154
}
157155

158-
DartDevelopmentServiceClient findFirstClientThatHandlesService(
156+
DartDevelopmentServiceClient? findFirstClientThatHandlesService(
159157
String service) {
160158
for (final client in clients) {
161159
if (client.services.containsKey(service)) {
@@ -173,7 +171,7 @@ class ClientManager {
173171

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

178176
final DartDevelopmentServiceImpl dds;
179177
}

pkg/dds/lib/src/constants.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
// @dart=2.10
6-
75
abstract class RPCResponses {
86
static const success = <String, dynamic>{
97
'type': 'Success',

0 commit comments

Comments
 (0)