Skip to content

[flutter_tools] The asset bundle is not rebuilt if an asset file is edited between flutter test commands #143513

@osaxma

Description

@osaxma

While working in adding Iterable<E>.whereType<T> method to collection_methods_unrelated_type lint rule in 351781, I came across the following case, which caused some tests to fail because of the new warning:

info • The argument type 'DevFSFileContent' isn't related to 'Iterable<AssetBundleEntry>' • packages/flutter_tools/lib/src/commands/test.dart:613:67 • collection_methods_unrelated_type

I already investigated this one to see if my change produced a correct report, and I believe it did for this case.

In line 623 of the method below (you may need to scroll to see it), there's a mapping by type (i.e. entries.values.whereType<DevFSFileContent>()) which will always produce an empty Iterable since entries.values is Iterable<AssetBundleEntry> and that will never contain a DevFSFileContent:

bool _needRebuild(Map<String, AssetBundleEntry> entries) {
// TODO(andrewkolos): This logic might fail in the future if we change the
// schema of the contents of the asset manifest file and the user does not
// perform a `flutter clean` after upgrading.
// See https://github.com/flutter/flutter/issues/128563.
final File manifest = globals.fs.file(globals.fs.path.join('build', 'unit_test_assets', 'AssetManifest.bin'));
if (!manifest.existsSync()) {
return true;
}
final DateTime lastModified = manifest.lastModifiedSync();
final File pub = globals.fs.file('pubspec.yaml');
if (pub.lastModifiedSync().isAfter(lastModified)) {
return true;
}
for (final 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;
}
}

I assume this part should be something like this if I am not mistaken:

for (final DevFSFileContent entry in entries.values.map((asset) => asset.content).whereType<DevFSFileContent>())

Metadata

Metadata

Assignees

Labels

P1High-priority issues at the top of the work lista: assetsPackaging, accessing, or using assetsfound in release: 3.20Found to occur in 3.20r: fixedIssue is closed as already fixed in a newer versionteam-toolOwned by Flutter Tool teamtoolAffects the "flutter" command-line tool. See also t: labels.triaged-toolTriaged by Flutter Tool team

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions