Skip to content

Commit fc9f7de

Browse files
Allowing adding/updating packages during hot reload (flutter#29747)
1 parent c80366a commit fc9f7de

File tree

3 files changed

+22
-5
lines changed

3 files changed

+22
-5
lines changed

packages/flutter_tools/lib/src/devfs.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,9 @@ class DevFS {
481481
outputPath: dillOutputPath ?? getDefaultApplicationKernelPath(trackWidgetCreation: trackWidgetCreation),
482482
packagesFilePath : _packagesFilePath,
483483
);
484+
if (compilerOutput == null) {
485+
return UpdateFSReport(success: false);
486+
}
484487
// list of sources that needs to be monitored are in [compilerOutput.sources]
485488
sources = compilerOutput.sources;
486489
//

packages/flutter_tools/lib/src/run_hot.dart

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,9 @@ class HotRunner extends ResidentRunner {
317317
// for all devices should be in sync.
318318
final List<Uri> invalidatedFiles = ProjectFileInvalidator.findInvalidated(
319319
lastCompiled: flutterDevices[0].devFS.lastCompiled,
320-
urisToMonitor: flutterDevices[0].devFS.sources);
320+
urisToMonitor: flutterDevices[0].devFS.sources,
321+
packagesPath: packagesFilePath,
322+
);
321323
final UpdateFSReport results = UpdateFSReport(success: true);
322324
for (FlutterDevice device in flutterDevices) {
323325
results.incorporateResults(await device.updateDevFS(
@@ -939,8 +941,11 @@ class ProjectFileInvalidator {
939941
static const String _pubCachePathLinuxAndMac = '.pub-cache';
940942
static const String _pubCachePathWindows = 'Pub/Cache';
941943

942-
static List<Uri> findInvalidated({@required DateTime lastCompiled,
943-
@required List<Uri> urisToMonitor}) {
944+
static List<Uri> findInvalidated({
945+
@required DateTime lastCompiled,
946+
@required List<Uri> urisToMonitor,
947+
@required String packagesPath,
948+
}) {
944949
final List<Uri> invalidatedFiles = <Uri>[];
945950
int scanned = 0;
946951
final Stopwatch stopwatch = Stopwatch()..start();
@@ -960,6 +965,13 @@ class ProjectFileInvalidator {
960965
invalidatedFiles.add(uri);
961966
}
962967
}
968+
// we need to check the .packages file too since it is not used in compilation.
969+
final DateTime packagesUpdatedAt = fs.statSync(packagesPath).modified;
970+
if (lastCompiled != null && packagesUpdatedAt != null
971+
&& packagesUpdatedAt.millisecondsSinceEpoch > lastCompiled.millisecondsSinceEpoch) {
972+
invalidatedFiles.add(fs.file(packagesPath).uri);
973+
scanned++;
974+
}
963975
printTrace('Scanned through $scanned files in ${stopwatch.elapsedMilliseconds}ms');
964976
return invalidatedFiles;
965977
}

packages/flutter_tools/test/project_file_invalidator_test.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ void main() {
1414
final MemoryFileSystem memoryFileSystem = MemoryFileSystem();
1515
testUsingContext('Empty project', () async {
1616
expect(
17-
ProjectFileInvalidator.findInvalidated(lastCompiled: DateTime.now(), urisToMonitor: <Uri>[]),
17+
ProjectFileInvalidator.findInvalidated(lastCompiled: DateTime.now(), urisToMonitor: <Uri>[], packagesPath: ''),
1818
isEmpty);
1919
}, overrides: <Type, Generator>{
2020
FileSystem: () => memoryFileSystem,
@@ -24,7 +24,9 @@ void main() {
2424
expect(
2525
ProjectFileInvalidator.findInvalidated(
2626
lastCompiled: DateTime.now(),
27-
urisToMonitor: <Uri>[Uri.parse('/not-there-anymore')]),
27+
urisToMonitor: <Uri>[Uri.parse('/not-there-anymore'),],
28+
packagesPath: '',
29+
),
2830
isEmpty);
2931
}, overrides: <Type, Generator>{
3032
FileSystem: () => memoryFileSystem,

0 commit comments

Comments
 (0)