Skip to content

Commit 2a543aa

Browse files
authored
[native_assets] Fix framework name deduplication (#149761)
Applies flutter/flutter@02d5286 to MacOS. I'm hoping this will fix: * flutter/flutter#148955
1 parent ae47eda commit 2a543aa

File tree

2 files changed

+27
-5
lines changed

2 files changed

+27
-5
lines changed

packages/flutter_tools/lib/src/isolated/native_assets/macos/native_assets.dart

+13-4
Original file line numberDiff line numberDiff line change
@@ -214,10 +214,19 @@ Map<AssetImpl, KernelAsset> _assetTargetLocations(
214214
Uri? absolutePath,
215215
) {
216216
final Set<String> alreadyTakenNames = <String>{};
217-
return <AssetImpl, KernelAsset>{
218-
for (final AssetImpl asset in nativeAssets)
219-
asset: _targetLocationMacOS(asset, absolutePath, alreadyTakenNames),
220-
};
217+
final Map<String, KernelAssetPath> idToPath = <String, KernelAssetPath>{};
218+
final Map<AssetImpl, KernelAsset> result = <AssetImpl, KernelAsset>{};
219+
for (final AssetImpl asset in nativeAssets) {
220+
final KernelAssetPath path = idToPath[asset.id] ??
221+
_targetLocationMacOS(asset, absolutePath, alreadyTakenNames).path;
222+
idToPath[asset.id] = path;
223+
result[asset] = KernelAsset(
224+
id: (asset as NativeCodeAssetImpl).id,
225+
target: Target.fromArchitectureAndOS(asset.architecture!, asset.os),
226+
path: path,
227+
);
228+
}
229+
return result;
221230
}
222231

223232
KernelAsset _targetLocationMacOS(

packages/flutter_tools/test/general.shard/isolated/macos/native_assets_test.dart

+14-1
Original file line numberDiff line numberDiff line change
@@ -177,12 +177,25 @@ void main() {
177177
nativeAssetsYaml,
178178
projectUri.resolve('build/native_assets/macos/native_assets.yaml'),
179179
);
180+
final String nativeAssetsYamlContents =
181+
await fileSystem.file(nativeAssetsYaml).readAsString();
180182
expect(
181-
await fileSystem.file(nativeAssetsYaml).readAsString(),
183+
nativeAssetsYamlContents,
182184
contains('package:bar/bar.dart'),
183185
);
184186
expect(buildRunner.buildDryRunInvocations, 1);
185187
expect(buildRunner.linkDryRunInvocations, 1);
188+
// Check that the framework uri is identical for both archs.
189+
final String pathSeparator = const LocalPlatform().pathSeparator;
190+
expect(
191+
nativeAssetsYamlContents,
192+
stringContainsInOrder(
193+
<String>[
194+
'bar.framework${pathSeparator}bar',
195+
'bar.framework${pathSeparator}bar',
196+
],
197+
),
198+
);
186199
});
187200

188201
testUsingContext('build with assets but not enabled', overrides: <Type, Generator>{

0 commit comments

Comments
 (0)