Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 11d520d

Browse files
author
Dart CI
committed
Version 2.19.0-338.0.dev
Merge 9629401 into dev
2 parents 1e6d3fe + 9629401 commit 11d520d

File tree

5 files changed

+138
-51
lines changed

5 files changed

+138
-51
lines changed

pkg/dds/lib/src/dap/adapters/dart.dart

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,9 @@ abstract class DartDebugAdapter<TL extends LaunchRequestArguments,
324324
/// yet been made.
325325
vm.VmServiceInterface? vmService;
326326

327+
/// The root of the Dart SDK containing the VM running the debug adapter.
328+
late final String sdkRoot;
329+
327330
/// The DDS instance that was started and that [vmService] is connected to.
328331
///
329332
/// `null` if the session is running in noDebug mode of the connection has not
@@ -446,6 +449,9 @@ abstract class DartDebugAdapter<TL extends LaunchRequestArguments,
446449
}) : super(channel, onError: onError) {
447450
channel.closed.then((_) => shutdown());
448451

452+
final vmPath = Platform.resolvedExecutable;
453+
sdkRoot = path.dirname(path.dirname(vmPath));
454+
449455
_isolateManager = IsolateManager(this);
450456
_converter = ProtocolConverter(this);
451457
}
@@ -1310,6 +1316,56 @@ abstract class DartDebugAdapter<TL extends LaunchRequestArguments,
13101316
);
13111317
}
13121318

1319+
/// The default location for [dartlangSdkRootUri].
1320+
final _defaultDartlangSdkRootUri = Uri.parse('org-dartlang-sdk:///sdk');
1321+
1322+
/// The (org-dartlang-sdk) URI for the root of the Dart SDK.
1323+
///
1324+
/// This can be overriden by debug adapters like Flutter where the Dart SDK
1325+
/// root is at another path (such as
1326+
/// `org-dartlang-sdk:///third_party/dart/sdk/`).
1327+
Uri get dartlangSdkRootUri => _defaultDartlangSdkRootUri;
1328+
1329+
/// Converts a URI in the form org-dartlang-sdk:///sdk/lib/collection/hash_set.dart
1330+
/// to a local file path based on the current SDK.
1331+
String? convertOrgDartlangSdkToPath(Uri uri) {
1332+
// org-dartlang-sdk URIs can be in multiple forms:
1333+
//
1334+
// - org-dartlang-sdk:///sdk/lib/collection/hash_set.dart
1335+
// - org-dartlang-sdk:///runtime/lib/convert_patch.dart
1336+
//
1337+
// We currently only handle the sdk folder, as we don't know which runtime
1338+
// is being used (this code is shared) and do not want to map to the wrong
1339+
// sources.
1340+
if (uri.pathSegments.isNotEmpty &&
1341+
uri.path.startsWith(dartlangSdkRootUri.path)) {
1342+
return path.joinAll([
1343+
sdkRoot,
1344+
...uri.pathSegments.skip(dartlangSdkRootUri.pathSegments.length),
1345+
]);
1346+
}
1347+
1348+
return null;
1349+
}
1350+
1351+
/// Converts a file path inside the current SDK root into a URI in the form
1352+
/// org-dartlang-sdk:///sdk/lib/collection/hash_set.dart.
1353+
Uri? convertPathToOrgDartlangSdk(String input) {
1354+
if (path.isWithin(sdkRoot, input)) {
1355+
final relative = path.relative(input, from: sdkRoot);
1356+
return Uri(
1357+
scheme: dartlangSdkRootUri.scheme,
1358+
host: '',
1359+
pathSegments: [
1360+
...dartlangSdkRootUri.pathSegments,
1361+
...path.split(relative)
1362+
],
1363+
);
1364+
}
1365+
1366+
return null;
1367+
}
1368+
13131369
/// [sourceRequest] is called by the client to request source code for a given
13141370
/// source.
13151371
///

pkg/dds/lib/src/dap/isolate_manager.dart

Lines changed: 5 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,8 @@
44

55
import 'dart:async';
66
import 'dart:convert';
7-
import 'dart:io';
87

