@@ -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 {
@@ -225,6 +244,58 @@ class BuildExamplesCommand extends PackageLoopingCommand {
225
244
}
226
245
}
227
246
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
+
228
299
final int exitCode = await processRunner.runAndStream (
229
300
flutterCommand,
230
301
< String > [
0 commit comments