From 441bb070fe6e6ace5dcd058856fcdb2f0847ae54 Mon Sep 17 00:00:00 2001 From: Matan Lurey Date: Thu, 13 Feb 2025 21:40:03 -0800 Subject: [PATCH] Add `.flutter-plugins-dependencies` to `FlutterBuildSystem`; update logic, add tests. (#163278) I happened to run into this while chasing other bugs, and noticed `.flutter-plugins-dependencies` is omitted. I am guessing this is probably quite stale, but something something [Chesterton's fence](https://en.wiktionary.org/wiki/Chesterton%27s_fence), and added tests. --- .../lib/src/build_system/build_system.dart | 17 +++-- .../build_system/build_system_test.dart | 73 +++++++++++++++++++ 2 files changed, 84 insertions(+), 6 deletions(-) diff --git a/packages/flutter_tools/lib/src/build_system/build_system.dart b/packages/flutter_tools/lib/src/build_system/build_system.dart index b93eeb3622..2fe3111c51 100644 --- a/packages/flutter_tools/lib/src/build_system/build_system.dart +++ b/packages/flutter_tools/lib/src/build_system/build_system.dart @@ -639,15 +639,20 @@ class FlutterBuildSystem extends BuildSystem { // We also remove files under .dart_tool, since these are intermediaries // and don't need to be tracked by external systems. { + bool isUnconditionalFile(String path) { + return switch (_fileSystem.path.basename(path)) { + '.flutter-plugins' || '.flutter-plugins-dependencies' => true, + _ when _fileSystem.path.extension(path) == '.xcconfig' => true, + _ when _fileSystem.path.split(path).contains('.dart_tool') => true, + _ => false, + }; + } + buildInstance.inputFiles.removeWhere((String path, File file) { - return path.contains('.flutter-plugins') || - path.contains('xcconfig') || - path.contains('.dart_tool'); + return isUnconditionalFile(path); }); buildInstance.outputFiles.removeWhere((String path, File file) { - return path.contains('.flutter-plugins') || - path.contains('xcconfig') || - path.contains('.dart_tool'); + return isUnconditionalFile(path); }); } trackSharedBuildDirectory(environment, _fileSystem, buildInstance.outputFiles); diff --git a/packages/flutter_tools/test/general.shard/build_system/build_system_test.dart b/packages/flutter_tools/test/general.shard/build_system/build_system_test.dart index e7b75b2640..72c8b6005a 100644 --- a/packages/flutter_tools/test/general.shard/build_system/build_system_test.dart +++ b/packages/flutter_tools/test/general.shard/build_system/build_system_test.dart @@ -152,6 +152,79 @@ void main() { expect(result.outputFiles.single.path, '${environment.buildDir.path}/out'); }); + group('BuildResult.outputs filtering', () { + final TestTarget allFilesTarget = + TestTarget((Environment environment) async {}) + ..name = 'allTextFiles' + ..inputs = const [ + Source.pattern('{PROJECT_DIR}/*'), + Source.pattern('{PROJECT_DIR}/*/*'), + ] + ..outputs = const [Source.pattern('{BUILD_DIR}/out')] + ..dependencies = []; + late BuildSystem buildSystem; + + setUp(() { + buildSystem = setUpBuildSystem(fileSystem); + }); + + testWithoutContext('normally would update when something has changed', () async { + environment.projectDir.childFile('foo.dart').createSync(); + final BuildResult result = await buildSystem.build(allFilesTarget, environment); + expect( + result.inputFiles, + contains(isA().having((File f) => f.path, 'path', endsWith('foo.dart'))), + ); + }); + + testWithoutContext('ignores the .dart_tool directory', () async { + environment.projectDir.childDirectory('.dart_tool').createSync(); + environment.projectDir.childDirectory('.dart_tool').childFile('IGNORE_ME.txt').createSync(); + final BuildResult result = await buildSystem.build(allFilesTarget, environment); + expect( + result.inputFiles, + isNot(contains(isA().having((File f) => f.path, 'path', endsWith('IGNORE_ME.txt')))), + ); + }); + + testWithoutContext('ignores files named .flutter-plugins', () async { + environment.projectDir.childFile('.flutter-plugins').createSync(); + final BuildResult result = await buildSystem.build(allFilesTarget, environment); + expect( + result.inputFiles, + isNot( + contains(isA().having((File f) => f.path, 'path', endsWith('.flutter-plugins'))), + ), + ); + }); + + testWithoutContext('ignores files named .flutter-plugins-dependencies', () async { + environment.projectDir.childFile('.flutter-plugins-dependencies').createSync(); + final BuildResult result = await buildSystem.build(allFilesTarget, environment); + expect( + result.inputFiles, + isNot( + contains( + isA().having( + (File f) => f.path, + 'path', + endsWith('.flutter-plugins-dependencies'), + ), + ), + ), + ); + }); + + testWithoutContext('ignores files ending with .xcconfig', () async { + environment.projectDir.childFile('foo.xcconfig').createSync(); + final BuildResult result = await buildSystem.build(allFilesTarget, environment); + expect( + result.inputFiles, + isNot(contains(isA().having((File f) => f.path, 'path', endsWith('.xcconfig')))), + ); + }); + }); + testWithoutContext('Does not re-invoke build if stamp is valid', () async { final BuildSystem buildSystem = setUpBuildSystem(fileSystem);