Unverified Commit 14c5c6e1 authored by James D. Lin's avatar James D. Lin Committed by GitHub

Clean up ProjectFileInvalidator.findInvalidated a bit (#41889)

In preparation for some refactoring that I will be doing to
`ProjectFileInvalidator.findInvalidated`, make its code a bit
clearer:
* Indicate which arguments may be null.
* Don't bother calling `FileStat.statSync` on the `.packages` file
  for the initial load.  This makes the checks for the `.packages`
  file consistent with those for other files.
* Use `DateTime.isAfter()` instead of comparing microseconds
  ourselves.

While I was touching this file, I also removed some unnecessary
comparisons to `false`. (`_ManifestAssetBundle.wasBuiltOnce()` is the
only implementation I can find of `AssetBundle.wasBuiltOnce()`, and
it never returns `null`.)
parent 3024053c
...@@ -283,7 +283,7 @@ class HotRunner extends ResidentRunner { ...@@ -283,7 +283,7 @@ class HotRunner extends ResidentRunner {
} }
Future<UpdateFSReport> _updateDevFS({ bool fullRestart = false }) async { Future<UpdateFSReport> _updateDevFS({ bool fullRestart = false }) async {
final bool isFirstUpload = assetBundle.wasBuiltOnce() == false; final bool isFirstUpload = !assetBundle.wasBuiltOnce();
final bool rebuildBundle = assetBundle.needsBuild(); final bool rebuildBundle = assetBundle.needsBuild();
if (rebuildBundle) { if (rebuildBundle) {
printTrace('Updating assets'); printTrace('Updating assets');
...@@ -308,7 +308,7 @@ class HotRunner extends ResidentRunner { ...@@ -308,7 +308,7 @@ class HotRunner extends ResidentRunner {
bundle: assetBundle, bundle: assetBundle,
firstBuildTime: firstBuildTime, firstBuildTime: firstBuildTime,
bundleFirstUpload: isFirstUpload, bundleFirstUpload: isFirstUpload,
bundleDirty: isFirstUpload == false && rebuildBundle, bundleDirty: !isFirstUpload && rebuildBundle,
fullRestart: fullRestart, fullRestart: fullRestart,
projectRootPath: projectRootPath, projectRootPath: projectRootPath,
pathToReload: getReloadPath(fullRestart: fullRestart), pathToReload: getReloadPath(fullRestart: fullRestart),
...@@ -1045,6 +1045,14 @@ class ProjectFileInvalidator { ...@@ -1045,6 +1045,14 @@ class ProjectFileInvalidator {
@required List<Uri> urisToMonitor, @required List<Uri> urisToMonitor,
@required String packagesPath, @required String packagesPath,
}) { }) {
assert(urisToMonitor != null);
assert(packagesPath != null);
if (lastCompiled == null) {
assert(urisToMonitor.isEmpty);
return <Uri>[];
}
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();
...@@ -1057,17 +1065,13 @@ class ProjectFileInvalidator { ...@@ -1057,17 +1065,13 @@ class ProjectFileInvalidator {
final DateTime updatedAt = fs.statSync( final DateTime updatedAt = fs.statSync(
uri.toFilePath(windows: platform.isWindows)).modified; uri.toFilePath(windows: platform.isWindows)).modified;
scanned++; scanned++;
if (updatedAt == null) { if (updatedAt != null && updatedAt.isAfter(lastCompiled)) {
continue;
}
if (updatedAt.millisecondsSinceEpoch > lastCompiled.millisecondsSinceEpoch) {
invalidatedFiles.add(uri); invalidatedFiles.add(uri);
} }
} }
// we need to check the .packages file too since it is not used in compilation. // We need to check the .packages file too since it is not used in compilation.
final DateTime packagesUpdatedAt = fs.statSync(packagesPath).modified; final DateTime packagesUpdatedAt = fs.statSync(packagesPath).modified;
if (lastCompiled != null && packagesUpdatedAt != null if (packagesUpdatedAt != null && packagesUpdatedAt.isAfter(lastCompiled)) {
&& packagesUpdatedAt.millisecondsSinceEpoch > lastCompiled.millisecondsSinceEpoch) {
invalidatedFiles.add(fs.file(packagesPath).uri); invalidatedFiles.add(fs.file(packagesPath).uri);
scanned++; scanned++;
} }
......
...@@ -12,6 +12,12 @@ import '../src/context.dart'; ...@@ -12,6 +12,12 @@ import '../src/context.dart';
void main() { void main() {
group('ProjectFileInvalidator', () { group('ProjectFileInvalidator', () {
final MemoryFileSystem memoryFileSystem = MemoryFileSystem(); final MemoryFileSystem memoryFileSystem = MemoryFileSystem();
testUsingContext('No last compile', () async {
expect(
ProjectFileInvalidator.findInvalidated(lastCompiled: null, urisToMonitor: <Uri>[], packagesPath: ''),
isEmpty);
});
testUsingContext('Empty project', () async { testUsingContext('Empty project', () async {
expect( expect(
ProjectFileInvalidator.findInvalidated(lastCompiled: DateTime.now(), urisToMonitor: <Uri>[], packagesPath: ''), ProjectFileInvalidator.findInvalidated(lastCompiled: DateTime.now(), urisToMonitor: <Uri>[], packagesPath: ''),
......
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