From 558ee42b2ed28f0b20ceca349cc131e8413047ad Mon Sep 17 00:00:00 2001 From: Alexander Aprelev Date: Fri, 26 Oct 2018 08:04:58 -0700 Subject: [PATCH] Register expression compiler in flutter test setting. (#23511) * Register expression compiler in flutter test setting so that debugger expression evaluation is functional there. * Fix analyzer lints --- .../lib/src/test/flutter_platform.dart | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/packages/flutter_tools/lib/src/test/flutter_platform.dart b/packages/flutter_tools/lib/src/test/flutter_platform.dart index f10a02f24f..5ac03650c7 100644 --- a/packages/flutter_tools/lib/src/test/flutter_platform.dart +++ b/packages/flutter_tools/lib/src/test/flutter_platform.dart @@ -24,6 +24,7 @@ import '../bundle.dart'; import '../compile.dart'; import '../dart/package_map.dart'; import '../globals.dart'; +import '../vmservice.dart'; import 'watcher.dart'; /// The timeout we give the test process to connect to the test harness @@ -413,6 +414,22 @@ class _FlutterPlatform extends PlatformPlugin { return remoteChannel; } + Future _compileExpressionService(String isolateId, String expression, + List definitions, List typeDefinitions, + String libraryUri, String klass, bool isStatic, + ) async { + if (compiler == null || compiler.compiler == null) { + throw 'Compiler is not set up properly to compile $expression'; + } + final CompilerOutput compilerOutput = + await compiler.compiler.compileExpression(expression, definitions, + typeDefinitions, libraryUri, klass, isStatic); + if (compilerOutput != null && compilerOutput.outputFilename != null) { + return base64.encode(fs.file(compilerOutput.outputFilename).readAsBytesSync()); + } + throw 'Failed to compile $expression'; + } + Future<_AsyncError> _startTest( String testPath, StreamChannel controller, @@ -526,6 +543,16 @@ class _FlutterPlatform extends PlatformPlugin { printTrace('test $ourTestCount: using observatory uri $detectedUri from pid ${process.pid}'); } processObservatoryUri = detectedUri; + + { + printTrace('Connecting to service protocol: $processObservatoryUri'); + final Future localVmService = VMService.connect(processObservatoryUri, + compileExpression: _compileExpressionService); + localVmService.then((VMService vmservice) { + printTrace('Successfully connected to service protocol: $processObservatoryUri'); + }); + } + gotProcessObservatoryUri.complete(); watcher?.handleStartedProcess(ProcessEvent(ourTestCount, process, processObservatoryUri)); },