Unverified Commit 73ae3243 authored by Chris Bracken's avatar Chris Bracken Committed by GitHub

[tool] Migrate off deprecated coverage paramters (#104997)

In https://github.com/flutter/flutter/pull/103771, we rolled
dependencies in Flutter, which triggered an update of package:coverage
to v1.3.1. The new version includes
https://github.com/dart-lang/coverage/pull/370 in which two deprecations
landed:

* The `Resolver` default constructor was deprecated and replaced with
  the `Resolver.create` static factory method, which unfortunately
  happens to be async.
* The `packagesPath` parameter to `HitMap.parseJson`, which takes the
  path to the `.packages` file of the package for which coverage is to
  be collected, was deprecated. This parameter was replaced with
  `packagePath` in https://github.com/dart-lang/coverage/pull/370 which
  was part of the overall deprecation of the .packages file in Dart
  itself https://github.com/dart-lang/sdk/issues/48272. The overall goal
  being that end-user code shouldn't need to know about implementation
  details such as whether dependency information is stored in a
  .packages file or a package_info.json file, but rather use the
  package_config package to obtain the package metadata and perform
  other functions such as resolving its dependencies to filesystem
  paths. packagesPath was replaced by packagePath, which takes the path
  to the package directory itself. Internally, package:coverage then
  uses package_config to do the rest of the package/script URI
  resolution to filesystem paths.

This migrates off the deprecated `packagesPath` parameter to the
replacement `packagePath` paramter.

Issue: https://github.com/flutter/flutter/issues/103830
parent 116d6579
...@@ -164,7 +164,7 @@ Future<void> run(List<String> args) async { ...@@ -164,7 +164,7 @@ Future<void> run(List<String> args) async {
} else { } else {
globals.fs.currentDirectory = testDirectory; globals.fs.currentDirectory = testDirectory;
} }
if (!collector.collectCoverageData(argResults[_kOptionCoveragePath] as String, coverageDirectory: coverageDirectory)) { if (!await collector.collectCoverageData(argResults[_kOptionCoveragePath] as String, coverageDirectory: coverageDirectory)) {
throwToolExit('Failed to collect coverage data'); throwToolExit('Failed to collect coverage data');
} }
} }
......
...@@ -461,7 +461,7 @@ class TestCommand extends FlutterCommand with DeviceBasedDevelopmentArtifacts { ...@@ -461,7 +461,7 @@ class TestCommand extends FlutterCommand with DeviceBasedDevelopmentArtifacts {
); );
if (collector != null) { if (collector != null) {
final bool collectionResult = collector.collectCoverageData( final bool collectionResult = await collector.collectCoverageData(
stringArgDeprecated('coverage-path'), stringArgDeprecated('coverage-path'),
mergeCoverageData: boolArgDeprecated('merge-coverage'), mergeCoverageData: boolArgDeprecated('merge-coverage'),
); );
......
...@@ -92,9 +92,7 @@ class CoverageCollector extends TestWatcher { ...@@ -92,9 +92,7 @@ class CoverageCollector extends TestWatcher {
_logMessage('($observatoryUri): collected coverage data; merging...'); _logMessage('($observatoryUri): collected coverage data; merging...');
_addHitmap(await coverage.HitMap.parseJson( _addHitmap(await coverage.HitMap.parseJson(
data['coverage'] as List<Map<String, dynamic>>, data['coverage'] as List<Map<String, dynamic>>,
// TODO(cbracken): https://github.com/flutter/flutter/issues/103830 packagePath: packageDirectory,
// Replace with packagePath: packageDirectory
packagesPath: packagesPath, // ignore: deprecated_member_use
checkIgnoredLines: true, checkIgnoredLines: true,
)); ));
_logMessage('($observatoryUri): done merging coverage data into global coverage map.'); _logMessage('($observatoryUri): done merging coverage data into global coverage map.');
...@@ -137,9 +135,7 @@ class CoverageCollector extends TestWatcher { ...@@ -137,9 +135,7 @@ class CoverageCollector extends TestWatcher {
_logMessage('Merging coverage data...'); _logMessage('Merging coverage data...');
_addHitmap(await coverage.HitMap.parseJson( _addHitmap(await coverage.HitMap.parseJson(
data['coverage'] as List<Map<String, dynamic>>, data['coverage'] as List<Map<String, dynamic>>,
// TODO(cbracken): https://github.com/flutter/flutter/issues/103830 packagePath: packageDirectory,
// Replace with packagePath: packageDirectory
packagesPath: packagesPath, // ignore: deprecated_member_use
checkIgnoredLines: true, checkIgnoredLines: true,
)); ));
_logMessage('Done merging coverage data into global coverage map.'); _logMessage('Done merging coverage data into global coverage map.');
...@@ -149,19 +145,16 @@ class CoverageCollector extends TestWatcher { ...@@ -149,19 +145,16 @@ class CoverageCollector extends TestWatcher {
/// ///
/// This will not start any collection tasks. It us up to the caller of to /// This will not start any collection tasks. It us up to the caller of to
/// call [collectCoverage] for each process first. /// call [collectCoverage] for each process first.
String finalizeCoverage({ Future<String> finalizeCoverage({
String Function(Map<String, coverage.HitMap> hitmap) formatter, String Function(Map<String, coverage.HitMap> hitmap) formatter,
coverage.Resolver resolver, coverage.Resolver resolver,
Directory coverageDirectory, Directory coverageDirectory,
}) { }) async {
if (_globalHitmap == null) { if (_globalHitmap == null) {
return null; return null;
} }
if (formatter == null) { if (formatter == null) {
// TODO(cbracken): https://github.com/flutter/flutter/issues/103830 resolver ??= await coverage.Resolver.create(packagesPath: packagesPath);
// Replace with: resolver ??= await coverage.Resolver.create(packagesPath: packagesPath);
// ignore: deprecated_member_use
resolver ??= coverage.Resolver(packagesPath: packagesPath);
final String packagePath = globals.fs.currentDirectory.path; final String packagePath = globals.fs.currentDirectory.path;
final List<String> reportOn = coverageDirectory == null final List<String> reportOn = coverageDirectory == null
? <String>[globals.fs.path.join(packagePath, 'lib')] ? <String>[globals.fs.path.join(packagePath, 'lib')]
...@@ -174,8 +167,8 @@ class CoverageCollector extends TestWatcher { ...@@ -174,8 +167,8 @@ class CoverageCollector extends TestWatcher {
return result; return result;
} }
bool collectCoverageData(String coveragePath, { bool mergeCoverageData = false, Directory coverageDirectory }) { Future<bool> collectCoverageData(String coveragePath, { bool mergeCoverageData = false, Directory coverageDirectory }) async {
final String coverageData = finalizeCoverage( final String coverageData = await finalizeCoverage(
coverageDirectory: coverageDirectory, coverageDirectory: coverageDirectory,
); );
_logMessage('coverage information collection complete'); _logMessage('coverage information collection complete');
......
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