From 6abef222514e8039bde5c47ab7864abbc4caf7e8 Mon Sep 17 00:00:00 2001 From: Rexios Date: Wed, 4 Sep 2024 16:54:24 -0400 Subject: [PATCH] [tool] Update `.gitignore` templates to include `.flutter-plugins` files (#152950) Fixes https://github.com/flutter/flutter/issues/152793 --- .../templates/package/.gitignore.tmpl | 2 + .../templates/package_ffi/.gitignore.tmpl | 2 + .../templates/plugin_shared/.gitignore.tmpl | 2 + .../commands.shard/permeable/create_test.dart | 74 ++++++++++++++----- 4 files changed, 61 insertions(+), 19 deletions(-) diff --git a/packages/flutter_tools/templates/package/.gitignore.tmpl b/packages/flutter_tools/templates/package/.gitignore.tmpl index ac5aa9893e..eb6c05cd3d 100644 --- a/packages/flutter_tools/templates/package/.gitignore.tmpl +++ b/packages/flutter_tools/templates/package/.gitignore.tmpl @@ -26,4 +26,6 @@ migrate_working_dir/ /pubspec.lock **/doc/api/ .dart_tool/ +.flutter-plugins +.flutter-plugins-dependencies build/ diff --git a/packages/flutter_tools/templates/package_ffi/.gitignore.tmpl b/packages/flutter_tools/templates/package_ffi/.gitignore.tmpl index 96486fd930..da66cc90cd 100644 --- a/packages/flutter_tools/templates/package_ffi/.gitignore.tmpl +++ b/packages/flutter_tools/templates/package_ffi/.gitignore.tmpl @@ -26,5 +26,7 @@ migrate_working_dir/ /pubspec.lock **/doc/api/ .dart_tool/ +.flutter-plugins +.flutter-plugins-dependencies .packages build/ diff --git a/packages/flutter_tools/templates/plugin_shared/.gitignore.tmpl b/packages/flutter_tools/templates/plugin_shared/.gitignore.tmpl index ea810a521d..e7d347d9d3 100644 --- a/packages/flutter_tools/templates/plugin_shared/.gitignore.tmpl +++ b/packages/flutter_tools/templates/plugin_shared/.gitignore.tmpl @@ -28,4 +28,6 @@ migrate_working_dir/ /pubspec.lock **/doc/api/ .dart_tool/ +.flutter-plugins +.flutter-plugins-dependencies build/ diff --git a/packages/flutter_tools/test/commands.shard/permeable/create_test.dart b/packages/flutter_tools/test/commands.shard/permeable/create_test.dart index 11734f1be7..aa0a1ff115 100644 --- a/packages/flutter_tools/test/commands.shard/permeable/create_test.dart +++ b/packages/flutter_tools/test/commands.shard/permeable/create_test.dart @@ -66,6 +66,12 @@ const String samplesIndexJson = ''' { "id": "sample2" } ]'''; +/// These files are generated for all project types. +const List flutterPluginsIgnores = [ + '.flutter-plugins', + '.flutter-plugins-dependencies', +]; + void main() { late Directory tempDir; late Directory projectDir; @@ -177,6 +183,7 @@ void main() { 'ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage.png', 'lib/main.dart', ], + expectedGitignoreLines: flutterPluginsIgnores, ); expect(logger.statusText, contains('In order to run your application, type:')); // Check that we're telling them about documentation @@ -246,6 +253,7 @@ void main() { 'pubspec.yaml', 'README.md', ], + expectedGitignoreLines: flutterPluginsIgnores, ); return _runFlutterTest(projectDir); }, overrides: { @@ -288,22 +296,28 @@ void main() { }); testUsingContext('creates a module project correctly', () async { - await _createAndAnalyzeProject(projectDir, [ - '--template=module', - ], [ - '.android/app/', - '.gitignore', - '.ios/Flutter', - '.metadata', - 'analysis_options.yaml', - 'lib/main.dart', - 'pubspec.yaml', - 'README.md', - 'test/widget_test.dart', - ], unexpectedPaths: [ - 'android/', - 'ios/', - ]); + await _createAndAnalyzeProject( + projectDir, + [ + '--template=module', + ], + [ + '.android/app/', + '.gitignore', + '.ios/Flutter', + '.metadata', + 'analysis_options.yaml', + 'lib/main.dart', + 'pubspec.yaml', + 'README.md', + 'test/widget_test.dart', + ], + unexpectedPaths: [ + 'android/', + 'ios/', + ], + expectedGitignoreLines: flutterPluginsIgnores, + ); return _runFlutterTest(projectDir); }, overrides: { Pub: () => Pub.test( @@ -568,6 +582,7 @@ void main() { 'linux/flutter/generated_plugins.cmake', 'macos/Flutter/GeneratedPluginRegistrant.swift', ], + expectedGitignoreLines: flutterPluginsIgnores, ); return _runFlutterTest(projectDir); }, overrides: { @@ -599,6 +614,7 @@ void main() { 'example/android/app/src/main/java/com/example/flutter_project_example/MainActivity.java', 'lib/flutter_project_web.dart', ], + expectedGitignoreLines: flutterPluginsIgnores, ); return _runFlutterTest(projectDir.childDirectory('example')); }, overrides: { @@ -2148,6 +2164,7 @@ void main() { 'ios/Flutter/AppFrameworkInfo.plist', ], unexpectedPaths: ['test'], + expectedGitignoreLines: flutterPluginsIgnores, ); expect(projectDir.childDirectory('lib').childFile('main.dart').readAsStringSync(), contains("Text('Hello World!')")); @@ -2236,6 +2253,7 @@ void main() { 'ios/Flutter/AppFrameworkInfo.plist', ], unexpectedPaths: ['test'], + expectedGitignoreLines: flutterPluginsIgnores, ); expect(projectDir.childDirectory('lib').childFile('main.dart').readAsStringSync(), contains('void main() {}')); @@ -3915,6 +3933,7 @@ Future _createProject( List createArgs, List expectedPaths, { List unexpectedPaths = const [], + List expectedGitignoreLines = const [], }) async { Cache.flutterRoot = '../..'; final CreateCommand command = CreateCommand(); @@ -3930,7 +3949,7 @@ Future _createProject( return globals.fs.typeSync(fullPath) != FileSystemEntityType.notFound; } - final List failures = [ + final List pathFailures = [ for (final String path in expectedPaths) if (!pathExists(path)) 'Path "$path" does not exist.', @@ -3938,7 +3957,17 @@ Future _createProject( if (pathExists(path)) 'Path "$path" exists when it shouldn\'t.', ]; - expect(failures, isEmpty, reason: failures.join('\n')); + expect(pathFailures, isEmpty, reason: pathFailures.join('\n')); + + final String gitignorePath = globals.fs.path.join(dir.path, '.gitignore'); + final List gitignore = globals.fs.file(gitignorePath).readAsLinesSync(); + + final List gitignoreFailures = [ + for (final String line in expectedGitignoreLines) + if (!gitignore.contains(line)) + 'Expected .gitignore to contain "$line".', + ]; + expect(gitignoreFailures, isEmpty, reason: gitignoreFailures.join('\n')); } Future _createAndAnalyzeProject( @@ -3946,8 +3975,15 @@ Future _createAndAnalyzeProject( List createArgs, List expectedPaths, { List unexpectedPaths = const [], + List expectedGitignoreLines = const [], }) async { - await _createProject(dir, createArgs, expectedPaths, unexpectedPaths: unexpectedPaths); + await _createProject( + dir, + createArgs, + expectedPaths, + unexpectedPaths: unexpectedPaths, + expectedGitignoreLines: expectedGitignoreLines, + ); await _analyzeProject(dir.path); }