Unverified Commit d121df99 authored by chunhtai's avatar chunhtai Committed by GitHub

fix 31511: Test performance has regressed (#31582)

parent 14f2f98f
......@@ -13,6 +13,7 @@ import '../bundle.dart';
import '../cache.dart';
import '../codegen.dart';
import '../dart/pub.dart';
import '../devfs.dart';
import '../globals.dart';
import '../project.dart';
import '../runner/flutter_command.dart';
......@@ -239,7 +240,30 @@ class TestCommand extends FastFlutterCommand {
if (build != 0) {
throwToolExit('Error: Failed to build asset bundle');
}
await writeBundle(fs.directory(fs.path.join('build', 'unit_test_assets')), assetBundle.entries);
if (_needRebuild(assetBundle.entries)) {
await writeBundle(fs.directory(fs.path.join('build', 'unit_test_assets')),
assetBundle.entries);
}
}
bool _needRebuild(Map<String, DevFSContent> entries) {
final File manifest = fs.file(fs.path.join('build', 'unit_test_assets', 'AssetManifest.json'));
if (!manifest.existsSync()) {
return true;
}
final DateTime lastModified = manifest.lastModifiedSync();
final File pub = fs.file('pubspec.yaml');
if (pub.lastModifiedSync().isAfter(lastModified)) {
return true;
}
for (DevFSFileContent entry in entries.values.whereType<DevFSFileContent>()) {
// Calling isModified to access file stats first in order for isModifiedAfter
// to work.
if (entry.isModified && entry.isModifiedAfter(lastModified)) {
return true;
}
}
return false;
}
}
......
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