Add a note to generated plugins files (#45557)
There has been some confusion about whether or not
.flutter-plugins-dependencies should be tracked in version control or
not. Added a comment to both it and .flutter-plugins explaining that
it's generated and shouldn't be.
.flutter-plugins-dependencies is parsed through JSON, and the JSON spec
doesn't support comments. So unfortunately the note is living in an
arbitrary "_info" key instead of an obvious top level comment.
diff --git a/packages/flutter_tools/lib/src/plugins.dart b/packages/flutter_tools/lib/src/plugins.dart
index 12456fd..3a72c95 100644
--- a/packages/flutter_tools/lib/src/plugins.dart
+++ b/packages/flutter_tools/lib/src/plugins.dart
@@ -317,7 +317,8 @@
/// otherwise returns [false].
bool _writeFlutterPluginsList(FlutterProject project, List<Plugin> plugins) {
final List<dynamic> directAppDependencies = <dynamic>[];
- final StringBuffer flutterPluginsBuffer = StringBuffer();
+ const String info = 'This is a generated file; do not edit or check into version control.';
+ final StringBuffer flutterPluginsBuffer = StringBuffer('# $info\n');
final Set<String> pluginNames = <String>{};
for (Plugin plugin in plugins) {
@@ -334,7 +335,7 @@
final File pluginsFile = project.flutterPluginsFile;
final String oldPluginFileContent = _readFileContent(pluginsFile);
final String pluginFileContent = flutterPluginsBuffer.toString();
- if (pluginFileContent.isNotEmpty) {
+ if (pluginNames.isNotEmpty) {
pluginsFile.writeAsStringSync(pluginFileContent, flush: true);
} else {
if (pluginsFile.existsSync()) {
@@ -345,9 +346,10 @@
final File dependenciesFile = project.flutterPluginsDependenciesFile;
final String oldDependenciesFileContent = _readFileContent(dependenciesFile);
final String dependenciesFileContent = json.encode(<String, dynamic>{
+ '_info': '// $info',
'dependencyGraph': directAppDependencies,
});
- if (pluginFileContent.isNotEmpty) {
+ if (pluginNames.isNotEmpty) {
dependenciesFile.writeAsStringSync(dependenciesFileContent, flush: true);
} else {
if (dependenciesFile.existsSync()) {
diff --git a/packages/flutter_tools/test/general.shard/plugins_test.dart b/packages/flutter_tools/test/general.shard/plugins_test.dart
index 5d35408..0a84b8c 100644
--- a/packages/flutter_tools/test/general.shard/plugins_test.dart
+++ b/packages/flutter_tools/test/general.shard/plugins_test.dart
@@ -273,6 +273,7 @@
expect(flutterProject.flutterPluginsFile.existsSync(), true);
expect(flutterProject.flutterPluginsDependenciesFile.existsSync(), true);
expect(flutterProject.flutterPluginsFile.readAsStringSync(),
+ '# This is a generated file; do not edit or check into version control.\n'
'plugin-a=/.tmp_rand0/plugin.rand0/\n'
'plugin-b=/.tmp_rand0/plugin.rand1/\n'
'plugin-c=/.tmp_rand0/plugin.rand2/\n'
@@ -280,6 +281,7 @@
);
expect(flutterProject.flutterPluginsDependenciesFile.readAsStringSync(),
'{'
+ '"_info":"// This is a generated file; do not edit or check into version control.",'
'"dependencyGraph":['
'{'
'"name":"plugin-a",'