From 901eb0fc8169353c4b36cbaa92e3edbc33497ad8 Mon Sep 17 00:00:00 2001 From: Michael Klimushyn Date: Mon, 25 Nov 2019 11:47:20 -0800 Subject: [PATCH] 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. --- packages/flutter_tools/lib/src/plugins.dart | 8 +++++--- .../flutter_tools/test/general.shard/plugins_test.dart | 2 ++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/packages/flutter_tools/lib/src/plugins.dart b/packages/flutter_tools/lib/src/plugins.dart index 12456fd19e..3a72c95e77 100644 --- a/packages/flutter_tools/lib/src/plugins.dart +++ b/packages/flutter_tools/lib/src/plugins.dart @@ -317,7 +317,8 @@ List findPlugins(FlutterProject project) { /// otherwise returns [false]. bool _writeFlutterPluginsList(FlutterProject project, List plugins) { final List directAppDependencies = []; - 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 pluginNames = {}; for (Plugin plugin in plugins) { @@ -334,7 +335,7 @@ bool _writeFlutterPluginsList(FlutterProject project, List plugins) { 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 @@ bool _writeFlutterPluginsList(FlutterProject project, List plugins) { final File dependenciesFile = project.flutterPluginsDependenciesFile; final String oldDependenciesFileContent = _readFileContent(dependenciesFile); final String dependenciesFileContent = json.encode({ + '_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 5d3540877c..0a84b8cc60 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 @@ dependencies: 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 @@ dependencies: ); expect(flutterProject.flutterPluginsDependenciesFile.readAsStringSync(), '{' + '"_info":"// This is a generated file; do not edit or check into version control.",' '"dependencyGraph":[' '{' '"name":"plugin-a",'