Fix frameworks added to bundle multiple times instead of lipo (#144688)

*Replace this paragraph with a description of what this PR is changing or adding, and why. Consider including before/after screenshots.*

*List which issues are fixed by this PR. You must list at least one issue. An issue is not required if the PR fixes something trivial like a typo.*

*If you had to change anything in the [flutter/tests] repo, include a link to the migration guide as per the [breaking change policy].*
This commit is contained in:
Matej Knopp 2024-03-07 16:09:15 +01:00 committed by GitHub
parent 4d44662242
commit de72832079
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 36 additions and 21 deletions

View file

@ -148,8 +148,15 @@ Target _getNativeTarget(DarwinArch darwinArch) {
Map<KernelAssetPath, List<Asset>> _fatAssetTargetLocations(List<Asset> nativeAssets) {
final Set<String> alreadyTakenNames = <String>{};
final Map<KernelAssetPath, List<Asset>> result = <KernelAssetPath, List<Asset>>{};
final Map<String, KernelAssetPath> idToPath = <String, KernelAssetPath>{};
for (final Asset asset in nativeAssets) {
final KernelAssetPath path = _targetLocationIOS(asset, alreadyTakenNames).path;
// Use same target path for all assets with the same id.
final KernelAssetPath path = idToPath[asset.id] ??
_targetLocationIOS(
asset,
alreadyTakenNames,
).path;
idToPath[asset.id] = path;
result[path] ??= <Asset>[];
result[path]!.add(asset);
}

View file

@ -175,12 +175,16 @@ Map<KernelAssetPath, List<Asset>> _fatAssetTargetLocations(
final Set<String> alreadyTakenNames = <String>{};
final Map<KernelAssetPath, List<Asset>> result =
<KernelAssetPath, List<Asset>>{};
final Map<String, KernelAssetPath> idToPath = <String, KernelAssetPath>{};
for (final Asset asset in nativeAssets) {
final KernelAssetPath path = _targetLocationMacOS(
asset,
absolutePath,
alreadyTakenNames,
).path;
// Use same target path for all assets with the same id.
final KernelAssetPath path = idToPath[asset.id] ??
_targetLocationMacOS(
asset,
absolutePath,
alreadyTakenNames,
).path;
idToPath[asset.id] = path;
result[path] ??= <Asset>[];
result[path]!.add(asset);
}

View file

@ -18,6 +18,7 @@ class FakeNativeAssetsBuildRunner implements NativeAssetsBuildRunner {
FakeNativeAssetsBuildRunner({
this.hasPackageConfigResult = true,
this.packagesWithNativeAssetsResult = const <Package>[],
this.onBuild,
this.dryRunResult = const FakeNativeAssetsBuilderResult(),
this.buildResult = const FakeNativeAssetsBuilderResult(),
CCompilerConfig? cCompilerConfigResult,
@ -25,6 +26,7 @@ class FakeNativeAssetsBuildRunner implements NativeAssetsBuildRunner {
}) : cCompilerConfigResult = cCompilerConfigResult ?? CCompilerConfig(),
ndkCCompilerConfigResult = ndkCCompilerConfigResult ?? CCompilerConfig();
final native_assets_builder.BuildResult Function(Target)? onBuild;
final native_assets_builder.BuildResult buildResult;
final native_assets_builder.DryRunResult dryRunResult;
final bool hasPackageConfigResult;
@ -51,7 +53,7 @@ class FakeNativeAssetsBuildRunner implements NativeAssetsBuildRunner {
}) async {
buildInvocations++;
lastBuildMode = buildMode;
return buildResult;
return onBuild?.call(target) ?? buildResult;
}
@override

View file

@ -222,7 +222,8 @@ void main() {
'-create',
'-output',
'/build/native_assets/ios/bar.framework/bar',
'libbar.dylib',
'arm64/libbar.dylib',
'x64/libbar.dylib',
],
),
const FakeCommand(
@ -253,7 +254,7 @@ void main() {
await packageConfig.parent.create();
await packageConfig.create();
await buildNativeAssetsIOS(
darwinArchs: <DarwinArch>[DarwinArch.arm64],
darwinArchs: <DarwinArch>[DarwinArch.arm64, DarwinArch.x86_64],
environmentType: EnvironmentType.simulator,
projectUri: projectUri,
buildMode: BuildMode.debug,
@ -263,13 +264,13 @@ void main() {
packagesWithNativeAssetsResult: <Package>[
Package('bar', projectUri),
],
buildResult: FakeNativeAssetsBuilderResult(
onBuild: (native_assets_cli.Target target) => FakeNativeAssetsBuilderResult(
assets: <Asset>[
Asset(
id: 'package:bar/bar.dart',
linkMode: LinkMode.dynamic,
target: native_assets_cli.Target.iOSArm64,
path: AssetAbsolutePath(Uri.file('libbar.dylib')),
target: target,
path: AssetAbsolutePath(Uri.file('${target.architecture}/libbar.dylib')),
),
],
),
@ -278,8 +279,8 @@ void main() {
expect(
(globals.logger as BufferLogger).traceText,
stringContainsInOrder(<String>[
'Building native assets for [ios_arm64] debug.',
'Building native assets for [ios_arm64] done.',
'Building native assets for [ios_arm64, ios_x64] debug.',
'Building native assets for [ios_arm64, ios_x64] done.',
]),
);
expect(

View file

@ -259,7 +259,8 @@ void main() {
'-create',
'-output',
dylibPath,
'libbar.dylib',
'arm64/libbar.dylib',
'x64/libbar.dylib',
],
),
if (!flutterTester)
@ -291,7 +292,7 @@ void main() {
await packageConfig.parent.create();
await packageConfig.create();
final (Uri? nativeAssetsYaml, _) = await buildNativeAssetsMacOS(
darwinArchs: <DarwinArch>[DarwinArch.arm64],
darwinArchs: <DarwinArch>[DarwinArch.arm64, DarwinArch.x86_64],
projectUri: projectUri,
buildMode: BuildMode.debug,
fileSystem: fileSystem,
@ -300,13 +301,13 @@ void main() {
packagesWithNativeAssetsResult: <Package>[
Package('bar', projectUri),
],
buildResult: FakeNativeAssetsBuilderResult(
onBuild: (native_assets_cli.Target target) => FakeNativeAssetsBuilderResult(
assets: <Asset>[
Asset(
id: 'package:bar/bar.dart',
linkMode: LinkMode.dynamic,
target: native_assets_cli.Target.macOSArm64,
path: AssetAbsolutePath(Uri.file('libbar.dylib')),
target: target,
path: AssetAbsolutePath(Uri.file('${target.architecture}/libbar.dylib')),
),
],
),
@ -315,8 +316,8 @@ void main() {
expect(
(globals.logger as BufferLogger).traceText,
stringContainsInOrder(<String>[
'Building native assets for [macos_arm64] debug.',
'Building native assets for [macos_arm64] done.',
'Building native assets for [macos_arm64, macos_x64] debug.',
'Building native assets for [macos_arm64, macos_x64] done.',
]),
);
expect(