From 1f0c3d462e03515608007206926e32d47039a529 Mon Sep 17 00:00:00 2001 From: "James D. Lin" Date: Tue, 5 Nov 2019 21:40:48 -0800 Subject: [PATCH] Make ProjectFileInvalidator injectable (#44200) Allow ProjectFileInvalidator to be overridden with a different implementation. I stole this from https://github.com/flutter/flutter/pull/39217. --- packages/flutter_tools/lib/src/run_hot.dart | 12 ++++++++---- .../general.shard/project_file_invalidator_test.dart | 8 +++++--- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/packages/flutter_tools/lib/src/run_hot.dart b/packages/flutter_tools/lib/src/run_hot.dart index 82b359501c..970d332c7f 100644 --- a/packages/flutter_tools/lib/src/run_hot.dart +++ b/packages/flutter_tools/lib/src/run_hot.dart @@ -27,6 +27,10 @@ import 'reporting/reporting.dart'; import 'resident_runner.dart'; import 'vmservice.dart'; +ProjectFileInvalidator get projectFileInvalidator => context.get() ?? const ProjectFileInvalidator(); + +HotRunnerConfig get hotRunnerConfig => context.get(); + class HotRunnerConfig { /// Should the hot runner assume that the minimal Dart dependencies do not change? bool stableDartDependencies = false; @@ -46,8 +50,6 @@ class HotRunnerConfig { } } -HotRunnerConfig get hotRunnerConfig => context.get(); - const bool kHotReloadDefault = true; class DeviceReloadReport { @@ -301,7 +303,7 @@ class HotRunner extends ResidentRunner { // Picking up first device's compiler as a source of truth - compilers // for all devices should be in sync. - final List invalidatedFiles = await ProjectFileInvalidator.findInvalidated( + final List invalidatedFiles = await projectFileInvalidator.findInvalidated( lastCompiled: flutterDevices[0].devFS.lastCompiled, urisToMonitor: flutterDevices[0].devFS.sources, packagesPath: packagesFilePath, @@ -1047,6 +1049,8 @@ class HotRunner extends ResidentRunner { } class ProjectFileInvalidator { + const ProjectFileInvalidator(); + static const String _pubCachePathLinuxAndMac = '.pub-cache'; static const String _pubCachePathWindows = 'Pub/Cache'; @@ -1058,7 +1062,7 @@ class ProjectFileInvalidator { // ~2000 files. static const int _kMaxPendingStats = 8; - static Future> findInvalidated({ + Future> findInvalidated({ @required DateTime lastCompiled, @required List urisToMonitor, @required String packagesPath, diff --git a/packages/flutter_tools/test/general.shard/project_file_invalidator_test.dart b/packages/flutter_tools/test/general.shard/project_file_invalidator_test.dart index db1a4a9afc..0694528632 100644 --- a/packages/flutter_tools/test/general.shard/project_file_invalidator_test.dart +++ b/packages/flutter_tools/test/general.shard/project_file_invalidator_test.dart @@ -23,9 +23,11 @@ void main() { } void _testProjectFileInvalidator({@required bool asyncScanning}) { + const ProjectFileInvalidator projectFileInvalidator = ProjectFileInvalidator(); + testUsingContext('No last compile', () async { expect( - await ProjectFileInvalidator.findInvalidated( + await projectFileInvalidator.findInvalidated( lastCompiled: null, urisToMonitor: [], packagesPath: '', @@ -37,7 +39,7 @@ void _testProjectFileInvalidator({@required bool asyncScanning}) { testUsingContext('Empty project', () async { expect( - await ProjectFileInvalidator.findInvalidated( + await projectFileInvalidator.findInvalidated( lastCompiled: inFuture, urisToMonitor: [], packagesPath: '', @@ -52,7 +54,7 @@ void _testProjectFileInvalidator({@required bool asyncScanning}) { testUsingContext('Non-existent files are ignored', () async { expect( - await ProjectFileInvalidator.findInvalidated( + await projectFileInvalidator.findInvalidated( lastCompiled: inFuture, urisToMonitor: [Uri.parse('/not-there-anymore'),], packagesPath: '',