@@ -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 {
@@ -202,6 +221,58 @@ class BuildExamplesCommand extends PackageLoopingCommand {
202221 : PackageResult .fail (errors);
203222 }
204223
224+ Iterable <String > _readExtraBuildFlagsConfiguration (
225+ Directory directory) sync * {
226+ final File pluginToolsConfig =
227+ directory.childFile (_pluginToolsConfigFileName);
228+ if (pluginToolsConfig.existsSync ()) {
229+ final Object ? configuration =
230+ loadYaml (pluginToolsConfig.readAsStringSync ());
231+ if (configuration is ! YamlMap ) {
232+ printError ('The $_pluginToolsConfigFileName file must be a YAML map.' );
233+ printError (
234+ 'Currently, the key "$_pluginToolsConfigBuildFlagsKey " is the only one that has an effect.' );
235+ printError (
236+ 'It must itself be a map. Currently, in that map only the key "$_pluginToolsConfigGlobalKey "' );
237+ printError (
238+ 'has any effect; it must contain a list of arguments to pass to the' );
239+ printError ('flutter tool.' );
240+ printError (_pluginToolsConfigExample);
241+ throw ToolExit (_exitInvalidPluginToolsConfig);
242+ }
243+ if (configuration.containsKey (_pluginToolsConfigBuildFlagsKey)) {
244+ final Object ? buildFlagsConfiguration =
245+ configuration[_pluginToolsConfigBuildFlagsKey];
246+ if (buildFlagsConfiguration is ! YamlMap ) {
247+ printError (
248+ 'The $_pluginToolsConfigFileName file\' s "$_pluginToolsConfigBuildFlagsKey " key must be a map.' );
249+ printError (
250+ 'Currently, in that map only the key "$_pluginToolsConfigGlobalKey " has any effect; it must ' );
251+ printError (
252+ 'contain a list of arguments to pass to the flutter tool.' );
253+ printError (_pluginToolsConfigExample);
254+ throw ToolExit (_exitInvalidPluginToolsConfig);
255+ }
256+ if (buildFlagsConfiguration.containsKey (_pluginToolsConfigGlobalKey)) {
257+ final Object ? globalBuildFlagsConfiguration =
258+ buildFlagsConfiguration[_pluginToolsConfigGlobalKey];
259+ if (globalBuildFlagsConfiguration is ! YamlList ) {
260+ printError (
261+ 'The $_pluginToolsConfigFileName file\' s "$_pluginToolsConfigBuildFlagsKey " key must be a map' );
262+ printError ('whose "$_pluginToolsConfigGlobalKey " key is a list.' );
263+ printError (
264+ 'That list must contain a list of arguments to pass to the flutter tool.' );
265+ printError (
266+ 'For example, the $_pluginToolsConfigFileName file could look like:' );
267+ printError (_pluginToolsConfigExample);
268+ throw ToolExit (_exitInvalidPluginToolsConfig);
269+ }
270+ yield * globalBuildFlagsConfiguration.cast <String >();
271+ }
272+ }
273+ }
274+ }
275+
205276 Future <bool > _buildExample (
206277 RepositoryPackage example,
207278 String flutterBuildType, {
@@ -231,6 +302,7 @@ class BuildExamplesCommand extends PackageLoopingCommand {
231302 'build' ,
232303 flutterBuildType,
233304 ...extraBuildFlags,
305+ ..._readExtraBuildFlagsConfiguration (example.directory),
234306 if (enableExperiment.isNotEmpty)
235307 '--enable-experiment=$enableExperiment ' ,
236308 ],
0 commit comments