98
import 'package:collection/collection.dart';
10-
import 'package:path/path.dart' as path;
119
import 'package:vm_service/vm_service.dart' as vm;
1210

1311
import '../rpc_error_codes.dart';
@@ -67,9 +65,6 @@ class IsolateManager {
6765
/// first time the user resumes.
6866
bool autoResumeStartingIsolates = true;
6967

70-
/// The root of the Dart SDK containing the VM running the debug adapter.
71-
late final String sdkRoot;
72-
7368
/// Tracks breakpoints last provided by the client so they can be sent to new
7469
/// isolates that appear after initial breakpoints were sent.
7570
final Map<String, List<SourceBreakpoint>> _clientBreakpointsByUri = {};
@@ -115,10 +110,7 @@ class IsolateManager {
115110
/// Any leading character matched in place of the dollar is in the first capture.
116111
final _braceNotPrefixedByDollarOrBackslashPattern = RegExp(r'(^|[^\\\$]){');
117112

118-
IsolateManager(this._adapter) {
119-
final vmPath = Platform.resolvedExecutable;
120-
sdkRoot = path.dirname(path.dirname(vmPath));
121-
}
113+
IsolateManager(this._adapter);
122114

123115
/// A list of all current active isolates.
124116
///
@@ -866,7 +858,8 @@ class ThreadInfo {
866858
// URIs directly for SDK sources (we do not need to convert to 'dart:'),
867859
// however this method is Future-returning in case this changes in future
868860
// and we need to include a call to lookupPackageUris here.
869-
return _convertPathToOrgDartlangSdk(filePath) ?? Uri.file(filePath);
861+
return _manager._adapter.convertPathToOrgDartlangSdk(filePath) ??
862+
Uri.file(filePath);
870863
}
871864

872865
/// Batch resolves source URIs from the VM to a file path for the package lib
@@ -982,28 +975,6 @@ class ThreadInfo {
982975
/// that are round-tripped to the client.
983976
int storeData(Object data) => _manager.storeData(this, data);
984977

985-
/// Converts a URI in the form org-dartlang-sdk:///sdk/lib/collection/hash_set.dart
986-
/// to a local file path based on the current SDK.
987-
String? _convertOrgDartlangSdkToPath(Uri uri) {
988-
// org-dartlang-sdk URIs can be in multiple forms:
989-
//
990-
// - org-dartlang-sdk:///sdk/lib/collection/hash_set.dart
991-
// - org-dartlang-sdk:///runtime/lib/convert_patch.dart
992-
//
993-
// We currently only handle the sdk folder, as we don't know which runtime
994-
// is being used (this code is shared) and do not want to map to the wrong
995-
// sources.
996-
if (uri.pathSegments.isNotEmpty && uri.pathSegments.first == 'sdk') {
997-
// TODO(dantup): Do we need to worry about this content not matching
998-
// up with what's local (eg. for Flutter the VM running the app is
999-
// on another device to the VM running this DA).
1000-
final sdkRoot = _manager.sdkRoot;
1001-
return path.joinAll([sdkRoot, ...uri.pathSegments.skip(1)]);
1002-
}
1003-
1004-
return null;
1005-
}
1006-
1007978
Uri? _convertPathToGoogle3Uri(String input) {
1008979
const search = '/google3/';
1009980
if (input.startsWith('/google') && input.contains(search)) {
@@ -1019,22 +990,6 @@ class ThreadInfo {
1019990
return null;
1020991
}
1021992

1022-
/// Converts a file path inside the current SDK root into a URI in the form
1023-
/// org-dartlang-sdk:///sdk/lib/collection/hash_set.dart.
1024-
Uri? _convertPathToOrgDartlangSdk(String input) {
1025-
final sdkRoot = _manager.sdkRoot;
1026-
if (path.isWithin(sdkRoot, input)) {
1027-
final relative = path.relative(input, from: sdkRoot);
1028-
return Uri(
1029-
scheme: 'org-dartlang-sdk',
1030-
host: '',
1031-
pathSegments: ['sdk', ...path.split(relative)],
1032-
);
1033-
}
1034-
1035-
return null;
1036-
}
1037-
1038993
/// Converts a URI to a file path.
1039994
///
1040995
/// Supports file:// URIs and org-dartlang-sdk:// URIs.
@@ -1043,8 +998,8 @@ class ThreadInfo {
1043998
return null;
1044999
} else if (input.isScheme('file')) {
10451000
return input.toFilePath();
1046-
} else if (input.isScheme('org-dartlang-sdk')) {
1047-
return _convertOrgDartlangSdkToPath(input);
1001+
} else if (input.isScheme(_manager._adapter.dartlangSdkRootUri.scheme)) {
1002+
return _manager._adapter.convertOrgDartlangSdkToPath(input);
10481003
} else {
10491004
return null;
10501005
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
// Copyright (c) 2022, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import 'dart:io';
6+
7+
import 'package:path/path.dart' as path;
8+
import 'package:test/test.dart';
9+
10+
import 'mocks.dart';
11+
12+
main() {
13+
group('dart base adapter', () {
14+
final vmPath = Platform.resolvedExecutable;
15+
final sdkRoot = path.dirname(path.dirname(vmPath));
16+
17+
final sdkCorePath = path.join(sdkRoot, 'lib', 'core.dart');
18+
final defaultCoreUri = Uri.parse('org-dartlang-sdk:///sdk/lib/core.dart');
19+
20+
group('default org-dartlang-sdk', () {
21+
final adapter = MockDartCliDebugAdapter();
22+
23+
test('can SDK paths to org-dartlang-sdk:///', () async {
24+
expect(
25+
adapter.convertPathToOrgDartlangSdk(sdkCorePath),
26+
defaultCoreUri,
27+
);
28+
});
29+
30+
test('converts org-dartlang-sdk:/// to SDK paths', () async {
31+
expect(
32+
adapter.convertOrgDartlangSdkToPath(defaultCoreUri),
33+
sdkCorePath,
34+
);
35+
});
36+
});
37+
38+
group('custom org-dartlang-sdk', () {
39+
final adapter = MockDartCliDebugAdapter()
40+
..dartlangSdkRootUriOverride =
41+
Uri.parse('org-dartlang-sdk:///custom/sdk');
42+
final customCoreUri =
43+
Uri.parse('org-dartlang-sdk:///custom/sdk/lib/core.dart');
44+
45+
test('converts SDK paths to custom org-dartlang-sdk:///', () async {
46+
expect(
47+
adapter.convertPathToOrgDartlangSdk(sdkCorePath),
48+
customCoreUri,
49+
);
50+
});
51+
52+
test('converts custom org-dartlang-sdk:/// to SDK paths', () async {
53+
expect(
54+
adapter.convertOrgDartlangSdkToPath(customCoreUri),
55+
sdkCorePath,
56+
);
57+
});
58+
59+
test('does not convert default org-dartlang-sdk:///', () async {
60+
expect(
61+
adapter.convertOrgDartlangSdkToPath(defaultCoreUri),
62+
isNull,
63+
);
64+
});
65+
});
66+
});
67+
}

pkg/dds/test/dap/mocks.dart

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,15 @@ class MockDartCliDebugAdapter extends DartCliDebugAdapter {
3030
stdinController.sink, stdoutController.stream, channel);
3131
}
3232

33+
/// An override for [dartlangSdkRootUri].
34+
///
35+
/// If not set, the default base value will be used.
36+
Uri? dartlangSdkRootUriOverride;
37+
38+
@override
39+
Uri get dartlangSdkRootUri =>
40+
dartlangSdkRootUriOverride ?? super.dartlangSdkRootUri;
41+
3342
MockDartCliDebugAdapter._(
3443
this.stdin, this.stdout, ByteStreamServerChannel channel)
3544
: super(channel);

tools/VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,5 @@ CHANNEL dev
2727
MAJOR 2
2828
MINOR 19
2929
PATCH 0
30-
PRERELEASE 337
30+
PRERELEASE 338
3131
PRERELEASE_PATCH 0

0 commit comments

Comments
 (0)