@@ -6,6 +6,7 @@ import 'dart:async';
6
6
7
7
import 'package:file/file.dart' ;
8
8
import 'package:platform/platform.dart' ;
9
+ import 'package:yaml/yaml.dart' ;
9
10
10
11
import 'common/core.dart' ;
11
12
import 'common/package_looping_command.dart' ;
@@ -16,7 +17,19 @@ import 'common/repository_package.dart';
16
17
/// Key for APK.
17
18
const String _platformFlagApk = 'apk' ;
18
19
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
+
19
31
const int _exitNoPlatformFlags = 3 ;
32
+ const int _exitInvalidPluginToolsConfig = 4 ;
20
33
21
34
// Flutter build types. These are the values passed to `flutter build <foo>`.
22
35
const String _flutterBuildTypeAndroid = 'apk' ;
@@ -99,7 +112,13 @@ class BuildExamplesCommand extends PackageLoopingCommand {
99
112
@override
100
113
final String description =
101
114
'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.' ;
103
122
104
123
@override
105
124
Future <void > initializeRun () async {
@@ -202,6 +221,58 @@ class BuildExamplesCommand extends PackageLoopingCommand {
202
221
: PackageResult .fail (errors);
203
222
}
204
223
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
+
205
276
Future <bool > _buildExample (
206
277
RepositoryPackage example,
207
278
String flutterBuildType, {
@@ -231,6 +302,7 @@ class BuildExamplesCommand extends PackageLoopingCommand {
231
302
'build' ,
232
303
flutterBuildType,
233
304
...extraBuildFlags,
305
+ ..._readExtraBuildFlagsConfiguration (example.directory),
234
306
if (enableExperiment.isNotEmpty)
235
307
'--enable-experiment=$enableExperiment ' ,
236
308
],
0 commit comments