From 2a543aa43bfa2cdfa55d1725b340ab912d267a57 Mon Sep 17 00:00:00 2001 From: Daco Harkes Date: Fri, 7 Jun 2024 09:07:08 +0200 Subject: [PATCH] [native_assets] Fix framework name deduplication (#149761) Applies https://github.com/flutter/flutter/commit/02d5286e02e4c9f2b80a49a9dee22e8814cf3764 to MacOS. I'm hoping this will fix: * https://github.com/flutter/flutter/issues/148955 --- .../native_assets/macos/native_assets.dart | 17 +++++++++++++---- .../isolated/macos/native_assets_test.dart | 15 ++++++++++++++- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/packages/flutter_tools/lib/src/isolated/native_assets/macos/native_assets.dart b/packages/flutter_tools/lib/src/isolated/native_assets/macos/native_assets.dart index c506c7f80a1a..a29a35b9fd32 100644 --- a/packages/flutter_tools/lib/src/isolated/native_assets/macos/native_assets.dart +++ b/packages/flutter_tools/lib/src/isolated/native_assets/macos/native_assets.dart @@ -214,10 +214,19 @@ Map _assetTargetLocations( Uri? absolutePath, ) { final Set alreadyTakenNames = {}; - return { - for (final AssetImpl asset in nativeAssets) - asset: _targetLocationMacOS(asset, absolutePath, alreadyTakenNames), - }; + final Map idToPath = {}; + final Map result = {}; + for (final AssetImpl asset in nativeAssets) { + final KernelAssetPath path = idToPath[asset.id] ?? + _targetLocationMacOS(asset, absolutePath, alreadyTakenNames).path; + idToPath[asset.id] = path; + result[asset] = KernelAsset( + id: (asset as NativeCodeAssetImpl).id, + target: Target.fromArchitectureAndOS(asset.architecture!, asset.os), + path: path, + ); + } + return result; } KernelAsset _targetLocationMacOS( diff --git a/packages/flutter_tools/test/general.shard/isolated/macos/native_assets_test.dart b/packages/flutter_tools/test/general.shard/isolated/macos/native_assets_test.dart index 69add748a0ea..d3f646682824 100644 --- a/packages/flutter_tools/test/general.shard/isolated/macos/native_assets_test.dart +++ b/packages/flutter_tools/test/general.shard/isolated/macos/native_assets_test.dart @@ -177,12 +177,25 @@ void main() { nativeAssetsYaml, projectUri.resolve('build/native_assets/macos/native_assets.yaml'), ); + final String nativeAssetsYamlContents = + await fileSystem.file(nativeAssetsYaml).readAsString(); expect( - await fileSystem.file(nativeAssetsYaml).readAsString(), + nativeAssetsYamlContents, contains('package:bar/bar.dart'), ); expect(buildRunner.buildDryRunInvocations, 1); expect(buildRunner.linkDryRunInvocations, 1); + // Check that the framework uri is identical for both archs. + final String pathSeparator = const LocalPlatform().pathSeparator; + expect( + nativeAssetsYamlContents, + stringContainsInOrder( + [ + 'bar.framework${pathSeparator}bar', + 'bar.framework${pathSeparator}bar', + ], + ), + ); }); testUsingContext('build with assets but not enabled', overrides: {