Skip to content

Commit 0f0d0b2

Browse files
committed
Split out post process builder state.
1 parent c858c78 commit 0f0d0b2

File tree

4 files changed

+81
-132
lines changed

4 files changed

+81
-132
lines changed

build_runner_core/lib/src/asset_graph/graph.dart

+26-16
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class AssetGraph implements GeneratedAssetHider {
4646

4747
final BuiltMap<String, LanguageVersion?> packageLanguageVersions;
4848

49-
Map<AssetId, Set<AssetId>>? _anchorOutputs;
49+
final Map<PostProcessAction, Set<AssetId>> _postProcessActions = {};
5050

5151
AssetGraph._(
5252
this.buildPhasesDigest,
@@ -161,11 +161,6 @@ class AssetGraph implements GeneratedAssetHider {
161161
}
162162
_nodesByPackage.putIfAbsent(node.id.package, () => {})[node.id.path] = node;
163163

164-
if (node.type == NodeType.postProcessAnchor) {
165-
// Invalidate `_anchorOutputs`, it will be recomputed when needed.
166-
_anchorOutputs = null;
167-
}
168-
169164
return node;
170165
}
171166

@@ -255,14 +250,14 @@ class AssetGraph implements GeneratedAssetHider {
255250
var node = get(id);
256251
if (node == null) return removedIds;
257252
removedIds.add(id);
258-
anchorOutputs ??= _computeAnchorOutputs();
253+
/*anchorOutputs ??= _computeAnchorOutputs();
259254
for (var anchor in (anchorOutputs[node.id] ?? const <AssetId>{})) {
260255
_removeRecursive(
261256
anchor,
262257
removedIds: removedIds,
263258
anchorOutputs: anchorOutputs,
264259
);
265-
}
260+
}*/
266261
for (var output in node.primaryOutputs.toList()) {
267262
_removeRecursive(
268263
output,
@@ -320,7 +315,7 @@ class AssetGraph implements GeneratedAssetHider {
320315
/// Returns a cached value if possible. Recomputes if any
321316
/// [AssetNode.postProcessAnchor] has been added since it was last computed;
322317
/// not recomputed for removes as values for missing nodes are harmless.
323-
Map<AssetId, Set<AssetId>> _computeAnchorOutputs() {
318+
/*Map<AssetId, Set<AssetId>> _computeAnchorOutputs() {
324319
if (_anchorOutputs != null) return _anchorOutputs!;
325320
final result = <AssetId, Set<AssetId>>{};
326321
for (final node in allNodes) {
@@ -330,7 +325,7 @@ class AssetGraph implements GeneratedAssetHider {
330325
}
331326
}
332327
return _anchorOutputs = result;
333-
}
328+
}*/
334329

335330
/// All nodes in the graph, whether source files or generated outputs.
336331
Iterable<AssetNode> get allNodes =>
@@ -340,6 +335,21 @@ class AssetGraph implements GeneratedAssetHider {
340335
Iterable<AssetNode> packageNodes(String package) =>
341336
_nodesByPackage[package]?.values ?? [];
342337

338+
Iterable<PostProcessAction> packagePostProcessActions(String package) =>
339+
_postProcessActions.keys.where((a) => a.primaryInput.package == package);
340+
341+
void clearPostProcessActionOutputs(PostProcessAction action) {
342+
_postProcessActions[action]!.clear();
343+
}
344+
345+
void addPostProcessActionOutput(PostProcessAction action, AssetId output) {
346+
_postProcessActions[action]!.add(output);
347+
}
348+
349+
Iterable<AssetId> postProcessActionOutputs(PostProcessAction action) {
350+
return _postProcessActions[action]!;
351+
}
352+
343353
/// All the generated outputs in the graph.
344354
Iterable<AssetId> get outputs =>
345355
allNodes.where((n) => n.type == NodeType.generated).map((n) => n.id);
@@ -649,12 +659,12 @@ class AssetGraph implements GeneratedAssetHider {
649659
var inputs = allInputs.where((input) => _actionMatches(action, input));
650660
for (var input in inputs) {
651661
var buildOptionsNodeId = builderOptionsIdForAction(action, actionNum);
652-
var anchor = AssetNode.postProcessAnchorForInputAndAction(
653-
input,
654-
actionNum,
655-
buildOptionsNodeId,
656-
);
657-
add(anchor);
662+
var postProcessAction = PostProcessAction((b) {
663+
b.primaryInput = input;
664+
b.actionNumber = actionNum;
665+
b.builderOptionsId = buildOptionsNodeId;
666+
});
667+
_postProcessActions[postProcessAction] = {};
658668
}
659669
actionNum++;
660670
}

build_runner_core/lib/src/asset_graph/node.dart

+2-4
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ import 'package:built_value/built_value.dart';
1010
import 'package:built_value/serializer.dart';
1111
import 'package:crypto/crypto.dart';
1212

13-
import '../generate/phase.dart';
14-
1513
part 'node.g.dart';
1614

1715
/// Types of [AssetNode].
@@ -348,7 +346,7 @@ abstract class GlobNodeState
348346
abstract class PostProcessAction
349347
implements Built<PostProcessAction, PostProcessActionBuilder> {
350348
static Serializer<PostProcessAction> get serializer =>
351-
_$postProcessAnchorNodeSerializer;
349+
_$postProcessActionSerializer;
352350

353351
int get actionNumber;
354352
AssetId get builderOptionsId;
@@ -357,7 +355,7 @@ abstract class PostProcessAction
357355
PostProcessAction._();
358356

359357
factory PostProcessAction(void Function(PostProcessActionBuilder) updates) =
360-
_$PostProcessAnchorNodeConfiguration;
358+
_$PostProcessAction;
361359
}
362360

363361
/// Work that needs doing for a node that tracks its inputs.

0 commit comments

Comments
 (0)