diff --git a/packages/flutter_tools/lib/src/asset.dart b/packages/flutter_tools/lib/src/asset.dart index 70e2ec7dae..e845551842 100644 --- a/packages/flutter_tools/lib/src/asset.dart +++ b/packages/flutter_tools/lib/src/asset.dart @@ -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); diff --git a/packages/flutter_tools/lib/src/devfs.dart b/packages/flutter_tools/lib/src/devfs.dart index b4c8293ed6..c825689790 100644 --- a/packages/flutter_tools/lib/src/devfs.dart +++ b/packages/flutter_tools/lib/src/devfs.dart @@ -385,7 +385,6 @@ class DevFS { final String fsName; final Directory rootDirectory; String _packagesFilePath; - final Map _entries = {}; final Set assetPathsToEvict = {}; List sources = []; 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 dirtyEntries = {}; + + 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 dirtyEntries = {}; - - 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(); } diff --git a/packages/flutter_tools/lib/src/resident_runner.dart b/packages/flutter_tools/lib/src/resident_runner.dart index 4cb6e437ce..c61a1b601e 100644 --- a/packages/flutter_tools/lib/src/resident_runner.dart +++ b/packages/flutter_tools/lib/src/resident_runner.dart @@ -455,7 +455,6 @@ class FlutterDevice { bundle: bundle, firstBuildTime: firstBuildTime, bundleFirstUpload: bundleFirstUpload, - bundleDirty: bundleDirty, generator: generator, fullRestart: fullRestart, dillOutputPath: dillOutputPath, diff --git a/packages/flutter_tools/lib/src/run_hot.dart b/packages/flutter_tools/lib/src/run_hot.dart index 485ede231f..bf5e325063 100644 --- a/packages/flutter_tools/lib/src/run_hot.dart +++ b/packages/flutter_tools/lib/src/run_hot.dart @@ -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 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 +} diff --git a/packages/flutter_tools/test/hot_test.dart b/packages/flutter_tools/test/hot_test.dart index 8dcc8ad68c..0425139d54 100644 --- a/packages/flutter_tools/test/hot_test.dart +++ b/packages/flutter_tools/test/hot_test.dart @@ -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'),