[reland] Support conditional bundling of assets based on --flavor (#139834)
Reland of https://github.com/flutter/flutter/pull/132985. Fixes the path to AssetManifest.bin in flavors_test_ios
This commit is contained in:
@@ -58,6 +58,7 @@ 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"
|
||||
@@ -74,4 +75,4 @@ dependencies:
|
||||
dev_dependencies:
|
||||
test_api: 0.6.1
|
||||
|
||||
# PUBSPEC CHECKSUM: 29d2
|
||||
# PUBSPEC CHECKSUM: b875
|
||||
|
||||
@@ -2,12 +2,17 @@
|
||||
// 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<void> main() async {
|
||||
deviceOperatingSystem = DeviceOperatingSystem.android;
|
||||
@@ -15,31 +20,20 @@ Future<void> main() async {
|
||||
await createFlavorsTest().call();
|
||||
await createIntegrationTestFlavorsTest().call();
|
||||
|
||||
final String projectPath = '${flutterDirectory.path}/dev/integration_tests/flavors';
|
||||
final TaskResult installTestsResult = await inDirectory(
|
||||
'${flutterDirectory.path}/dev/integration_tests/flavors',
|
||||
projectPath,
|
||||
() async {
|
||||
await flutter(
|
||||
'install',
|
||||
options: <String>['--debug', '--flavor', 'paid'],
|
||||
);
|
||||
await flutter(
|
||||
'install',
|
||||
options: <String>['--debug', '--flavor', 'paid', '--uninstall-only'],
|
||||
);
|
||||
final List<TaskResult> testResults = <TaskResult>[
|
||||
await _testInstallDebugPaidFlavor(projectPath),
|
||||
await _testInstallBogusFlavor(),
|
||||
];
|
||||
|
||||
final StringBuffer stderr = StringBuffer();
|
||||
await evalFlutter(
|
||||
'install',
|
||||
canFail: true,
|
||||
stderr: stderr,
|
||||
options: <String>['--flavor', 'bogus'],
|
||||
);
|
||||
final TaskResult? firstInstallFailure = testResults
|
||||
.firstWhereOrNull((TaskResult element) => element.failed);
|
||||
|
||||
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');
|
||||
if (firstInstallFailure != null) {
|
||||
return firstInstallFailure;
|
||||
}
|
||||
|
||||
return TaskResult.success(null);
|
||||
@@ -49,3 +43,49 @@ Future<void> main() async {
|
||||
return installTestsResult;
|
||||
});
|
||||
}
|
||||
|
||||
// Ensures installation works. Also tests asset bundling while we are at it.
|
||||
Future<TaskResult> _testInstallDebugPaidFlavor(String projectDir) async {
|
||||
await evalFlutter(
|
||||
'install',
|
||||
options: <String>['--debug', '--flavor', 'paid'],
|
||||
);
|
||||
|
||||
final Uint8List assetManifestFileData = File(
|
||||
path.join(projectDir, 'build', 'app', 'intermediates', 'assets', 'paidDebug', '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('Assets declared with a flavor not equal to the '
|
||||
'argued --flavor value should not be bundled.');
|
||||
}
|
||||
|
||||
await flutter(
|
||||
'install',
|
||||
options: <String>['--debug', '--flavor', 'paid', '--uninstall-only'],
|
||||
);
|
||||
|
||||
return TaskResult.success(null);
|
||||
}
|
||||
|
||||
Future<TaskResult> _testInstallBogusFlavor() async {
|
||||
final StringBuffer stderr = StringBuffer();
|
||||
await evalFlutter(
|
||||
'install',
|
||||
canFail: true,
|
||||
stderr: stderr,
|
||||
options: <String>['--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);
|
||||
}
|
||||
|
||||
@@ -2,11 +2,17 @@
|
||||
// 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<void> main() async {
|
||||
deviceOperatingSystem = DeviceOperatingSystem.ios;
|
||||
@@ -14,29 +20,20 @@ Future<void> 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(
|
||||
'${flutterDirectory.path}/dev/integration_tests/flavors',
|
||||
projectDir,
|
||||
() async {
|
||||
await flutter(
|
||||
'install',
|
||||
options: <String>['--flavor', 'paid'],
|
||||
);
|
||||
await flutter(
|
||||
'install',
|
||||
options: <String>['--flavor', 'paid', '--uninstall-only'],
|
||||
);
|
||||
final StringBuffer stderr = StringBuffer();
|
||||
await evalFlutter(
|
||||
'install',
|
||||
canFail: true,
|
||||
stderr: stderr,
|
||||
options: <String>['--flavor', 'bogus'],
|
||||
);
|
||||
final List<TaskResult> testResults = <TaskResult>[
|
||||
await _testInstallDebugPaidFlavor(projectDir),
|
||||
await _testInstallBogusFlavor(),
|
||||
];
|
||||
|
||||
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');
|
||||
final TaskResult? firstInstallFailure = testResults
|
||||
.firstWhereOrNull((TaskResult element) => element.failed);
|
||||
|
||||
if (firstInstallFailure != null) {
|
||||
return firstInstallFailure;
|
||||
}
|
||||
|
||||
return TaskResult.success(null);
|
||||
@@ -46,3 +43,56 @@ Future<void> main() async {
|
||||
return installTestsResult;
|
||||
});
|
||||
}
|
||||
|
||||
Future<TaskResult> _testInstallDebugPaidFlavor(String projectDir) async {
|
||||
await evalFlutter(
|
||||
'install',
|
||||
options: <String>['--flavor', 'paid'],
|
||||
);
|
||||
final Uint8List assetManifestFileData = File(
|
||||
path.join(
|
||||
projectDir,
|
||||
'build',
|
||||
'ios',
|
||||
'iphoneos',
|
||||
'Paid App.app',
|
||||
'Frameworks',
|
||||
'App.framework',
|
||||
'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('Assets declared with a flavor not equal to the '
|
||||
'argued --flavor value should not be bundled.');
|
||||
}
|
||||
|
||||
await flutter(
|
||||
'install',
|
||||
options: <String>['--flavor', 'paid', '--uninstall-only'],
|
||||
);
|
||||
|
||||
return TaskResult.success(null);
|
||||
}
|
||||
|
||||
Future<TaskResult> _testInstallBogusFlavor() async {
|
||||
final StringBuffer stderr = StringBuffer();
|
||||
await evalFlutter(
|
||||
'install',
|
||||
canFail: true,
|
||||
stderr: stderr,
|
||||
options: <String>['--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);
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ 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"
|
||||
@@ -72,4 +73,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: 6040
|
||||
# PUBSPEC CHECKSUM: 70e2
|
||||
|
||||
1
dev/integration_tests/flavors/assets/common/common.txt
Normal file
1
dev/integration_tests/flavors/assets/common/common.txt
Normal file
@@ -0,0 +1 @@
|
||||
this is a test asset not meant for any specific flavor
|
||||
1
dev/integration_tests/flavors/assets/free/free.txt
Normal file
1
dev/integration_tests/flavors/assets/free/free.txt
Normal file
@@ -0,0 +1 @@
|
||||
this is a test asset for --flavor free
|
||||
1
dev/integration_tests/flavors/assets/paid/paid.txt
Normal file
1
dev/integration_tests/flavors/assets/paid/paid.txt
Normal file
@@ -0,0 +1 @@
|
||||
this is a test asset for --flavor paid
|
||||
1
dev/integration_tests/flavors/assets/premium/premium.txt
Normal file
1
dev/integration_tests/flavors/assets/premium/premium.txt
Normal file
@@ -0,0 +1 @@
|
||||
premium
|
||||
@@ -75,5 +75,13 @@ 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
|
||||
|
||||
Reference in New Issue
Block a user