Eliminate build_all_plugins_app.sh (#4232)

Removes the `build_all_plugins_app.sh` bash script, in support of the goal of eliminating all use of bash from the repository (for maintainability, and for better Windows compatibility).

- The exclusion list moves to a config file, match other recent repo changes
- The exclusion logging moves into the tool itself, consistent with the tool doing more logging of skipped and excluded plugins
- The bulk of the logic moves to a Cirrus task template. This was done instead of rewriting the script in Dart, even though it will mean more work for alternate CI support (e.g., bringing this up on a Windows LUCI bot), because breaking it into components makes it easier to pinpoint failures from the CI UI rather than having all the steps smashed together.
This commit is contained in:
stuartmorgan
2021-08-13 16:22:24 -07:00
committed by GitHub
parent 1ee7bef513
commit 9b590484f6
3 changed files with 58 additions and 16 deletions

View File

@ -191,7 +191,7 @@ abstract class PluginCommand extends Command<void> {
} }
/// Returns the set of plugins to exclude based on the `--exclude` argument. /// Returns the set of plugins to exclude based on the `--exclude` argument.
Set<String> _getExcludedPackageName() { Set<String> getExcludedPackageNames() {
final Set<String> excludedPackages = _excludedPackages ?? final Set<String> excludedPackages = _excludedPackages ??
getStringListArg(_excludeArg).expand<String>((String item) { getStringListArg(_excludeArg).expand<String>((String item) {
if (item.endsWith('.yaml')) { if (item.endsWith('.yaml')) {
@ -265,7 +265,7 @@ abstract class PluginCommand extends Command<void> {
Stream<PackageEnumerationEntry> _getAllPackages() async* { Stream<PackageEnumerationEntry> _getAllPackages() async* {
Set<String> plugins = Set<String>.from(getStringListArg(_packagesArg)); Set<String> plugins = Set<String>.from(getStringListArg(_packagesArg));
final Set<String> excludedPluginNames = _getExcludedPackageName(); final Set<String> excludedPluginNames = getExcludedPackageNames();
final bool runOnChangedPackages = getBoolArg(_runOnChangedPackagesArg); final bool runOnChangedPackages = getBoolArg(_runOnChangedPackagesArg);
if (plugins.isEmpty && if (plugins.isEmpty &&

View File

@ -12,22 +12,27 @@ import 'package:pubspec_parse/pubspec_parse.dart';
import 'common/core.dart'; import 'common/core.dart';
import 'common/plugin_command.dart'; import 'common/plugin_command.dart';
const String _outputDirectoryFlag = 'output-dir';
/// A command to create an application that builds all in a single application. /// A command to create an application that builds all in a single application.
class CreateAllPluginsAppCommand extends PluginCommand { class CreateAllPluginsAppCommand extends PluginCommand {
/// Creates an instance of the builder command. /// Creates an instance of the builder command.
CreateAllPluginsAppCommand( CreateAllPluginsAppCommand(
Directory packagesDir, { Directory packagesDir, {
Directory? pluginsRoot, Directory? pluginsRoot,
}) : pluginsRoot = pluginsRoot ?? packagesDir.fileSystem.currentDirectory, }) : super(packagesDir) {
super(packagesDir) { final Directory defaultDir =
appDirectory = this.pluginsRoot.childDirectory('all_plugins'); pluginsRoot ?? packagesDir.fileSystem.currentDirectory;
argParser.addOption(_outputDirectoryFlag,
defaultsTo: defaultDir.path,
help: 'The path the directory to create the "all_plugins" project in.\n'
'Defaults to the repository root.');
} }
/// The root directory of the plugin repository.
Directory pluginsRoot;
/// The location of the synthesized app project. /// The location of the synthesized app project.
late Directory appDirectory; Directory get appDirectory => packagesDir.fileSystem
.directory(getStringArg(_outputDirectoryFlag))
.childDirectory('all_plugins');
@override @override
String get description => String get description =>
@ -43,6 +48,15 @@ class CreateAllPluginsAppCommand extends PluginCommand {
throw ToolExit(exitCode); throw ToolExit(exitCode);
} }
final Set<String> excluded = getExcludedPackageNames();
if (excluded.isNotEmpty) {
print('Exluding the following plugins from the combined build:');
for (final String plugin in excluded) {
print(' $plugin');
}
print('');
}
await Future.wait(<Future<void>>[ await Future.wait(<Future<void>>[
_genPubspecWithAllPlugins(), _genPubspecWithAllPlugins(),
_updateAppGradle(), _updateAppGradle(),

View File

@ -13,10 +13,10 @@ import 'util.dart';
void main() { void main() {
group('$CreateAllPluginsAppCommand', () { group('$CreateAllPluginsAppCommand', () {
late CommandRunner<void> runner; late CommandRunner<void> runner;
FileSystem fileSystem; late CreateAllPluginsAppCommand command;
late FileSystem fileSystem;
late Directory testRoot; late Directory testRoot;
late Directory packagesDir; late Directory packagesDir;
late Directory appDir;
setUp(() { setUp(() {
// Since the core of this command is a call to 'flutter create', the test // Since the core of this command is a call to 'flutter create', the test
@ -26,11 +26,10 @@ void main() {
testRoot = fileSystem.systemTempDirectory.createTempSync(); testRoot = fileSystem.systemTempDirectory.createTempSync();
packagesDir = testRoot.childDirectory('packages'); packagesDir = testRoot.childDirectory('packages');
final CreateAllPluginsAppCommand command = CreateAllPluginsAppCommand( command = CreateAllPluginsAppCommand(
packagesDir, packagesDir,
pluginsRoot: testRoot, pluginsRoot: testRoot,
); );
appDir = command.appDirectory;
runner = CommandRunner<void>( runner = CommandRunner<void>(
'create_all_test', 'Test for $CreateAllPluginsAppCommand'); 'create_all_test', 'Test for $CreateAllPluginsAppCommand');
runner.addCommand(command); runner.addCommand(command);
@ -47,7 +46,7 @@ void main() {
await runCapturingPrint(runner, <String>['all-plugins-app']); await runCapturingPrint(runner, <String>['all-plugins-app']);
final List<String> pubspec = final List<String> pubspec =
appDir.childFile('pubspec.yaml').readAsLinesSync(); command.appDirectory.childFile('pubspec.yaml').readAsLinesSync();
expect( expect(
pubspec, pubspec,
@ -65,7 +64,7 @@ void main() {
await runCapturingPrint(runner, <String>['all-plugins-app']); await runCapturingPrint(runner, <String>['all-plugins-app']);
final List<String> pubspec = final List<String> pubspec =
appDir.childFile('pubspec.yaml').readAsLinesSync(); command.appDirectory.childFile('pubspec.yaml').readAsLinesSync();
expect( expect(
pubspec, pubspec,
@ -82,9 +81,38 @@ void main() {
await runCapturingPrint(runner, <String>['all-plugins-app']); await runCapturingPrint(runner, <String>['all-plugins-app']);
final String pubspec = final String pubspec =
appDir.childFile('pubspec.yaml').readAsStringSync(); command.appDirectory.childFile('pubspec.yaml').readAsStringSync();
expect(pubspec, contains(RegExp('sdk:\\s*(?:["\']>=|[^])2\\.12\\.'))); expect(pubspec, contains(RegExp('sdk:\\s*(?:["\']>=|[^])2\\.12\\.')));
}); });
test('handles --output-dir', () async {
createFakePlugin('plugina', packagesDir);
final Directory customOutputDir =
fileSystem.systemTempDirectory.createTempSync();
await runCapturingPrint(runner,
<String>['all-plugins-app', '--output-dir=${customOutputDir.path}']);
expect(command.appDirectory.path,
customOutputDir.childDirectory('all_plugins').path);
});
test('logs exclusions', () async {
createFakePlugin('plugina', packagesDir);
createFakePlugin('pluginb', packagesDir);
createFakePlugin('pluginc', packagesDir);
final List<String> output = await runCapturingPrint(
runner, <String>['all-plugins-app', '--exclude=pluginb,pluginc']);
expect(
output,
containsAllInOrder(<String>[
'Exluding the following plugins from the combined build:',
' pluginb',
' pluginc',
]));
});
}); });
} }