Unverified Commit fc9f7dea authored by Jonah Williams's avatar Jonah Williams Committed by GitHub

Allowing adding/updating packages during hot reload (#29747)

parent c80366a1
...@@ -481,6 +481,9 @@ class DevFS { ...@@ -481,6 +481,9 @@ class DevFS {
outputPath: dillOutputPath ?? getDefaultApplicationKernelPath(trackWidgetCreation: trackWidgetCreation), outputPath: dillOutputPath ?? getDefaultApplicationKernelPath(trackWidgetCreation: trackWidgetCreation),
packagesFilePath : _packagesFilePath, packagesFilePath : _packagesFilePath,
); );
if (compilerOutput == null) {
return UpdateFSReport(success: false);
}
// list of sources that needs to be monitored are in [compilerOutput.sources] // list of sources that needs to be monitored are in [compilerOutput.sources]
sources = compilerOutput.sources; sources = compilerOutput.sources;
// //
......
...@@ -317,7 +317,9 @@ class HotRunner extends ResidentRunner { ...@@ -317,7 +317,9 @@ class HotRunner extends ResidentRunner {
// for all devices should be in sync. // for all devices should be in sync.
final List<Uri> invalidatedFiles = ProjectFileInvalidator.findInvalidated( final List<Uri> invalidatedFiles = ProjectFileInvalidator.findInvalidated(
lastCompiled: flutterDevices[0].devFS.lastCompiled, lastCompiled: flutterDevices[0].devFS.lastCompiled,
urisToMonitor: flutterDevices[0].devFS.sources); urisToMonitor: flutterDevices[0].devFS.sources,
packagesPath: packagesFilePath,
);
final UpdateFSReport results = UpdateFSReport(success: true); final UpdateFSReport results = UpdateFSReport(success: true);
for (FlutterDevice device in flutterDevices) { for (FlutterDevice device in flutterDevices) {
results.incorporateResults(await device.updateDevFS( results.incorporateResults(await device.updateDevFS(
...@@ -939,8 +941,11 @@ class ProjectFileInvalidator { ...@@ -939,8 +941,11 @@ class ProjectFileInvalidator {
static const String _pubCachePathLinuxAndMac = '.pub-cache'; static const String _pubCachePathLinuxAndMac = '.pub-cache';
static const String _pubCachePathWindows = 'Pub/Cache'; static const String _pubCachePathWindows = 'Pub/Cache';
static List<Uri> findInvalidated({@required DateTime lastCompiled, static List<Uri> findInvalidated({
@required List<Uri> urisToMonitor}) { @required DateTime lastCompiled,
@required List<Uri> urisToMonitor,
@required String packagesPath,
}) {
final List<Uri> invalidatedFiles = <Uri>[]; final List<Uri> invalidatedFiles = <Uri>[];
int scanned = 0; int scanned = 0;
final Stopwatch stopwatch = Stopwatch()..start(); final Stopwatch stopwatch = Stopwatch()..start();
...@@ -960,6 +965,13 @@ class ProjectFileInvalidator { ...@@ -960,6 +965,13 @@ class ProjectFileInvalidator {
invalidatedFiles.add(uri); 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'); printTrace('Scanned through $scanned files in ${stopwatch.elapsedMilliseconds}ms');
return invalidatedFiles; return invalidatedFiles;
} }
......
...@@ -14,7 +14,7 @@ void main() { ...@@ -14,7 +14,7 @@ void main() {
final MemoryFileSystem memoryFileSystem = MemoryFileSystem(); final MemoryFileSystem memoryFileSystem = MemoryFileSystem();
testUsingContext('Empty project', () async { testUsingContext('Empty project', () async {
expect( expect(
ProjectFileInvalidator.findInvalidated(lastCompiled: DateTime.now(), urisToMonitor: <Uri>[]), ProjectFileInvalidator.findInvalidated(lastCompiled: DateTime.now(), urisToMonitor: <Uri>[], packagesPath: ''),
isEmpty); isEmpty);
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
FileSystem: () => memoryFileSystem, FileSystem: () => memoryFileSystem,
...@@ -24,7 +24,9 @@ void main() { ...@@ -24,7 +24,9 @@ void main() {
expect( expect(
ProjectFileInvalidator.findInvalidated( ProjectFileInvalidator.findInvalidated(
lastCompiled: DateTime.now(), lastCompiled: DateTime.now(),
urisToMonitor: <Uri>[Uri.parse('/not-there-anymore')]), urisToMonitor: <Uri>[Uri.parse('/not-there-anymore'),],
packagesPath: '',
),
isEmpty); isEmpty);
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
FileSystem: () => memoryFileSystem, FileSystem: () => memoryFileSystem,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment