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 {
}
Future<UpdateFSReport> _updateDevFS({ bool fullRestart = false }) async {
final bool isFirstUpload = assetBundle.wasBuiltOnce() == false;
final bool isFirstUpload = !assetBundle.wasBuiltOnce();
final bool rebuildBundle = assetBundle.needsBuild();
if (rebuildBundle) {
printTrace('Updating assets');
......@@ -308,7 +308,7 @@ class HotRunner extends ResidentRunner {
bundle: assetBundle,
firstBuildTime: firstBuildTime,
bundleFirstUpload: isFirstUpload,
bundleDirty: isFirstUpload == false && rebuildBundle,
bundleDirty: !isFirstUpload && rebuildBundle,
fullRestart: fullRestart,
projectRootPath: projectRootPath,
pathToReload: getReloadPath(fullRestart: fullRestart),
......@@ -1045,6 +1045,14 @@ class ProjectFileInvalidator {
@required List<Uri> urisToMonitor,
@required String packagesPath,
}) {
assert(urisToMonitor != null);
assert(packagesPath != null);
if (lastCompiled == null) {
assert(urisToMonitor.isEmpty);
return <Uri>[];
}
final List<Uri> invalidatedFiles = <Uri>[];
int scanned = 0;
final Stopwatch stopwatch = Stopwatch()..start();
......@@ -1057,17 +1065,13 @@ class ProjectFileInvalidator {
final DateTime updatedAt = fs.statSync(
uri.toFilePath(windows: platform.isWindows)).modified;
scanned++;
if (updatedAt == null) {
continue;
}
if (updatedAt.millisecondsSinceEpoch > lastCompiled.millisecondsSinceEpoch) {
if (updatedAt != null && updatedAt.isAfter(lastCompiled)) {
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;
if (lastCompiled != null && packagesUpdatedAt != null
&& packagesUpdatedAt.millisecondsSinceEpoch > lastCompiled.millisecondsSinceEpoch) {
if (packagesUpdatedAt != null && packagesUpdatedAt.isAfter(lastCompiled)) {
invalidatedFiles.add(fs.file(packagesPath).uri);
scanned++;
}
......
......@@ -12,6 +12,12 @@ import '../src/context.dart';
void main() {
group('ProjectFileInvalidator', () {
final MemoryFileSystem memoryFileSystem = MemoryFileSystem();
testUsingContext('No last compile', () async {
expect(
ProjectFileInvalidator.findInvalidated(lastCompiled: null, urisToMonitor: <Uri>[], packagesPath: ''),
isEmpty);
});
testUsingContext('Empty project', () async {
expect(
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