Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

Commit d26c227

Browse files
committed
build-examples .pluginToolsConfig.yaml support
1 parent 0857331 commit d26c227

File tree

4 files changed

+123
-5
lines changed

4 files changed

+123
-5
lines changed

script/tool/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.7.1
2+
3+
- Add support for `.pluginToolsConfig.yaml` in the `build-examples` command.
4+
15
## 0.7.0
26

37
- `native-test` now supports `--linux` for unit tests.

script/tool/lib/src/build_examples_command.dart

Lines changed: 73 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import 'dart:async';
66

77
import 'package:file/file.dart';
88
import 'package:platform/platform.dart';
9+
import 'package:yaml/yaml.dart';
910

1011
import 'common/core.dart';
1112
import 'common/package_looping_command.dart';
@@ -16,7 +17,19 @@ import 'common/repository_package.dart';
1617
/// Key for APK.
1718
const 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+
1931
const int _exitNoPlatformFlags = 3;
32+
const int _exitInvalidPluginToolsConfig = 4;
2033

2134
// Flutter build types. These are the values passed to `flutter build <foo>`.
2235
const 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
],

script/tool/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: flutter_plugin_tools
22
description: Productivity utils for flutter/plugins and flutter/packages
33
repository: https://github.com/flutter/plugins/tree/master/script/tool
4-
version: 0.7.0
4+
version: 0.7.1
55

66
dependencies:
77
args: ^2.1.0

script/tool/test/build_examples_command_test.dart

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,6 @@ void main() {
379379
]),
380380
);
381381

382-
print(processRunner.recordedCalls);
383382
// Output should be empty since running build-examples --macos with no macos
384383
// implementation is a no-op.
385384
expect(processRunner.recordedCalls, orderedEquals(<ProcessCall>[]));
@@ -407,7 +406,6 @@ void main() {
407406
]),
408407
);
409408

410-
print(processRunner.recordedCalls);
411409
expect(
412410
processRunner.recordedCalls,
413411
containsAll(<ProcessCall>[
@@ -436,7 +434,6 @@ void main() {
436434
contains('Creating temporary winuwp folder'),
437435
);
438436

439-
print(processRunner.recordedCalls);
440437
expect(
441438
processRunner.recordedCalls,
442439
orderedEquals(<ProcessCall>[
@@ -679,5 +676,50 @@ void main() {
679676
]));
680677
});
681678
});
679+
680+
test('The .pluginToolsConfig.yaml file', () async {
681+
mockPlatform.isLinux = true;
682+
final Directory pluginDirectory = createFakePlugin('plugin', packagesDir,
683+
platformSupport: <String, PlatformDetails>{
684+
kPlatformLinux: const PlatformDetails(PlatformSupport.inline),
685+
kPlatformMacos: const PlatformDetails(PlatformSupport.inline),
686+
});
687+
688+
final Directory pluginExampleDirectory =
689+
pluginDirectory.childDirectory('example');
690+
691+
final File pluginExampleConfigFile =
692+
pluginExampleDirectory.childFile('.pluginToolsConfig.yaml');
693+
pluginExampleConfigFile
694+
.writeAsStringSync('buildFlags:\n global:\n - "test argument"');
695+
696+
final List<String> output = <String>[
697+
...await runCapturingPrint(
698+
runner, <String>['build-examples', '--linux']),
699+
...await runCapturingPrint(
700+
runner, <String>['build-examples', '--macos']),
701+
];
702+
703+
expect(
704+
output,
705+
containsAllInOrder(<String>[
706+
'\nBUILDING plugin/example for Linux',
707+
'\nBUILDING plugin/example for macOS',
708+
]),
709+
);
710+
711+
expect(
712+
processRunner.recordedCalls,
713+
orderedEquals(<ProcessCall>[
714+
ProcessCall(
715+
getFlutterCommand(mockPlatform),
716+
const <String>['build', 'linux', 'test argument'],
717+
pluginExampleDirectory.path),
718+
ProcessCall(
719+
getFlutterCommand(mockPlatform),
720+
const <String>['build', 'macos', 'test argument'],
721+
pluginExampleDirectory.path),
722+
]));
723+
});
682724
});
683725
}

0 commit comments

Comments
 (0)