@@ -141,7 +141,8 @@ class BuildCommand extends DartdevCommand {
141
141
stderr.write ('Native assets build failed.' );
142
142
return 255 ;
143
143
}
144
- final staticAssets = nativeAssets.whereLinkMode (LinkMode .static );
144
+ final staticAssets =
145
+ nativeAssets.where ((e) => e.linkMode == LinkMode .static );
145
146
if (staticAssets.isNotEmpty) {
146
147
stderr.write (
147
148
"""'dart build' does not yet support native artifacts packaged as ${LinkMode .static .name }.
@@ -154,42 +155,51 @@ Use linkMode as dynamic library instead.""");
154
155
final tempDir = Directory .systemTemp.createTempSync ();
155
156
if (nativeAssets.isNotEmpty) {
156
157
stdout.writeln ('Copying native assets.' );
157
- Asset targetLocation (Asset asset) {
158
+ KernelAsset targetLocation (Asset asset) {
158
159
final path = asset.path;
160
+ final KernelAssetPath kernelAssetPath;
159
161
switch (path) {
160
162
case AssetSystemPath _:
163
+ kernelAssetPath = KernelAssetSystemPath (path.uri);
161
164
case AssetInExecutable _:
165
+ kernelAssetPath = KernelAssetInExecutable ();
162
166
case AssetInProcess _:
163
- return asset ;
167
+ kernelAssetPath = KernelAssetInProcess () ;
164
168
case AssetAbsolutePath _:
165
- return asset. copyWith (
166
- path: AssetRelativePath (
167
- Uri (
168
- path : path.uri.pathSegments.last,
169
- ),
170
- ) ,
169
+ kernelAssetPath = KernelAssetRelativePath (
170
+ Uri ( path: path.uri.pathSegments.last),
171
+ );
172
+ default :
173
+ throw Exception (
174
+ 'Unsupported asset path type ${ path . runtimeType } in asset $ asset ' ,
171
175
);
172
176
}
173
- throw 'Unsupported asset path type ${path .runtimeType } in asset $asset ' ;
177
+ return KernelAsset (
178
+ id: asset.id,
179
+ target: target,
180
+ path: kernelAssetPath,
181
+ );
174
182
}
175
183
176
184
final assetTargetLocations = {
177
185
for (final asset in nativeAssets) asset: targetLocation (asset),
178
186
};
179
- await Future .wait ([
187
+ final copiedFiles = await Future .wait ([
180
188
for (final assetMapping in assetTargetLocations.entries)
181
- if (assetMapping.key != assetMapping.value )
189
+ if (assetMapping.value.path is KernelAssetRelativePath )
182
190
File .fromUri ((assetMapping.key.path as AssetAbsolutePath ).uri).copy (
183
191
outputUri
184
192
.resolveUri (
185
- (assetMapping.value.path as AssetRelativePath ).uri)
193
+ (assetMapping.value.path as KernelAssetRelativePath )
194
+ .uri)
186
195
.toFilePath ())
187
196
]);
197
+ stdout.writeln ('Copied ${copiedFiles .length } native assets.' );
188
198
189
199
tempUri = tempDir.uri;
190
200
nativeAssetsDartUri = tempUri.resolve ('native_assets.yaml' );
191
- final assetsContent =
192
- assetTargetLocations.values. toList () .toNativeAssetsFile ();
201
+ final assetsContent = KernelAssets (assetTargetLocations.values. toList ())
202
+ .toNativeAssetsFile ();
193
203
await Directory .fromUri (nativeAssetsDartUri.resolve ('.' )).create ();
194
204
await File (nativeAssetsDartUri.toFilePath ()).writeAsString (assetsContent);
195
205
}
0 commit comments