diff --git a/script/tool/lib/src/build_examples_command.dart b/script/tool/lib/src/build_examples_command.dart index 53da9086ab..bb140bd429 100644 --- a/script/tool/lib/src/build_examples_command.dart +++ b/script/tool/lib/src/build_examples_command.dart @@ -19,6 +19,7 @@ class BuildExamplesCommand extends PluginCommand { }) : super(packagesDir, fileSystem, processRunner: processRunner) { argParser.addFlag(kLinux, defaultsTo: false); argParser.addFlag(kMacos, defaultsTo: false); + argParser.addFlag(kWeb, defaultsTo: false); argParser.addFlag(kWindows, defaultsTo: false); argParser.addFlag(kIpa, defaultsTo: io.Platform.isMacOS); argParser.addFlag(kApk); @@ -43,10 +44,10 @@ class BuildExamplesCommand extends PluginCommand { !argResults[kApk] && !argResults[kLinux] && !argResults[kMacos] && + !argResults[kWeb] && !argResults[kWindows]) { - print( - 'None of --linux, --macos, --windows, --apk nor --ipa were specified, ' - 'so not building anything.'); + print('None of --linux, --macos, --web, --windows, --apk, or --ipa were ' + 'specified, so not building anything.'); return; } final String flutterCommand = @@ -84,33 +85,43 @@ class BuildExamplesCommand extends PluginCommand { if (argResults[kMacos]) { print('\nBUILDING macOS for $packageName'); if (isMacOsPlugin(plugin, fileSystem)) { - // TODO(https://github.com/flutter/flutter/issues/46236): - // Builing macos without running flutter pub get first results - // in an error. int exitCode = await processRunner.runAndStream( - flutterCommand, <String>['pub', 'get'], + flutterCommand, + <String>[ + 'build', + kMacos, + if (enableExperiment.isNotEmpty) + '--enable-experiment=$enableExperiment', + ], workingDir: example); if (exitCode != 0) { failingPackages.add('$packageName (macos)'); - } else { - exitCode = await processRunner.runAndStream( - flutterCommand, - <String>[ - 'build', - kMacos, - if (enableExperiment.isNotEmpty) - '--enable-experiment=$enableExperiment', - ], - workingDir: example); - if (exitCode != 0) { - failingPackages.add('$packageName (macos)'); - } } } else { print('macOS is not supported by this plugin'); } } + if (argResults[kWeb]) { + print('\nBUILDING web for $packageName'); + if (isWebPlugin(plugin, fileSystem)) { + int buildExitCode = await processRunner.runAndStream( + flutterCommand, + <String>[ + 'build', + kWeb, + if (enableExperiment.isNotEmpty) + '--enable-experiment=$enableExperiment', + ], + workingDir: example); + if (buildExitCode != 0) { + failingPackages.add('$packageName (web)'); + } + } else { + print('Web is not supported by this plugin'); + } + } + if (argResults[kWindows]) { print('\nBUILDING Windows for $packageName'); if (isWindowsPlugin(plugin, fileSystem)) { diff --git a/script/tool/lib/src/format_command.dart b/script/tool/lib/src/format_command.dart index ec326b96c1..e1c14e04cf 100644 --- a/script/tool/lib/src/format_command.dart +++ b/script/tool/lib/src/format_command.dart @@ -22,10 +22,10 @@ class FormatCommand extends PluginCommand { FileSystem fileSystem, { ProcessRunner processRunner = const ProcessRunner(), }) : super(packagesDir, fileSystem, processRunner: processRunner) { - argParser.addFlag('travis', hide: true); + argParser.addFlag('fail-on-change', hide: true); argParser.addOption('clang-format', defaultsTo: 'clang-format', - help: 'Path to executable of clang-format v5.'); + help: 'Path to executable of clang-format.'); } @override @@ -46,7 +46,7 @@ class FormatCommand extends PluginCommand { await _formatJava(googleFormatterPath); await _formatCppAndObjectiveC(); - if (argResults['travis']) { + if (argResults['fail-on-change']) { final bool modified = await _didModifyAnything(); if (modified) { throw ToolExit(1); diff --git a/script/tool/test/build_examples_command_test.dart b/script/tool/test/build_examples_command_test.dart index eaf5049dcc..65417525d7 100644 --- a/script/tool/test/build_examples_command_test.dart +++ b/script/tool/test/build_examples_command_test.dart @@ -201,7 +201,7 @@ void main() { output, orderedEquals(<String>[ '\nBUILDING macOS for $packageName', - '\macOS is not supported by this plugin', + 'macOS is not supported by this plugin', '\n\n', 'All builds successful!', ]), @@ -213,6 +213,7 @@ void main() { expect(processRunner.recordedCalls, orderedEquals(<ProcessCall>[])); cleanupPackages(); }); + test('building for macos', () async { createFakePlugin('plugin', withExtraFiles: <List<String>>[ @@ -244,14 +245,81 @@ void main() { expect( processRunner.recordedCalls, orderedEquals(<ProcessCall>[ - ProcessCall(flutterCommand, <String>['pub', 'get'], - pluginExampleDirectory.path), ProcessCall(flutterCommand, <String>['build', 'macos'], pluginExampleDirectory.path), ])); cleanupPackages(); }); + test('building for web with no implementation results in no-op', () async { + createFakePlugin('plugin', withExtraFiles: <List<String>>[ + <String>['example', 'test'], + ]); + + final Directory pluginExampleDirectory = + mockPackagesDir.childDirectory('plugin').childDirectory('example'); + + createFakePubspec(pluginExampleDirectory, isFlutter: true); + + final List<String> output = await runCapturingPrint( + runner, <String>['build-examples', '--no-ipa', '--web']); + final String packageName = + p.relative(pluginExampleDirectory.path, from: mockPackagesDir.path); + + expect( + output, + orderedEquals(<String>[ + '\nBUILDING web for $packageName', + 'Web is not supported by this plugin', + '\n\n', + 'All builds successful!', + ]), + ); + + print(processRunner.recordedCalls); + // Output should be empty since running build-examples --macos with no macos + // implementation is a no-op. + expect(processRunner.recordedCalls, orderedEquals(<ProcessCall>[])); + cleanupPackages(); + }); + + test('building for web', () async { + createFakePlugin('plugin', + withExtraFiles: <List<String>>[ + <String>['example', 'test'], + <String>['example', 'web', 'index.html'], + ], + isWebPlugin: true); + + final Directory pluginExampleDirectory = + mockPackagesDir.childDirectory('plugin').childDirectory('example'); + + createFakePubspec(pluginExampleDirectory, isFlutter: true); + + final List<String> output = await runCapturingPrint( + runner, <String>['build-examples', '--no-ipa', '--web']); + final String packageName = + p.relative(pluginExampleDirectory.path, from: mockPackagesDir.path); + + expect( + output, + orderedEquals(<String>[ + '\nBUILDING web for $packageName', + '\n\n', + 'All builds successful!', + ]), + ); + + print(processRunner.recordedCalls); + expect( + processRunner.recordedCalls, + orderedEquals(<ProcessCall>[ + ProcessCall(flutterCommand, <String>['build', 'web'], + pluginExampleDirectory.path), + ])); + cleanupPackages(); + }); + test( 'building for Windows when plugin is not set up for Windows results in no-op', () async {