[flutter_plugin_tools] Add a new base command for looping over packages (#4067)

Most of our commands are generally of the form:
```
  for (each plugin as defined by the tool flags)
    check some things for success or failure
  print a summary all of the failing things
  exit non-zero if anything failed
```

Currently all that logic not consistent, having been at various points copied and pasted around, modified, in some cases rewritten. There's unnecessary boilerplate in each new command, and there's unnecessary variation that makes it harder both to maintain the tool, and to consume the test output:
- There's no standard format for separating each plugin's run to search within a log
- There's no standard format for the summary at the end
- In some cases commands have been written to ToolExit on failure, which means we don't actually get the rest of the runs

This makes a new base class for commands that follow this structure to use, with shared code for all the common bits. This makes it harder to accidentally write new commands incorrectly, easier to maintain the code, and lets us standardize output so that searching within large logs will be easier.

This ports two commands over as a proof of concept to demonstrate that it works; more will be converted in follow-ups.

Related to https://github.com/flutter/flutter/issues/83413
This commit is contained in:
stuartmorgan
2021-06-22 13:32:03 -07:00
committed by GitHub
parent f0967e5186
commit 356d316717
9 changed files with 710 additions and 96 deletions

View File

@ -14,6 +14,7 @@ import 'git_version_finder.dart';
import 'process_runner.dart';
/// Interface definition for all commands in this tool.
// TODO(stuartmorgan): Move most of this logic to PackageLoopingCommand.
abstract class PluginCommand extends Command<void> {
/// Creates a command to operate on [packagesDir] with the given environment.
PluginCommand(
@ -136,6 +137,8 @@ abstract class PluginCommand extends Command<void> {
/// Returns the root Dart package folders of the plugins involved in this
/// command execution.
// TODO(stuartmorgan): Rename/restructure this, _getAllPlugins, and
// getPackages, as the current naming is very confusing.
Stream<Directory> getPlugins() async* {
// To avoid assuming consistency of `Directory.list` across command
// invocations, we collect and sort the plugin folders before sharding.