Unverified Commit 542fbd4c authored by Ian Hickson's avatar Ian Hickson Committed by GitHub

Some minor fixes to the tool_coverage tool. (#36570)

Extracted from https://github.com/flutter/flutter/pull/36205
parent 45ae4f6d
...@@ -10,7 +10,7 @@ import 'dart:isolate'; ...@@ -10,7 +10,7 @@ import 'dart:isolate';
import 'package:async/async.dart'; import 'package:async/async.dart';
import 'package:coverage/coverage.dart'; import 'package:coverage/coverage.dart';
import 'package:flutter_tools/src/context_runner.dart'; import 'package:flutter_tools/src/context_runner.dart';
import 'package:path/path.dart' as p; import 'package:path/path.dart' as path;
import 'package:pedantic/pedantic.dart'; import 'package:pedantic/pedantic.dart';
import 'package:stream_channel/isolate_channel.dart'; import 'package:stream_channel/isolate_channel.dart';
import 'package:stream_channel/stream_channel.dart'; import 'package:stream_channel/stream_channel.dart';
...@@ -31,7 +31,7 @@ import 'package:flutter_tools/src/test/coverage_collector.dart'; ...@@ -31,7 +31,7 @@ import 'package:flutter_tools/src/test/coverage_collector.dart';
/// ///
/// Example invocation: /// Example invocation:
/// ///
/// dart tool/tool_coverage.dart. /// dart tool/tool_coverage.dart
Future<void> main(List<String> arguments) async { Future<void> main(List<String> arguments) async {
return runInContext(() async { return runInContext(() async {
final VMPlatform vmPlatform = VMPlatform(); final VMPlatform vmPlatform = VMPlatform();
...@@ -50,19 +50,19 @@ class VMPlatform extends PlatformPlugin { ...@@ -50,19 +50,19 @@ class VMPlatform extends PlatformPlugin {
flutterProject: FlutterProject.current(), flutterProject: FlutterProject.current(),
); );
final Map<String, Future<void>> _pending = <String, Future<void>>{}; final Map<String, Future<void>> _pending = <String, Future<void>>{};
final String precompiledPath = p.join('.dart_tool', 'build', 'generated', 'flutter_tools'); final String precompiledPath = path.join('.dart_tool', 'build', 'generated', 'flutter_tools');
@override @override
StreamChannel<void> loadChannel(String path, SuitePlatform platform) => StreamChannel<void> loadChannel(String codePath, SuitePlatform platform) =>
throw UnimplementedError(); throw UnimplementedError();
@override @override
Future<RunnerSuite> load(String path, SuitePlatform platform, Future<RunnerSuite> load(String codePath, SuitePlatform platform,
SuiteConfiguration suiteConfig, Object message) async { SuiteConfiguration suiteConfig, Object message) async {
final ReceivePort receivePort = ReceivePort(); final ReceivePort receivePort = ReceivePort();
Isolate isolate; Isolate isolate;
try { try {
isolate = await _spawnIsolate(path, receivePort.sendPort); isolate = await _spawnIsolate(codePath, receivePort.sendPort);
} catch (error) { } catch (error) {
receivePort.close(); receivePort.close();
rethrow; rethrow;
...@@ -71,7 +71,7 @@ class VMPlatform extends PlatformPlugin { ...@@ -71,7 +71,7 @@ class VMPlatform extends PlatformPlugin {
// When this is completed we remove it from the map of pending so we can // When this is completed we remove it from the map of pending so we can
// log the futures that get "stuck". // log the futures that get "stuck".
unawaited(completer.future.whenComplete(() { unawaited(completer.future.whenComplete(() {
_pending.remove(path); _pending.remove(codePath);
})); }));
final ServiceProtocolInfo info = await Service.controlWebServer(enable: true); final ServiceProtocolInfo info = await Service.controlWebServer(enable: true);
final dynamic channel = IsolateChannel<Object>.connectReceive(receivePort) final dynamic channel = IsolateChannel<Object>.connectReceive(receivePort)
...@@ -94,14 +94,14 @@ class VMPlatform extends PlatformPlugin { ...@@ -94,14 +94,14 @@ class VMPlatform extends PlatformPlugin {
VMEnvironment environment; VMEnvironment environment;
final RunnerSuiteController controller = deserializeSuite( final RunnerSuiteController controller = deserializeSuite(
path, codePath,
platform, platform,
suiteConfig, suiteConfig,
environment, environment,
channel, channel,
message, message,
); );
_pending[path] = completer.future; _pending[codePath] = completer.future;
return await controller.suite; return await controller.suite;
} }
...@@ -109,11 +109,11 @@ class VMPlatform extends PlatformPlugin { ...@@ -109,11 +109,11 @@ class VMPlatform extends PlatformPlugin {
/// ///
/// This isolate connects an [IsolateChannel] to [message] and sends the /// This isolate connects an [IsolateChannel] to [message] and sends the
/// serialized tests over that channel. /// serialized tests over that channel.
Future<Isolate> _spawnIsolate(String path, SendPort message) async { Future<Isolate> _spawnIsolate(String codePath, SendPort message) async {
String testPath = p.absolute(p.join(precompiledPath, path) + '.vm_test.dart'); String testPath = path.absolute(path.join(precompiledPath, codePath) + '.vm_test.dart');
testPath = testPath.substring(0, testPath.length - '.dart'.length) + '.vm.app.dill'; testPath = testPath.substring(0, testPath.length - '.dart'.length) + '.vm.app.dill';
return await Isolate.spawnUri(p.toUri(testPath), <String>[], message, return await Isolate.spawnUri(path.toUri(testPath), <String>[], message,
packageConfig: p.toUri('.packages'), packageConfig: path.toUri('.packages'),
checked: true, checked: true,
); );
} }
...@@ -126,8 +126,8 @@ class VMPlatform extends PlatformPlugin { ...@@ -126,8 +126,8 @@ class VMPlatform extends PlatformPlugin {
// TODO(jonahwilliams): resolve whether there are any specific tests that // TODO(jonahwilliams): resolve whether there are any specific tests that
// get stuck or if it is a general infra issue with how we are collecting // get stuck or if it is a general infra issue with how we are collecting
// coverage. // coverage.
// Log tests that are "Stuck" waiuting for coverage. // Log tests that are "Stuck" waiting for coverage.
print('The folllowing tests timed out waiting for coverage:'); print('The following tests timed out waiting for coverage:');
print(_pending.keys.join(', ')); print(_pending.keys.join(', '));
} }
final String packagePath = Directory.current.path; final String packagePath = Directory.current.path;
...@@ -139,7 +139,7 @@ class VMPlatform extends PlatformPlugin { ...@@ -139,7 +139,7 @@ class VMPlatform extends PlatformPlugin {
formatter: formatter, formatter: formatter,
); );
final String prefix = Platform.environment['SUBSHARD'] ?? ''; final String prefix = Platform.environment['SUBSHARD'] ?? '';
final String outputLcovPath = p.join('coverage', '$prefix.lcov.info'); final String outputLcovPath = path.join('coverage', '$prefix.lcov.info');
File(outputLcovPath) File(outputLcovPath)
..createSync(recursive: true) ..createSync(recursive: true)
..writeAsStringSync(result); ..writeAsStringSync(result);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment