[go: nahoru, domu]

Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

Commit

Permalink
[tool] Clean up "plugin" references (#6503)
Browse files Browse the repository at this point in the history
  • Loading branch information
stuartmorgan committed Sep 27, 2022
1 parent b3018c8 commit 2592df9
Show file tree
Hide file tree
Showing 33 changed files with 174 additions and 167 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,5 @@ jobs:
run: |
git config --global user.name ${{ secrets.USER_NAME }}
git config --global user.email ${{ secrets.USER_EMAIL }}
dart ./script/tool/lib/src/main.dart publish-plugin --all-changed --base-sha=HEAD~ --skip-confirmation --remote=origin
dart ./script/tool/lib/src/main.dart publish --all-changed --base-sha=HEAD~ --skip-confirmation --remote=origin
env: {PUB_CREDENTIALS: "${{ secrets.PUB_CREDENTIALS }}"}
8 changes: 8 additions & 0 deletions script/tool/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
## 0.11

* Renames `publish-plugin` to `publish`.
* Renames arguments to `list`:
* `--package` now lists top-level packages (previously `--plugin`).
* `--package-or-subpackage` now lists top-level packages (previously
`--package`).

## 0.10.0+1

* Recognizes `run_test.sh` as a developer-only file in `version-check`.
Expand Down
26 changes: 13 additions & 13 deletions script/tool/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ dart pub global run flutter_plugin_tools <args>
## Commands

Run with `--help` for a full list of commands and arguments, but the
following shows a number of common commands being run for a specific plugin.
following shows a number of common commands being run for a specific package.

All examples assume running from source; see above for running the
published version instead.
Expand All @@ -71,29 +71,29 @@ command is targetting. An package name can be any of:

```sh
cd <repository root>
dart run ./script/tool/bin/flutter_plugin_tools.dart format --packages plugin_name
dart run ./script/tool/bin/flutter_plugin_tools.dart format --packages package_name
```

### Run the Dart Static Analyzer

```sh
cd <repository root>
dart run ./script/tool/bin/flutter_plugin_tools.dart analyze --packages plugin_name
dart run ./script/tool/bin/flutter_plugin_tools.dart analyze --packages package_name
```

### Run Dart Unit Tests

```sh
cd <repository root>
dart run ./script/tool/bin/flutter_plugin_tools.dart test --packages plugin_name
dart run ./script/tool/bin/flutter_plugin_tools.dart test --packages package_name
```

### Run Dart Integration Tests

```sh
cd <repository root>
dart run ./script/tool/bin/flutter_plugin_tools.dart build-examples --apk --packages plugin_name
dart run ./script/tool/bin/flutter_plugin_tools.dart drive-examples --android --packages plugin_name
dart run ./script/tool/bin/flutter_plugin_tools.dart build-examples --apk --packages package_name
dart run ./script/tool/bin/flutter_plugin_tools.dart drive-examples --android --packages package_name
```

Replace `--apk`/`--android` with the platform you want to test against
Expand All @@ -110,11 +110,11 @@ Examples:
```sh
cd <repository root>
# Run just unit tests for iOS and Android:
dart run ./script/tool/bin/flutter_plugin_tools.dart native-test --ios --android --no-integration --packages plugin_name
dart run ./script/tool/bin/flutter_plugin_tools.dart native-test --ios --android --no-integration --packages package_name
# Run all tests for macOS:
dart run ./script/tool/bin/flutter_plugin_tools.dart native-test --macos --packages plugin_name
dart run ./script/tool/bin/flutter_plugin_tools.dart native-test --macos --packages package_name
# Run all tests for Windows:
dart run ./script/tool/bin/flutter_plugin_tools.dart native-test --windows --packages plugin_name
dart run ./script/tool/bin/flutter_plugin_tools.dart native-test --windows --packages package_name
```

### Update README.md from Example Sources
Expand All @@ -125,7 +125,7 @@ before running this command.

```sh
cd <repository root>
dart run ./script/tool/bin/flutter_plugin_tools.dart update-excerpts --packages plugin_name
dart run ./script/tool/bin/flutter_plugin_tools.dart update-excerpts --packages package_name
```

### Update CHANGELOG and Version
Expand Down Expand Up @@ -165,18 +165,18 @@ on the Flutter Wiki first.
```sh
cd <path_to_plugins>
git checkout <commit_hash_to_publish>
dart run ./script/tool/bin/flutter_plugin_tools.dart publish-plugin --packages <package>
dart run ./script/tool/bin/flutter_plugin_tools.dart publish --packages <package>
```

By default the tool tries to push tags to the `upstream` remote, but some
additional settings can be configured. Run `dart run ./script/tool/bin/flutter_plugin_tools.dart
publish-plugin --help` for more usage information.
publish --help` for more usage information.

The tool wraps `pub publish` for pushing the package to pub, and then will
automatically use git to try to create and push tags. It has some additional
safety checking around `pub publish` too. By default `pub publish` publishes
_everything_, including untracked or uncommitted files in version control.
`publish-plugin` will first check the status of the local
`publish` will first check the status of the local
directory and refuse to publish if there are any mismatched files with version
control present.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ class PackageEnumerationEntry {

/// Interface definition for all commands in this tool.
// TODO(stuartmorgan): Move most of this logic to PackageLoopingCommand.
abstract class PluginCommand extends Command<void> {
abstract class PackageCommand extends Command<void> {
/// Creates a command to operate on [packagesDir] with the given environment.
PluginCommand(
PackageCommand(
this.packagesDir, {
this.processRunner = const ProcessRunner(),
this.platform = const LocalPlatform(),
Expand All @@ -47,7 +47,7 @@ abstract class PluginCommand extends Command<void> {
help:
'Specifies which packages the command should run on (before sharding).\n',
valueHelp: 'package1,package2,...',
aliases: <String>[_pluginsArg],
aliases: <String>[_pluginsLegacyAliasArg],
);
argParser.addOption(
_shardIndexArg,
Expand All @@ -58,7 +58,7 @@ abstract class PluginCommand extends Command<void> {
);
argParser.addOption(
_shardCountArg,
help: 'Specifies the number of shards into which plugins are divided.',
help: 'Specifies the number of shards into which packages are divided.',
valueHelp: 'n',
defaultsTo: '1',
);
Expand All @@ -71,7 +71,7 @@ abstract class PluginCommand extends Command<void> {
defaultsTo: <String>[],
);
argParser.addFlag(_runOnChangedPackagesArg,
help: 'Run the command on changed packages/plugins.\n'
help: 'Run the command on changed packages.\n'
'If no packages have changed, or if there have been changes that may\n'
'affect all packages, the command runs on all packages.\n'
'Packages excluded with $_excludeArg are excluded even if changed.\n'
Expand Down Expand Up @@ -106,13 +106,13 @@ abstract class PluginCommand extends Command<void> {
static const String _logTimingArg = 'log-timing';
static const String _packagesArg = 'packages';
static const String _packagesForBranchArg = 'packages-for-branch';
static const String _pluginsArg = 'plugins';
static const String _pluginsLegacyAliasArg = 'plugins';
static const String _runOnChangedPackagesArg = 'run-on-changed-packages';
static const String _runOnDirtyPackagesArg = 'run-on-dirty-packages';
static const String _shardCountArg = 'shardCount';
static const String _shardIndexArg = 'shardIndex';

/// The directory containing the plugin packages.
/// The directory containing the packages.
final Directory packagesDir;

/// The process runner.
Expand Down Expand Up @@ -221,7 +221,7 @@ abstract class PluginCommand extends Command<void> {
_shardCount = shardCount;
}

/// Returns the set of plugins to exclude based on the `--exclude` argument.
/// Returns the set of packages to exclude based on the `--exclude` argument.
Set<String> getExcludedPackageNames() {
final Set<String> excludedPackages = _excludedPackages ??
getStringListArg(_excludeArg).expand<String>((String item) {
Expand Down Expand Up @@ -250,22 +250,22 @@ abstract class PluginCommand extends Command<void> {
Stream<PackageEnumerationEntry> getTargetPackages(
{bool filterExcluded = true}) async* {
// To avoid assuming consistency of `Directory.list` across command
// invocations, we collect and sort the plugin folders before sharding.
// invocations, we collect and sort the package folders before sharding.
// This is considered an implementation detail which is why the API still
// uses streams.
final List<PackageEnumerationEntry> allPlugins =
final List<PackageEnumerationEntry> allPackages =
await _getAllPackages().toList();
allPlugins.sort((PackageEnumerationEntry p1, PackageEnumerationEntry p2) =>
allPackages.sort((PackageEnumerationEntry p1, PackageEnumerationEntry p2) =>
p1.package.path.compareTo(p2.package.path));
final int shardSize = allPlugins.length ~/ shardCount +
(allPlugins.length % shardCount == 0 ? 0 : 1);
final int start = min(shardIndex * shardSize, allPlugins.length);
final int end = min(start + shardSize, allPlugins.length);

for (final PackageEnumerationEntry plugin
in allPlugins.sublist(start, end)) {
if (!(filterExcluded && plugin.excluded)) {
yield plugin;
final int shardSize = allPackages.length ~/ shardCount +
(allPackages.length % shardCount == 0 ? 0 : 1);
final int start = min(shardIndex * shardSize, allPackages.length);
final int end = min(start + shardSize, allPackages.length);

for (final PackageEnumerationEntry package
in allPackages.sublist(start, end)) {
if (!(filterExcluded && package.excluded)) {
yield package;
}
}
}
Expand Down Expand Up @@ -330,7 +330,7 @@ abstract class PluginCommand extends Command<void> {
runOnChangedPackages = false;
}

final Set<String> excludedPluginNames = getExcludedPackageNames();
final Set<String> excludedPackageNames = getExcludedPackageNames();

if (runOnChangedPackages) {
final GitVersionFinder gitVersionFinder = await retrieveVersionFinder();
Expand Down Expand Up @@ -368,15 +368,16 @@ abstract class PluginCommand extends Command<void> {
]) {
await for (final FileSystemEntity entity
in dir.list(followLinks: false)) {
// A top-level Dart package is a plugin package.
// A top-level Dart package is a standard package.
if (isPackage(entity)) {
if (packages.isEmpty || packages.contains(p.basename(entity.path))) {
yield PackageEnumerationEntry(
RepositoryPackage(entity as Directory),
excluded: excludedPluginNames.contains(entity.basename));
excluded: excludedPackageNames.contains(entity.basename));
}
} else if (entity is Directory) {
// Look for Dart packages under this top-level directory.
// Look for Dart packages under this top-level directory; this is the
// standard structure for federated plugins.
await for (final FileSystemEntity subdir
in entity.list(followLinks: false)) {
if (isPackage(subdir)) {
Expand All @@ -394,7 +395,7 @@ abstract class PluginCommand extends Command<void> {
packages.intersection(possibleMatches).isNotEmpty) {
yield PackageEnumerationEntry(
RepositoryPackage(subdir as Directory),
excluded: excludedPluginNames
excluded: excludedPackageNames
.intersection(possibleMatches)
.isNotEmpty);
}
Expand All @@ -415,11 +416,12 @@ abstract class PluginCommand extends Command<void> {
/// stream.
Stream<PackageEnumerationEntry> getTargetPackagesAndSubpackages(
{bool filterExcluded = true}) async* {
await for (final PackageEnumerationEntry plugin
await for (final PackageEnumerationEntry package
in getTargetPackages(filterExcluded: filterExcluded)) {
yield plugin;
yield* getSubpackages(plugin.package).map((RepositoryPackage package) =>
PackageEnumerationEntry(package, excluded: plugin.excluded));
yield package;
yield* getSubpackages(package.package).map(
(RepositoryPackage subPackage) =>
PackageEnumerationEntry(subPackage, excluded: package.excluded));
}
}

Expand Down Expand Up @@ -524,7 +526,7 @@ abstract class PluginCommand extends Command<void> {
}

// Returns true if one or more files changed that have the potential to affect
// any plugin (e.g., CI script changes).
// any packages (e.g., CI script changes).
bool _changesRequireFullTest(List<String> changedFiles) {
const List<String> specialFiles = <String>[
'.ci.yaml', // LUCI config.
Expand Down
4 changes: 2 additions & 2 deletions script/tool/lib/src/common/package_looping_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import 'package:platform/platform.dart';
import 'package:pub_semver/pub_semver.dart';

import 'core.dart';
import 'plugin_command.dart';
import 'package_command.dart';
import 'process_runner.dart';
import 'repository_package.dart';

Expand Down Expand Up @@ -82,7 +82,7 @@ class PackageResult {
/// An abstract base class for a command that iterates over a set of packages
/// controlled by a standard set of flags, running some actions on each package,
/// and collecting and reporting the success/failure of those actions.
abstract class PackageLoopingCommand extends PluginCommand {
abstract class PackageLoopingCommand extends PackageCommand {
/// Creates a command to operate on [packagesDir] with the given environment.
PackageLoopingCommand(
Directory packagesDir, {
Expand Down
2 changes: 1 addition & 1 deletion script/tool/lib/src/common/package_state_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ bool _isUnpublishedExampleChange(
return exampleComponents.first.toLowerCase() != 'readme.md';
}

// True if the change is only relevant to people working on the plugin.
// True if the change is only relevant to people working on the package.
Future<bool> _isDevChange(List<String> pathComponents,
{GitVersionFinder? git, String? repoPath}) async {
return _isTestChange(pathComponents) ||
Expand Down
4 changes: 2 additions & 2 deletions script/tool/lib/src/create_all_plugins_app_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ import 'package:pub_semver/pub_semver.dart';
import 'package:pubspec_parse/pubspec_parse.dart';

import 'common/core.dart';
import 'common/plugin_command.dart';
import 'common/package_command.dart';
import 'common/repository_package.dart';

const String _outputDirectoryFlag = 'output-dir';

/// A command to create an application that builds all in a single application.
class CreateAllPluginsAppCommand extends PluginCommand {
class CreateAllPluginsAppCommand extends PackageCommand {
/// Creates an instance of the builder command.
CreateAllPluginsAppCommand(
Directory packagesDir, {
Expand Down
2 changes: 1 addition & 1 deletion script/tool/lib/src/drive_examples_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class DriveExamplesCommand extends PackageLoopingCommand {
final String name = 'drive-examples';

@override
final String description = 'Runs driver tests for plugin example apps.\n\n'
final String description = 'Runs driver tests for package example apps.\n\n'
'For each *_test.dart in test_driver/ it drives an application with '
'either the corresponding test in test_driver (for example, '
'test_driver/app_test.dart would match test_driver/app.dart), or the '
Expand Down
4 changes: 2 additions & 2 deletions script/tool/lib/src/format_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import 'package:meta/meta.dart';
import 'package:platform/platform.dart';

import 'common/core.dart';
import 'common/plugin_command.dart';
import 'common/package_command.dart';
import 'common/process_runner.dart';

/// In theory this should be 8191, but in practice that was still resulting in
Expand All @@ -37,7 +37,7 @@ final Uri _googleFormatterUrl = Uri.https('github.com',
'/google/google-java-format/releases/download/google-java-format-1.3/google-java-format-1.3-all-deps.jar');

/// A command to format all package code.
class FormatCommand extends PluginCommand {
class FormatCommand extends PackageCommand {
/// Creates an instance of the format command.
FormatCommand(
Directory packagesDir, {
Expand Down
4 changes: 2 additions & 2 deletions script/tool/lib/src/license_check_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import 'package:path/path.dart' as p;
import 'package:platform/platform.dart';

import 'common/core.dart';
import 'common/plugin_command.dart';
import 'common/package_command.dart';

const Set<String> _codeFileExtensions = <String>{
'.c',
Expand Down Expand Up @@ -105,7 +105,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
''';

/// Validates that code files have copyright and license blocks.
class LicenseCheckCommand extends PluginCommand {
class LicenseCheckCommand extends PackageCommand {
/// Creates a new license check command for [packagesDir].
LicenseCheckCommand(Directory packagesDir,
{Platform platform = const LocalPlatform(), GitDir? gitDir})
Expand Down
Loading

0 comments on commit 2592df9

Please sign in to comment.