Fix flavor conditional asset bundling for macos (#140433)

Fixes https://github.com/flutter/flutter/issues/140430
Fixes https://github.com/flutter/flutter/issues/140432 while we are at it
This commit is contained in:
Andrew Kolos 2023-12-21 12:30:21 -08:00 committed by GitHub
parent a3e0fa56a3
commit 9e104eb7c8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 63 additions and 7 deletions

View File

@ -3164,8 +3164,7 @@ targets:
properties:
dependencies: >-
[
{"dependency": "xcode", "version": "14c18"},
{"dependency": "gems", "version": "v3.3.14"}
{"dependency": "ruby", "version": "ruby_3.1-pod_1.13"}
]
tags: >
["devicelab", "hostonly", "mac"]

View File

@ -59,8 +59,15 @@ Future<TaskResult> _testInstallDebugPaidFlavor(String projectDir) async {
.decodeMessage(ByteData.sublistView(assetManifestFileData)) as Map<Object?, Object?>;
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.');
return TaskResult.failure('Expected the asset "assets/free/free.txt", which '
' was declared with a flavor of "free" to not be included in the asset bundle '
' because the --flavor was set to "paid".');
}
if (!assetManifest.containsKey('assets/paid/paid.txt')) {
return TaskResult.failure('Expected the asset "assets/paid/paid.txt", which '
' was declared with a flavor of "paid" to be included in the asset bundle '
' because the --flavor was set to "paid".');
}
await flutter(

View File

@ -67,8 +67,15 @@ Future<TaskResult> _testInstallDebugPaidFlavor(String projectDir) async {
.decodeMessage(ByteData.sublistView(assetManifestFileData)) as Map<Object?, Object?>;
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.');
return TaskResult.failure('Expected the asset "assets/free/free.txt", which '
' was declared with a flavor of "free" to not be included in the asset bundle '
' because the --flavor was set to "paid".');
}
if (!assetManifest.containsKey('assets/paid/paid.txt')) {
return TaskResult.failure('Expected the asset "assets/paid/paid.txt", which '
' was declared with a flavor of "paid" to be included in the asset bundle '
' because the --flavor was set to "paid".');
}
await flutter(

View File

@ -2,11 +2,16 @@
// 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: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<void> main() async {
deviceOperatingSystem = DeviceOperatingSystem.macos;
@ -14,8 +19,9 @@ Future<void> main() async {
await createFlavorsTest().call();
await createIntegrationTestFlavorsTest().call();
final String projectDir = '${flutterDirectory.path}/dev/integration_tests/flavors';
final TaskResult installTestsResult = await inDirectory(
'${flutterDirectory.path}/dev/integration_tests/flavors',
projectDir,
() async {
await flutter(
'install',
@ -33,6 +39,39 @@ Future<void> main() async {
options: <String>['macos', '--flavor', 'bogus'],
);
final Uint8List assetManifestFileData = File(
path.join(
projectDir,
'build',
'macos',
'Build',
'Products',
'Debug-paid',
'Debug Paid.app',
'Contents',
'Frameworks',
'App.framework',
'Resources',
'flutter_assets',
'AssetManifest.bin'
),
).readAsBytesSync();
final Map<Object?, Object?> assetManifest = const StandardMessageCodec()
.decodeMessage(ByteData.sublistView(assetManifestFileData)) as Map<Object?, Object?>;
if (assetManifest.containsKey('assets/free/free.txt')) {
return TaskResult.failure('Expected the asset "assets/free/free.txt", which '
' was declared with a flavor of "free" to not be included in the asset bundle '
' because the --flavor was set to "paid".');
}
if (!assetManifest.containsKey('assets/paid/paid.txt')) {
return TaskResult.failure('Expected the asset "assets/paid/paid.txt", which '
' was declared with a flavor of "paid" to be included in the asset bundle '
' because the --flavor was set to "paid".');
}
final String stderrString = stderr.toString();
print(stderrString);
if (!stderrString.contains('The Xcode project defines schemes:')) {

View File

@ -131,6 +131,10 @@ BuildApp() {
"--build-outputs=${build_outputs_path}"
"--output=${BUILT_PRODUCTS_DIR}"
)
if [[ -n "$FLAVOR" ]]; then
flutter_args+=("-dFlavor=${FLAVOR}")
fi
if [[ -n "$PERFORMANCE_MEASUREMENT_FILE" ]]; then
flutter_args+=("--performance-measurement-file=${PERFORMANCE_MEASUREMENT_FILE}")
fi