@@ -238,12 +238,15 @@ class Configuration {
238238 var system = enumOption ("system" , System .names, System .find);
239239 var nnbdMode = enumOption ("nnbd" , NnbdMode .names, NnbdMode .find);
240240 var sanitizer = enumOption ("sanitizer" , Sanitizer .names, Sanitizer .find);
241+ var genSnapshotFormat = enumOption (
242+ "gen-snapshot-format" , GenSnapshotFormat .names, GenSnapshotFormat .find);
241243
242244 // Fill in any missing values using defaults when possible.
243245 architecture ?? = Architecture .host;
244246 system ?? = System .host;
245247 nnbdMode ?? = NnbdMode .strong;
246248 sanitizer ?? = Sanitizer .none;
249+ genSnapshotFormat ?? = GenSnapshotFormat .assembly;
247250
248251 // Infer runtime from executable if we don't know runtime and compiler.
249252 if (runtime == null && compiler == null && words.contains ("custom" )) {
@@ -295,9 +298,9 @@ class Configuration {
295298 isCsp: boolOption ("csp" ),
296299 enableHostAsserts: boolOption ("host-asserts" ),
297300 isMinified: boolOption ("minified" ),
301+ genSnapshotFormat: genSnapshotFormat,
298302 useAnalyzerCfe: boolOption ("use-cfe" ),
299303 useAnalyzerFastaParser: boolOption ("analyzer-use-fasta-parser" ),
300- useElf: boolOption ("use-elf" ),
301304 useHotReload: boolOption ("hot-reload" ),
302305 useHotReloadRollback: boolOption ("hot-reload-rollback" ),
303306 useSdk: boolOption ("use-sdk" ),
@@ -369,7 +372,7 @@ class Configuration {
369372 final bool useAnalyzerCfe;
370373 final bool useAnalyzerFastaParser;
371374
372- final bool useElf ;
375+ final GenSnapshotFormat ? genSnapshotFormat ;
373376
374377 final bool useHotReload;
375378 final bool useHotReloadRollback;
@@ -395,9 +398,9 @@ class Configuration {
395398 bool ? isCsp,
396399 bool ? enableHostAsserts,
397400 bool ? isMinified,
401+ GenSnapshotFormat ? genSnapshotFormat,
398402 bool ? useAnalyzerCfe,
399403 bool ? useAnalyzerFastaParser,
400- bool ? useElf,
401404 bool ? useHotReload,
402405 bool ? useHotReloadRollback,
403406 bool ? useSdk,
@@ -417,9 +420,11 @@ class Configuration {
417420 isCsp = isCsp ?? false ,
418421 enableHostAsserts = enableHostAsserts ?? false ,
419422 isMinified = isMinified ?? false ,
423+ // Use a null output for non-precompiler targets.
424+ genSnapshotFormat =
425+ compiler == Compiler .dartkp ? genSnapshotFormat : null ,
420426 useAnalyzerCfe = useAnalyzerCfe ?? false ,
421427 useAnalyzerFastaParser = useAnalyzerFastaParser ?? false ,
422- useElf = useElf ?? false ,
423428 useHotReload = useHotReload ?? false ,
424429 useHotReloadRollback = useHotReloadRollback ?? false ,
425430 useSdk = useSdk ?? false ,
@@ -456,9 +461,9 @@ class Configuration {
456461 required this .isCsp,
457462 required this .enableHostAsserts,
458463 required this .isMinified,
464+ required this .genSnapshotFormat,
459465 required this .useAnalyzerCfe,
460466 required this .useAnalyzerFastaParser,
461- required this .useElf,
462467 required this .useHotReload,
463468 required this .useHotReloadRollback,
464469 required this .useSdk,
@@ -493,9 +498,9 @@ class Configuration {
493498 isCsp: source.isCsp,
494499 enableHostAsserts: source.enableHostAsserts,
495500 isMinified: source.isMinified,
501+ genSnapshotFormat: source.genSnapshotFormat,
496502 useAnalyzerCfe: source.useAnalyzerCfe,
497503 useAnalyzerFastaParser: source.useAnalyzerFastaParser,
498- useElf: source.useElf,
499504 useHotReload: source.useHotReload,
500505 useHotReloadRollback: source.useHotReloadRollback,
501506 useSdk: source.useSdk,
@@ -531,7 +536,7 @@ class Configuration {
531536 isMinified == other.isMinified &&
532537 useAnalyzerCfe == other.useAnalyzerCfe &&
533538 useAnalyzerFastaParser == other.useAnalyzerFastaParser &&
534- useElf == other.useElf &&
539+ genSnapshotFormat == other.genSnapshotFormat &&
535540 useHotReload == other.useHotReload &&
536541 useHotReloadRollback == other.useHotReloadRollback &&
537542 useSdk == other.useSdk &&
@@ -566,6 +571,7 @@ class Configuration {
566571 mode.hashCode ^
567572 runtime.hashCode ^
568573 system.hashCode ^
574+ genSnapshotFormat.hashCode ^
569575 nnbdMode.hashCode ^
570576 builderTag.hashCode ^
571577 genKernelOptions.join (" & " ).hashCode ^
@@ -583,7 +589,6 @@ class Configuration {
583589 isMinified,
584590 useAnalyzerCfe,
585591 useAnalyzerFastaParser,
586- useElf,
587592 useHotReload,
588593 useHotReloadRollback,
589594 useSdk,
@@ -623,6 +628,11 @@ class Configuration {
623628 if (isCsp) fields.add ("csp" );
624629 if (enableHostAsserts) fields.add ("host-asserts" );
625630 if (isMinified) fields.add ("minified" );
631+ // Only output the requested gen_snapshot format if using gen_snapshot
632+ // or the output is unexpectedly non-null.
633+ if (compiler == Compiler .dartkp || genSnapshotFormat != null ) {
634+ fields.add ("gen-snapshot-format: $genSnapshotFormat " );
635+ }
626636 if (useAnalyzerCfe) fields.add ("use-cfe" );
627637 if (useAnalyzerFastaParser) fields.add ("analyzer-use-fasta-parser" );
628638 if (useHotReload) fields.add ("hot-reload" );
@@ -681,6 +691,15 @@ class Configuration {
681691 boolField ("csp" , isCsp, other.isCsp);
682692 boolField ("host-asserts" , enableHostAsserts, other.enableHostAsserts);
683693 boolField ("minified" , isMinified, other.isMinified);
694+ // Only output the requested gen_snapshot format if using gen_snapshot
695+ // or the output is unexpectedly non-null.
696+ if (compiler == Compiler .dartkp ||
697+ other.compiler == Compiler .dartkp ||
698+ genSnapshotFormat != null ||
699+ other.genSnapshotFormat != null ) {
700+ fields.add (
701+ "gen-snapshot-format: $genSnapshotFormat ${other .genSnapshotFormat }" );
702+ }
684703 boolField ("use-cfe" , useAnalyzerCfe, other.useAnalyzerCfe);
685704 boolField ("analyzer-use-fasta-parser" , useAnalyzerFastaParser,
686705 other.useAnalyzerFastaParser);
@@ -816,6 +835,33 @@ class Architecture extends NamedEnum {
816835 }
817836}
818837
838+ /// Specifies the output format used by gen_snapshot to create AOT snapshots.
839+ class GenSnapshotFormat extends NamedEnum {
840+ static const assembly = GenSnapshotFormat ._('assembly' , 'assembly' );
841+ static const elf = GenSnapshotFormat ._('elf' , 'elf' );
842+ static const machODylib = GenSnapshotFormat ._('macho-dylib' , 'macho' );
843+
844+ static final List <String > names = _all.keys.toList ();
845+
846+ static final _all = Map <String , GenSnapshotFormat >.fromIterable ([
847+ assembly,
848+ elf,
849+ machODylib,
850+ ], key: (format) => (format as GenSnapshotFormat ).name);
851+
852+ static GenSnapshotFormat find (String name) {
853+ var format = _all[name];
854+ if (format != null ) return format;
855+
856+ throw ArgumentError ('Unknown gen_snapshot format "$name ".' );
857+ }
858+
859+ String get snapshotType => 'app-aot-$name ' ;
860+
861+ final String fileOption;
862+ const GenSnapshotFormat ._(super .name, this .fileOption);
863+ }
864+
819865class Compiler extends NamedEnum {
820866 static const dart2js = Compiler ._('dart2js' );
821867 static const dart2analyzer = Compiler ._('dart2analyzer' );
0 commit comments