mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00

This implements the `DartDependencySetBuilder` completely in Dart instead of calling out to `sky_snapshot` (Linux/Mac) or `gen_snapshot` (Windows) and allows us to use the same code path on all supported host platforms. It also slightly reduces hot reload times on Linux from ~750ms to ~690ms for the unchanged flutter_gallery app and significantly reduces hot reload times on Windows from almost 1.5s to just slightly slower than on Linux. This change will also allow us to retire `sky_snapshot` completely in the future.
46 lines
1.5 KiB
Dart
46 lines
1.5 KiB
Dart
// Copyright 2016 The Chromium Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
import 'asset.dart';
|
|
import 'base/file_system.dart';
|
|
import 'dart/dependencies.dart';
|
|
import 'globals.dart';
|
|
|
|
class DependencyChecker {
|
|
final DartDependencySetBuilder builder;
|
|
final Set<String> _dependencies = new Set<String>();
|
|
final AssetBundle assets;
|
|
DependencyChecker(this.builder, this.assets);
|
|
|
|
/// Returns [true] if any components have been modified after [threshold] or
|
|
/// if it cannot be determined.
|
|
bool check(DateTime threshold) {
|
|
_dependencies.clear();
|
|
// Build the set of Dart dependencies.
|
|
try {
|
|
_dependencies.addAll(builder.build());
|
|
} catch (e, st) {
|
|
printTrace('DependencyChecker: error determining .dart dependencies:\n$e\n$st');
|
|
return true;
|
|
}
|
|
// TODO(johnmccutchan): Extract dependencies from the AssetBundle too.
|
|
|
|
// Check all dependency modification times.
|
|
for (String path in _dependencies) {
|
|
final File file = fs.file(path);
|
|
final FileStat stat = file.statSync();
|
|
if (stat.type == FileSystemEntityType.NOT_FOUND) {
|
|
printTrace('DependencyChecker: Error stating $path.');
|
|
return true;
|
|
}
|
|
if (stat.modified.isAfter(threshold)) {
|
|
printTrace('DependencyChecker: $path is newer than $threshold');
|
|
return true;
|
|
}
|
|
}
|
|
printTrace('DependencyChecker: nothing is modified after $threshold.');
|
|
return false;
|
|
}
|
|
}
|