dart-lang / sdk

The Dart SDK, including the VM, JS and Wasm compilers, analysis, core libraries, and more.
https://dart.dev
BSD 3-Clause "New" or "Revised" License
10.2k stars 1.57k forks source link

[native assets] `dart build` should create data assets under asset-id name not under original filename #56421

Open mkustermann opened 2 months ago

mkustermann commented 2 months ago

A package could emit two assets under two different ids but with the same from-source location. This works in dart run because the data assets aren't copied, but with dart build it fails because it copies based on the original file name, which can have a clash, as opposed to a unique name based on asset-id.

output.addAsset(DataAsset(id1, 'foo.txt'));
output.addAsset(DataAsset(id2, 'foo.txt'));

We should have a guarantee that all assets have unique assetId but not necessarily unique filename.

dart-github-bot commented 2 months ago

Summary: Currently, dart build copies data assets based on their original filenames, leading to conflicts when multiple assets with the same filename but different IDs are included. This issue proposes that dart build should instead use the unique asset ID to name the copied assets, ensuring no conflicts.

dcharkes commented 2 months ago

@mkustermann Did you mean NativeCodeAssets? DataAssets support hasn't landed yet.

mkustermann commented 2 months ago

@mkustermann Did you mean NativeCodeAssets? DataAssets support hasn't landed yet.

dart-lang/sdk@main has DEPS which pulls in dart-lang/native@b01a3f3ef5e3a219fefb182d4cfc41d2895f32ca, which exports DataAsset in package:native_assets_cli/native_assets_cli.dart (see here)

Also the SDK has code in dart run/build for data assets, see e.g. here which also has this copy logic in it.