Skip to content

Commit 113e278

Browse files
authored
Flatten remaining AssetNode subclasses into AssetNode. (#3908)
Convert configuration and state from removed subclasses to new classes.
1 parent 31043da commit 113e278

23 files changed

+908
-582
lines changed

_test_common/lib/matchers.dart

Lines changed: 113 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -85,104 +85,144 @@ class _AssetGraphMatcher extends Matcher {
8585
];
8686
matches = false;
8787
}
88-
if (node is NodeWithInputs) {
89-
if (expectedNode is NodeWithInputs) {
90-
if (node.state != expectedNode.state) {
91-
matchState['needsUpdate of ${node.id}'] = [
92-
node.state,
93-
expectedNode.state,
88+
if (node.type == NodeType.generated) {
89+
if (expectedNode.type == NodeType.generated) {
90+
final configuration = node.generatedNodeConfiguration;
91+
final expectedConfiguration = expectedNode.generatedNodeConfiguration;
92+
93+
if (configuration.primaryInput !=
94+
expectedConfiguration.primaryInput) {
95+
matchState['primaryInput of ${node.id}'] = [
96+
configuration.primaryInput,
97+
expectedConfiguration.primaryInput,
98+
];
99+
matches = false;
100+
}
101+
102+
final state = node.generatedNodeState;
103+
final expectedState = expectedNode.generatedNodeState;
104+
105+
if (state.pendingBuildAction != expectedState.pendingBuildAction) {
106+
matchState['pendingBuildAction of ${node.id}'] = [
107+
state.pendingBuildAction,
108+
expectedState.pendingBuildAction,
94109
];
95110
matches = false;
96111
}
97-
if (!unorderedEquals(node.inputs).matches(expectedNode.inputs, {})) {
112+
if (!unorderedEquals(
113+
state.inputs,
114+
).matches(expectedState.inputs, {})) {
98115
matchState['Inputs of ${node.id}'] = [
99-
node.inputs,
100-
expectedNode.inputs,
116+
state.inputs,
117+
expectedState.inputs,
118+
];
119+
matches = false;
120+
}
121+
122+
if (state.wasOutput != expectedState.wasOutput) {
123+
matchState['wasOutput of ${node.id}'] = [
124+
state.wasOutput,
125+
expectedState.wasOutput,
126+
];
127+
matches = false;
128+
}
129+
if (state.isFailure != expectedState.isFailure) {
130+
matchState['isFailure of ${node.id}'] = [
131+
state.isFailure,
132+
expectedState.isFailure,
133+
];
134+
matches = false;
135+
}
136+
if (checkPreviousInputsDigest &&
137+
state.previousInputsDigest !=
138+
expectedState.previousInputsDigest) {
139+
matchState['previousInputDigest of ${node.id}'] = [
140+
state.previousInputsDigest,
141+
expectedState.previousInputsDigest,
101142
];
102143
matches = false;
103144
}
104145
}
105-
if (node is GeneratedAssetNode) {
106-
if (expectedNode is GeneratedAssetNode) {
107-
if (node.primaryInput != expectedNode.primaryInput) {
108-
matchState['primaryInput of ${node.id}'] = [
109-
node.primaryInput,
110-
expectedNode.primaryInput,
111-
];
112-
matches = false;
113-
}
114-
if (node.wasOutput != expectedNode.wasOutput) {
115-
matchState['wasOutput of ${node.id}'] = [
116-
node.wasOutput,
117-
expectedNode.wasOutput,
118-
];
119-
matches = false;
120-
}
121-
if (node.isFailure != expectedNode.isFailure) {
122-
matchState['isFailure of ${node.id}'] = [
123-
node.isFailure,
124-
expectedNode.isFailure,
125-
];
126-
matches = false;
127-
}
128-
if (checkPreviousInputsDigest &&
129-
node.previousInputsDigest !=
130-
expectedNode.previousInputsDigest) {
131-
matchState['previousInputDigest of ${node.id}'] = [
132-
node.previousInputsDigest,
133-
expectedNode.previousInputsDigest,
134-
];
135-
matches = false;
136-
}
146+
} else if (node.type == NodeType.glob) {
147+
if (expectedNode.type == NodeType.glob) {
148+
final state = node.globNodeState;
149+
final expectedState = expectedNode.globNodeState;
150+
151+
if (state.pendingBuildAction != expectedState.pendingBuildAction) {
152+
matchState['pendingBuildAction of ${node.id}'] = [
153+
state.pendingBuildAction,
154+
expectedState.pendingBuildAction,
155+
];
156+
matches = false;
157+
}
158+
if (!unorderedEquals(
159+
state.inputs,
160+
).matches(expectedState.inputs, {})) {
161+
matchState['Inputs of ${node.id}'] = [
162+
state.inputs,
163+
expectedState.inputs,
164+
];
165+
matches = false;
166+
}
167+
168+
if (!unorderedEquals(
169+
state.results!,
170+
).matches(expectedState.results, {})) {
171+
matchState['results of ${node.id}'] = [
172+
state.results,
173+
expectedState.results,
174+
];
175+
matches = false;
137176
}
138-
} else if (node is GlobAssetNode) {
139-
if (expectedNode is GlobAssetNode) {
140-
if (!unorderedEquals(
141-
node.results!,
142-
).matches(expectedNode.results, {})) {
143-
matchState['results of ${node.id}'] = [
144-
node.results,
145-
expectedNode.results,
146-
];
147-
matches = false;
148-
}
149-
if (node.glob.pattern != expectedNode.glob.pattern) {
150-
matchState['glob of ${node.id}'] = [
151-
node.glob.pattern,
152-
expectedNode.glob.pattern,
153-
];
154-
matches = false;
155-
}
177+
178+
final configuration = node.globNodeConfiguration;
179+
final expectedConfiguration = expectedNode.globNodeConfiguration;
180+
if (configuration.glob.pattern !=
181+
expectedConfiguration.glob.pattern) {
182+
matchState['glob of ${node.id}'] = [
183+
configuration.glob.pattern,
184+
expectedConfiguration.glob.pattern,
185+
];
186+
matches = false;
156187
}
157188
}
158-
} else if (node is PostProcessAnchorNode) {
159-
if (expectedNode is PostProcessAnchorNode) {
160-
if (node.actionNumber != expectedNode.actionNumber) {
189+
} else if (node.type == NodeType.postProcessAnchor) {
190+
if (expectedNode.type == NodeType.postProcessAnchor) {
191+
final nodeConfiguration = node.postProcessAnchorNodeConfiguration;
192+
final expectedNodeConfiguration =
193+
expectedNode.postProcessAnchorNodeConfiguration;
194+
if (nodeConfiguration.actionNumber !=
195+
expectedNodeConfiguration.actionNumber) {
161196
matchState['actionNumber of ${node.id}'] = [
162-
node.actionNumber,
163-
expectedNode.actionNumber,
197+
nodeConfiguration.actionNumber,
198+
expectedNodeConfiguration.actionNumber,
164199
];
165200
matches = false;
166201
}
167-
if (node.builderOptionsId != expectedNode.builderOptionsId) {
202+
if (nodeConfiguration.builderOptionsId !=
203+
expectedNodeConfiguration.builderOptionsId) {
168204
matchState['builderOptionsId of ${node.id}'] = [
169-
node.builderOptionsId,
170-
expectedNode.builderOptionsId,
205+
nodeConfiguration.builderOptionsId,
206+
expectedNodeConfiguration.builderOptionsId,
171207
];
172208
matches = false;
173209
}
210+
final nodeState = node.postProcessAnchorNodeState;
211+
final expectedNodeState = expectedNode.postProcessAnchorNodeState;
174212
if (checkPreviousInputsDigest &&
175-
node.previousInputsDigest != expectedNode.previousInputsDigest) {
213+
nodeState.previousInputsDigest !=
214+
expectedNodeState.previousInputsDigest) {
176215
matchState['previousInputsDigest of ${node.id}'] = [
177-
node.previousInputsDigest,
178-
expectedNode.previousInputsDigest,
216+
nodeState.previousInputsDigest,
217+
expectedNodeState.previousInputsDigest,
179218
];
180219
matches = false;
181220
}
182-
if (node.primaryInput != expectedNode.primaryInput) {
221+
if (nodeConfiguration.primaryInput !=
222+
expectedNodeConfiguration.primaryInput) {
183223
matchState['primaryInput of ${node.id}'] = [
184-
node.primaryInput,
185-
expectedNode.primaryInput,
224+
nodeConfiguration.primaryInput,
225+
expectedNodeConfiguration.primaryInput,
186226
];
187227
matches = false;
188228
}

build_runner/bin/graph_inspector.dart

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -139,12 +139,14 @@ class InspectNodeCommand extends Command<bool> {
139139
..writeln('Asset: $stringUri')
140140
..writeln(' type: ${node.runtimeType}');
141141

142-
if (node is GeneratedAssetNode) {
142+
if (node.type == NodeType.generated) {
143+
final nodeState = node.generatedNodeState;
144+
final nodeConfiguration = node.generatedNodeConfiguration;
143145
description
144-
..writeln(' state: ${node.state}')
145-
..writeln(' wasOutput: ${node.wasOutput}')
146-
..writeln(' phase: ${node.phaseNumber}')
147-
..writeln(' isFailure: ${node.isFailure}');
146+
..writeln(' state: ${nodeState.pendingBuildAction}')
147+
..writeln(' wasOutput: ${nodeState.wasOutput}')
148+
..writeln(' phase: ${nodeConfiguration.phaseNumber}')
149+
..writeln(' isFailure: ${nodeState.isFailure}');
148150
}
149151

150152
void printAsset(AssetId asset) =>
@@ -159,7 +161,7 @@ class InspectNodeCommand extends Command<bool> {
159161
.difference(node.inspect.primaryOutputs)
160162
.forEach(printAsset);
161163

162-
if (node is NodeWithInputs) {
164+
if (node.type == NodeType.generated || node.type == NodeType.glob) {
163165
description.writeln(' inputs:');
164166
assetGraph.allNodes
165167
.where((n) => n.outputs.contains(node.id))

build_runner/lib/src/entrypoint/clean.dart

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ import 'package:args/command_runner.dart';
1010
import 'package:build_runner_core/build_runner_core.dart';
1111
// ignore: implementation_imports
1212
import 'package:build_runner_core/src/asset_graph/graph.dart';
13-
// ignore: implementation_imports
14-
import 'package:build_runner_core/src/asset_graph/node.dart';
1513
import 'package:logging/logging.dart';
1614

1715
import '../logging/std_io_logging.dart';
@@ -87,8 +85,8 @@ Future<void> _cleanUpSourceOutputs(
8785
var writer = ReaderWriter(packageGraph);
8886
for (var id in assetGraph.outputs) {
8987
if (id.package != packageGraph.root.name) continue;
90-
var node = assetGraph.get(id) as GeneratedAssetNode;
91-
if (node.wasOutput) {
88+
var node = assetGraph.get(id)!;
89+
if (node.generatedNodeState.wasOutput) {
9290
// Note that this does a file.exists check in the root package and
9391
// only tries to delete the file if it exists. This way we only
9492
// actually delete to_source outputs, without reading in the build

build_runner/lib/src/server/asset_graph_handler.dart

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,12 @@ class AssetGraphHandler {
126126
});
127127
nodes.add({'id': '$output', 'label': '$output'});
128128
}
129-
if (node is NodeWithInputs) {
130-
for (final input in node.inputs) {
129+
if (node.type == NodeType.generated || node.type == NodeType.glob) {
130+
final inputs =
131+
node.type == NodeType.generated
132+
? node.generatedNodeState.inputs
133+
: node.globNodeState.inputs;
134+
for (final input in inputs) {
131135
if (filterGlob != null && !filterGlob.matches(input.toString())) {
132136
continue;
133137
}
@@ -142,13 +146,35 @@ class AssetGraphHandler {
142146
var result = <String, dynamic>{
143147
'primary': {
144148
'id': '${node.id}',
145-
'hidden': node is GeneratedAssetNode ? node.isHidden : null,
146-
'state': node is NodeWithInputs ? '${node.state}' : null,
147-
'wasOutput': node is GeneratedAssetNode ? node.wasOutput : null,
148-
'isFailure': node is GeneratedAssetNode ? node.isFailure : null,
149-
'phaseNumber': node is NodeWithInputs ? node.phaseNumber : null,
149+
'hidden':
150+
node.type == NodeType.generated
151+
? node.generatedNodeConfiguration.isHidden
152+
: null,
153+
'state':
154+
node.type == NodeType.generated
155+
? '${node.generatedNodeState.pendingBuildAction}'
156+
: node.type == NodeType.glob
157+
? '${node.globNodeState.pendingBuildAction}'
158+
: null,
159+
'wasOutput':
160+
node.type == NodeType.generated
161+
? node.generatedNodeState.wasOutput
162+
: null,
163+
'isFailure':
164+
node.type == NodeType.generated
165+
? node.generatedNodeState.isFailure
166+
: null,
167+
'phaseNumber':
168+
node.type == NodeType.generated
169+
? node.generatedNodeConfiguration.phaseNumber
170+
: node.type == NodeType.glob
171+
? node.globNodeConfiguration.phaseNumber
172+
: null,
150173
'type': node.runtimeType.toString(),
151-
'glob': node is GlobAssetNode ? node.glob.pattern : null,
174+
'glob':
175+
node.type == NodeType.glob
176+
? node.globNodeConfiguration.glob.pattern
177+
: null,
152178
'lastKnownDigest': node.lastKnownDigest.toString(),
153179
},
154180
'edges': edges,

build_runner/test/generate/watch_test.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -370,11 +370,11 @@ void main() {
370370

371371
var bCopyId = makeAssetId('a|web/b.txt.copy');
372372
var bTxtId = makeAssetId('a|web/b.txt');
373-
var bCopyNode = GeneratedAssetNode(
373+
var bCopyNode = AssetNode.generated(
374374
bCopyId,
375375
phaseNumber: 0,
376376
primaryInput: makeAssetId('a|web/b.txt'),
377-
state: NodeState.upToDate,
377+
state: PendingBuildAction.none,
378378
wasOutput: true,
379379
isFailure: false,
380380
builderOptionsId: builderOptionsId,
@@ -393,11 +393,11 @@ void main() {
393393

394394
var cCopyId = makeAssetId('a|web/c.txt.copy');
395395
var cTxtId = makeAssetId('a|web/c.txt');
396-
var cCopyNode = GeneratedAssetNode(
396+
var cCopyNode = AssetNode.generated(
397397
cCopyId,
398398
phaseNumber: 0,
399399
primaryInput: cTxtId,
400-
state: NodeState.upToDate,
400+
state: PendingBuildAction.none,
401401
wasOutput: true,
402402
isFailure: false,
403403
builderOptionsId: builderOptionsId,

build_runner/test/server/asset_handler_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,11 +128,11 @@ void main() {
128128

129129
test('Fails request for failed outputs', () async {
130130
graph.add(
131-
GeneratedAssetNode(
131+
AssetNode.generated(
132132
AssetId('a', 'web/main.ddc.js'),
133133
builderOptionsId: AssetId('_\$fake', 'options_id'),
134134
phaseNumber: 0,
135-
state: NodeState.upToDate,
135+
state: PendingBuildAction.none,
136136
isHidden: false,
137137
wasOutput: true,
138138
isFailure: true,

build_runner/test/server/serve_handler_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,11 +201,11 @@ void main() {
201201
setUp(() async {
202202
addSource('a|web/index.html', '');
203203
assetGraph.add(
204-
GeneratedAssetNode(
204+
AssetNode.generated(
205205
AssetId('a', 'web/main.ddc.js'),
206206
builderOptionsId: AssetId('_\$fake', 'options_id'),
207207
phaseNumber: 0,
208-
state: NodeState.upToDate,
208+
state: PendingBuildAction.none,
209209
isHidden: false,
210210
wasOutput: true,
211211
isFailure: true,

0 commit comments

Comments
 (0)