@@ -36,16 +36,17 @@ class NativeAssetsBuildRunner {
36
36
/// If provided, only native assets of all transitive dependencies of
37
37
/// [runPackageName] are built.
38
38
Future <BuildResult > build ({
39
- required LinkModePreference linkModePreference,
39
+ required LinkModePreferenceImpl linkModePreference,
40
40
required Target target,
41
41
required Uri workingDirectory,
42
- required BuildMode buildMode,
43
- CCompilerConfig ? cCompilerConfig,
44
- IOSSdk ? targetIOSSdk,
42
+ required BuildModeImpl buildMode,
43
+ CCompilerConfigImpl ? cCompilerConfig,
44
+ IOSSdkImpl ? targetIOSSdk,
45
45
int ? targetAndroidNdkApi,
46
46
required bool includeParentEnvironment,
47
47
PackageLayout ? packageLayout,
48
48
String ? runPackageName,
49
+ Iterable <String >? supportedAssetTypes,
49
50
}) async {
50
51
packageLayout ?? = await PackageLayout .fromRootPackageRoot (workingDirectory);
51
52
final packagesWithNativeAssets =
@@ -77,7 +78,7 @@ class NativeAssetsBuildRunner {
77
78
buildPlan = plan;
78
79
packageGraph = planner.packageGraph;
79
80
}
80
- final assets = < Asset > [];
81
+ final assets = < AssetImpl > [];
81
82
final dependencies = < Uri > [];
82
83
final metadata = < String , Metadata > {};
83
84
var success = true ;
@@ -98,6 +99,7 @@ class NativeAssetsBuildRunner {
98
99
cCompilerConfig: cCompilerConfig,
99
100
targetIOSSdk: targetIOSSdk,
100
101
targetAndroidNdkApi: targetAndroidNdkApi,
102
+ supportedAssetTypes: supportedAssetTypes,
101
103
);
102
104
final (
103
105
packageAssets,
@@ -132,12 +134,13 @@ class NativeAssetsBuildRunner {
132
134
/// If provided, only native assets of all transitive dependencies of
133
135
/// [runPackageName] are built.
134
136
Future <DryRunResult > dryRun ({
135
- required LinkModePreference linkModePreference,
136
- required OS targetOs ,
137
+ required LinkModePreferenceImpl linkModePreference,
138
+ required OSImpl targetOS ,
137
139
required Uri workingDirectory,
138
140
required bool includeParentEnvironment,
139
141
PackageLayout ? packageLayout,
140
142
String ? runPackageName,
143
+ Iterable <String >? supportedAssetTypes,
141
144
}) async {
142
145
packageLayout ?? = await PackageLayout .fromRootPackageRoot (workingDirectory);
143
146
final packagesWithNativeAssets =
@@ -163,15 +166,16 @@ class NativeAssetsBuildRunner {
163
166
}
164
167
buildPlan = plan;
165
168
}
166
- final assets = < Asset > [];
169
+ final assets = < AssetImpl > [];
167
170
var success = true ;
168
171
for (final package in buildPlan) {
169
172
final config = await _cliConfigDryRun (
170
173
packageName: package.name,
171
174
packageRoot: packageLayout.packageRoot (package.name),
172
- targetOs : targetOs ,
175
+ targetOS : targetOS ,
173
176
linkMode: linkModePreference,
174
177
buildParentDir: packageLayout.dartToolNativeAssetsBuilder,
178
+ supportedAssetTypes: supportedAssetTypes,
175
179
);
176
180
final (packageAssets, _, _, packageSuccess) = await _buildPackage (
177
181
config,
@@ -180,7 +184,26 @@ class NativeAssetsBuildRunner {
180
184
includeParentEnvironment,
181
185
dryRun: true ,
182
186
);
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
+ }
184
207
success & = packageSuccess;
185
208
}
186
209
return _DryRunResultImpl (
@@ -190,21 +213,21 @@ class NativeAssetsBuildRunner {
190
213
}
191
214
192
215
Future <_PackageBuildRecord > _buildPackageCached (
193
- BuildConfig config,
216
+ BuildConfigImpl config,
194
217
Uri packageConfigUri,
195
218
Uri workingDirectory,
196
219
bool includeParentEnvironment,
197
220
) async {
198
221
final packageName = config.packageName;
199
- final outDir = config.outDir ;
222
+ final outDir = config.outputDirectory ;
200
223
if (! await Directory .fromUri (outDir).exists ()) {
201
224
await Directory .fromUri (outDir).create (recursive: true );
202
225
}
203
226
204
- final buildOutput = await BuildOutput .readFromFile (outDir: outDir);
227
+ final buildOutput = await BuildOutputImpl .readFromFile (outDir: outDir);
205
228
final lastBuilt = buildOutput? .timestamp.roundDownToSeconds () ??
206
229
DateTime .fromMillisecondsSinceEpoch (0 );
207
- final dependencies = buildOutput? .dependencies ;
230
+ final dependencies = buildOutput? .dependenciesModel ;
208
231
final lastChange = await dependencies? .lastModified () ?? DateTime .now ();
209
232
210
233
if (lastBuilt.isAfter (lastChange)) {
@@ -213,8 +236,8 @@ class NativeAssetsBuildRunner {
213
236
// All build flags go into [outDir]. Therefore we do not have to check
214
237
// here whether the config is equal.
215
238
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 ;
218
241
return (assets, dependencies, metadata, true );
219
242
}
220
243
@@ -228,19 +251,20 @@ class NativeAssetsBuildRunner {
228
251
}
229
252
230
253
Future <_PackageBuildRecord > _buildPackage (
231
- BuildConfig config,
254
+ BuildConfigImpl config,
232
255
Uri packageConfigUri,
233
256
Uri workingDirectory,
234
257
bool includeParentEnvironment, {
235
258
required bool dryRun,
236
259
}) async {
237
- final outDir = config.outDir ;
260
+ final outDir = config.outputDirectory ;
238
261
final configFile = outDir.resolve ('../config.yaml' );
239
262
final buildDotDart = config.packageRoot.resolve ('build.dart' );
240
263
final configFileContents = config.toYamlString ();
241
264
logger.info ('config.yaml contents: $configFileContents ' );
242
265
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));
244
268
if (await buildOutputFile.exists ()) {
245
269
// Ensure we'll never read outdated build results.
246
270
await buildOutputFile.delete ();
@@ -282,11 +306,11 @@ ${result.stdout}
282
306
}
283
307
284
308
try {
285
- final buildOutput = await BuildOutput .readFromFile (outDir: outDir);
309
+ final buildOutput = await BuildOutputImpl .readFromFile (outDir: outDir);
286
310
final assets = buildOutput? .assets ?? [];
287
311
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 ;
290
314
return (assets, dependencies, metadata, success);
291
315
} on FormatException catch (e) {
292
316
logger.severe ('''
@@ -295,7 +319,7 @@ build_output.yaml contained a format error.
295
319
${e .message }
296
320
''' );
297
321
success = false ;
298
- return (< Asset > [], < Uri > [], const Metadata ({}), false );
322
+ return (< NativeCodeAssetImpl > [], < Uri > [], const Metadata ({}), false );
299
323
// TODO(https://github.com/dart-lang/native/issues/109): Stop throwing
300
324
// type errors in native_assets_cli, release a new version of that package
301
325
// and then remove this.
@@ -306,53 +330,55 @@ Building native assets for package:${config.packageName} failed.
306
330
build_output.yaml contained a format error.
307
331
''' );
308
332
success = false ;
309
- return (< Asset > [], < Uri > [], const Metadata ({}), false );
333
+ return (< NativeCodeAssetImpl > [], < Uri > [], const Metadata ({}), false );
310
334
} finally {
311
335
if (! success) {
312
336
final buildOutputFile =
313
- File .fromUri (outDir.resolve (BuildOutput .fileName));
337
+ File .fromUri (outDir.resolve (BuildOutputImpl .fileName));
314
338
if (await buildOutputFile.exists ()) {
315
339
await buildOutputFile.delete ();
316
340
}
317
341
}
318
342
}
319
343
}
320
344
321
- static Future <BuildConfig > _cliConfig ({
345
+ static Future <BuildConfigImpl > _cliConfig ({
322
346
required String packageName,
323
347
required Uri packageRoot,
324
348
required Target target,
325
- IOSSdk ? targetIOSSdk,
349
+ IOSSdkImpl ? targetIOSSdk,
326
350
int ? targetAndroidNdkApi,
327
- required BuildMode buildMode,
328
- required LinkModePreference linkMode,
351
+ required BuildModeImpl buildMode,
352
+ required LinkModePreferenceImpl linkMode,
329
353
required Uri buildParentDir,
330
- CCompilerConfig ? cCompilerConfig,
354
+ CCompilerConfigImpl ? cCompilerConfig,
331
355
DependencyMetadata ? dependencyMetadata,
356
+ Iterable <String >? supportedAssetTypes,
332
357
}) async {
333
- final buildDirName = BuildConfig .checksum (
358
+ final buildDirName = BuildConfigImpl .checksum (
334
359
packageName: packageName,
335
360
packageRoot: packageRoot,
336
- targetOs : target.os,
361
+ targetOS : target.os,
337
362
targetArchitecture: target.architecture,
338
363
buildMode: buildMode,
339
364
linkModePreference: linkMode,
340
365
targetIOSSdk: targetIOSSdk,
341
366
cCompiler: cCompilerConfig,
342
367
dependencyMetadata: dependencyMetadata,
343
368
targetAndroidNdkApi: targetAndroidNdkApi,
369
+ supportedAssetTypes: supportedAssetTypes,
344
370
);
345
371
final outDirUri = buildParentDir.resolve ('$buildDirName /out/' );
346
372
final outDir = Directory .fromUri (outDirUri);
347
373
if (! await outDir.exists ()) {
348
374
// TODO(https://dartbug.com/50565): Purge old or unused folders.
349
375
await outDir.create (recursive: true );
350
376
}
351
- return BuildConfig (
377
+ return BuildConfigImpl (
352
378
outDir: outDirUri,
353
379
packageName: packageName,
354
380
packageRoot: packageRoot,
355
- targetOs : target.os,
381
+ targetOS : target.os,
356
382
targetArchitecture: target.architecture,
357
383
buildMode: buildMode,
358
384
linkModePreference: linkMode,
@@ -363,25 +389,27 @@ build_output.yaml contained a format error.
363
389
);
364
390
}
365
391
366
- static Future <BuildConfig > _cliConfigDryRun ({
392
+ static Future <BuildConfigImpl > _cliConfigDryRun ({
367
393
required String packageName,
368
394
required Uri packageRoot,
369
- required OS targetOs ,
370
- required LinkModePreference linkMode,
395
+ required OSImpl targetOS ,
396
+ required LinkModePreferenceImpl linkMode,
371
397
required Uri buildParentDir,
398
+ Iterable <String >? supportedAssetTypes,
372
399
}) async {
373
- final buildDirName = 'dry_run_${targetOs }_$linkMode ' ;
400
+ final buildDirName = 'dry_run_${targetOS }_$linkMode ' ;
374
401
final outDirUri = buildParentDir.resolve ('$buildDirName /out/' );
375
402
final outDir = Directory .fromUri (outDirUri);
376
403
if (! await outDir.exists ()) {
377
404
await outDir.create (recursive: true );
378
405
}
379
- return BuildConfig .dryRun (
406
+ return BuildConfigImpl .dryRun (
380
407
outDir: outDirUri,
381
408
packageName: packageName,
382
409
packageRoot: packageRoot,
383
- targetOs : targetOs ,
410
+ targetOS : targetOS ,
384
411
linkModePreference: linkMode,
412
+ supportedAssetTypes: supportedAssetTypes,
385
413
);
386
414
}
387
415
@@ -400,7 +428,7 @@ build_output.yaml contained a format error.
400
428
};
401
429
}
402
430
403
- bool validateAssetsPackage (List < Asset > assets, String packageName) {
431
+ bool validateAssetsPackage (Iterable < AssetImpl > assets, String packageName) {
404
432
final invalidAssetIds = assets
405
433
.map ((a) => a.id)
406
434
.where ((n) => ! n.startsWith ('package:$packageName /' ))
@@ -419,16 +447,16 @@ build_output.yaml contained a format error.
419
447
}
420
448
421
449
typedef _PackageBuildRecord = (
422
- List < Asset >,
423
- List <Uri > dependencies,
450
+ Iterable < AssetImpl >,
451
+ Iterable <Uri > dependencies,
424
452
Metadata ? ,
425
453
bool success,
426
454
);
427
455
428
456
/// The result from a [NativeAssetsBuildRunner.dryRun] .
429
457
abstract interface class DryRunResult {
430
458
/// The native assets for all [Target] s for the build or dry run.
431
- List <Asset > get assets;
459
+ List <AssetImpl > get assets;
432
460
433
461
/// Whether all builds completed without errors.
434
462
///
@@ -438,7 +466,7 @@ abstract interface class DryRunResult {
438
466
439
467
final class _DryRunResultImpl implements DryRunResult {
440
468
@override
441
- final List <Asset > assets;
469
+ final List <AssetImpl > assets;
442
470
443
471
@override
444
472
final bool success;
@@ -462,7 +490,7 @@ abstract class BuildResult implements DryRunResult {
462
490
463
491
final class _BuildResultImpl implements BuildResult {
464
492
@override
465
- final List <Asset > assets;
493
+ final List <AssetImpl > assets;
466
494
467
495
@override
468
496
final List <Uri > dependencies;
0 commit comments