@@ -36,16 +36,17 @@ class NativeAssetsBuildRunner {
3636 /// If provided, only native assets of all transitive dependencies of
3737 /// [runPackageName] are built.
3838 Future <BuildResult > build ({
39- required LinkModePreference linkModePreference,
39+ required LinkModePreferenceImpl linkModePreference,
4040 required Target target,
4141 required Uri workingDirectory,
42- required BuildMode buildMode,
43- CCompilerConfig ? cCompilerConfig,
44- IOSSdk ? targetIOSSdk,
42+ required BuildModeImpl buildMode,
43+ CCompilerConfigImpl ? cCompilerConfig,
44+ IOSSdkImpl ? targetIOSSdk,
4545 int ? targetAndroidNdkApi,
4646 required bool includeParentEnvironment,
4747 PackageLayout ? packageLayout,
4848 String ? runPackageName,
49+ Iterable <String >? supportedAssetTypes,
4950 }) async {
5051 packageLayout ?? = await PackageLayout .fromRootPackageRoot (workingDirectory);
5152 final packagesWithNativeAssets =
@@ -77,7 +78,7 @@ class NativeAssetsBuildRunner {
7778 buildPlan = plan;
7879 packageGraph = planner.packageGraph;
7980 }
80- final assets = < Asset > [];
81+ final assets = < AssetImpl > [];
8182 final dependencies = < Uri > [];
8283 final metadata = < String , Metadata > {};
8384 var success = true ;
@@ -98,6 +99,7 @@ class NativeAssetsBuildRunner {
9899 cCompilerConfig: cCompilerConfig,
99100 targetIOSSdk: targetIOSSdk,
100101 targetAndroidNdkApi: targetAndroidNdkApi,
102+ supportedAssetTypes: supportedAssetTypes,
101103 );
102104 final (
103105 packageAssets,
@@ -132,12 +134,13 @@ class NativeAssetsBuildRunner {
132134 /// If provided, only native assets of all transitive dependencies of
133135 /// [runPackageName] are built.
134136 Future <DryRunResult > dryRun ({
135- required LinkModePreference linkModePreference,
136- required OS targetOs ,
137+ required LinkModePreferenceImpl linkModePreference,
138+ required OSImpl targetOS ,
137139 required Uri workingDirectory,
138140 required bool includeParentEnvironment,
139141 PackageLayout ? packageLayout,
140142 String ? runPackageName,
143+ Iterable <String >? supportedAssetTypes,
141144 }) async {
142145 packageLayout ?? = await PackageLayout .fromRootPackageRoot (workingDirectory);
143146 final packagesWithNativeAssets =
@@ -163,15 +166,16 @@ class NativeAssetsBuildRunner {
163166 }
164167 buildPlan = plan;
165168 }
166- final assets = < Asset > [];
169+ final assets = < AssetImpl > [];
167170 var success = true ;
168171 for (final package in buildPlan) {
169172 final config = await _cliConfigDryRun (
170173 packageName: package.name,
171174 packageRoot: packageLayout.packageRoot (package.name),
172- targetOs : targetOs ,
175+ targetOS : targetOS ,
173176 linkMode: linkModePreference,
174177 buildParentDir: packageLayout.dartToolNativeAssetsBuilder,
178+ supportedAssetTypes: supportedAssetTypes,
175179 );
176180 final (packageAssets, _, _, packageSuccess) = await _buildPackage (
177181 config,
@@ -180,7 +184,26 @@ class NativeAssetsBuildRunner {
180184 includeParentEnvironment,
181185 dryRun: true ,
182186 );
183- assets.addAll (packageAssets);
187+ for (final asset in packageAssets) {
188+ switch (asset) {
189+ case NativeCodeAssetImpl _:
190+ if (asset.architecture != null ) {
191+ // Backwards compatibility, if an architecture is provided use it.
192+ assets.add (asset);
193+ } else {
194+ // Dry run does not report architecture. Dart VM branches on OS
195+ // and Target when looking up assets, so populate assets for all
196+ // architectures.
197+ for (final architecture in asset.os.architectures) {
198+ assets.add (asset.copyWith (
199+ architecture: architecture,
200+ ));
201+ }
202+ }
203+ case DataAssetImpl _:
204+ assets.add (asset);
205+ }
206+ }
184207 success & = packageSuccess;
185208 }
186209 return _DryRunResultImpl (
@@ -190,21 +213,21 @@ class NativeAssetsBuildRunner {
190213 }
191214
192215 Future <_PackageBuildRecord > _buildPackageCached (
193- BuildConfig config,
216+ BuildConfigImpl config,
194217 Uri packageConfigUri,
195218 Uri workingDirectory,
196219 bool includeParentEnvironment,
197220 ) async {
198221 final packageName = config.packageName;
199- final outDir = config.outDir ;
222+ final outDir = config.outputDirectory ;
200223 if (! await Directory .fromUri (outDir).exists ()) {
201224 await Directory .fromUri (outDir).create (recursive: true );
202225 }
203226
204- final buildOutput = await BuildOutput .readFromFile (outDir: outDir);
227+ final buildOutput = await BuildOutputImpl .readFromFile (outDir: outDir);
205228 final lastBuilt = buildOutput? .timestamp.roundDownToSeconds () ??
206229 DateTime .fromMillisecondsSinceEpoch (0 );
207- final dependencies = buildOutput? .dependencies ;
230+ final dependencies = buildOutput? .dependenciesModel ;
208231 final lastChange = await dependencies? .lastModified () ?? DateTime .now ();
209232
210233 if (lastBuilt.isAfter (lastChange)) {
@@ -213,8 +236,8 @@ class NativeAssetsBuildRunner {
213236 // All build flags go into [outDir]. Therefore we do not have to check
214237 // here whether the config is equal.
215238 final assets = buildOutput! .assets;
216- final dependencies = buildOutput.dependencies.dependencies ;
217- final metadata = buildOutput.metadata ;
239+ final dependencies = buildOutput.dependencies;
240+ final metadata = buildOutput.metadataModel ;
218241 return (assets, dependencies, metadata, true );
219242 }
220243
@@ -228,19 +251,20 @@ class NativeAssetsBuildRunner {
228251 }
229252
230253 Future <_PackageBuildRecord > _buildPackage (
231- BuildConfig config,
254+ BuildConfigImpl config,
232255 Uri packageConfigUri,
233256 Uri workingDirectory,
234257 bool includeParentEnvironment, {
235258 required bool dryRun,
236259 }) async {
237- final outDir = config.outDir ;
260+ final outDir = config.outputDirectory ;
238261 final configFile = outDir.resolve ('../config.yaml' );
239262 final buildDotDart = config.packageRoot.resolve ('build.dart' );
240263 final configFileContents = config.toYamlString ();
241264 logger.info ('config.yaml contents: $configFileContents ' );
242265 await File .fromUri (configFile).writeAsString (configFileContents);
243- final buildOutputFile = File .fromUri (outDir.resolve (BuildOutput .fileName));
266+ final buildOutputFile =
267+ File .fromUri (outDir.resolve (BuildOutputImpl .fileName));
244268 if (await buildOutputFile.exists ()) {
245269 // Ensure we'll never read outdated build results.
246270 await buildOutputFile.delete ();
@@ -282,11 +306,11 @@ ${result.stdout}
282306 }
283307
284308 try {
285- final buildOutput = await BuildOutput .readFromFile (outDir: outDir);
309+ final buildOutput = await BuildOutputImpl .readFromFile (outDir: outDir);
286310 final assets = buildOutput? .assets ?? [];
287311 success & = validateAssetsPackage (assets, config.packageName);
288- final dependencies = buildOutput? .dependencies.dependencies ?? [];
289- final metadata = dryRun ? null : buildOutput? .metadata ;
312+ final dependencies = buildOutput? .dependencies ?? [];
313+ final metadata = dryRun ? null : buildOutput? .metadataModel ;
290314 return (assets, dependencies, metadata, success);
291315 } on FormatException catch (e) {
292316 logger.severe ('''
@@ -295,7 +319,7 @@ build_output.yaml contained a format error.
295319${e .message }
296320 ''' );
297321 success = false ;
298- return (< Asset > [], < Uri > [], const Metadata ({}), false );
322+ return (< NativeCodeAssetImpl > [], < Uri > [], const Metadata ({}), false );
299323 // TODO(https://github.com/dart-lang/native/issues/109): Stop throwing
300324 // type errors in native_assets_cli, release a new version of that package
301325 // and then remove this.
@@ -306,53 +330,55 @@ Building native assets for package:${config.packageName} failed.
306330build_output.yaml contained a format error.
307331 ''' );
308332 success = false ;
309- return (< Asset > [], < Uri > [], const Metadata ({}), false );
333+ return (< NativeCodeAssetImpl > [], < Uri > [], const Metadata ({}), false );
310334 } finally {
311335 if (! success) {
312336 final buildOutputFile =
313- File .fromUri (outDir.resolve (BuildOutput .fileName));
337+ File .fromUri (outDir.resolve (BuildOutputImpl .fileName));
314338 if (await buildOutputFile.exists ()) {
315339 await buildOutputFile.delete ();
316340 }
317341 }
318342 }
319343 }
320344
321- static Future <BuildConfig > _cliConfig ({
345+ static Future <BuildConfigImpl > _cliConfig ({
322346 required String packageName,
323347 required Uri packageRoot,
324348 required Target target,
325- IOSSdk ? targetIOSSdk,
349+ IOSSdkImpl ? targetIOSSdk,
326350 int ? targetAndroidNdkApi,
327- required BuildMode buildMode,
328- required LinkModePreference linkMode,
351+ required BuildModeImpl buildMode,
352+ required LinkModePreferenceImpl linkMode,
329353 required Uri buildParentDir,
330- CCompilerConfig ? cCompilerConfig,
354+ CCompilerConfigImpl ? cCompilerConfig,
331355 DependencyMetadata ? dependencyMetadata,
356+ Iterable <String >? supportedAssetTypes,
332357 }) async {
333- final buildDirName = BuildConfig .checksum (
358+ final buildDirName = BuildConfigImpl .checksum (
334359 packageName: packageName,
335360 packageRoot: packageRoot,
336- targetOs : target.os,
361+ targetOS : target.os,
337362 targetArchitecture: target.architecture,
338363 buildMode: buildMode,
339364 linkModePreference: linkMode,
340365 targetIOSSdk: targetIOSSdk,
341366 cCompiler: cCompilerConfig,
342367 dependencyMetadata: dependencyMetadata,
343368 targetAndroidNdkApi: targetAndroidNdkApi,
369+ supportedAssetTypes: supportedAssetTypes,
344370 );
345371 final outDirUri = buildParentDir.resolve ('$buildDirName /out/' );
346372 final outDir = Directory .fromUri (outDirUri);
347373 if (! await outDir.exists ()) {
348374 // TODO(https://dartbug.com/50565): Purge old or unused folders.
349375 await outDir.create (recursive: true );
350376 }
351- return BuildConfig (
377+ return BuildConfigImpl (
352378 outDir: outDirUri,
353379 packageName: packageName,
354380 packageRoot: packageRoot,
355- targetOs : target.os,
381+ targetOS : target.os,
356382 targetArchitecture: target.architecture,
357383 buildMode: buildMode,
358384 linkModePreference: linkMode,
@@ -363,25 +389,27 @@ build_output.yaml contained a format error.
363389 );
364390 }
365391
366- static Future <BuildConfig > _cliConfigDryRun ({
392+ static Future <BuildConfigImpl > _cliConfigDryRun ({
367393 required String packageName,
368394 required Uri packageRoot,
369- required OS targetOs ,
370- required LinkModePreference linkMode,
395+ required OSImpl targetOS ,
396+ required LinkModePreferenceImpl linkMode,
371397 required Uri buildParentDir,
398+ Iterable <String >? supportedAssetTypes,
372399 }) async {
373- final buildDirName = 'dry_run_${targetOs }_$linkMode ' ;
400+ final buildDirName = 'dry_run_${targetOS }_$linkMode ' ;
374401 final outDirUri = buildParentDir.resolve ('$buildDirName /out/' );
375402 final outDir = Directory .fromUri (outDirUri);
376403 if (! await outDir.exists ()) {
377404 await outDir.create (recursive: true );
378405 }
379- return BuildConfig .dryRun (
406+ return BuildConfigImpl .dryRun (
380407 outDir: outDirUri,
381408 packageName: packageName,
382409 packageRoot: packageRoot,
383- targetOs : targetOs ,
410+ targetOS : targetOS ,
384411 linkModePreference: linkMode,
412+ supportedAssetTypes: supportedAssetTypes,
385413 );
386414 }
387415
@@ -400,7 +428,7 @@ build_output.yaml contained a format error.
400428 };
401429 }
402430
403- bool validateAssetsPackage (List < Asset > assets, String packageName) {
431+ bool validateAssetsPackage (Iterable < AssetImpl > assets, String packageName) {
404432 final invalidAssetIds = assets
405433 .map ((a) => a.id)
406434 .where ((n) => ! n.startsWith ('package:$packageName /' ))
@@ -419,16 +447,16 @@ build_output.yaml contained a format error.
419447}
420448
421449typedef _PackageBuildRecord = (
422- List < Asset >,
423- List <Uri > dependencies,
450+ Iterable < AssetImpl >,
451+ Iterable <Uri > dependencies,
424452 Metadata ? ,
425453 bool success,
426454);
427455
428456/// The result from a [NativeAssetsBuildRunner.dryRun] .
429457abstract interface class DryRunResult {
430458 /// The native assets for all [Target] s for the build or dry run.
431- List <Asset > get assets;
459+ List <AssetImpl > get assets;
432460
433461 /// Whether all builds completed without errors.
434462 ///
@@ -438,7 +466,7 @@ abstract interface class DryRunResult {
438466
439467final class _DryRunResultImpl implements DryRunResult {
440468 @override
441- final List <Asset > assets;
469+ final List <AssetImpl > assets;
442470
443471 @override
444472 final bool success;
@@ -462,7 +490,7 @@ abstract class BuildResult implements DryRunResult {
462490
463491final class _BuildResultImpl implements BuildResult {
464492 @override
465- final List <Asset > assets;
493+ final List <AssetImpl > assets;
466494
467495 @override
468496 final List <Uri > dependencies;
0 commit comments