Commit 4e2657d2 authored by Devon Carew's avatar Devon Carew

exclude files from build/ when looking for asset variants (#3512)

* exclude files from build/ when looking for asset variants

* exclude some dirs when creating flx files
parent ace1a64b
...@@ -93,14 +93,22 @@ List<_Asset> _getMaterialAssets(String fontSet) { ...@@ -93,14 +93,22 @@ List<_Asset> _getMaterialAssets(String fontSet) {
return result; return result;
} }
/// Given an assetBase location and a flutter.yaml manifest, return a map of
/// assets to asset variants.
Map<_Asset, List<_Asset>> _parseAssets( Map<_Asset, List<_Asset>> _parseAssets(
PackageMap packageMap, PackageMap packageMap,
Map<String, dynamic> manifestDescriptor, Map<String, dynamic> manifestDescriptor,
String assetBase String assetBase, {
) { List<String> excludeDirs: const <String>[]
}) {
Map<_Asset, List<_Asset>> result = <_Asset, List<_Asset>>{}; Map<_Asset, List<_Asset>> result = <_Asset, List<_Asset>>{};
if (manifestDescriptor == null) if (manifestDescriptor == null)
return result; return result;
excludeDirs = excludeDirs.map(
(String exclude) => path.absolute(exclude) + Platform.pathSeparator).toList();
if (manifestDescriptor.containsKey('assets')) { if (manifestDescriptor.containsKey('assets')) {
for (String asset in manifestDescriptor['assets']) { for (String asset in manifestDescriptor['assets']) {
_Asset baseAsset = _resolveAsset(packageMap, assetBase, asset); _Asset baseAsset = _resolveAsset(packageMap, assetBase, asset);
...@@ -116,9 +124,14 @@ Map<_Asset, List<_Asset>> _parseAssets( ...@@ -116,9 +124,14 @@ Map<_Asset, List<_Asset>> _parseAssets(
List<FileSystemEntity> files = assetDir.listSync(recursive: true); List<FileSystemEntity> files = assetDir.listSync(recursive: true);
for (FileSystemEntity entity in files) { for (FileSystemEntity entity in files) {
if (path.basename(entity.path) == assetFilename && if (!FileSystemEntity.isFileSync(entity.path))
FileSystemEntity.isFileSync(entity.path) && continue;
entity.path != assetPath) {
// Exclude any files in the given directories.
if (excludeDirs.any((String exclude) => entity.path.startsWith(exclude)))
continue;
if (path.basename(entity.path) == assetFilename && entity.path != assetPath) {
String key = path.relative(entity.path, from: baseAsset.base); String key = path.relative(entity.path, from: baseAsset.base);
String assetEntry; String assetEntry;
if (baseAsset.symbolicPrefix != null) if (baseAsset.symbolicPrefix != null)
...@@ -201,11 +214,11 @@ ZipEntry _createAssetEntry(_Asset asset) { ...@@ -201,11 +214,11 @@ ZipEntry _createAssetEntry(_Asset asset) {
return new ZipEntry.fromFile(asset.assetEntry, file); return new ZipEntry.fromFile(asset.assetEntry, file);
} }
ZipEntry _createAssetManifest(Map<_Asset, List<_Asset>> assets) { ZipEntry _createAssetManifest(Map<_Asset, List<_Asset>> assetVariants) {
Map<String, List<String>> json = <String, List<String>>{}; Map<String, List<String>> json = <String, List<String>>{};
for (_Asset main in assets.keys) { for (_Asset main in assetVariants.keys) {
List<String> variants = <String>[]; List<String> variants = <String>[];
for (_Asset variant in assets[main]) for (_Asset variant in assetVariants[main])
variants.add(variant.relativePath); variants.add(variant.relativePath);
json[main.relativePath] = variants; json[main.relativePath] = variants;
} }
...@@ -327,23 +340,28 @@ Future<int> assemble({ ...@@ -327,23 +340,28 @@ Future<int> assemble({
}) async { }) async {
printTrace('Building $outputPath'); printTrace('Building $outputPath');
PackageMap packageMap = new PackageMap(path.join(assetBasePath, '.packages')); Map<_Asset, List<_Asset>> assetVariants = _parseAssets(
Map<_Asset, List<_Asset>> assets = _parseAssets(packageMap, manifestDescriptor, assetBasePath); new PackageMap(path.join(assetBasePath, '.packages')),
manifestDescriptor,
assetBasePath,
excludeDirs: <String>[workingDirPath, path.join(assetBasePath, 'build')]
);
final bool usesMaterialDesign = manifestDescriptor != null && manifestDescriptor['uses-material-design'] == true; final bool usesMaterialDesign = manifestDescriptor != null &&
manifestDescriptor['uses-material-design'] == true;
ZipBuilder zipBuilder = new ZipBuilder(); ZipBuilder zipBuilder = new ZipBuilder();
if (snapshotFile != null) if (snapshotFile != null)
zipBuilder.addEntry(new ZipEntry.fromFile(_kSnapshotKey, snapshotFile)); zipBuilder.addEntry(new ZipEntry.fromFile(_kSnapshotKey, snapshotFile));
for (_Asset asset in assets.keys) { for (_Asset asset in assetVariants.keys) {
ZipEntry assetEntry = _createAssetEntry(asset); ZipEntry assetEntry = _createAssetEntry(asset);
if (assetEntry == null) if (assetEntry == null)
return 1; return 1;
zipBuilder.addEntry(assetEntry); zipBuilder.addEntry(assetEntry);
for (_Asset variant in assets[asset]) { for (_Asset variant in assetVariants[asset]) {
ZipEntry variantEntry = _createAssetEntry(variant); ZipEntry variantEntry = _createAssetEntry(variant);
if (variantEntry == null) if (variantEntry == null)
return 1; return 1;
...@@ -364,7 +382,7 @@ Future<int> assemble({ ...@@ -364,7 +382,7 @@ Future<int> assemble({
zipBuilder.addEntry(assetEntry); zipBuilder.addEntry(assetEntry);
} }
zipBuilder.addEntry(_createAssetManifest(assets)); zipBuilder.addEntry(_createAssetManifest(assetVariants));
ZipEntry fontManifest = _createFontManifest(manifestDescriptor, usesMaterialDesign, includeRobotoFonts); ZipEntry fontManifest = _createFontManifest(manifestDescriptor, usesMaterialDesign, includeRobotoFonts);
if (fontManifest != null) if (fontManifest != null)
......
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