@@ -6,6 +6,7 @@ import 'dart:async';
66
77import 'package:file/file.dart' ;
88import 'package:platform/platform.dart' ;
9+ import 'package:yaml/yaml.dart' ;
910
1011import 'common/core.dart' ;
1112import 'common/package_looping_command.dart' ;
@@ -16,7 +17,19 @@ import 'common/repository_package.dart';
1617/// Key for APK.
1718const String _platformFlagApk = 'apk' ;
1819
20+ const String _pluginToolsConfigFileName = '.pluginToolsConfig.yaml' ;
21+ const String _pluginToolsConfigBuildFlagsKey = 'buildFlags' ;
22+ const String _pluginToolsConfigGlobalKey = 'global' ;
23+
24+ const String _pluginToolsConfigExample = '''
25+ $_pluginToolsConfigBuildFlagsKey :
26+ $_pluginToolsConfigGlobalKey :
27+ - "--no-tree-shake-icons"
28+ - "--dart-define=buildmode=testing"
29+ ''' ;
30+
1931const int _exitNoPlatformFlags = 3 ;
32+ const int _exitInvalidPluginToolsConfig = 4 ;
2033
2134// Flutter build types. These are the values passed to `flutter build <foo>`.
2235const String _flutterBuildTypeAndroid = 'apk' ;
@@ -99,7 +112,13 @@ class BuildExamplesCommand extends PackageLoopingCommand {
99112 @override
100113 final String description =
101114 'Builds all example apps (IPA for iOS and APK for Android).\n\n '
102- 'This command requires "flutter" to be in your path.' ;
115+ 'This command requires "flutter" to be in your path.\n\n '
116+ 'A $_pluginToolsConfigFileName file can be placed in an example app '
117+ 'directory to specify additional build arguments. It should be a YAML '
118+ 'file with a top-level map containing a single key '
119+ '"$_pluginToolsConfigBuildFlagsKey " containing a map containing a '
120+ 'single key "$_pluginToolsConfigGlobalKey " containing a list of build '
121+ 'arguments.' ;
103122
104123 @override
105124 Future <void > initializeRun () async {
@@ -225,6 +244,58 @@ class BuildExamplesCommand extends PackageLoopingCommand {
225244 }
226245 }
227246
247+ final File pluginToolsConfig =
248+ example.directory.childFile (_pluginToolsConfigFileName);
249+ if (pluginToolsConfig.existsSync ()) {
250+ final Object ? configuration =
251+ loadYaml (pluginToolsConfig.readAsStringSync ());
252+ if (configuration is ! YamlMap ) {
253+ printError ('The $_pluginToolsConfigFileName file must be a YAML map.' );
254+ printError (
255+ 'Currently, the key "$_pluginToolsConfigBuildFlagsKey " is the only one that has an effect.' );
256+ printError (
257+ 'It must itself be a map. Currently, in that map only the key "$_pluginToolsConfigGlobalKey "' );
258+ printError (
259+ 'has any effect; it must contain a list of arguments to pass to the' );
260+ printError ('flutter tool.' );
261+ printError (_pluginToolsConfigExample);
262+ throw ToolExit (_exitInvalidPluginToolsConfig);
263+ }
264+ if (configuration.containsKey (_pluginToolsConfigBuildFlagsKey)) {
265+ final Object ? buildFlagsConfiguration =
266+ configuration[_pluginToolsConfigBuildFlagsKey];
267+ if (buildFlagsConfiguration is ! YamlMap ) {
268+ printError (
269+ 'The $_pluginToolsConfigFileName file\' s "$_pluginToolsConfigBuildFlagsKey " key must be a map.' );
270+ printError (
271+ 'Currently, in that map only the key "$_pluginToolsConfigGlobalKey " has any effect; it must ' );
272+ printError (
273+ 'contain a list of arguments to pass to the flutter tool.' );
274+ printError (_pluginToolsConfigExample);
275+ throw ToolExit (_exitInvalidPluginToolsConfig);
276+ }
277+ if (buildFlagsConfiguration.containsKey (_pluginToolsConfigGlobalKey)) {
278+ final Object ? globalBuildFlagsConfiguration =
279+ buildFlagsConfiguration[_pluginToolsConfigGlobalKey];
280+ if (globalBuildFlagsConfiguration is ! YamlList ) {
281+ printError (
282+ 'The $_pluginToolsConfigFileName file\' s "$_pluginToolsConfigBuildFlagsKey " key must be a map' );
283+ printError ('whose "$_pluginToolsConfigGlobalKey " key is a list.' );
284+ printError (
285+ 'That list must contain a list of arguments to pass to the flutter tool.' );
286+ printError (
287+ 'For example, the $_pluginToolsConfigFileName file could look like:' );
288+ printError (_pluginToolsConfigExample);
289+ throw ToolExit (_exitInvalidPluginToolsConfig);
290+ }
291+ extraBuildFlags = < String > [
292+ ...extraBuildFlags,
293+ ...globalBuildFlagsConfiguration.cast <String >()
294+ ];
295+ }
296+ }
297+ }
298+
228299 final int exitCode = await processRunner.runAndStream (
229300 flutterCommand,
230301 < String > [
0 commit comments