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

Commit c51faf1

Browse files
committed
build-examples .pluginToolsConfig.yaml support
1 parent 887ba2d commit c51faf1

File tree

4 files changed

+80
-2
lines changed

4 files changed

+80
-2
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.8.0
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: 31 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,10 @@ import 'common/repository_package.dart';
1617
/// Key for APK.
1718
const String _platformFlagApk = 'apk';
1819

20+
const String _pluginToolsConfigFileName = '.pluginToolsConfig.yaml';
21+
1922
const int _exitNoPlatformFlags = 3;
23+
const int _exitInvalidPluginToolsConfig = 4;
2024

2125
// Flutter build types. These are the values passed to `flutter build <foo>`.
2226
const String _flutterBuildTypeAndroid = 'apk';
@@ -99,7 +103,10 @@ class BuildExamplesCommand extends PackageLoopingCommand {
99103
@override
100104
final String description =
101105
'Builds all example apps (IPA for iOS and APK for Android).\n\n'
102-
'This command requires "flutter" to be in your path.';
106+
'This command requires "flutter" to be in your path.\n\n'
107+
'A $_pluginToolsConfigFileName file can be placed in an example app '
108+
'directory to specify additional build arguments. It should be a YAML '
109+
'file giving a list of arguments.';
103110

104111
@override
105112
Future<void> initializeRun() async {
@@ -225,6 +232,29 @@ class BuildExamplesCommand extends PackageLoopingCommand {
225232
}
226233
}
227234

235+
final File pluginToolsConfig =
236+
example.directory.childFile(_pluginToolsConfigFileName);
237+
if (pluginToolsConfig.existsSync()) {
238+
final Object? configuration =
239+
loadYaml(pluginToolsConfig.readAsStringSync());
240+
if (configuration is! YamlList ||
241+
configuration.any((Object? value) => value is! String)) {
242+
printError(
243+
'The $_pluginToolsConfigFileName file must consist of a list of arguments');
244+
printError('to pass to `flutter build` command, as in:');
245+
printError(' - "--no-tree-shake-icons" ');
246+
printError(' - "--dart-define=buildmode=testing"');
247+
printError(
248+
'It appears that currently it does not match this format (the root is not');
249+
printError('a list of strings).');
250+
throw ToolExit(_exitInvalidPluginToolsConfig);
251+
}
252+
extraBuildFlags = <String>[
253+
...extraBuildFlags,
254+
...configuration.cast<String>()
255+
];
256+
}
257+
228258
final int exitCode = await processRunner.runAndStream(
229259
flutterCommand,
230260
<String>[

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.8.0
55

66
dependencies:
77
args: ^2.1.0

script/tool/test/build_examples_command_test.dart

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -679,5 +679,49 @@ void main() {
679679
]));
680680
});
681681
});
682+
683+
test('The .pluginToolsConfig.yaml file', () async {
684+
mockPlatform.isLinux = true;
685+
final Directory pluginDirectory = createFakePlugin('plugin', packagesDir,
686+
platformSupport: <String, PlatformDetails>{
687+
kPlatformLinux: const PlatformDetails(PlatformSupport.inline),
688+
kPlatformMacos: const PlatformDetails(PlatformSupport.inline),
689+
});
690+
691+
final Directory pluginExampleDirectory =
692+
pluginDirectory.childDirectory('example');
693+
694+
final File pluginExampleConfigFile =
695+
pluginExampleDirectory.childFile('.pluginToolsConfig.yaml');
696+
pluginExampleConfigFile.writeAsStringSync(' - "test argument"');
697+
698+
final List<String> output = <String>[
699+
...await runCapturingPrint(
700+
runner, <String>['build-examples', '--linux']),
701+
...await runCapturingPrint(
702+
runner, <String>['build-examples', '--macos']),
703+
];
704+
705+
expect(
706+
output,
707+
containsAllInOrder(<String>[
708+
'\nBUILDING plugin/example for Linux',
709+
'\nBUILDING plugin/example for macOS',
710+
]),
711+
);
712+
713+
expect(
714+
processRunner.recordedCalls,
715+
orderedEquals(<ProcessCall>[
716+
ProcessCall(
717+
getFlutterCommand(mockPlatform),
718+
const <String>['build', 'linux', 'test argument'],
719+
pluginExampleDirectory.path),
720+
ProcessCall(
721+
getFlutterCommand(mockPlatform),
722+
const <String>['build', 'macos', 'test argument'],
723+
pluginExampleDirectory.path),
724+
]));
725+
});
682726
});
683727
}

0 commit comments

Comments
 (0)