Skip to content

Commit

Permalink
[tool] Migrate off deprecated coverage paramters (#104997)
Browse files Browse the repository at this point in the history
In flutter/flutter#103771, we rolled
dependencies in Flutter, which triggered an update of package:coverage
to v1.3.1. The new version includes
dart-archive/coverage#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 dart-archive/coverage#370 which
  was part of the overall deprecation of the .packages file in Dart
  itself dart-lang/sdk#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: flutter/flutter#103830
  • Loading branch information
cbracken authored May 31, 2022
1 parent 116d657 commit 73ae324
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 16 deletions.
2 changes: 1 addition & 1 deletion packages/flutter_tools/bin/fuchsia_tester.dart
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ Future<void> run(List<String> args) async {
} else {
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');
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/flutter_tools/lib/src/commands/test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ class TestCommand extends FlutterCommand with DeviceBasedDevelopmentArtifacts {
);

if (collector != null) {
final bool collectionResult = collector.collectCoverageData(
final bool collectionResult = await collector.collectCoverageData(
stringArgDeprecated('coverage-path'),
mergeCoverageData: boolArgDeprecated('merge-coverage'),
);
Expand Down
21 changes: 7 additions & 14 deletions packages/flutter_tools/lib/src/test/coverage_collector.dart
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,7 @@ class CoverageCollector extends TestWatcher {
_logMessage('($observatoryUri): collected coverage data; merging...');
_addHitmap(await coverage.HitMap.parseJson(
data['coverage'] as List<Map<String, dynamic>>,
// TODO(cbracken): https://github.com/flutter/flutter/issues/103830
// Replace with packagePath: packageDirectory
packagesPath: packagesPath, // ignore: deprecated_member_use
packagePath: packageDirectory,
checkIgnoredLines: true,
));
_logMessage('($observatoryUri): done merging coverage data into global coverage map.');
Expand Down Expand Up @@ -137,9 +135,7 @@ class CoverageCollector extends TestWatcher {
_logMessage('Merging coverage data...');
_addHitmap(await coverage.HitMap.parseJson(
data['coverage'] as List<Map<String, dynamic>>,
// TODO(cbracken): https://github.com/flutter/flutter/issues/103830
// Replace with packagePath: packageDirectory
packagesPath: packagesPath, // ignore: deprecated_member_use
packagePath: packageDirectory,
checkIgnoredLines: true,
));
_logMessage('Done merging coverage data into global coverage map.');
Expand All @@ -149,19 +145,16 @@ class CoverageCollector extends TestWatcher {
///
/// This will not start any collection tasks. It us up to the caller of to
/// call [collectCoverage] for each process first.
String finalizeCoverage({
Future<String> finalizeCoverage({
String Function(Map<String, coverage.HitMap> hitmap) formatter,
coverage.Resolver resolver,
Directory coverageDirectory,
}) {
}) async {
if (_globalHitmap == null) {
return null;
}
if (formatter == null) {
// TODO(cbracken): https://github.com/flutter/flutter/issues/103830
// Replace with: resolver ??= await coverage.Resolver.create(packagesPath: packagesPath);
// ignore: deprecated_member_use
resolver ??= coverage.Resolver(packagesPath: packagesPath);
resolver ??= await coverage.Resolver.create(packagesPath: packagesPath);
final String packagePath = globals.fs.currentDirectory.path;
final List<String> reportOn = coverageDirectory == null
? <String>[globals.fs.path.join(packagePath, 'lib')]
Expand All @@ -174,8 +167,8 @@ class CoverageCollector extends TestWatcher {
return result;
}

bool collectCoverageData(String coveragePath, { bool mergeCoverageData = false, Directory coverageDirectory }) {
final String coverageData = finalizeCoverage(
Future<bool> collectCoverageData(String coveragePath, { bool mergeCoverageData = false, Directory coverageDirectory }) async {
final String coverageData = await finalizeCoverage(
coverageDirectory: coverageDirectory,
);
_logMessage('coverage information collection complete');
Expand Down

0 comments on commit 73ae324

Please sign in to comment.