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

Commit af7488c

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

File tree

4 files changed

+81
-2
lines changed

4 files changed

+81
-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: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
// found in the LICENSE file.
44

55
import 'dart:async';
6+
import 'dart:io';
67

78
import 'package:file/file.dart';
89
import 'package:platform/platform.dart';
10+
import 'package:yaml/yaml.dart';
911

1012
import 'common/core.dart';
1113
import 'common/package_looping_command.dart';
@@ -16,7 +18,10 @@ import 'common/repository_package.dart';
1618
/// Key for APK.
1719
const String _platformFlagApk = 'apk';
1820

21+
const String _pluginToolsConfigFileName = '.pluginToolsConfig.yaml';
22+
1923
const int _exitNoPlatformFlags = 3;
24+
const int _exitInvalidPluginToolsConfig = 4;
2025

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

104112
@override
105113
Future<void> initializeRun() async {
@@ -225,6 +233,29 @@ class BuildExamplesCommand extends PackageLoopingCommand {
225233
}
226234
}
227235

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