From fc9f7dea1aef7da5bbf4def16d9e43bb16384150 Mon Sep 17 00:00:00 2001 From: Jonah Williams Date: Thu, 21 Mar 2019 13:59:38 -0700 Subject: [PATCH] Allowing adding/updating packages during hot reload (#29747) --- packages/flutter_tools/lib/src/devfs.dart | 3 +++ packages/flutter_tools/lib/src/run_hot.dart | 18 +++++++++++++++--- .../test/project_file_invalidator_test.dart | 6 ++++-- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/packages/flutter_tools/lib/src/devfs.dart b/packages/flutter_tools/lib/src/devfs.dart index c825689790..73e0214d81 100644 --- a/packages/flutter_tools/lib/src/devfs.dart +++ b/packages/flutter_tools/lib/src/devfs.dart @@ -481,6 +481,9 @@ class DevFS { outputPath: dillOutputPath ?? getDefaultApplicationKernelPath(trackWidgetCreation: trackWidgetCreation), packagesFilePath : _packagesFilePath, ); + if (compilerOutput == null) { + return UpdateFSReport(success: false); + } // list of sources that needs to be monitored are in [compilerOutput.sources] sources = compilerOutput.sources; // diff --git a/packages/flutter_tools/lib/src/run_hot.dart b/packages/flutter_tools/lib/src/run_hot.dart index bf5e325063..50f445d784 100644 --- a/packages/flutter_tools/lib/src/run_hot.dart +++ b/packages/flutter_tools/lib/src/run_hot.dart @@ -317,7 +317,9 @@ class HotRunner extends ResidentRunner { // for all devices should be in sync. final List invalidatedFiles = ProjectFileInvalidator.findInvalidated( lastCompiled: flutterDevices[0].devFS.lastCompiled, - urisToMonitor: flutterDevices[0].devFS.sources); + urisToMonitor: flutterDevices[0].devFS.sources, + packagesPath: packagesFilePath, + ); final UpdateFSReport results = UpdateFSReport(success: true); for (FlutterDevice device in flutterDevices) { results.incorporateResults(await device.updateDevFS( @@ -939,8 +941,11 @@ class ProjectFileInvalidator { static const String _pubCachePathLinuxAndMac = '.pub-cache'; static const String _pubCachePathWindows = 'Pub/Cache'; - static List findInvalidated({@required DateTime lastCompiled, - @required List urisToMonitor}) { + static List findInvalidated({ + @required DateTime lastCompiled, + @required List urisToMonitor, + @required String packagesPath, + }) { final List invalidatedFiles = []; int scanned = 0; final Stopwatch stopwatch = Stopwatch()..start(); @@ -960,6 +965,13 @@ class ProjectFileInvalidator { invalidatedFiles.add(uri); } } + // we need to check the .packages file too since it is not used in compilation. + final DateTime packagesUpdatedAt = fs.statSync(packagesPath).modified; + if (lastCompiled != null && packagesUpdatedAt != null + && packagesUpdatedAt.millisecondsSinceEpoch > lastCompiled.millisecondsSinceEpoch) { + invalidatedFiles.add(fs.file(packagesPath).uri); + scanned++; + } printTrace('Scanned through $scanned files in ${stopwatch.elapsedMilliseconds}ms'); return invalidatedFiles; } diff --git a/packages/flutter_tools/test/project_file_invalidator_test.dart b/packages/flutter_tools/test/project_file_invalidator_test.dart index 6beff734e8..c13a38da20 100644 --- a/packages/flutter_tools/test/project_file_invalidator_test.dart +++ b/packages/flutter_tools/test/project_file_invalidator_test.dart @@ -14,7 +14,7 @@ void main() { final MemoryFileSystem memoryFileSystem = MemoryFileSystem(); testUsingContext('Empty project', () async { expect( - ProjectFileInvalidator.findInvalidated(lastCompiled: DateTime.now(), urisToMonitor: []), + ProjectFileInvalidator.findInvalidated(lastCompiled: DateTime.now(), urisToMonitor: [], packagesPath: ''), isEmpty); }, overrides: { FileSystem: () => memoryFileSystem, @@ -24,7 +24,9 @@ void main() { expect( ProjectFileInvalidator.findInvalidated( lastCompiled: DateTime.now(), - urisToMonitor: [Uri.parse('/not-there-anymore')]), + urisToMonitor: [Uri.parse('/not-there-anymore'),], + packagesPath: '', + ), isEmpty); }, overrides: { FileSystem: () => memoryFileSystem,