Unverified Commit 377f4451 authored by Jonah Williams's avatar Jonah Williams Committed by GitHub

fix asset reloading (#29469)

parent 4e796415
......@@ -193,7 +193,7 @@ class _ManifestAssetBundle implements AssetBundle {
}
for (_Asset variant in assetVariants[asset]) {
assert(variant.assetFileExists);
entries[variant.entryUri.path] = DevFSFileContent(variant.assetFile);
entries[variant.entryUri.path] ??= DevFSFileContent(variant.assetFile);
}
}
......@@ -203,7 +203,7 @@ class _ManifestAssetBundle implements AssetBundle {
}
for (_Asset asset in materialAssets) {
assert(asset.assetFileExists);
entries[asset.entryUri.path] = DevFSFileContent(asset.assetFile);
entries[asset.entryUri.path] ??= DevFSFileContent(asset.assetFile);
}
entries[_assetManifestJson] = _createAssetManifest(assetVariants);
......
......@@ -385,7 +385,6 @@ class DevFS {
final String fsName;
final Directory rootDirectory;
String _packagesFilePath;
final Map<Uri, DevFSContent> _entries = <Uri, DevFSContent>{};
final Set<String> assetPathsToEvict = <String>{};
List<Uri> sources = <Uri>[];
DateTime lastCompiled;
......@@ -434,7 +433,6 @@ class DevFS {
AssetBundle bundle,
DateTime firstBuildTime,
bool bundleFirstUpload = false,
bool bundleDirty = false,
@required ResidentCompiler generator,
String dillOutputPath,
@required bool trackWidgetCreation,
......@@ -446,6 +444,11 @@ class DevFS {
assert(trackWidgetCreation != null);
assert(generator != null);
// Update modified files
final String assetBuildDirPrefix = _asUriPath(getAssetBuildDirectory());
final Map<Uri, DevFSContent> dirtyEntries = <Uri, DevFSContent>{};
int syncedBytes = 0;
if (bundle != null) {
printTrace('Scanning asset files');
// We write the assets into the AssetBundle working dir so that they
......@@ -453,29 +456,20 @@ class DevFS {
final String assetDirectory = getAssetBuildDirectory();
bundle.entries.forEach((String archivePath, DevFSContent content) {
final Uri deviceUri = fs.path.toUri(fs.path.join(assetDirectory, archivePath));
_entries[deviceUri] = content;
if (deviceUri.path.startsWith(assetBuildDirPrefix)) {
archivePath = deviceUri.path.substring(assetBuildDirPrefix.length);
}
// Only update assets if they have been modified, or if this is the
// first upload of the asset bundle.
if (content.isModified || (bundleFirstUpload && archivePath != null)) {
dirtyEntries[deviceUri] = content;
syncedBytes += content.size;
if (archivePath != null && !bundleFirstUpload) {
assetPathsToEvict.add(archivePath);
}
}
});
}
// Update modified files
final String assetBuildDirPrefix = _asUriPath(getAssetBuildDirectory());
final Map<Uri, DevFSContent> dirtyEntries = <Uri, DevFSContent>{};
int syncedBytes = 0;
_entries.forEach((Uri deviceUri, DevFSContent content) {
String archivePath;
if (deviceUri.path.startsWith(assetBuildDirPrefix))
archivePath = deviceUri.path.substring(assetBuildDirPrefix.length);
// When doing full restart, copy content so that isModified does not
// reset last check timestamp because we want to report all modified
// files to incremental compiler next time user does hot reload.
if (content.isModified || ((bundleDirty || bundleFirstUpload) && archivePath != null)) {
dirtyEntries[deviceUri] = content;
syncedBytes += content.size;
if (archivePath != null && (!bundleFirstUpload || content.isModifiedAfter(firstBuildTime)))
assetPathsToEvict.add(archivePath);
}
});
if (fullRestart) {
generator.reset();
}
......
......@@ -455,7 +455,6 @@ class FlutterDevice {
bundle: bundle,
firstBuildTime: firstBuildTime,
bundleFirstUpload: bundleFirstUpload,
bundleDirty: bundleDirty,
generator: generator,
fullRestart: fullRestart,
dillOutputPath: dillOutputPath,
......
......@@ -936,7 +936,7 @@ class HotRunner extends ResidentRunner {
}
class ProjectFileInvalidator {
static const String _pubCachePathLinuxAndWindows = '.pub-cache';
static const String _pubCachePathLinuxAndMac = '.pub-cache';
static const String _pubCachePathWindows = 'Pub/Cache';
static List<Uri> findInvalidated({@required DateTime lastCompiled,
......@@ -946,7 +946,7 @@ class ProjectFileInvalidator {
final Stopwatch stopwatch = Stopwatch()..start();
for (Uri uri in urisToMonitor) {
if ((platform.isWindows && uri.path.contains(_pubCachePathWindows))
|| uri.path.contains(_pubCachePathLinuxAndWindows)) {
|| uri.path.contains(_pubCachePathLinuxAndMac)) {
// Don't watch pub cache directories to speed things up a little.
continue;
}
......@@ -963,4 +963,4 @@ class ProjectFileInvalidator {
printTrace('Scanned through $scanned files in ${stopwatch.elapsedMilliseconds}ms');
return invalidatedFiles;
}
}
\ No newline at end of file
}
......@@ -104,7 +104,6 @@ void main() {
bundle: anyNamed('bundle'),
firstBuildTime: anyNamed('firstBuildTime'),
bundleFirstUpload: anyNamed('bundleFirstUpload'),
bundleDirty: anyNamed('bundleDirty'),
generator: anyNamed('generator'),
fullRestart: anyNamed('fullRestart'),
dillOutputPath: anyNamed('dillOutputPath'),
......
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