@@ -7,15 +7,17 @@ import 'dart:convert';
7
7
import 'package:build/build.dart' hide Builder;
8
8
import 'package:built_collection/built_collection.dart' ;
9
9
import 'package:built_value/built_value.dart' ;
10
+ import 'package:built_value/serializer.dart' ;
10
11
import 'package:crypto/crypto.dart' ;
11
- import 'package:glob/glob.dart' ;
12
12
13
13
import '../generate/phase.dart' ;
14
14
15
15
part 'node.g.dart' ;
16
16
17
17
/// Types of [AssetNode] .
18
18
class NodeType extends EnumClass {
19
+ static Serializer <NodeType > get serializer => _$nodeTypeSerializer;
20
+
19
21
static const NodeType builderOptions = _$builderOptions;
20
22
static const NodeType generated = _$generated;
21
23
static const NodeType glob = _$glob;
@@ -33,6 +35,8 @@ class NodeType extends EnumClass {
33
35
34
36
/// A node in the asset graph which may be an input to other assets.
35
37
abstract class AssetNode implements Built <AssetNode , AssetNodeBuilder > {
38
+ static Serializer <AssetNode > get serializer => _$assetNodeSerializer;
39
+
36
40
AssetId get id;
37
41
NodeType get type;
38
42
@@ -219,7 +223,7 @@ abstract class AssetNode implements Built<AssetNode, AssetNodeBuilder> {
219
223
factory AssetNode .glob (
220
224
AssetId id, {
221
225
Digest ? lastKnownDigest,
222
- required Glob glob,
226
+ required String glob,
223
227
required int phaseNumber,
224
228
Iterable <AssetId >? inputs,
225
229
required PendingBuildAction pendingBuildAction,
@@ -236,11 +240,8 @@ abstract class AssetNode implements Built<AssetNode, AssetNodeBuilder> {
236
240
..lastKnownDigest = lastKnownDigest,
237
241
);
238
242
239
- static AssetId createGlobNodeId (String package, Glob glob, int phaseNum) =>
240
- AssetId (
241
- package,
242
- 'glob.$phaseNum .${base64 .encode (utf8 .encode (glob .pattern ))}' ,
243
- );
243
+ static AssetId createGlobNodeId (String package, String glob, int phaseNum) =>
244
+ AssetId (package, 'glob.$phaseNum .${base64 .encode (utf8 .encode (glob ))}' );
244
245
245
246
/// A [primaryInput] to a [PostBuildAction] .
246
247
///
@@ -313,6 +314,9 @@ abstract class AssetNode implements Built<AssetNode, AssetNodeBuilder> {
313
314
abstract class GeneratedNodeConfiguration
314
315
implements
315
316
Built <GeneratedNodeConfiguration , GeneratedNodeConfigurationBuilder > {
317
+ static Serializer <GeneratedNodeConfiguration > get serializer =>
318
+ _$generatedNodeConfigurationSerializer;
319
+
316
320
/// The primary input which generated this node.
317
321
AssetId get primaryInput;
318
322
@@ -342,6 +346,9 @@ abstract class GeneratedNodeConfiguration
342
346
/// State for an [AssetNode.generated] that changes during the build.
343
347
abstract class GeneratedNodeState
344
348
implements Built <GeneratedNodeState , GeneratedNodeStateBuilder > {
349
+ static Serializer <GeneratedNodeState > get serializer =>
350
+ _$generatedNodeStateSerializer;
351
+
345
352
/// All the inputs that were read when generating this asset, or deciding not
346
353
/// to generate it.
347
354
BuiltSet <AssetId > get inputs;
@@ -373,7 +380,10 @@ abstract class GeneratedNodeState
373
380
/// Additional configuration for an [AssetNode.glob] .
374
381
abstract class GlobNodeConfiguration
375
382
implements Built <GlobNodeConfiguration , GlobNodeConfigurationBuilder > {
376
- Glob get glob;
383
+ static Serializer <GlobNodeConfiguration > get serializer =>
384
+ _$globNodeConfigurationSerializer;
385
+
386
+ String get glob;
377
387
int get phaseNumber;
378
388
379
389
factory GlobNodeConfiguration (
@@ -386,6 +396,10 @@ abstract class GlobNodeConfiguration
386
396
/// State for an [AssetNode.glob] that changes during the build.
387
397
abstract class GlobNodeState
388
398
implements Built <GlobNodeState , GlobNodeStateBuilder > {
399
+ static Serializer <GlobNodeState > get serializer => _$globNodeStateSerializer;
400
+
401
+ /// The next work that needs doing on this node.
402
+
389
403
/// All the potential inputs matching this glob.
390
404
///
391
405
/// This field differs from [results] in that [AssetNode.generated] which may
@@ -412,6 +426,9 @@ abstract class PostProcessAnchorNodeConfiguration
412
426
PostProcessAnchorNodeConfiguration ,
413
427
PostProcessAnchorNodeConfigurationBuilder
414
428
> {
429
+ static Serializer <PostProcessAnchorNodeConfiguration > get serializer =>
430
+ _$postProcessAnchorNodeConfigurationSerializer;
431
+
415
432
int get actionNumber;
416
433
AssetId get builderOptionsId;
417
434
AssetId get primaryInput;
@@ -427,6 +444,9 @@ abstract class PostProcessAnchorNodeConfiguration
427
444
abstract class PostProcessAnchorNodeState
428
445
implements
429
446
Built <PostProcessAnchorNodeState , PostProcessAnchorNodeStateBuilder > {
447
+ static Serializer <PostProcessAnchorNodeState > get serializer =>
448
+ _$postProcessAnchorNodeStateSerializer;
449
+
430
450
Digest ? get previousInputsDigest;
431
451
432
452
factory PostProcessAnchorNodeState (
@@ -438,6 +458,9 @@ abstract class PostProcessAnchorNodeState
438
458
439
459
/// Work that needs doing for a node that tracks its inputs.
440
460
class PendingBuildAction extends EnumClass {
461
+ static Serializer <PendingBuildAction > get serializer =>
462
+ _$pendingBuildActionSerializer;
463
+
441
464
static const PendingBuildAction none = _$none;
442
465
static const PendingBuildAction buildIfInputsChanged = _$buildIfInputsChanged;
443
466
static const PendingBuildAction build = _$build;
@@ -448,3 +471,59 @@ class PendingBuildAction extends EnumClass {
448
471
static PendingBuildAction valueOf (String name) =>
449
472
_$pendingBuildActionValueOf (name);
450
473
}
474
+
475
+ @SerializersFor ([AssetNode ])
476
+ final Serializers serializers =
477
+ (_$serializers.toBuilder ()
478
+ ..add (AssetIdSerializer ())
479
+ ..add (DigestSerializer ()))
480
+ .build ();
481
+
482
+ /// Serializer for [AssetId] .
483
+ ///
484
+ /// It would also work to make `AssetId` a `built_value` class, but there's
485
+ /// little benefit and it's nicer to keep codegen local to this package.
486
+ class AssetIdSerializer implements PrimitiveSerializer <AssetId > {
487
+ @override
488
+ Iterable <Type > get types => [AssetId ];
489
+
490
+ @override
491
+ String get wireName => 'AssetId' ;
492
+
493
+ @override
494
+ AssetId deserialize (
495
+ Serializers serializers,
496
+ Object serialized, {
497
+ FullType specifiedType = FullType .unspecified,
498
+ }) => AssetId .parse (serialized as String );
499
+
500
+ @override
501
+ Object serialize (
502
+ Serializers serializers,
503
+ AssetId object, {
504
+ FullType specifiedType = FullType .unspecified,
505
+ }) => object.toString ();
506
+ }
507
+
508
+ /// Serializer for [Digest] .
509
+ class DigestSerializer implements PrimitiveSerializer <Digest > {
510
+ @override
511
+ Iterable <Type > get types => [Digest ];
512
+
513
+ @override
514
+ String get wireName => 'Digest' ;
515
+
516
+ @override
517
+ Digest deserialize (
518
+ Serializers serializers,
519
+ Object serialized, {
520
+ FullType specifiedType = FullType .unspecified,
521
+ }) => Digest (base64.decode (serialized as String ));
522
+
523
+ @override
524
+ Object serialize (
525
+ Serializers serializers,
526
+ Digest object, {
527
+ FullType specifiedType = FullType .unspecified,
528
+ }) => base64.encode (object.bytes);
529
+ }
0 commit comments