From 21766a4f9f07e50073ee8401843803dfba31b108 Mon Sep 17 00:00:00 2001
From: "auto-submit[bot]" <98614782+auto-submit[bot]@users.noreply.github.com>
Date: Fri, 8 Dec 2023 06:40:28 +0000
Subject: [PATCH] Reverts "Support conditional bundling of assets based on
`--flavor`" (#139787)
Reverts flutter/flutter#132985
Initiated by: christopherfujino
This change reverts the following previous change:
Original Description:
Provides support for conditional bundling of assets through the existing `--flavor` option for `flutter build` and `flutter run`. Closes https://github.com/flutter/flutter/issues/21682. Resolves https://github.com/flutter/flutter/issues/136092
## Change
Within the `assets` section pubspec.yaml, the user can now specify one or more `flavors` that an asset belongs to. Consider this example:
```yaml
# pubspec.yaml
flutter:
assets:
- assets/normal-asset.png
- path: assets/vanilla/ice-cream.png
flavors:
- vanilla
- path: assets/strawberry/ice-cream.png
flavors:
- strawberry
```
With this pubspec,
* `flutter run --flavor vanilla` will not include `assets/strawberry/ice-cream.png` in the build output.
* `flutter run --flavor strawberry` will not include `assets/vanilla/ice-cream.png`.
* `flutter run` will only include `assets/normal-asset.png`.
## Open questions
* Should this be supported for all platforms, or should this change be limited to ones with documented `--flavor` support (Android, iOS, and (implicitly) MacOS)? This PR currently only enables this feature for officially supported platforms.
## Design thoughts, what this PR does not do, etc.
### This does not provide an automatic mapping/resolution of asset keys/paths to others based on flavor at runtime.
The implementation in this PR represents a simplest approach. Notably, it does not give Flutter the ability to dynamically choose an asset based on flavor using a single asset key. For example, one can't use `Image.asset('config.json')` to dynamically choose between different "flavors" of `config.json` (such as `dev-flavor/config.json` or `prod-flavor/config.json`). However, a user could always implement such a mechanism in their project or in a library by examining the flavor at runtime.
### When multiple entries affect the same file and 1) at least one of these entries have a `flavors` list provided and 2) these lists are not equivalent, we always consider the manifest to be ambiguous and will throw a `ToolExit`.
For example, these manifests would all be considered ambiguous:
```yaml
assets:
- assets/
- path: assets/vanilla.png
flavors:
- vanilla
assets:
- path: assets/vanilla/
flavors:
- vanilla
- path: assets/vanilla/cherry.png
flavor:
- cherry
# Thinking towards the future where we might add glob/regex support and more conditions other than flavor:
assets:
- path: assets/vanilla/**
flavors:
- vanilla
- path: assets/**/ios/**
platforms:
- ios
# Ambiguous in the case of assets like "assets/vanilla/ios/icon.svg" since we
# don't know if flavor `vanilla` and platform `ios` should be combined using or-logic or and-logic.
```
See [this review comment thread](https://github.com/flutter/flutter/pull/132985#discussion_r1381909942) for the full story on how I arrived at this decision.
### This does not support Android's multidimensional flavors feature (in an intuitive way)
Conder this excerpt from a Flutter project's android/app/build.gradle file:
```groovy
android {
// ...
flavorDimensions "mode", "api"
productFlavors {
free {
dimension "mode"
applicationIdSuffix ".free"
}
premium {
dimension "mode"
applicationIdSuffix ".premium"
}
minApi23 {
dimension "api"
versionNameSuffix "-minApi23"
}
minApi21 {
dimension "api"
versionNameSuffix "-minApi21"
}
}
}
```
In this setup, the following values are valid `--flavor` are valid `freeMinApi21`, `freeMinApi23`, `premiumMinApi21`, and `premiumMinApi23`. We call these values "flavor combinations". Consider the following from the Android documentation[^1]:
> In addition to the source set directories you can create for each individual product flavor and build variant, you can also create source set directories for each combination of product flavors. For example, you can create and add Java sources to the src/demoMinApi24/java/ directory, and Gradle uses those sources only when building a variant that combines those two product flavors.
>
> Source sets you create for product flavor combinations have a higher priority than source sets that belong to each individual product flavor. To learn more about source sets and how Gradle merges resources, read the section about how to [create source sets](https://developer.android.com/build/build-variants#sourcesets).
This feature will not behave in this way. If a user utilizes this feature and also Android's multidimensional flavors feature, they will have to list out all flavor combinations that contain the flavor they want to limit an asset to:
```yaml
assets:
- assets/free/
flavors:
- freeMinApi21
- freeMinApi23
```
This is mostly due to a technical limitation in the hot-reload feature of `flutter run`. During a hot reload, the tool will try to update the asset bundle on the device, but the tool does not know the flavors contained within the flavor combination (that the user passes to `--flavor`). Gradle is the source of truth of what flavors were involved in the build, and `flutter run` currently does not access to that information since it's an implementation detail of the build process. We could bubble up this information, but it would require a nontrivial amount of engineering work, and it's unclear how desired this functionality is. It might not be worth implementing.
See https://flutter.dev/go/flavor-specific-assets for the (outdated) design document.
Pre-launch Checklist
[^1]: https://developer.android.com/build/build-variants#flavor-dimensions
---
dev/bots/pubspec.yaml | 3 +-
dev/devicelab/bin/tasks/flavors_test.dart | 82 ++------
dev/devicelab/bin/tasks/flavors_test_ios.dart | 81 ++-----
dev/devicelab/pubspec.yaml | 3 +-
.../flavors/assets/common/common.txt | 1 -
.../flavors/assets/free/free.txt | 1 -
.../flavors/assets/paid/paid.txt | 1 -
.../flavors/assets/premium/premium.txt | 1 -
dev/integration_tests/flavors/pubspec.yaml | 8 -
packages/flutter_tools/bin/xcode_backend.dart | 1 -
.../gradle/src/main/groovy/flutter.groovy | 7 -
packages/flutter_tools/lib/src/asset.dart | 183 ++--------------
.../lib/src/base/deferred_component.dart | 14 +-
.../flutter_tools/lib/src/build_info.dart | 5 -
.../lib/src/build_system/targets/android.dart | 2 -
.../lib/src/build_system/targets/assets.dart | 3 -
.../lib/src/build_system/targets/common.dart | 3 -
.../lib/src/build_system/targets/ios.dart | 1 -
.../lib/src/build_system/targets/macos.dart | 2 -
.../flutter_tools/lib/src/bundle_builder.dart | 2 -
.../lib/src/flutter_manifest.dart | 197 +++++-------------
packages/flutter_tools/lib/src/run_hot.dart | 7 +-
.../commands.shard/hermetic/run_test.dart | 1 -
.../test/general.shard/asset_bundle_test.dart | 187 -----------------
.../base/deferred_component_test.dart | 26 +--
.../test/general.shard/build_info_test.dart | 5 +-
.../build_system/targets/assets_test.dart | 64 ------
.../test/general.shard/devfs_test.dart | 9 +-
.../general.shard/flutter_manifest_test.dart | 181 ++++++++--------
.../general.shard/xcode_backend_test.dart | 2 -
30 files changed, 212 insertions(+), 871 deletions(-)
delete mode 100644 dev/integration_tests/flavors/assets/common/common.txt
delete mode 100644 dev/integration_tests/flavors/assets/free/free.txt
delete mode 100644 dev/integration_tests/flavors/assets/paid/paid.txt
delete mode 100644 dev/integration_tests/flavors/assets/premium/premium.txt
diff --git a/dev/bots/pubspec.yaml b/dev/bots/pubspec.yaml
index b00966d5ff..2be63de606 100644
--- a/dev/bots/pubspec.yaml
+++ b/dev/bots/pubspec.yaml
@@ -58,7 +58,6 @@ dependencies:
source_maps: 0.10.12 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
source_span: 1.10.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
stack_trace: 1.11.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
- standard_message_codec: 0.0.1+4 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
stream_channel: 2.1.2 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
string_scanner: 1.2.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
term_glyph: 1.2.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
@@ -75,4 +74,4 @@ dependencies:
dev_dependencies:
test_api: 0.6.1
-# PUBSPEC CHECKSUM: b875
+# PUBSPEC CHECKSUM: 29d2
diff --git a/dev/devicelab/bin/tasks/flavors_test.dart b/dev/devicelab/bin/tasks/flavors_test.dart
index e9ebe40824..2db0956f79 100644
--- a/dev/devicelab/bin/tasks/flavors_test.dart
+++ b/dev/devicelab/bin/tasks/flavors_test.dart
@@ -2,17 +2,12 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-import 'dart:io' show File;
-import 'dart:typed_data';
-
-import 'package:collection/collection.dart';
import 'package:flutter_devicelab/framework/devices.dart';
import 'package:flutter_devicelab/framework/framework.dart';
import 'package:flutter_devicelab/framework/task_result.dart';
import 'package:flutter_devicelab/framework/utils.dart';
import 'package:flutter_devicelab/tasks/integration_tests.dart';
import 'package:path/path.dart' as path;
-import 'package:standard_message_codec/standard_message_codec.dart';
Future main() async {
deviceOperatingSystem = DeviceOperatingSystem.android;
@@ -20,20 +15,31 @@ Future main() async {
await createFlavorsTest().call();
await createIntegrationTestFlavorsTest().call();
- final String projectPath = '${flutterDirectory.path}/dev/integration_tests/flavors';
final TaskResult installTestsResult = await inDirectory(
- projectPath,
+ '${flutterDirectory.path}/dev/integration_tests/flavors',
() async {
- final List testResults = [
- await _testInstallDebugPaidFlavor(projectPath),
- await _testInstallBogusFlavor(),
- ];
+ await flutter(
+ 'install',
+ options: ['--debug', '--flavor', 'paid'],
+ );
+ await flutter(
+ 'install',
+ options: ['--debug', '--flavor', 'paid', '--uninstall-only'],
+ );
- final TaskResult? firstInstallFailure = testResults
- .firstWhereOrNull((TaskResult element) => element.failed);
+ final StringBuffer stderr = StringBuffer();
+ await evalFlutter(
+ 'install',
+ canFail: true,
+ stderr: stderr,
+ options: ['--flavor', 'bogus'],
+ );
- if (firstInstallFailure != null) {
- return firstInstallFailure;
+ final String stderrString = stderr.toString();
+ final String expectedApkPath = path.join('build', 'app', 'outputs', 'flutter-apk', 'app-bogus-release.apk');
+ if (!stderrString.contains('"$expectedApkPath" does not exist.')) {
+ print(stderrString);
+ return TaskResult.failure('Should not succeed with bogus flavor');
}
return TaskResult.success(null);
@@ -43,49 +49,3 @@ Future main() async {
return installTestsResult;
});
}
-
-// Ensures installation works. Also tests asset bundling while we are at it.
-Future _testInstallDebugPaidFlavor(String projectDir) async {
- await evalFlutter(
- 'install',
- options: ['--debug', '--flavor', 'paid'],
- );
-
- final Uint8List assetManifestFileData = File(
- path.join(projectDir, 'build', 'app', 'intermediates', 'assets', 'paidDebug', 'flutter_assets', 'AssetManifest.bin'),
- ).readAsBytesSync();
-
- final Map assetManifest = const StandardMessageCodec()
- .decodeMessage(ByteData.sublistView(assetManifestFileData)) as Map;
-
- if (assetManifest.containsKey('assets/free/free.txt')) {
- return TaskResult.failure('Assets declared with a flavor not equal to the '
- 'argued --flavor value should not be bundled.');
- }
-
- await flutter(
- 'install',
- options: ['--debug', '--flavor', 'paid', '--uninstall-only'],
- );
-
- return TaskResult.success(null);
-}
-
-Future _testInstallBogusFlavor() async {
- final StringBuffer stderr = StringBuffer();
- await evalFlutter(
- 'install',
- canFail: true,
- stderr: stderr,
- options: ['--flavor', 'bogus'],
- );
-
- final String stderrString = stderr.toString();
- final String expectedApkPath = path.join('build', 'app', 'outputs', 'flutter-apk', 'app-bogus-release.apk');
- if (!stderrString.contains('"$expectedApkPath" does not exist.')) {
- print(stderrString);
- return TaskResult.failure('Should not succeed with bogus flavor');
- }
-
- return TaskResult.success(null);
-}
diff --git a/dev/devicelab/bin/tasks/flavors_test_ios.dart b/dev/devicelab/bin/tasks/flavors_test_ios.dart
index 120b2be41f..4e84ed4ec3 100644
--- a/dev/devicelab/bin/tasks/flavors_test_ios.dart
+++ b/dev/devicelab/bin/tasks/flavors_test_ios.dart
@@ -2,17 +2,11 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-import 'dart:io';
-import 'dart:typed_data';
-
-import 'package:collection/collection.dart';
import 'package:flutter_devicelab/framework/devices.dart';
import 'package:flutter_devicelab/framework/framework.dart';
import 'package:flutter_devicelab/framework/task_result.dart';
import 'package:flutter_devicelab/framework/utils.dart';
import 'package:flutter_devicelab/tasks/integration_tests.dart';
-import 'package:path/path.dart' as path;
-import 'package:standard_message_codec/standard_message_codec.dart';
Future main() async {
deviceOperatingSystem = DeviceOperatingSystem.ios;
@@ -20,20 +14,29 @@ Future main() async {
await createFlavorsTest().call();
await createIntegrationTestFlavorsTest().call();
// test install and uninstall of flavors app
- final String projectDir = '${flutterDirectory.path}/dev/integration_tests/flavors';
final TaskResult installTestsResult = await inDirectory(
- projectDir,
+ '${flutterDirectory.path}/dev/integration_tests/flavors',
() async {
- final List testResults = [
- await _testInstallDebugPaidFlavor(projectDir),
- await _testInstallBogusFlavor(),
- ];
+ await flutter(
+ 'install',
+ options: ['--flavor', 'paid'],
+ );
+ await flutter(
+ 'install',
+ options: ['--flavor', 'paid', '--uninstall-only'],
+ );
+ final StringBuffer stderr = StringBuffer();
+ await evalFlutter(
+ 'install',
+ canFail: true,
+ stderr: stderr,
+ options: ['--flavor', 'bogus'],
+ );
- final TaskResult? firstInstallFailure = testResults
- .firstWhereOrNull((TaskResult element) => element.failed);
-
- if (firstInstallFailure != null) {
- return firstInstallFailure;
+ final String stderrString = stderr.toString();
+ if (!stderrString.contains('The Xcode project defines schemes: free, paid')) {
+ print(stderrString);
+ return TaskResult.failure('Should not succeed with bogus flavor');
}
return TaskResult.success(null);
@@ -43,47 +46,3 @@ Future main() async {
return installTestsResult;
});
}
-
-Future _testInstallDebugPaidFlavor(String projectDir) async {
- await evalFlutter(
- 'install',
- options: ['--flavor', 'paid'],
- );
-
- final Uint8List assetManifestFileData = File(
- path.join(projectDir, 'build', 'ios', 'Release-iphoneos', 'App.framework', 'flutter_assets', 'AssetManifest.bin'),
- ).readAsBytesSync();
-
- final Map assetManifest = const StandardMessageCodec()
- .decodeMessage(ByteData.sublistView(assetManifestFileData)) as Map;
-
- if (assetManifest.containsKey('assets/free/free.txt')) {
- return TaskResult.failure('Assets declared with a flavor not equal to the '
- 'argued --flavor value should not be bundled.');
- }
-
- await flutter(
- 'install',
- options: ['--flavor', 'paid', '--uninstall-only'],
- );
-
- return TaskResult.success(null);
-}
-
-Future _testInstallBogusFlavor() async {
- final StringBuffer stderr = StringBuffer();
- await evalFlutter(
- 'install',
- canFail: true,
- stderr: stderr,
- options: ['--flavor', 'bogus'],
- );
-
- final String stderrString = stderr.toString();
- if (!stderrString.contains('The Xcode project defines schemes: free, paid')) {
- print(stderrString);
- return TaskResult.failure('Should not succeed with bogus flavor');
- }
-
- return TaskResult.success(null);
-}
diff --git a/dev/devicelab/pubspec.yaml b/dev/devicelab/pubspec.yaml
index ed834b7a61..e938780138 100644
--- a/dev/devicelab/pubspec.yaml
+++ b/dev/devicelab/pubspec.yaml
@@ -24,7 +24,6 @@ dependencies:
web: 0.4.0
webkit_inspection_protocol: 1.2.1
xml: 6.5.0
- standard_message_codec: 0.0.1+4
_discoveryapis_commons: 1.0.6 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
async: 2.11.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
@@ -73,4 +72,4 @@ dev_dependencies:
watcher: 1.1.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
web_socket_channel: 2.4.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
-# PUBSPEC CHECKSUM: 70e2
+# PUBSPEC CHECKSUM: 6040
diff --git a/dev/integration_tests/flavors/assets/common/common.txt b/dev/integration_tests/flavors/assets/common/common.txt
deleted file mode 100644
index b804e9886a..0000000000
--- a/dev/integration_tests/flavors/assets/common/common.txt
+++ /dev/null
@@ -1 +0,0 @@
-this is a test asset not meant for any specific flavor
\ No newline at end of file
diff --git a/dev/integration_tests/flavors/assets/free/free.txt b/dev/integration_tests/flavors/assets/free/free.txt
deleted file mode 100644
index 8f7a269f72..0000000000
--- a/dev/integration_tests/flavors/assets/free/free.txt
+++ /dev/null
@@ -1 +0,0 @@
-this is a test asset for --flavor free
\ No newline at end of file
diff --git a/dev/integration_tests/flavors/assets/paid/paid.txt b/dev/integration_tests/flavors/assets/paid/paid.txt
deleted file mode 100644
index c6b999fd68..0000000000
--- a/dev/integration_tests/flavors/assets/paid/paid.txt
+++ /dev/null
@@ -1 +0,0 @@
-this is a test asset for --flavor paid
\ No newline at end of file
diff --git a/dev/integration_tests/flavors/assets/premium/premium.txt b/dev/integration_tests/flavors/assets/premium/premium.txt
deleted file mode 100644
index f790245218..0000000000
--- a/dev/integration_tests/flavors/assets/premium/premium.txt
+++ /dev/null
@@ -1 +0,0 @@
-premium
\ No newline at end of file
diff --git a/dev/integration_tests/flavors/pubspec.yaml b/dev/integration_tests/flavors/pubspec.yaml
index d0c979db4e..6b05736c80 100644
--- a/dev/integration_tests/flavors/pubspec.yaml
+++ b/dev/integration_tests/flavors/pubspec.yaml
@@ -75,13 +75,5 @@ dev_dependencies:
flutter:
uses-material-design: true
- assets:
- - assets/common/common.txt
- - path: assets/paid/
- flavors:
- - paid
- - path: assets/free/
- flavors:
- - free
# PUBSPEC CHECKSUM: 6bd3
diff --git a/packages/flutter_tools/bin/xcode_backend.dart b/packages/flutter_tools/bin/xcode_backend.dart
index dca13dad5f..70e856405e 100644
--- a/packages/flutter_tools/bin/xcode_backend.dart
+++ b/packages/flutter_tools/bin/xcode_backend.dart
@@ -401,7 +401,6 @@ class Context {
'-dTargetPlatform=ios',
'-dTargetFile=$targetPath',
'-dBuildMode=$buildMode',
- if (environment['FLAVOR'] != null) '-dFlavor=${environment['FLAVOR']}',
'-dIosArchs=${environment['ARCHS'] ?? ''}',
'-dSdkRoot=${environment['SDKROOT'] ?? ''}',
'-dSplitDebugInfo=${environment['SPLIT_DEBUG_INFO'] ?? ''}',
diff --git a/packages/flutter_tools/gradle/src/main/groovy/flutter.groovy b/packages/flutter_tools/gradle/src/main/groovy/flutter.groovy
index 2bbce95251..d7580f7c98 100644
--- a/packages/flutter_tools/gradle/src/main/groovy/flutter.groovy
+++ b/packages/flutter_tools/gradle/src/main/groovy/flutter.groovy
@@ -1042,7 +1042,6 @@ class FlutterPlugin implements Plugin {
boolean isAndroidLibraryValue = isBuildingAar || isUsedAsSubproject
String variantBuildMode = buildModeFor(variant.buildType)
- String flavorValue = variant.getFlavorName()
String taskName = toCamelCase(["compile", FLUTTER_BUILD_PREFIX, variant.name])
// Be careful when configuring task below, Groovy has bizarre
// scoping rules: writing `verbose isVerbose()` means calling
@@ -1080,7 +1079,6 @@ class FlutterPlugin implements Plugin {
deferredComponents deferredComponentsValue
validateDeferredComponents validateDeferredComponentsValue
isAndroidLibrary isAndroidLibraryValue
- flavor flavorValue
doLast {
project.exec {
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
@@ -1338,8 +1336,6 @@ abstract class BaseFlutterTask extends DefaultTask {
Boolean validateDeferredComponents
@Optional @Input
Boolean isAndroidLibrary
- @Optional @Input
- String flavor
@OutputFiles
FileCollection getDependenciesFiles() {
@@ -1420,9 +1416,6 @@ abstract class BaseFlutterTask extends DefaultTask {
if (codeSizeDirectory != null) {
args "-dCodeSizeDirectory=${codeSizeDirectory}"
}
- if (flavor != null) {
- args "-dFlavor=${flavor}"
- }
if (extraGenSnapshotOptions != null) {
args "--ExtraGenSnapshotOptions=${extraGenSnapshotOptions}"
}
diff --git a/packages/flutter_tools/lib/src/asset.dart b/packages/flutter_tools/lib/src/asset.dart
index 9d936156d5..7eda50bc1f 100644
--- a/packages/flutter_tools/lib/src/asset.dart
+++ b/packages/flutter_tools/lib/src/asset.dart
@@ -8,7 +8,6 @@ import 'package:meta/meta.dart';
import 'package:package_config/package_config.dart';
import 'package:standard_message_codec/standard_message_codec.dart';
-import 'base/common.dart';
import 'base/context.dart';
import 'base/deferred_component.dart';
import 'base/file_system.dart';
@@ -103,7 +102,6 @@ abstract class AssetBundle {
required String packagesPath,
bool deferredComponentsEnabled = false,
TargetPlatform? targetPlatform,
- String? flavor,
});
}
@@ -218,8 +216,8 @@ class ManifestAssetBundle implements AssetBundle {
required String packagesPath,
bool deferredComponentsEnabled = false,
TargetPlatform? targetPlatform,
- String? flavor,
}) async {
+
if (flutterProject == null) {
try {
flutterProject = FlutterProject.fromDirectory(_fileSystem.file(manifestPath).parent);
@@ -270,7 +268,6 @@ class ManifestAssetBundle implements AssetBundle {
wildcardDirectories,
assetBasePath,
targetPlatform,
- flavor: flavor,
);
if (assetVariants == null) {
@@ -284,7 +281,6 @@ class ManifestAssetBundle implements AssetBundle {
assetBasePath,
wildcardDirectories,
flutterProject.directory,
- flavor: flavor,
);
if (!_splitDeferredAssets || !deferredComponentsEnabled) {
// Include the assets in the regular set of assets if not using deferred
@@ -625,7 +621,7 @@ class ManifestAssetBundle implements AssetBundle {
String assetBasePath,
List wildcardDirectories,
Directory projectDirectory, {
- String? flavor,
+ List excludeDirs = const [],
}) {
final List? components = flutterManifest.deferredComponents;
final Map>> deferredComponentsAssetVariants = >>{};
@@ -633,18 +629,18 @@ class ManifestAssetBundle implements AssetBundle {
return deferredComponentsAssetVariants;
}
for (final DeferredComponent component in components) {
+ deferredComponentsAssetVariants[component.name] = <_Asset, List<_Asset>>{};
final _AssetDirectoryCache cache = _AssetDirectoryCache(_fileSystem);
- final Map<_Asset, List<_Asset>> componentAssets = <_Asset, List<_Asset>>{};
- for (final AssetsEntry assetsEntry in component.assets) {
- if (assetsEntry.uri.path.endsWith('/')) {
- wildcardDirectories.add(assetsEntry.uri);
+ for (final Uri assetUri in component.assets) {
+ if (assetUri.path.endsWith('/')) {
+ wildcardDirectories.add(assetUri);
_parseAssetsFromFolder(
packageConfig,
flutterManifest,
assetBasePath,
cache,
- componentAssets,
- assetsEntry.uri,
+ deferredComponentsAssetVariants[component.name]!,
+ assetUri,
);
} else {
_parseAssetFromFile(
@@ -652,14 +648,12 @@ class ManifestAssetBundle implements AssetBundle {
flutterManifest,
assetBasePath,
cache,
- componentAssets,
- assetsEntry.uri,
+ deferredComponentsAssetVariants[component.name]!,
+ assetUri,
+ excludeDirs: excludeDirs,
);
}
}
-
- componentAssets.removeWhere((_Asset asset, List<_Asset> variants) => !asset.matchesFlavor(flavor));
- deferredComponentsAssetVariants[component.name] = componentAssets;
}
return deferredComponentsAssetVariants;
}
@@ -806,24 +800,22 @@ class ManifestAssetBundle implements AssetBundle {
TargetPlatform? targetPlatform, {
String? packageName,
Package? attributedPackage,
- String? flavor,
}) {
final Map<_Asset, List<_Asset>> result = <_Asset, List<_Asset>>{};
final _AssetDirectoryCache cache = _AssetDirectoryCache(_fileSystem);
- for (final AssetsEntry assetsEntry in flutterManifest.assets) {
- if (assetsEntry.uri.path.endsWith('/')) {
- wildcardDirectories.add(assetsEntry.uri);
+ for (final Uri assetUri in flutterManifest.assets) {
+ if (assetUri.path.endsWith('/')) {
+ wildcardDirectories.add(assetUri);
_parseAssetsFromFolder(
packageConfig,
flutterManifest,
assetBase,
cache,
result,
- assetsEntry.uri,
+ assetUri,
packageName: packageName,
attributedPackage: attributedPackage,
- flavors: assetsEntry.flavors,
);
} else {
_parseAssetFromFile(
@@ -832,24 +824,13 @@ class ManifestAssetBundle implements AssetBundle {
assetBase,
cache,
result,
- assetsEntry.uri,
+ assetUri,
packageName: packageName,
attributedPackage: attributedPackage,
- flavors: assetsEntry.flavors,
);
}
}
- result.removeWhere((_Asset asset, List<_Asset> variants) {
- if (!asset.matchesFlavor(flavor)) {
- _logger.printTrace('Skipping assets entry "${asset.entryUri.path}" since '
- 'its configured flavor(s) did not match the provided flavor (if any).\n'
- 'Configured flavors: ${asset.flavors.join(', ')}\n');
- return true;
- }
- return false;
- });
-
for (final Uri shaderUri in flutterManifest.shaders) {
_parseAssetFromFile(
packageConfig,
@@ -897,7 +878,6 @@ class ManifestAssetBundle implements AssetBundle {
result[baseAsset] = <_Asset>[];
}
}
-
return result;
}
@@ -910,7 +890,6 @@ class ManifestAssetBundle implements AssetBundle {
Uri assetUri, {
String? packageName,
Package? attributedPackage,
- List? flavors,
}) {
final String directoryPath = _fileSystem.path.join(
assetBase, assetUri.toFilePath(windows: _platform.isWindows));
@@ -936,8 +915,6 @@ class ManifestAssetBundle implements AssetBundle {
uri,
packageName: packageName,
attributedPackage: attributedPackage,
- originUri: assetUri,
- flavors: flavors,
);
}
}
@@ -949,11 +926,10 @@ class ManifestAssetBundle implements AssetBundle {
_AssetDirectoryCache cache,
Map<_Asset, List<_Asset>> result,
Uri assetUri, {
- Uri? originUri,
+ List excludeDirs = const [],
String? packageName,
Package? attributedPackage,
AssetKind assetKind = AssetKind.regular,
- List? flavors,
}) {
final _Asset asset = _resolveAsset(
packageConfig,
@@ -962,15 +938,9 @@ class ManifestAssetBundle implements AssetBundle {
packageName,
attributedPackage,
assetKind: assetKind,
- originUri: originUri,
- flavors: flavors,
);
-
- _checkForFlavorConflicts(asset, result.keys.toList());
-
final List<_Asset> variants = <_Asset>[];
final File assetFile = asset.lookupAssetFile(_fileSystem);
-
for (final String path in cache.variantsFor(assetFile.path)) {
final String relativePath = _fileSystem.path.relative(path, from: asset.baseDir);
final Uri relativeUri = _fileSystem.path.toUri(relativePath);
@@ -993,83 +963,13 @@ class ManifestAssetBundle implements AssetBundle {
result[asset] = variants;
}
- // Since it is not clear how overlapping asset declarations should work in the
- // presence of conditions such as `flavor`, we throw an Error.
- //
- // To be more specific, it is not clear if conditions should be combined with
- // or-logic or and-logic, or if it should depend on the specificity of the
- // declarations (file versus directory). If you would like examples, consider these:
- //
- // ```yaml
- // # Should assets/free.mp3 always be included since "assets/" has no flavor?
- // assets:
- // - assets/
- // - path: assets/free.mp3
- // flavor: free
- //
- // # Should "assets/paid/pip.mp3" be included for both the "paid" and "free" flavors?
- // # Or, since "assets/paid/pip.mp3" is more specific than "assets/paid/"", should
- // # it take precedence over the latter (included only in "free" flavor)?
- // assets:
- // - path: assets/paid/
- // flavor: paid
- // - path: assets/paid/pip.mp3
- // flavor: free
- // - asset
- // ```
- //
- // Since it is not obvious what logic (if any) would be intuitive and preferable
- // to the vast majority of users (if any), we play it safe by throwing a `ToolExit`
- // in any of these situations. We can always loosen up this restriction later
- // without breaking anyone.
- void _checkForFlavorConflicts(_Asset newAsset, List<_Asset> previouslyParsedAssets) {
- bool cameFromDirectoryEntry(_Asset asset) {
- return asset.originUri.path.endsWith('/');
- }
-
- String flavorErrorInfo(_Asset asset) {
- if (asset.flavors.isEmpty) {
- return 'An entry with the path "${asset.originUri}" does not specify any flavors.';
- }
-
- final Iterable flavorsWrappedWithQuotes = asset.flavors.map((String e) => '"$e"');
- return 'An entry with the path "${asset.originUri}" specifies the flavor(s): '
- '${flavorsWrappedWithQuotes.join(', ')}.';
- }
-
- final _Asset? preExistingAsset = previouslyParsedAssets
- .where((_Asset other) => other.entryUri == newAsset.entryUri)
- .firstOrNull;
-
- if (preExistingAsset == null || preExistingAsset.hasEquivalentFlavorsWith(newAsset)) {
- return;
- }
-
- final StringBuffer errorMessage = StringBuffer(
- 'Multiple assets entries include the file '
- '"${newAsset.entryUri.path}", but they specify different lists of flavors.\n');
-
- errorMessage.writeln(flavorErrorInfo(preExistingAsset));
- errorMessage.writeln(flavorErrorInfo(newAsset));
-
- if (cameFromDirectoryEntry(newAsset)|| cameFromDirectoryEntry(preExistingAsset)) {
- errorMessage.writeln();
- errorMessage.write('Consider organizing assets with different flavors '
- 'into different directories.');
- }
-
- throwToolExit(errorMessage.toString());
- }
-
_Asset _resolveAsset(
PackageConfig packageConfig,
String assetsBaseDir,
Uri assetUri,
String? packageName,
Package? attributedPackage, {
- Uri? originUri,
AssetKind assetKind = AssetKind.regular,
- List? flavors,
}) {
final String assetPath = _fileSystem.path.fromUri(assetUri);
if (assetUri.pathSegments.first == 'packages'
@@ -1081,8 +981,6 @@ class ManifestAssetBundle implements AssetBundle {
packageConfig,
attributedPackage,
assetKind: assetKind,
- originUri: originUri,
- flavors: flavors,
);
if (packageAsset != null) {
return packageAsset;
@@ -1096,9 +994,7 @@ class ManifestAssetBundle implements AssetBundle {
: Uri(pathSegments: ['packages', packageName, ...assetUri.pathSegments]), // Asset from, and declared in $packageName.
relativeUri: assetUri,
package: attributedPackage,
- originUri: originUri,
assetKind: assetKind,
- flavors: flavors,
);
}
@@ -1107,8 +1003,6 @@ class ManifestAssetBundle implements AssetBundle {
PackageConfig packageConfig,
Package? attributedPackage, {
AssetKind assetKind = AssetKind.regular,
- Uri? originUri,
- List? flavors,
}) {
assert(assetUri.pathSegments.first == 'packages');
if (assetUri.pathSegments.length > 1) {
@@ -1122,8 +1016,6 @@ class ManifestAssetBundle implements AssetBundle {
relativeUri: Uri(pathSegments: assetUri.pathSegments.sublist(2)),
package: attributedPackage,
assetKind: assetKind,
- originUri: originUri,
- flavors: flavors,
);
}
}
@@ -1140,22 +1032,16 @@ class ManifestAssetBundle implements AssetBundle {
class _Asset {
const _Asset({
required this.baseDir,
- Uri? originUri,
required this.relativeUri,
required this.entryUri,
required this.package,
this.assetKind = AssetKind.regular,
- List? flavors,
- }): originUri = originUri ?? entryUri, flavors = flavors ?? const [];
+ });
final String baseDir;
final Package? package;
- /// The platform-independent URL provided by the user in the pubspec that this
- /// asset was found from.
- final Uri originUri;
-
/// A platform-independent URL where this asset can be found on disk on the
/// host system relative to [baseDir].
final Uri relativeUri;
@@ -1165,8 +1051,6 @@ class _Asset {
final AssetKind assetKind;
- final List flavors;
-
File lookupAssetFile(FileSystem fileSystem) {
return fileSystem.file(fileSystem.path.join(baseDir, fileSystem.path.fromUri(relativeUri)));
}
@@ -1181,26 +1065,6 @@ class _Asset {
return index == -1 ? null : Uri(path: entryUri.path.substring(0, index));
}
- bool matchesFlavor(String? flavor) {
- if (flavors.isEmpty) {
- return true;
- }
-
- if (flavor == null) {
- return false;
- }
-
- return flavors.contains(flavor);
- }
-
- bool hasEquivalentFlavorsWith(_Asset other) {
- final Set assetFlavors = flavors.toSet();
- final Set otherFlavors = other.flavors.toSet();
- return assetFlavors.length == otherFlavors.length && assetFlavors.every(
- (String e) => otherFlavors.contains(e),
- );
- }
-
@override
String toString() => 'asset: $entryUri';
@@ -1216,18 +1080,11 @@ class _Asset {
&& other.baseDir == baseDir
&& other.relativeUri == relativeUri
&& other.entryUri == entryUri
- && other.assetKind == assetKind
- && hasEquivalentFlavorsWith(other);
+ && other.assetKind == assetKind;
}
@override
- int get hashCode => Object.hashAll([
- baseDir,
- relativeUri,
- entryUri,
- assetKind,
- ...flavors,
- ]);
+ int get hashCode => Object.hash(baseDir, relativeUri, entryUri.hashCode);
}
// Given an assets directory like this:
diff --git a/packages/flutter_tools/lib/src/base/deferred_component.dart b/packages/flutter_tools/lib/src/base/deferred_component.dart
index 6bf2219e9e..748b0086c2 100644
--- a/packages/flutter_tools/lib/src/base/deferred_component.dart
+++ b/packages/flutter_tools/lib/src/base/deferred_component.dart
@@ -5,7 +5,6 @@
import '../base/file_system.dart';
import '../base/logger.dart';
import '../convert.dart';
-import '../flutter_manifest.dart';
/// Represents a configured deferred component as defined in
/// the app's pubspec.yaml.
@@ -13,7 +12,7 @@ class DeferredComponent {
DeferredComponent({
required this.name,
this.libraries = const [],
- this.assets = const [],
+ this.assets = const [],
}) : _assigned = false;
/// The name of the deferred component. There should be a matching
@@ -29,8 +28,8 @@ class DeferredComponent {
/// libraries that are not listed here.
final List libraries;
- /// Assets that are part of this component.
- final List assets;
+ /// Assets that are part of this component as a Uri relative to the project directory.
+ final List assets;
/// The minimal set of [LoadingUnit]s needed that contain all of the dart libraries in
/// [libraries].
@@ -96,11 +95,8 @@ class DeferredComponent {
}
}
out.write('\n Assets:');
- for (final AssetsEntry asset in assets) {
- out.write('\n - ${asset.uri.path}');
- if (asset.flavors.isNotEmpty) {
- out.write(' (flavors: ${asset.flavors.join(', ')})');
- }
+ for (final Uri asset in assets) {
+ out.write('\n - ${asset.path}');
}
return out.toString();
}
diff --git a/packages/flutter_tools/lib/src/build_info.dart b/packages/flutter_tools/lib/src/build_info.dart
index b42edc1d51..825b0df74a 100644
--- a/packages/flutter_tools/lib/src/build_info.dart
+++ b/packages/flutter_tools/lib/src/build_info.dart
@@ -286,8 +286,6 @@ class BuildInfo {
'PACKAGE_CONFIG': packagesPath,
if (codeSizeDirectory != null)
'CODE_SIZE_DIRECTORY': codeSizeDirectory!,
- if (flavor != null)
- 'FLAVOR': flavor!,
};
}
@@ -991,9 +989,6 @@ const String kBundleSkSLPath = 'BundleSkSLPath';
/// The define to pass build name
const String kBuildName = 'BuildName';
-/// The app flavor to build.
-const String kFlavor = 'Flavor';
-
/// The define to pass build number
const String kBuildNumber = 'BuildNumber';
diff --git a/packages/flutter_tools/lib/src/build_system/targets/android.dart b/packages/flutter_tools/lib/src/build_system/targets/android.dart
index 8254234de2..1c8e8fb785 100644
--- a/packages/flutter_tools/lib/src/build_system/targets/android.dart
+++ b/packages/flutter_tools/lib/src/build_system/targets/android.dart
@@ -46,7 +46,6 @@ abstract class AndroidAssetBundle extends Target {
if (buildModeEnvironment == null) {
throw MissingDefineException(kBuildMode, name);
}
-
final BuildMode buildMode = BuildMode.fromCliName(buildModeEnvironment);
final Directory outputDirectory = environment.outputDir
.childDirectory('flutter_assets')
@@ -69,7 +68,6 @@ abstract class AndroidAssetBundle extends Target {
targetPlatform: TargetPlatform.android,
buildMode: buildMode,
shaderTarget: ShaderTarget.impellerAndroid,
- flavor: environment.defines[kFlavor],
);
environment.depFileService.writeToFile(
assetDepfile,
diff --git a/packages/flutter_tools/lib/src/build_system/targets/assets.dart b/packages/flutter_tools/lib/src/build_system/targets/assets.dart
index 6ad00d1eba..dc9c9aff91 100644
--- a/packages/flutter_tools/lib/src/build_system/targets/assets.dart
+++ b/packages/flutter_tools/lib/src/build_system/targets/assets.dart
@@ -34,7 +34,6 @@ Future copyAssets(
BuildMode? buildMode,
required ShaderTarget shaderTarget,
List additionalInputs = const [],
- String? flavor,
}) async {
// Check for an SkSL bundle.
final String? shaderBundlePath = environment.defines[kBundleSkSLPath] ?? environment.inputs[kBundleSkSLPath];
@@ -59,7 +58,6 @@ Future copyAssets(
packagesPath: environment.projectDir.childFile('.packages').path,
deferredComponentsEnabled: environment.defines[kDeferredComponents] == 'true',
targetPlatform: targetPlatform,
- flavor: flavor,
);
if (resultCode != 0) {
throw Exception('Failed to bundle asset files.');
@@ -325,7 +323,6 @@ class CopyAssets extends Target {
output,
targetPlatform: TargetPlatform.android,
shaderTarget: ShaderTarget.sksl,
- flavor: environment.defines[kFlavor],
);
environment.depFileService.writeToFile(
depfile,
diff --git a/packages/flutter_tools/lib/src/build_system/targets/common.dart b/packages/flutter_tools/lib/src/build_system/targets/common.dart
index 461638298b..c3507abb34 100644
--- a/packages/flutter_tools/lib/src/build_system/targets/common.dart
+++ b/packages/flutter_tools/lib/src/build_system/targets/common.dart
@@ -58,8 +58,6 @@ class CopyFlutterBundle extends Target {
if (buildModeEnvironment == null) {
throw MissingDefineException(kBuildMode, 'copy_flutter_bundle');
}
- final String? flavor = environment.defines[kFlavor];
-
final BuildMode buildMode = BuildMode.fromCliName(buildModeEnvironment);
environment.outputDir.createSync(recursive: true);
@@ -80,7 +78,6 @@ class CopyFlutterBundle extends Target {
targetPlatform: TargetPlatform.android,
buildMode: buildMode,
shaderTarget: ShaderTarget.sksl,
- flavor: flavor,
);
environment.depFileService.writeToFile(
assetDepfile,
diff --git a/packages/flutter_tools/lib/src/build_system/targets/ios.dart b/packages/flutter_tools/lib/src/build_system/targets/ios.dart
index 9336cd7415..66c806b60c 100644
--- a/packages/flutter_tools/lib/src/build_system/targets/ios.dart
+++ b/packages/flutter_tools/lib/src/build_system/targets/ios.dart
@@ -533,7 +533,6 @@ abstract class IosAssetBundle extends Target {
flutterProject.ios.infoPlist,
flutterProject.ios.appFrameworkInfoPlist,
],
- flavor: environment.defines[kFlavor],
);
environment.depFileService.writeToFile(
assetDepfile,
diff --git a/packages/flutter_tools/lib/src/build_system/targets/macos.dart b/packages/flutter_tools/lib/src/build_system/targets/macos.dart
index 7cd1e8193d..85bd01a9e5 100644
--- a/packages/flutter_tools/lib/src/build_system/targets/macos.dart
+++ b/packages/flutter_tools/lib/src/build_system/targets/macos.dart
@@ -393,7 +393,6 @@ abstract class MacOSBundleFlutterAssets extends Target {
if (buildModeEnvironment == null) {
throw MissingDefineException(kBuildMode, 'compile_macos_framework');
}
-
final BuildMode buildMode = BuildMode.fromCliName(buildModeEnvironment);
final Directory frameworkRootDirectory = environment
.outputDir
@@ -440,7 +439,6 @@ abstract class MacOSBundleFlutterAssets extends Target {
assetDirectory,
targetPlatform: TargetPlatform.darwin,
shaderTarget: ShaderTarget.sksl,
- flavor: environment.defines[kFlavor],
);
environment.depFileService.writeToFile(
assetDepfile,
diff --git a/packages/flutter_tools/lib/src/bundle_builder.dart b/packages/flutter_tools/lib/src/bundle_builder.dart
index 496f2d0138..f1ec2b1357 100644
--- a/packages/flutter_tools/lib/src/bundle_builder.dart
+++ b/packages/flutter_tools/lib/src/bundle_builder.dart
@@ -114,7 +114,6 @@ Future buildAssets({
String? assetDirPath,
String? packagesPath,
TargetPlatform? targetPlatform,
- String? flavor,
}) async {
assetDirPath ??= getAssetBuildDirectory();
packagesPath ??= globals.fs.path.absolute('.packages');
@@ -125,7 +124,6 @@ Future buildAssets({
manifestPath: manifestPath,
packagesPath: packagesPath,
targetPlatform: targetPlatform,
- flavor: flavor,
);
if (result != 0) {
return null;
diff --git a/packages/flutter_tools/lib/src/flutter_manifest.dart b/packages/flutter_tools/lib/src/flutter_manifest.dart
index 473413982b..68554d6ce9 100644
--- a/packages/flutter_tools/lib/src/flutter_manifest.dart
+++ b/packages/flutter_tools/lib/src/flutter_manifest.dart
@@ -231,12 +231,29 @@ class FlutterManifest {
_logger.printError('Expected deferred component manifest to be a map.');
continue;
}
+ List assetsUri = [];
+ final List? assets = component['assets'] as List?;
+ if (assets == null) {
+ assetsUri = const [];
+ } else {
+ for (final Object? asset in assets) {
+ if (asset is! String || asset == '') {
+ _logger.printError('Deferred component asset manifest contains a null or empty uri.');
+ continue;
+ }
+ try {
+ assetsUri.add(Uri.parse(asset));
+ } on FormatException {
+ _logger.printError('Asset manifest contains invalid uri: $asset.');
+ }
+ }
+ }
components.add(
DeferredComponent(
name: component['name'] as String,
libraries: component['libraries'] == null ?
[] : (component['libraries'] as List).cast(),
- assets: _computeAssets(component['assets']),
+ assets: assetsUri,
)
);
}
@@ -294,7 +311,26 @@ class FlutterManifest {
: fontList.map?>(castStringKeyedMap).whereType>().toList();
}
- late final List assets = _computeAssets(_flutterDescriptor['assets']);
+ late final List assets = _computeAssets();
+ List _computeAssets() {
+ final List? assets = _flutterDescriptor['assets'] as List?;
+ if (assets == null) {
+ return const [];
+ }
+ final List results = [];
+ for (final Object? asset in assets) {
+ if (asset is! String || asset == '') {
+ _logger.printError('Asset manifest contains a null or empty uri.');
+ continue;
+ }
+ try {
+ results.add(Uri(pathSegments: asset.split('/')));
+ } on FormatException {
+ _logger.printError('Asset manifest contains invalid uri: $asset.');
+ }
+ }
+ return results;
+ }
late final List fonts = _extractFonts();
@@ -485,7 +521,15 @@ void _validateFlutter(YamlMap? yaml, List errors) {
errors.add('Expected "$yamlKey" to be a bool, but got $yamlValue (${yamlValue.runtimeType}).');
}
case 'assets':
- errors.addAll(_validateAssets(yamlValue));
+ if (yamlValue is! YamlList) {
+ errors.add('Expected "$yamlKey" to be a list, but got $yamlValue (${yamlValue.runtimeType}).');
+ } else if (yamlValue.isEmpty) {
+ break;
+ } else if (yamlValue[0] is! String) {
+ errors.add(
+ 'Expected "$yamlKey" to be a list of strings, but the first element is $yamlValue (${yamlValue.runtimeType}).',
+ );
+ }
case 'shaders':
if (yamlValue is! YamlList) {
errors.add('Expected "$yamlKey" to be a list, but got $yamlValue (${yamlValue.runtimeType}).');
@@ -596,52 +640,17 @@ void _validateDeferredComponents(MapEntry kvp, List er
}
}
if (valueMap.containsKey('assets')) {
- errors.addAll(_validateAssets(valueMap['assets']));
+ final Object? assets = valueMap['assets'];
+ if (assets is! YamlList) {
+ errors.add('Expected "assets" to be a list, but got $assets (${assets.runtimeType}).');
+ } else {
+ _validateListType(assets, errors, '"assets" key in the $i element of "${kvp.key}"', 'file paths');
+ }
}
}
}
}
-List _validateAssets(Object? yaml) {
- final (_, List errors) = _computeAssetsSafe(yaml);
- return errors;
-}
-
-// TODO(andrewkolos): We end up parsing the assets section twice, once during
-// validation and once when the assets getter is called. We should consider
-// refactoring this class to parse and store everything in the constructor.
-// https://github.com/flutter/flutter/issues/139183
-(List, List errors) _computeAssetsSafe(Object? yaml) {
- if (yaml == null) {
- return (const [], const []);
- }
- if (yaml is! YamlList) {
- final String error = 'Expected "assets" to be a list, but got $yaml (${yaml.runtimeType}).';
- return (const [], [error]);
- }
- final List results = [];
- final List errors = [];
- for (final Object? rawAssetEntry in yaml) {
- final (AssetsEntry? parsed, String? error) = AssetsEntry.parseFromYamlSafe(rawAssetEntry);
- if (parsed != null) {
- results.add(parsed);
- }
- if (error != null) {
- errors.add(error);
- }
- }
- return (results, errors);
-}
-
-List _computeAssets(Object? assetsSection) {
- final (List result, List errors) = _computeAssetsSafe(assetsSection);
- if (errors.isNotEmpty) {
- throw Exception('Uncaught error(s) in assets section: '
- '${errors.join('\n')}');
- }
- return result;
-}
-
void _validateFonts(YamlList fonts, List errors) {
const Set fontWeights = {
100, 200, 300, 400, 500, 600, 700, 800, 900,
@@ -694,103 +703,3 @@ void _validateFonts(YamlList fonts, List errors) {
}
}
}
-
-/// Represents an entry under the `assets` section of a pubspec.
-@immutable
-class AssetsEntry {
- const AssetsEntry({
- required this.uri,
- this.flavors = const [],
- });
-
- final Uri uri;
- final List flavors;
-
- static const String _pathKey = 'path';
- static const String _flavorKey = 'flavors';
-
- static AssetsEntry? parseFromYaml(Object? yaml) {
- final (AssetsEntry? value, String? error) = parseFromYamlSafe(yaml);
- if (error != null) {
- throw Exception('Unexpected error when parsing assets entry');
- }
- return value!;
- }
-
- static (AssetsEntry? assetsEntry, String? error) parseFromYamlSafe(Object? yaml) {
-
- (Uri?, String?) tryParseUri(String uri) {
- try {
- return (Uri(pathSegments: uri.split('/')), null);
- } on FormatException {
- return (null, 'Asset manifest contains invalid uri: $uri.');
- }
- }
-
- if (yaml == null || yaml == '') {
- return (null, 'Asset manifest contains a null or empty uri.');
- }
-
- if (yaml is String) {
- final (Uri? uri, String? error) = tryParseUri(yaml);
- return uri == null ? (null, error) : (AssetsEntry(uri: uri), null);
- }
-
- if (yaml is Map) {
- if (yaml.keys.isEmpty) {
- return (null, null);
- }
-
- final Object? path = yaml[_pathKey];
- final Object? flavors = yaml[_flavorKey];
-
- if (path == null || path is! String) {
- return (null, 'Asset manifest entry is malformed. '
- 'Expected asset entry to be either a string or a map '
- 'containing a "$_pathKey" entry. Got ${path.runtimeType} instead.');
- }
-
- final Uri uri = Uri(pathSegments: path.split('/'));
-
- if (flavors == null) {
- return (AssetsEntry(uri: uri), null);
- }
-
- if (flavors is! YamlList) {
- return(null, 'Asset manifest entry is malformed. '
- 'Expected "$_flavorKey" entry to be a list of strings. '
- 'Got ${flavors.runtimeType} instead.');
- }
-
- final List flavorsListErrors = [];
- _validateListType(flavors, flavorsListErrors, 'flavors list of entry "$path"', 'String');
- if (flavorsListErrors.isNotEmpty) {
- return (null, 'Asset manifest entry is malformed. '
- 'Expected "$_flavorKey" entry to be a list of strings.\n'
- '${flavorsListErrors.join('\n')}');
- }
-
- final AssetsEntry entry = AssetsEntry(
- uri: Uri(pathSegments: path.split('/')),
- flavors: List.from(flavors),
- );
-
- return (entry, null);
- }
-
- return (null, 'Assets entry had unexpected shape. '
- 'Expected a string or an object. Got ${yaml.runtimeType} instead.');
- }
-
- @override
- bool operator ==(Object other) {
- if (other is! AssetsEntry) {
- return false;
- }
-
- return uri == other.uri && flavors == other.flavors;
- }
-
- @override
- int get hashCode => Object.hash(uri.hashCode, flavors.hashCode);
-}
diff --git a/packages/flutter_tools/lib/src/run_hot.dart b/packages/flutter_tools/lib/src/run_hot.dart
index 740b18961e..117e0f389c 100644
--- a/packages/flutter_tools/lib/src/run_hot.dart
+++ b/packages/flutter_tools/lib/src/run_hot.dart
@@ -141,8 +141,6 @@ class HotRunner extends ResidentRunner {
NativeAssetsBuildRunner? _buildRunner;
- String? flavor;
-
Future _calculateTargetPlatform() async {
if (_targetPlatform != null) {
return;
@@ -496,10 +494,7 @@ class HotRunner extends ResidentRunner {
final bool rebuildBundle = assetBundle.needsBuild();
if (rebuildBundle) {
globals.printTrace('Updating assets');
- final int result = await assetBundle.build(
- packagesPath: '.packages',
- flavor: debuggingOptions.buildInfo.flavor,
- );
+ final int result = await assetBundle.build(packagesPath: '.packages');
if (result != 0) {
return UpdateFSReport();
}
diff --git a/packages/flutter_tools/test/commands.shard/hermetic/run_test.dart b/packages/flutter_tools/test/commands.shard/hermetic/run_test.dart
index 6aef5d2ebb..3032eafd9a 100644
--- a/packages/flutter_tools/test/commands.shard/hermetic/run_test.dart
+++ b/packages/flutter_tools/test/commands.shard/hermetic/run_test.dart
@@ -1567,7 +1567,6 @@ class CapturingAppDomain extends AppDomain {
bool machine = true,
String? userIdentifier,
bool enableDevTools = true,
- String? flavor,
}) async {
this.multidexEnabled = multidexEnabled;
this.userIdentifier = userIdentifier;
diff --git a/packages/flutter_tools/test/general.shard/asset_bundle_test.dart b/packages/flutter_tools/test/general.shard/asset_bundle_test.dart
index 3704f1bb08..4b798f61ec 100644
--- a/packages/flutter_tools/test/general.shard/asset_bundle_test.dart
+++ b/packages/flutter_tools/test/general.shard/asset_bundle_test.dart
@@ -9,15 +9,11 @@ import 'package:file/memory.dart';
import 'package:flutter_tools/src/artifacts.dart';
import 'package:flutter_tools/src/asset.dart';
import 'package:flutter_tools/src/base/file_system.dart';
-import 'package:flutter_tools/src/base/logger.dart';
import 'package:flutter_tools/src/base/platform.dart';
-import 'package:flutter_tools/src/base/user_messages.dart';
import 'package:flutter_tools/src/build_info.dart';
import 'package:flutter_tools/src/bundle_builder.dart';
-import 'package:flutter_tools/src/cache.dart';
import 'package:flutter_tools/src/devfs.dart';
import 'package:flutter_tools/src/globals.dart' as globals;
-import 'package:flutter_tools/src/project.dart';
import 'package:standard_message_codec/standard_message_codec.dart';
import '../src/common.dart';
@@ -27,9 +23,7 @@ const String shaderLibDir = '/./shader_lib';
void main() {
group('AssetBundle.build', () {
- late Logger logger;
late FileSystem testFileSystem;
- late Platform platform;
setUp(() async {
testFileSystem = MemoryFileSystem(
@@ -38,8 +32,6 @@ void main() {
: FileSystemStyle.posix,
);
testFileSystem.currentDirectory = testFileSystem.systemTempDirectory.createTempSync('flutter_asset_bundle_test.');
- logger = BufferLogger.test();
- platform = FakePlatform(operatingSystem: globals.platform.operatingSystem);
});
testUsingContext('nonempty', () async {
@@ -331,185 +323,6 @@ flutter:
FileSystem: () => testFileSystem,
ProcessManager: () => FakeProcessManager.any(),
});
-
- group('flavors feature', () {
- Future buildBundleWithFlavor(String? flavor) async {
- final ManifestAssetBundle bundle = ManifestAssetBundle(
- logger: logger,
- fileSystem: testFileSystem,
- platform: platform,
- splitDeferredAssets: true,
- );
-
- await bundle.build(
- packagesPath: '.packages',
- flutterProject: FlutterProject.fromDirectoryTest(testFileSystem.currentDirectory),
- flavor: flavor,
- );
- return bundle;
- }
-
- late final String? previousCacheFlutterRootValue;
-
- setUpAll(() {
- previousCacheFlutterRootValue = Cache.flutterRoot;
- Cache.flutterRoot = Cache.defaultFlutterRoot(platform: platform, fileSystem: testFileSystem, userMessages: UserMessages());
- });
-
- tearDownAll(() => Cache.flutterRoot = previousCacheFlutterRootValue);
-
- testWithoutContext('correctly bundles assets given a simple asset manifest with flavors', () async {
- testFileSystem.file('.packages').createSync();
- testFileSystem.file(testFileSystem.path.join('assets', 'common', 'image.png')).createSync(recursive: true);
- testFileSystem.file(testFileSystem.path.join('assets', 'vanilla', 'ice-cream.png')).createSync(recursive: true);
- testFileSystem.file(testFileSystem.path.join('assets', 'strawberry', 'ice-cream.png')).createSync(recursive: true);
- testFileSystem.file(testFileSystem.path.join('assets', 'orange', 'ice-cream.png')).createSync(recursive: true);
- testFileSystem.file('pubspec.yaml')
- ..createSync()
- ..writeAsStringSync(r'''
-name: example
-flutter:
- assets:
- - assets/common/
- - path: assets/vanilla/
- flavors:
- - vanilla
- - path: assets/strawberry/
- flavors:
- - strawberry
- - path: assets/orange/ice-cream.png
- flavors:
- - orange
- ''');
-
- ManifestAssetBundle bundle;
- bundle = await buildBundleWithFlavor(null);
- expect(bundle.entries.keys, contains('assets/common/image.png'));
- expect(bundle.entries.keys, isNot(contains('assets/vanilla/ice-cream.png')));
- expect(bundle.entries.keys, isNot(contains('assets/strawberry/ice-cream.png')));
- expect(bundle.entries.keys, isNot(contains('assets/orange/ice-cream.png')));
-
- bundle = await buildBundleWithFlavor('strawberry');
- expect(bundle.entries.keys, contains('assets/common/image.png'));
- expect(bundle.entries.keys, isNot(contains('assets/vanilla/ice-cream.png')));
- expect(bundle.entries.keys, contains('assets/strawberry/ice-cream.png'));
- expect(bundle.entries.keys, isNot(contains('assets/orange/ice-cream.png')));
-
- bundle = await buildBundleWithFlavor('orange');
- expect(bundle.entries.keys, contains('assets/common/image.png'));
- expect(bundle.entries.keys, isNot(contains('assets/vanilla/ice-cream.png')));
- expect(bundle.entries.keys, isNot(contains('assets/strawberry/ice-cream.png')));
- expect(bundle.entries.keys, contains('assets/orange/ice-cream.png'));
- });
-
- testWithoutContext('throws a tool exit when a non-flavored folder contains a flavored asset', () async {
- testFileSystem.file('.packages').createSync();
- testFileSystem.file(testFileSystem.path.join('assets', 'unflavored.png')).createSync(recursive: true);
- testFileSystem.file(testFileSystem.path.join('assets', 'vanillaOrange.png')).createSync(recursive: true);
-
- testFileSystem.file('pubspec.yaml')
- ..createSync()
- ..writeAsStringSync(r'''
- name: example
- flutter:
- assets:
- - assets/
- - path: assets/vanillaOrange.png
- flavors:
- - vanilla
- - orange
- ''');
-
- expect(
- buildBundleWithFlavor(null),
- throwsToolExit(message: 'Multiple assets entries include the file '
- '"assets/vanillaOrange.png", but they specify different lists of flavors.\n'
- 'An entry with the path "assets/" does not specify any flavors.\n'
- 'An entry with the path "assets/vanillaOrange.png" specifies the flavor(s): "vanilla", "orange".\n\n'
- 'Consider organizing assets with different flavors into different directories.'),
- );
- });
-
- testWithoutContext('throws a tool exit when a flavored folder contains a flavorless asset', () async {
- testFileSystem.file('.packages').createSync();
- testFileSystem.file(testFileSystem.path.join('vanilla', 'vanilla.png')).createSync(recursive: true);
- testFileSystem.file(testFileSystem.path.join('vanilla', 'flavorless.png')).createSync(recursive: true);
-
- testFileSystem.file('pubspec.yaml')
- ..createSync()
- ..writeAsStringSync(r'''
- name: example
- flutter:
- assets:
- - path: vanilla/
- flavors:
- - vanilla
- - vanilla/flavorless.png
- ''');
- expect(
- buildBundleWithFlavor(null),
- throwsToolExit(message: 'Multiple assets entries include the file '
- '"vanilla/flavorless.png", but they specify different lists of flavors.\n'
- 'An entry with the path "vanilla/" specifies the flavor(s): "vanilla".\n'
- 'An entry with the path "vanilla/flavorless.png" does not specify any flavors.\n\n'
- 'Consider organizing assets with different flavors into different directories.'),
- );
- });
-
- testWithoutContext('tool exits when two file-explicit entries give the same asset different flavors', () {
- testFileSystem.file('.packages').createSync();
- testFileSystem.file('orange.png').createSync(recursive: true);
- testFileSystem.file('pubspec.yaml')
- ..createSync()
- ..writeAsStringSync(r'''
- name: example
- flutter:
- assets:
- - path: orange.png
- flavors:
- - orange
- - path: orange.png
- flavors:
- - mango
- ''');
-
- expect(
- buildBundleWithFlavor(null),
- throwsToolExit(message: 'Multiple assets entries include the file '
- '"orange.png", but they specify different lists of flavors.\n'
- 'An entry with the path "orange.png" specifies the flavor(s): "orange".\n'
- 'An entry with the path "orange.png" specifies the flavor(s): "mango".'),
- );
- });
-
- testWithoutContext('throws ToolExit when flavor from file-level declaration has different flavor from containing folder flavor declaration', () async {
- testFileSystem.file('.packages').createSync();
- testFileSystem.file(testFileSystem.path.join('vanilla', 'actually-strawberry.png')).createSync(recursive: true);
- testFileSystem.file(testFileSystem.path.join('vanilla', 'vanilla.png')).createSync(recursive: true);
-
- testFileSystem.file('pubspec.yaml')
- ..createSync()
- ..writeAsStringSync(r'''
- name: example
- flutter:
- assets:
- - path: vanilla/
- flavors:
- - vanilla
- - path: vanilla/actually-strawberry.png
- flavors:
- - strawberry
- ''');
- expect(
- buildBundleWithFlavor(null),
- throwsToolExit(message: 'Multiple assets entries include the file '
- '"vanilla/actually-strawberry.png", but they specify different lists of flavors.\n'
- 'An entry with the path "vanilla/" specifies the flavor(s): "vanilla".\n'
- 'An entry with the path "vanilla/actually-strawberry.png" '
- 'specifies the flavor(s): "strawberry".'),
- );
- });
- });
});
group('AssetBundle.build (web builds)', () {
diff --git a/packages/flutter_tools/test/general.shard/base/deferred_component_test.dart b/packages/flutter_tools/test/general.shard/base/deferred_component_test.dart
index c2acb6829f..3a718f40f2 100644
--- a/packages/flutter_tools/test/general.shard/base/deferred_component_test.dart
+++ b/packages/flutter_tools/test/general.shard/base/deferred_component_test.dart
@@ -6,7 +6,6 @@ import 'package:file/memory.dart';
import 'package:flutter_tools/src/base/deferred_component.dart';
import 'package:flutter_tools/src/base/file_system.dart';
import 'package:flutter_tools/src/base/logger.dart';
-import 'package:flutter_tools/src/flutter_manifest.dart';
import '../../src/common.dart';
@@ -16,27 +15,18 @@ void main() {
final DeferredComponent component = DeferredComponent(
name: 'bestcomponent',
libraries: ['lib1', 'lib2'],
- assets: [
- AssetsEntry(uri: Uri.file('asset1')),
- AssetsEntry(uri: Uri.file('asset2')),
- ],
+ assets: [Uri.file('asset1'), Uri.file('asset2')],
);
expect(component.name, 'bestcomponent');
expect(component.libraries, ['lib1', 'lib2']);
- expect(component.assets, [
- AssetsEntry(uri: Uri.file('asset1')),
- AssetsEntry(uri: Uri.file('asset2')),
- ]);
+ expect(component.assets, [Uri.file('asset1'), Uri.file('asset2')]);
});
testWithoutContext('assignLoadingUnits selects the needed loading units and sets assigned', () {
final DeferredComponent component = DeferredComponent(
name: 'bestcomponent',
libraries: ['lib1', 'lib2'],
- assets: [
- AssetsEntry(uri: Uri.file('asset1')),
- AssetsEntry(uri: Uri.file('asset2')),
- ],
+ assets: [Uri.file('asset1'), Uri.file('asset2')],
);
expect(component.libraries, ['lib1', 'lib2']);
expect(component.assigned, false);
@@ -104,10 +94,7 @@ void main() {
final DeferredComponent component = DeferredComponent(
name: 'bestcomponent',
libraries: ['lib1', 'lib2'],
- assets: [
- AssetsEntry(uri: Uri.file('asset1')),
- AssetsEntry(uri: Uri.file('asset2')),
- ],
+ assets: [Uri.file('asset1'), Uri.file('asset2')],
);
expect(component.toString(), '\nDeferredComponent: bestcomponent\n Libraries:\n - lib1\n - lib2\n Assets:\n - asset1\n - asset2');
});
@@ -116,10 +103,7 @@ void main() {
final DeferredComponent component = DeferredComponent(
name: 'bestcomponent',
libraries: ['lib1', 'lib2'],
- assets: [
- AssetsEntry(uri: Uri.file('asset1')),
- AssetsEntry(uri: Uri.file('asset2')),
- ],
+ assets: [Uri.file('asset1'), Uri.file('asset2')],
);
component.assignLoadingUnits([LoadingUnit(id: 2, libraries: ['lib1'])]);
expect(component.toString(), '\nDeferredComponent: bestcomponent\n Libraries:\n - lib1\n - lib2\n LoadingUnits:\n - 2\n Assets:\n - asset1\n - asset2');
diff --git a/packages/flutter_tools/test/general.shard/build_info_test.dart b/packages/flutter_tools/test/general.shard/build_info_test.dart
index 0ef3c35945..ae1c92529d 100644
--- a/packages/flutter_tools/test/general.shard/build_info_test.dart
+++ b/packages/flutter_tools/test/general.shard/build_info_test.dart
@@ -207,7 +207,7 @@ void main() {
});
testWithoutContext('toEnvironmentConfig encoding of standard values', () {
- const BuildInfo buildInfo = BuildInfo(BuildMode.debug, 'strawberry',
+ const BuildInfo buildInfo = BuildInfo(BuildMode.debug, '',
treeShakeIcons: true,
trackWidgetCreation: true,
dartDefines: ['foo=2', 'bar=2'],
@@ -220,7 +220,7 @@ void main() {
packagesPath: 'foo/.dart_tool/package_config.json',
codeSizeDirectory: 'foo/code-size',
// These values are ignored by toEnvironmentConfig
- androidProjectArgs: ['foo=bar', 'fizz=bazz'],
+ androidProjectArgs: ['foo=bar', 'fizz=bazz']
);
expect(buildInfo.toEnvironmentConfig(), {
@@ -235,7 +235,6 @@ void main() {
'BUNDLE_SKSL_PATH': 'foo/bar/baz.sksl.json',
'PACKAGE_CONFIG': 'foo/.dart_tool/package_config.json',
'CODE_SIZE_DIRECTORY': 'foo/code-size',
- 'FLAVOR': 'strawberry',
});
});
diff --git a/packages/flutter_tools/test/general.shard/build_system/targets/assets_test.dart b/packages/flutter_tools/test/general.shard/build_system/targets/assets_test.dart
index 0a06c7d603..e021361f03 100644
--- a/packages/flutter_tools/test/general.shard/build_system/targets/assets_test.dart
+++ b/packages/flutter_tools/test/general.shard/build_system/targets/assets_test.dart
@@ -32,7 +32,6 @@ void main() {
fileSystem: fileSystem,
logger: BufferLogger.test(),
platform: FakePlatform(),
- defines: {},
);
fileSystem.file(environment.buildDir.childFile('app.dill')).createSync(recursive: true);
fileSystem.file('packages/flutter_tools/lib/src/build_system/targets/assets.dart')
@@ -94,69 +93,6 @@ flutter:
ProcessManager: () => FakeProcessManager.any(),
});
- group("Only copies assets with a flavor if the assets' flavor matches the flavor in the environment", () {
- testUsingContext('When the environment does not have a flavor defined', () async {
- fileSystem.file('pubspec.yaml')
- ..createSync()
- ..writeAsStringSync('''
- name: example
- flutter:
- assets:
- - assets/common/
- - path: assets/vanilla/
- flavors:
- - vanilla
- - path: assets/strawberry/
- flavors:
- - strawberry
- ''');
-
- fileSystem.file('assets/common/image.png').createSync(recursive: true);
- fileSystem.file('assets/vanilla/ice-cream.png').createSync(recursive: true);
- fileSystem.file('assets/strawberry/ice-cream.png').createSync(recursive: true);
-
- await const CopyAssets().build(environment);
-
- expect(fileSystem.file('${environment.buildDir.path}/flutter_assets/assets/common/image.png'), exists);
- expect(fileSystem.file('${environment.buildDir.path}/flutter_assets/assets/vanilla/ice-cream.png'), isNot(exists));
- expect(fileSystem.file('${environment.buildDir.path}/flutter_assets/assets/strawberry/ice-cream.png'), isNot(exists));
- }, overrides: {
- FileSystem: () => fileSystem,
- ProcessManager: () => FakeProcessManager.any(),
- });
-
- testUsingContext('When the environment has a flavor defined', () async {
- environment.defines[kFlavor] = 'strawberry';
- fileSystem.file('pubspec.yaml')
- ..createSync()
- ..writeAsStringSync('''
- name: example
- flutter:
- assets:
- - assets/common/
- - path: assets/vanilla/
- flavors:
- - vanilla
- - path: assets/strawberry/
- flavors:
- - strawberry
- ''');
-
- fileSystem.file('assets/common/image.png').createSync(recursive: true);
- fileSystem.file('assets/vanilla/ice-cream.png').createSync(recursive: true);
- fileSystem.file('assets/strawberry/ice-cream.png').createSync(recursive: true);
-
- await const CopyAssets().build(environment);
-
- expect(fileSystem.file('${environment.buildDir.path}/flutter_assets/assets/common/image.png'), exists);
- expect(fileSystem.file('${environment.buildDir.path}/flutter_assets/assets/vanilla/ice-cream.png'), isNot(exists));
- expect(fileSystem.file('${environment.buildDir.path}/flutter_assets/assets/strawberry/ice-cream.png'), exists);
- }, overrides: {
- FileSystem: () => fileSystem,
- ProcessManager: () => FakeProcessManager.any(),
- });
- });
-
testUsingContext('Throws exception if pubspec contains missing files', () async {
fileSystem.file('pubspec.yaml')
..createSync()
diff --git a/packages/flutter_tools/test/general.shard/devfs_test.dart b/packages/flutter_tools/test/general.shard/devfs_test.dart
index 4872cddaa6..d4b4e5fcf1 100644
--- a/packages/flutter_tools/test/general.shard/devfs_test.dart
+++ b/packages/flutter_tools/test/general.shard/devfs_test.dart
@@ -733,14 +733,7 @@ class FakeBundle extends AssetBundle {
List get additionalDependencies => [];
@override
- Future build({
- String manifestPath = defaultManifestPath,
- String? assetDirPath,
- String? packagesPath,
- bool deferredComponentsEnabled = false,
- TargetPlatform? targetPlatform,
- String? flavor,
- }) async {
+ Future build({String manifestPath = defaultManifestPath, String? assetDirPath, String? packagesPath, bool deferredComponentsEnabled = false, TargetPlatform? targetPlatform}) async {
return 0;
}
diff --git a/packages/flutter_tools/test/general.shard/flutter_manifest_test.dart b/packages/flutter_tools/test/general.shard/flutter_manifest_test.dart
index dc048f5c8f..d0ca23fc3b 100644
--- a/packages/flutter_tools/test/general.shard/flutter_manifest_test.dart
+++ b/packages/flutter_tools/test/general.shard/flutter_manifest_test.dart
@@ -13,17 +13,12 @@ import 'package:flutter_tools/src/flutter_manifest.dart';
import '../src/common.dart';
void main() {
- late BufferLogger logger;
-
setUpAll(() {
Cache.flutterRoot = getFlutterRoot();
});
- setUp(() {
- logger = BufferLogger.test();
- });
-
testWithoutContext('FlutterManifest is empty when the pubspec.yaml file is empty', () async {
+ final BufferLogger logger = BufferLogger.test();
final FlutterManifest flutterManifest = FlutterManifest.createFromString(
'',
logger: logger,
@@ -39,6 +34,7 @@ void main() {
});
testWithoutContext('FlutterManifest is null when the pubspec.yaml file is not a map', () async {
+ final BufferLogger logger = BufferLogger.test();
expect(FlutterManifest.createFromString(
'Not a map',
logger: logger,
@@ -54,6 +50,7 @@ dependencies:
flutter:
sdk: flutter
''';
+ final BufferLogger logger = BufferLogger.test();
final FlutterManifest flutterManifest = FlutterManifest.createFromString(
manifest,
logger: logger,
@@ -77,6 +74,7 @@ dependencies:
flutter:
uses-material-design: true
''';
+ final BufferLogger logger = BufferLogger.test();
final FlutterManifest flutterManifest = FlutterManifest.createFromString(
manifest,
logger: logger,
@@ -94,6 +92,7 @@ dependencies:
flutter:
generate: true
''';
+ final BufferLogger logger = BufferLogger.test();
final FlutterManifest flutterManifest = FlutterManifest.createFromString(
manifest,
logger: logger,
@@ -111,6 +110,7 @@ dependencies:
flutter:
generate: "invalid"
''';
+ final BufferLogger logger = BufferLogger.test();
final FlutterManifest flutterManifest = FlutterManifest.createFromString(
manifest,
logger: logger,
@@ -128,6 +128,7 @@ dependencies:
flutter:
generate: false
''';
+ final BufferLogger logger = BufferLogger.test();
final FlutterManifest flutterManifest = FlutterManifest.createFromString(
manifest,
logger: logger,
@@ -148,38 +149,18 @@ flutter:
- a/foo
- a/bar
''';
-
+ final BufferLogger logger = BufferLogger.test();
final FlutterManifest flutterManifest = FlutterManifest.createFromString(
manifest,
logger: logger,
)!;
- expect(flutterManifest.assets, [
- AssetsEntry(uri: Uri.parse('a/foo')),
- AssetsEntry(uri: Uri.parse('a/bar')),
+ expect(flutterManifest.assets, [
+ Uri.parse('a/foo'),
+ Uri.parse('a/bar'),
]);
});
- testWithoutContext('FlutterManifest assets entry flavor is not a string', () async {
- const String manifest = '''
-name: test
-dependencies:
- flutter:
- sdk: flutter
-flutter:
- uses-material-design: true
- assets:
- - assets/folder/
- - path: assets/vanilla/
- flavors:
- - key1: value1
- key2: value2
-''';
- FlutterManifest.createFromString(manifest, logger: logger);
- expect(logger.errorText, contains('Asset manifest entry is malformed. '
- 'Expected "flavors" entry to be a list of strings.'));
- });
-
testWithoutContext('FlutterManifest has one font family with one asset', () async {
const String manifest = '''
name: test
@@ -193,7 +174,7 @@ flutter:
fonts:
- asset: a/bar
''';
-
+ final BufferLogger logger = BufferLogger.test();
final FlutterManifest flutterManifest = FlutterManifest.createFromString(
manifest,
logger: logger,
@@ -230,7 +211,7 @@ flutter:
- asset: a/bar
weight: 400
''';
-
+ final BufferLogger logger = BufferLogger.test();
final FlutterManifest flutterManifest = FlutterManifest.createFromString(
manifest,
logger: logger,
@@ -270,7 +251,7 @@ flutter:
weight: 400
style: italic
''';
-
+ final BufferLogger logger = BufferLogger.test();
final FlutterManifest flutterManifest = FlutterManifest.createFromString(
manifest,
logger: logger,
@@ -316,7 +297,7 @@ flutter:
asset: a/baz
style: italic
''';
-
+ final BufferLogger logger = BufferLogger.test();
final FlutterManifest flutterManifest = FlutterManifest.createFromString(
manifest,
logger: logger,
@@ -378,7 +359,7 @@ flutter:
asset: a/baz
style: italic
''';
-
+ final BufferLogger logger = BufferLogger.test();
final FlutterManifest flutterManifest = FlutterManifest.createFromString(
manifest,
logger: logger,
@@ -424,7 +405,7 @@ flutter:
weight: 400
style: italic
''';
-
+ final BufferLogger logger = BufferLogger.test();
final FlutterManifest flutterManifest = FlutterManifest.createFromString(
manifest,
logger: logger,
@@ -467,7 +448,7 @@ flutter:
style: italic
- family: bar
''';
-
+ final BufferLogger logger = BufferLogger.test();
final FlutterManifest flutterManifest = FlutterManifest.createFromString(
manifest,
logger: logger,
@@ -506,7 +487,7 @@ flutter:
fonts:
- weight: 400
''';
-
+ final BufferLogger logger = BufferLogger.test();
final FlutterManifest flutterManifest = FlutterManifest.createFromString(
manifest,
logger: logger,
@@ -524,7 +505,7 @@ dependencies:
sdk: flutter
flutter:
''';
-
+ final BufferLogger logger = BufferLogger.test();
final FlutterManifest flutterManifest = FlutterManifest.createFromString(
manifest,
logger: logger,
@@ -545,7 +526,7 @@ flutter:
androidPackage: com.example
androidX: true
''';
-
+ final BufferLogger logger = BufferLogger.test();
final FlutterManifest flutterManifest = FlutterManifest.createFromString(
manifest,
logger: logger,
@@ -563,7 +544,7 @@ flutter:
plugin:
androidPackage: com.example
''';
-
+ final BufferLogger logger = BufferLogger.test();
final FlutterManifest flutterManifest = FlutterManifest.createFromString(
manifest,
logger: logger,
@@ -584,7 +565,7 @@ flutter:
package: com.example
pluginClass: TestPlugin
''';
-
+ final BufferLogger logger = BufferLogger.test();
final FlutterManifest flutterManifest = FlutterManifest.createFromString(
manifest,
logger: logger,
@@ -604,7 +585,7 @@ flutter:
ios:
pluginClass: HelloPlugin
''';
-
+ final BufferLogger logger = BufferLogger.test();
final FlutterManifest flutterManifest = FlutterManifest.createFromString(
manifest,
logger: logger,
@@ -620,7 +601,7 @@ name: test
flutter:
plugin:
''';
-
+ final BufferLogger logger = BufferLogger.test();
final FlutterManifest? flutterManifest = FlutterManifest.createFromString(
manifest,
logger: logger,
@@ -640,7 +621,7 @@ dependencies:
sdk: flutter
flutter:
''';
-
+ final BufferLogger logger = BufferLogger.test();
final FlutterManifest? flutterManifest = FlutterManifest.createFromString(
manifest,
logger: logger,
@@ -662,7 +643,7 @@ dependencies:
sdk: flutter
flutter:
''';
-
+ final BufferLogger logger = BufferLogger.test();
final FlutterManifest? flutterManifest = FlutterManifest.createFromString(
manifest,
logger: logger,
@@ -683,7 +664,7 @@ dependencies:
sdk: flutter
flutter:
''';
-
+ final BufferLogger logger = BufferLogger.test();
final FlutterManifest? flutterManifest = FlutterManifest.createFromString(
manifest,
logger: logger,
@@ -705,7 +686,7 @@ dependencies:
sdk: flutter
flutter:
''';
-
+ final BufferLogger logger = BufferLogger.test();
final FlutterManifest? flutterManifest = FlutterManifest.createFromString(
manifest,
logger: logger,
@@ -727,7 +708,7 @@ dependencies:
sdk: flutter
flutter:
''';
-
+ final BufferLogger logger = BufferLogger.test();
final FlutterManifest? flutterManifest = FlutterManifest.createFromString(
manifest,
logger: logger,
@@ -744,7 +725,7 @@ dependencies:
sdk: flutter
flutter:
''';
-
+ final BufferLogger logger = BufferLogger.test();
final FlutterManifest? flutterManifest = FlutterManifest.createFromString(
manifest,
logger: logger,
@@ -766,7 +747,7 @@ flutter:
fonts:
-asset: a/bar
''';
-
+ final BufferLogger logger = BufferLogger.test();
final FlutterManifest? flutterManifest = FlutterManifest.createFromString(
manifest,
logger: logger,
@@ -786,7 +767,7 @@ dependencies:
flutter:
fonts: []
''';
-
+ final BufferLogger logger = BufferLogger.test();
final FlutterManifest? flutterManifest = FlutterManifest.createFromString(
manifest,
logger: logger,
@@ -805,7 +786,7 @@ dependencies:
flutter:
assets: []
''';
-
+ final BufferLogger logger = BufferLogger.test();
final FlutterManifest? flutterManifest = FlutterManifest.createFromString(
manifest,
logger: logger,
@@ -828,7 +809,7 @@ flutter:
fonts:
- asset
''';
-
+ final BufferLogger logger = BufferLogger.test();
final FlutterManifest? flutterManifest = FlutterManifest.createFromString(
manifest,
logger: logger,
@@ -852,7 +833,7 @@ flutter:
fonts:
-asset: a/bar
''';
-
+ final BufferLogger logger = BufferLogger.test();
final FlutterManifest? flutterManifest = FlutterManifest.createFromString(
manifest,
logger: logger,
@@ -877,7 +858,7 @@ flutter:
- asset: a/bar
- string
''';
-
+ final BufferLogger logger = BufferLogger.test();
final FlutterManifest? flutterManifest = FlutterManifest.createFromString(
manifest,
logger: logger,
@@ -899,13 +880,15 @@ flutter:
- lib/gallery/example_code.dart
-
''';
-
- FlutterManifest.createFromString(
+ final BufferLogger logger = BufferLogger.test();
+ final FlutterManifest flutterManifest = FlutterManifest.createFromString(
manifest,
logger: logger,
- );
+ )!;
+ final List assets = flutterManifest.assets;
expect(logger.errorText, contains('Asset manifest contains a null or empty uri.'));
+ expect(assets, hasLength(1));
});
testWithoutContext('FlutterManifest handles special characters in asset URIs', () {
@@ -921,18 +904,18 @@ flutter:
- lib/gallery/abc?xyz
- lib/gallery/aaa bbb
''';
-
+ final BufferLogger logger = BufferLogger.test();
final FlutterManifest flutterManifest = FlutterManifest.createFromString(
manifest,
logger: logger,
)!;
- final List assets = flutterManifest.assets;
+ final List assets = flutterManifest.assets;
expect(assets, hasLength(3));
- expect(assets, [
- AssetsEntry(uri: Uri.parse('lib/gallery/abc%23xyz')),
- AssetsEntry(uri: Uri.parse('lib/gallery/abc%3Fxyz')),
- AssetsEntry(uri: Uri.parse('lib/gallery/aaa%20bbb')),
+ expect(assets, [
+ Uri.parse('lib/gallery/abc%23xyz'),
+ Uri.parse('lib/gallery/abc%3Fxyz'),
+ Uri.parse('lib/gallery/aaa%20bbb'),
]);
});
@@ -946,7 +929,7 @@ dependencies:
flutter:
- uses-material-design: true
''';
-
+ final BufferLogger logger = BufferLogger.test();
final FlutterManifest? flutterManifest = FlutterManifest.createFromString(
manifest,
logger: logger,
@@ -971,7 +954,7 @@ flutter:
''';
final FileSystem fileSystem = MemoryFileSystem.test();
fileSystem.file('pubspec.yaml').writeAsStringSync(manifest);
-
+ final BufferLogger logger = BufferLogger.test();
final FlutterManifest flutterManifest = FlutterManifest.createFromPath(
'pubspec.yaml',
fileSystem: fileSystem,
@@ -992,7 +975,7 @@ flutter:
final FileSystem fileSystem = MemoryFileSystem.test(style: FileSystemStyle.windows);
fileSystem.file('pubspec.yaml').writeAsStringSync(manifest);
-
+ final BufferLogger logger = BufferLogger.test();
final FlutterManifest flutterManifest = FlutterManifest.createFromPath(
'pubspec.yaml',
fileSystem: fileSystem,
@@ -1009,7 +992,7 @@ flutter:
plugin:
androidPackage: com.example
''';
-
+ final BufferLogger logger = BufferLogger.test();
final FlutterManifest flutterManifest = FlutterManifest.createFromString(
manifest,
logger: logger,
@@ -1028,7 +1011,7 @@ flutter:
some_platform:
pluginClass: SomeClass
''';
-
+ final BufferLogger logger = BufferLogger.test();
final FlutterManifest flutterManifest = FlutterManifest.createFromString(
manifest,
logger: logger,
@@ -1049,7 +1032,7 @@ flutter:
ios:
pluginClass: SomeClass
''';
-
+ final BufferLogger logger = BufferLogger.test();
final FlutterManifest flutterManifest = FlutterManifest.createFromString(
manifest,
logger: logger,
@@ -1075,7 +1058,7 @@ flutter:
ios:
pluginClass: SomeClass
''';
-
+ final BufferLogger logger = BufferLogger.test();
final FlutterManifest flutterManifest = FlutterManifest.createFromString(
manifest,
logger: logger,
@@ -1099,7 +1082,7 @@ flutter:
platforms:
- android
''';
-
+ final BufferLogger logger = BufferLogger.test();
final FlutterManifest? flutterManifest = FlutterManifest.createFromString(
manifest,
logger: logger,
@@ -1121,7 +1104,7 @@ flutter:
ios:
pluginClass: SomeClass
''';
-
+ final BufferLogger logger = BufferLogger.test();
final FlutterManifest? flutterManifest = FlutterManifest.createFromString(
manifest,
logger: logger,
@@ -1141,7 +1124,7 @@ dependencies:
flutter:
licenses: []
''';
-
+ final BufferLogger logger = BufferLogger.test();
final FlutterManifest? flutterManifest = FlutterManifest.createFromString(
manifest,
logger: logger,
@@ -1161,7 +1144,7 @@ flutter:
licenses:
- foo.txt
''';
-
+ final BufferLogger logger = BufferLogger.test();
final FlutterManifest flutterManifest = FlutterManifest.createFromString(
manifest,
logger: logger,
@@ -1179,7 +1162,7 @@ dependencies:
flutter:
licenses: foo.txt
''';
-
+ final BufferLogger logger = BufferLogger.test();
final FlutterManifest? flutterManifest = FlutterManifest.createFromString(
manifest,
logger: logger,
@@ -1200,7 +1183,7 @@ flutter:
- foo.txt
- bar: fizz
''';
-
+ final BufferLogger logger = BufferLogger.test();
final FlutterManifest? flutterManifest = FlutterManifest.createFromString(
manifest,
logger: logger,
@@ -1224,7 +1207,7 @@ flutter:
assets:
- path/to/asset.jpg
''';
-
+ final BufferLogger logger = BufferLogger.test();
final FlutterManifest flutterManifest = FlutterManifest.createFromString(
manifest,
logger: logger,
@@ -1237,7 +1220,7 @@ flutter:
expect(deferredComponents[0].libraries.length, 1);
expect(deferredComponents[0].libraries[0], 'lib1');
expect(deferredComponents[0].assets.length, 1);
- expect(deferredComponents[0].assets[0].uri.path, 'path/to/asset.jpg');
+ expect(deferredComponents[0].assets[0].path, 'path/to/asset.jpg');
});
testWithoutContext('FlutterManifest parses multiple deferred components', () async {
@@ -1260,7 +1243,7 @@ flutter:
assets:
- path/to/asset2.jpg
''';
-
+ final BufferLogger logger = BufferLogger.test();
final FlutterManifest flutterManifest = FlutterManifest.createFromString(
manifest,
logger: logger,
@@ -1273,14 +1256,14 @@ flutter:
expect(deferredComponents[0].libraries.length, 1);
expect(deferredComponents[0].libraries[0], 'lib1');
expect(deferredComponents[0].assets.length, 1);
- expect(deferredComponents[0].assets[0].uri.path, 'path/to/asset.jpg');
+ expect(deferredComponents[0].assets[0].path, 'path/to/asset.jpg');
expect(deferredComponents[1].name, 'component2');
expect(deferredComponents[1].libraries.length, 2);
expect(deferredComponents[1].libraries[0], 'lib2');
expect(deferredComponents[1].libraries[1], 'lib3');
expect(deferredComponents[1].assets.length, 1);
- expect(deferredComponents[1].assets[0].uri.path, 'path/to/asset2.jpg');
+ expect(deferredComponents[1].assets[0].path, 'path/to/asset2.jpg');
});
testWithoutContext('FlutterManifest parses empty deferred components', () async {
@@ -1292,7 +1275,7 @@ dependencies:
flutter:
deferred-components:
''';
-
+ final BufferLogger logger = BufferLogger.test();
final FlutterManifest flutterManifest = FlutterManifest.createFromString(
manifest,
logger: logger,
@@ -1313,7 +1296,7 @@ flutter:
- libraries:
- lib1
''';
-
+ final BufferLogger logger = BufferLogger.test();
final FlutterManifest? flutterManifest = FlutterManifest.createFromString(
manifest,
logger: logger,
@@ -1332,7 +1315,7 @@ dependencies:
flutter:
deferred-components: blah
''';
-
+ final BufferLogger logger = BufferLogger.test();
final FlutterManifest? flutterManifest = FlutterManifest.createFromString(
manifest,
logger: logger,
@@ -1353,7 +1336,7 @@ flutter:
- name: blah
libraries: blah
''';
-
+ final BufferLogger logger = BufferLogger.test();
final FlutterManifest? flutterManifest = FlutterManifest.createFromString(
manifest,
logger: logger,
@@ -1375,7 +1358,7 @@ flutter:
libraries:
- not-a-string:
''';
-
+ final BufferLogger logger = BufferLogger.test();
final FlutterManifest? flutterManifest = FlutterManifest.createFromString(
manifest,
logger: logger,
@@ -1397,14 +1380,14 @@ flutter:
assets:
- not-a-string:
''';
-
+ final BufferLogger logger = BufferLogger.test();
final FlutterManifest? flutterManifest = FlutterManifest.createFromString(
manifest,
logger: logger,
);
expect(flutterManifest, null);
- expect(logger.errorText, 'Asset manifest entry is malformed. Expected asset entry to be either a string or a map containing a "path" entry. Got Null instead.\n');
+ expect(logger.errorText, 'Expected "assets" key in the 0 element of "deferred-components" to be a list of file paths, but element 0 was a YamlMap\n');
});
testWithoutContext('FlutterManifest deferred component multiple assets is string', () async {
@@ -1421,14 +1404,14 @@ flutter:
- also-not-a-string:
- woo
''';
-
+ final BufferLogger logger = BufferLogger.test();
final FlutterManifest? flutterManifest = FlutterManifest.createFromString(
manifest,
logger: logger,
);
expect(flutterManifest, null);
- expect(logger.errorText, 'Asset manifest entry is malformed. Expected asset entry to be either a string or a map containing a "path" entry. Got Null instead.\n');
+ expect(logger.errorText, 'Expected "assets" key in the 0 element of "deferred-components" to be a list of file paths, but element 1 was a YamlMap\n');
});
testWithoutContext('FlutterManifest multiple deferred components assets is string', () async {
@@ -1448,14 +1431,14 @@ flutter:
- not-a-string:
- woo
''';
-
+ final BufferLogger logger = BufferLogger.test();
final FlutterManifest? flutterManifest = FlutterManifest.createFromString(
manifest,
logger: logger,
);
expect(flutterManifest, null);
- expect(logger.errorText, 'Asset manifest entry is malformed. Expected asset entry to be either a string or a map containing a "path" entry. Got Null instead.\n');
+ expect(logger.errorText, 'Expected "assets" key in the 1 element of "deferred-components" to be a list of file paths, but element 1 was a YamlMap\n');
});
testWithoutContext('FlutterManifest deferred component assets is list', () async {
@@ -1469,7 +1452,7 @@ flutter:
- name: blah
assets: blah
''';
-
+ final BufferLogger logger = BufferLogger.test();
final FlutterManifest? flutterManifest = FlutterManifest.createFromString(
manifest,
logger: logger,
@@ -1493,7 +1476,7 @@ flutter:
- path/to/asset2.jpg
- path/to/asset3.jpg
''';
-
+ final BufferLogger logger = BufferLogger.test();
final FlutterManifest flutterManifest = FlutterManifest.createFromString(
manifest,
logger: logger,
@@ -1505,9 +1488,9 @@ flutter:
expect(deferredComponents[0].name, 'component1');
expect(deferredComponents[0].libraries.length, 0);
expect(deferredComponents[0].assets.length, 3);
- expect(deferredComponents[0].assets[0].uri.path, 'path/to/asset1.jpg');
- expect(deferredComponents[0].assets[1].uri.path, 'path/to/asset2.jpg');
- expect(deferredComponents[0].assets[2].uri.path, 'path/to/asset3.jpg');
+ expect(deferredComponents[0].assets[0].path, 'path/to/asset1.jpg');
+ expect(deferredComponents[0].assets[1].path, 'path/to/asset2.jpg');
+ expect(deferredComponents[0].assets[2].path, 'path/to/asset3.jpg');
});
testWithoutContext('FlutterManifest can parse empty dependencies', () async {
diff --git a/packages/flutter_tools/test/general.shard/xcode_backend_test.dart b/packages/flutter_tools/test/general.shard/xcode_backend_test.dart
index b91968bd9f..5215644437 100644
--- a/packages/flutter_tools/test/general.shard/xcode_backend_test.dart
+++ b/packages/flutter_tools/test/general.shard/xcode_backend_test.dart
@@ -160,7 +160,6 @@ void main() {
'FRONTEND_SERVER_STARTER_PATH': frontendServerStarterPath,
'INFOPLIST_PATH': 'Info.plist',
'SDKROOT': sdkRoot,
- 'FLAVOR': 'strawberry',
'SPLIT_DEBUG_INFO': splitDebugInfo,
'TRACK_WIDGET_CREATION': trackWidgetCreation,
'TREE_SHAKE_ICONS': treeShake,
@@ -175,7 +174,6 @@ void main() {
'-dTargetPlatform=ios',
'-dTargetFile=lib/main.dart',
'-dBuildMode=${buildMode.toLowerCase()}',
- '-dFlavor=strawberry',
'-dIosArchs=$archs',
'-dSdkRoot=$sdkRoot',
'-dSplitDebugInfo=$splitDebugInfo',