Skip to content

Commit

Permalink
Implement lookupResolvedPackageUris and lookupPackageUris (#1458)
Browse files Browse the repository at this point in the history
* Implement lookupResolvedPackageUris and lookupPackageUris

- implement the new API from vm service 7.4.0
- add tests
- does not suport dart: scheme uris yet:
  #1457

Closes: #1446

* Mentiion new issue in TODO

* Added examples of path conversion

* fix comments

* Support resolving SDK uris, add tests

* Addressed CR comments

* Build

* Revert some merge breaks and formatting changes, address more CR comments

* Revert accidental formatting changes, fix converting uri to file path on Windows
  • Loading branch information
Anna Gringauze authored Dec 10, 2021
1 parent cdb7fb4 commit 6e3200e
Show file tree
Hide file tree
Showing 10 changed files with 362 additions and 115 deletions.
10 changes: 9 additions & 1 deletion dwds/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
## 11.5.2-dev
## 12.0.0-dev

- Implement `lookupResolvedPackageUris` and `lookupPackageUris` vm service API.
- Update `vm_service` version to `^7.5.0`.
- Make `ExpressionCompilerService` infer location of `libraries.json` from
`sdkDir` parameter.
- Show an alert in the Dart Debug Extension for a multi-app scenario.

**Breaking changes:**

- Add `sdkDir` argument to `Dwds.start` to help file resolution for sdk uris.

## 11.5.1

- Update SDK contraint to `>=2.15.0 <3.0.0`.
Expand Down
4 changes: 4 additions & 0 deletions dwds/lib/dwds.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import 'src/readers/asset_reader.dart';
import 'src/servers/devtools.dart';
import 'src/servers/extension_backend.dart';
import 'src/services/expression_compiler.dart';
import 'src/utilities/dart_uri.dart';

export 'src/connections/app_connection.dart' show AppConnection;
export 'src/connections/debug_connection.dart' show DebugConnection;
Expand Down Expand Up @@ -111,6 +112,7 @@ class Dwds {
bool spawnDds,
bool enableDevtoolsLaunch,
DevtoolsLauncher devtoolsLauncher,
Uri sdkDir,
}) async {
hostname ??= 'localhost';
enableDebugging ??= true;
Expand All @@ -122,6 +124,8 @@ class Dwds {
spawnDds ??= true;
globalLoadStrategy = loadStrategy;

await DartUri.initialize(sdkDir: sdkDir);

DevTools devTools;
Future<String> extensionUri;
ExtensionBackend extensionBackend;
Expand Down
4 changes: 2 additions & 2 deletions dwds/lib/src/debugging/inspector.dart
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,11 @@ class AppInspector extends Domain {
Future<void> _initialize() async {
var libraries = await libraryHelper.libraryRefs;
isolate.rootLib = await libraryHelper.rootLib;

isolate.libraries.addAll(libraries);
await DartUri.recordAbsoluteUris(libraries.map((lib) => lib.uri));

var scripts = await scriptRefs;

await DartUri.recordAbsoluteUris(libraries.map((lib) => lib.uri));
await DartUri.recordAbsoluteUris(scripts.map((script) => script.uri));

isolate.extensionRPCs.addAll(await _getExtensionRpcs());
Expand Down
26 changes: 13 additions & 13 deletions dwds/lib/src/services/chrome_proxy_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,19 @@ ${globalLoadStrategy.loadModuleSnippet}("dart_sdk").developer.invokeExtension(
return (await _debugger).pause();
}

@override
Future<UriList> lookupResolvedPackageUris(
String isolateId, List<String> uris) async {
await isInitialized;
return UriList(uris: uris.map(DartUri.toResolvedUri).toList());
}

@override
Future<UriList> lookupPackageUris(String isolateId, List<String> uris) async {
await isInitialized;
return UriList(uris: uris.map(DartUri.toPackageUri).toList());
}

@override
Future<Success> registerService(String service, String alias) async {
return _rpcNotSupportedFuture('registerService');
Expand Down Expand Up @@ -1037,19 +1050,6 @@ ${globalLoadStrategy.loadModuleSnippet}("dart_sdk").developer.invokeExtension(
String isolateId, String breakpointId, bool enable) =>
throw UnimplementedError();

@override
Future<UriList> lookupPackageUris(String isolateId, List<String> uris) {
// TODO(https://github.com/dart-lang/webdev/issues/1446): implement.
throw UnimplementedError();
}

@override
Future<UriList> lookupResolvedPackageUris(
String isolateId, List<String> uris) {
// TODO(https://github.com/dart-lang/webdev/issues/1446): implement.
throw UnimplementedError();
}

/// Prevent DWDS from blocking Dart SDK rolls if changes in package:vm_service
/// are unimplemented in DWDS.
@override
Expand Down
28 changes: 11 additions & 17 deletions dwds/lib/src/services/expression_compiler_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -235,10 +235,8 @@ class _Compiler {
/// Uses [_address] and [_port] to communicate and [_assetHandler] to
/// redirect asset requests to the asset server.
///
/// [_sdkRoot] is the path to the directory containing the sdk summary files,
/// [_workerPath] is the path to the DDC worker snapshot,
/// [_librariesPath] is the path to libraries definitions file
/// libraries.json.
/// [_sdkDir] is the path to the SDK installation directory.
/// [_workerPath] is the path to the DDC worker snapshot.
///
/// Users need to stop the service by calling [stop].
class ExpressionCompilerService implements ExpressionCompiler {
Expand All @@ -248,15 +246,13 @@ class ExpressionCompilerService implements ExpressionCompiler {
final Handler _assetHandler;
final bool _verbose;

final String _sdkRoot;
final String _librariesPath;
final String _sdkDir;
final String _workerPath;

ExpressionCompilerService(
this._address, this._port, this._assetHandler, this._verbose,
{String sdkRoot, String librariesPath, String workerPath})
: _sdkRoot = sdkRoot,
_librariesPath = librariesPath,
{String sdkDir, String workerPath})
: _sdkDir = sdkDir,
_workerPath = workerPath;

@override
Expand All @@ -277,16 +273,14 @@ class ExpressionCompilerService implements ExpressionCompiler {
if (_compiler.isCompleted) return;
soundNullSafety ??= false;

final executable = Platform.resolvedExecutable;
final binDir = p.dirname(executable);
final sdkDir = p.dirname(binDir);
final binDir = p.dirname(Platform.resolvedExecutable);
var sdkDir = _sdkDir ?? p.dirname(binDir);

var sdkRoot = _sdkRoot ?? p.join(sdkDir, 'lib', '_internal');
var sdkSummaryRoot = p.join(sdkDir, 'lib', '_internal');
var sdkSummaryPath = soundNullSafety
? p.join(sdkRoot, 'ddc_outline_sound.dill')
: p.join(sdkRoot, 'ddc_sdk.dill');
var librariesPath =
_librariesPath ?? p.join(sdkDir, 'lib', 'libraries.json');
? p.join(sdkSummaryRoot, 'ddc_outline_sound.dill')
: p.join(sdkSummaryRoot, 'ddc_sdk.dill');
var librariesPath = p.join(sdkDir, 'lib', 'libraries.json');
var workerPath =
_workerPath ?? p.join(binDir, 'snapshots', 'dartdevc.dart.snapshot');

Expand Down
Loading

0 comments on commit 6e3200e

Please sign in to comment.