Unverified Commit 9e104eb7 authored by Andrew Kolos's avatar Andrew Kolos Committed by GitHub

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
parent a3e0fa56
...@@ -3164,8 +3164,7 @@ targets: ...@@ -3164,8 +3164,7 @@ targets:
properties: properties:
dependencies: >- dependencies: >-
[ [
{"dependency": "xcode", "version": "14c18"}, {"dependency": "ruby", "version": "ruby_3.1-pod_1.13"}
{"dependency": "gems", "version": "v3.3.14"}
] ]
tags: > tags: >
["devicelab", "hostonly", "mac"] ["devicelab", "hostonly", "mac"]
......
...@@ -59,8 +59,15 @@ Future<TaskResult> _testInstallDebugPaidFlavor(String projectDir) async { ...@@ -59,8 +59,15 @@ Future<TaskResult> _testInstallDebugPaidFlavor(String projectDir) async {
.decodeMessage(ByteData.sublistView(assetManifestFileData)) as Map<Object?, Object?>; .decodeMessage(ByteData.sublistView(assetManifestFileData)) as Map<Object?, Object?>;
if (assetManifest.containsKey('assets/free/free.txt')) { if (assetManifest.containsKey('assets/free/free.txt')) {
return TaskResult.failure('Assets declared with a flavor not equal to the ' return TaskResult.failure('Expected the asset "assets/free/free.txt", which '
'argued --flavor value should not be bundled.'); ' 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( await flutter(
......
...@@ -67,8 +67,15 @@ Future<TaskResult> _testInstallDebugPaidFlavor(String projectDir) async { ...@@ -67,8 +67,15 @@ Future<TaskResult> _testInstallDebugPaidFlavor(String projectDir) async {
.decodeMessage(ByteData.sublistView(assetManifestFileData)) as Map<Object?, Object?>; .decodeMessage(ByteData.sublistView(assetManifestFileData)) as Map<Object?, Object?>;
if (assetManifest.containsKey('assets/free/free.txt')) { if (assetManifest.containsKey('assets/free/free.txt')) {
return TaskResult.failure('Assets declared with a flavor not equal to the ' return TaskResult.failure('Expected the asset "assets/free/free.txt", which '
'argued --flavor value should not be bundled.'); ' 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( await flutter(
......
...@@ -2,11 +2,16 @@ ...@@ -2,11 +2,16 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
import 'dart:io';
import 'dart:typed_data';
import 'package:flutter_devicelab/framework/devices.dart'; import 'package:flutter_devicelab/framework/devices.dart';
import 'package:flutter_devicelab/framework/framework.dart'; import 'package:flutter_devicelab/framework/framework.dart';
import 'package:flutter_devicelab/framework/task_result.dart'; import 'package:flutter_devicelab/framework/task_result.dart';
import 'package:flutter_devicelab/framework/utils.dart'; import 'package:flutter_devicelab/framework/utils.dart';
import 'package:flutter_devicelab/tasks/integration_tests.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 { Future<void> main() async {
deviceOperatingSystem = DeviceOperatingSystem.macos; deviceOperatingSystem = DeviceOperatingSystem.macos;
...@@ -14,8 +19,9 @@ Future<void> main() async { ...@@ -14,8 +19,9 @@ Future<void> main() async {
await createFlavorsTest().call(); await createFlavorsTest().call();
await createIntegrationTestFlavorsTest().call(); await createIntegrationTestFlavorsTest().call();
final String projectDir = '${flutterDirectory.path}/dev/integration_tests/flavors';
final TaskResult installTestsResult = await inDirectory( final TaskResult installTestsResult = await inDirectory(
'${flutterDirectory.path}/dev/integration_tests/flavors', projectDir,
() async { () async {
await flutter( await flutter(
'install', 'install',
...@@ -33,6 +39,39 @@ Future<void> main() async { ...@@ -33,6 +39,39 @@ Future<void> main() async {
options: <String>['macos', '--flavor', 'bogus'], 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(); final String stderrString = stderr.toString();
print(stderrString); print(stderrString);
if (!stderrString.contains('The Xcode project defines schemes:')) { if (!stderrString.contains('The Xcode project defines schemes:')) {
......
...@@ -131,6 +131,10 @@ BuildApp() { ...@@ -131,6 +131,10 @@ BuildApp() {
"--build-outputs=${build_outputs_path}" "--build-outputs=${build_outputs_path}"
"--output=${BUILT_PRODUCTS_DIR}" "--output=${BUILT_PRODUCTS_DIR}"
) )
if [[ -n "$FLAVOR" ]]; then
flutter_args+=("-dFlavor=${FLAVOR}")
fi
if [[ -n "$PERFORMANCE_MEASUREMENT_FILE" ]]; then if [[ -n "$PERFORMANCE_MEASUREMENT_FILE" ]]; then
flutter_args+=("--performance-measurement-file=${PERFORMANCE_MEASUREMENT_FILE}") flutter_args+=("--performance-measurement-file=${PERFORMANCE_MEASUREMENT_FILE}")
fi fi
......
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