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 { ...@@ -193,7 +193,7 @@ class _ManifestAssetBundle implements AssetBundle {
} }
for (_Asset variant in assetVariants[asset]) { for (_Asset variant in assetVariants[asset]) {
assert(variant.assetFileExists); 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 { ...@@ -203,7 +203,7 @@ class _ManifestAssetBundle implements AssetBundle {
} }
for (_Asset asset in materialAssets) { for (_Asset asset in materialAssets) {
assert(asset.assetFileExists); assert(asset.assetFileExists);
entries[asset.entryUri.path] = DevFSFileContent(asset.assetFile); entries[asset.entryUri.path] ??= DevFSFileContent(asset.assetFile);
} }
entries[_assetManifestJson] = _createAssetManifest(assetVariants); entries[_assetManifestJson] = _createAssetManifest(assetVariants);
......
...@@ -385,7 +385,6 @@ class DevFS { ...@@ -385,7 +385,6 @@ class DevFS {
final String fsName; final String fsName;
final Directory rootDirectory; final Directory rootDirectory;
String _packagesFilePath; String _packagesFilePath;
final Map<Uri, DevFSContent> _entries = <Uri, DevFSContent>{};
final Set<String> assetPathsToEvict = <String>{}; final Set<String> assetPathsToEvict = <String>{};
List<Uri> sources = <Uri>[]; List<Uri> sources = <Uri>[];
DateTime lastCompiled; DateTime lastCompiled;
...@@ -434,7 +433,6 @@ class DevFS { ...@@ -434,7 +433,6 @@ class DevFS {
AssetBundle bundle, AssetBundle bundle,
DateTime firstBuildTime, DateTime firstBuildTime,
bool bundleFirstUpload = false, bool bundleFirstUpload = false,
bool bundleDirty = false,
@required ResidentCompiler generator, @required ResidentCompiler generator,
String dillOutputPath, String dillOutputPath,
@required bool trackWidgetCreation, @required bool trackWidgetCreation,
...@@ -446,6 +444,11 @@ class DevFS { ...@@ -446,6 +444,11 @@ class DevFS {
assert(trackWidgetCreation != null); assert(trackWidgetCreation != null);
assert(generator != 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) { if (bundle != null) {
printTrace('Scanning asset files'); printTrace('Scanning asset files');
// We write the assets into the AssetBundle working dir so that they // We write the assets into the AssetBundle working dir so that they
...@@ -453,29 +456,20 @@ class DevFS { ...@@ -453,29 +456,20 @@ class DevFS {
final String assetDirectory = getAssetBuildDirectory(); final String assetDirectory = getAssetBuildDirectory();
bundle.entries.forEach((String archivePath, DevFSContent content) { bundle.entries.forEach((String archivePath, DevFSContent content) {
final Uri deviceUri = fs.path.toUri(fs.path.join(assetDirectory, archivePath)); 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) { if (fullRestart) {
generator.reset(); generator.reset();
} }
......
...@@ -455,7 +455,6 @@ class FlutterDevice { ...@@ -455,7 +455,6 @@ class FlutterDevice {
bundle: bundle, bundle: bundle,
firstBuildTime: firstBuildTime, firstBuildTime: firstBuildTime,
bundleFirstUpload: bundleFirstUpload, bundleFirstUpload: bundleFirstUpload,
bundleDirty: bundleDirty,
generator: generator, generator: generator,
fullRestart: fullRestart, fullRestart: fullRestart,
dillOutputPath: dillOutputPath, dillOutputPath: dillOutputPath,
......
...@@ -936,7 +936,7 @@ class HotRunner extends ResidentRunner { ...@@ -936,7 +936,7 @@ class HotRunner extends ResidentRunner {
} }
class ProjectFileInvalidator { class ProjectFileInvalidator {
static const String _pubCachePathLinuxAndWindows = '.pub-cache'; static const String _pubCachePathLinuxAndMac = '.pub-cache';
static const String _pubCachePathWindows = 'Pub/Cache'; static const String _pubCachePathWindows = 'Pub/Cache';
static List<Uri> findInvalidated({@required DateTime lastCompiled, static List<Uri> findInvalidated({@required DateTime lastCompiled,
...@@ -946,7 +946,7 @@ class ProjectFileInvalidator { ...@@ -946,7 +946,7 @@ class ProjectFileInvalidator {
final Stopwatch stopwatch = Stopwatch()..start(); final Stopwatch stopwatch = Stopwatch()..start();
for (Uri uri in urisToMonitor) { for (Uri uri in urisToMonitor) {
if ((platform.isWindows && uri.path.contains(_pubCachePathWindows)) 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. // Don't watch pub cache directories to speed things up a little.
continue; continue;
} }
...@@ -963,4 +963,4 @@ class ProjectFileInvalidator { ...@@ -963,4 +963,4 @@ class ProjectFileInvalidator {
printTrace('Scanned through $scanned files in ${stopwatch.elapsedMilliseconds}ms'); printTrace('Scanned through $scanned files in ${stopwatch.elapsedMilliseconds}ms');
return invalidatedFiles; return invalidatedFiles;
} }
} }
\ No newline at end of file
...@@ -104,7 +104,6 @@ void main() { ...@@ -104,7 +104,6 @@ void main() {
bundle: anyNamed('bundle'), bundle: anyNamed('bundle'),
firstBuildTime: anyNamed('firstBuildTime'), firstBuildTime: anyNamed('firstBuildTime'),
bundleFirstUpload: anyNamed('bundleFirstUpload'), bundleFirstUpload: anyNamed('bundleFirstUpload'),
bundleDirty: anyNamed('bundleDirty'),
generator: anyNamed('generator'), generator: anyNamed('generator'),
fullRestart: anyNamed('fullRestart'), fullRestart: anyNamed('fullRestart'),
dillOutputPath: anyNamed('dillOutputPath'), 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