Skip to content

Do invalidation in Build instead of the asset graph #3984

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions _test_common/lib/assets.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ import 'package:crypto/crypto.dart';
AssetNode makeAssetNode([
String? assetIdString,
List<AssetId>? outputs,
Digest? lastKnownDigest,
Digest? digest,
]) {
var id = makeAssetId(assetIdString);
return AssetNode.source(
id,
lastKnownDigest: lastKnownDigest,
digest: digest,
outputs: outputs,
primaryOutputs: outputs,
);
Expand Down
2 changes: 2 additions & 0 deletions build_runner/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
- Use `built_value` for `AssetNode` and related types.
- Add details of what changed and what is built to `--verbose` logging.
- Compute outputs as needed instead of storing them in the asset graph.
- Refactor invalidation to track current build progress in `Build` instead of
in the asset graph.

## 2.4.15

Expand Down
5 changes: 2 additions & 3 deletions build_runner/bin/graph_inspector.dart
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,9 @@ class InspectNodeCommand extends Command<bool> {
final nodeState = node.generatedNodeState!;
final nodeConfiguration = node.generatedNodeConfiguration!;
description
..writeln(' state: ${nodeState.pendingBuildAction}')
..writeln(' wasOutput: ${nodeState.wasOutput}')
..writeln(' wasOutput: ${node.wasOutput}')
..writeln(' phase: ${nodeConfiguration.phaseNumber}')
..writeln(' isFailure: ${nodeState.isFailure}');
..writeln(' result: ${nodeState.result}');
}

void printAsset(AssetId asset) =>
Expand Down
2 changes: 1 addition & 1 deletion build_runner/lib/src/entrypoint/clean.dart
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ Future<void> _cleanUpSourceOutputs(
for (var id in assetGraph.outputs) {
if (id.package != packageGraph.root.name) continue;
var node = assetGraph.get(id)!;
if (node.generatedNodeState!.wasOutput) {
if (node.wasOutput) {
// Note that this does a file.exists check in the root package and
// only tries to delete the file if it exists. This way we only
// actually delete to_source outputs, without reading in the build
Expand Down
17 changes: 4 additions & 13 deletions build_runner/lib/src/server/asset_graph_handler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -151,19 +151,10 @@ class AssetGraphHandler {
node.type == NodeType.generated
? node.generatedNodeConfiguration!.isHidden
: null,
'state':
'wasOutput': node.type == NodeType.generated ? node.wasOutput : null,
'result':
node.type == NodeType.generated
? '${node.generatedNodeState!.pendingBuildAction}'
: node.type == NodeType.glob
? '${node.globNodeState!.pendingBuildAction}'
: null,
'wasOutput':
node.type == NodeType.generated
? node.generatedNodeState!.wasOutput
: null,
'isFailure':
node.type == NodeType.generated
? node.generatedNodeState!.isFailure
? node.generatedNodeState!.result
: null,
'phaseNumber':
node.type == NodeType.generated
Expand All @@ -176,7 +167,7 @@ class AssetGraphHandler {
node.type == NodeType.glob
? node.globNodeConfiguration!.glob
: null,
'lastKnownDigest': node.lastKnownDigest.toString(),
'digest': node.digest.toString(),
},
'edges': edges,
'nodes': nodes,
Expand Down
2 changes: 1 addition & 1 deletion build_runner/lib/src/watcher/change_filter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ FutureOr<bool> shouldProcess(
reader.cache.invalidate([change.id]);
return reader
.digest(change.id)
.then((newDigest) => node.lastKnownDigest != newDigest);
.then((newDigest) => node.digest != newDigest);
}
} else {
if (change.type != ChangeType.ADD) return false;
Expand Down
12 changes: 4 additions & 8 deletions build_runner/test/generate/watch_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -371,10 +371,8 @@ void main() {
bCopyId,
phaseNumber: 0,
primaryInput: makeAssetId('a|web/b.txt'),
pendingBuildAction: PendingBuildAction.none,
wasOutput: true,
isFailure: false,
lastKnownDigest: computeDigest(bCopyId, 'b2'),
result: true,
digest: computeDigest(bCopyId, 'b2'),
inputs: [makeAssetId('a|web/b.txt')],
isHidden: false,
);
Expand All @@ -395,10 +393,8 @@ void main() {
cCopyId,
phaseNumber: 0,
primaryInput: cTxtId,
pendingBuildAction: PendingBuildAction.none,
wasOutput: true,
isFailure: false,
lastKnownDigest: computeDigest(cCopyId, 'c'),
result: true,
digest: computeDigest(cCopyId, 'c'),
inputs: [makeAssetId('a|web/c.txt')],
isHidden: false,
);
Expand Down
6 changes: 3 additions & 3 deletions build_runner/test/server/asset_handler_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import 'package:build_runner_core/src/asset_graph/post_process_build_step_id.dar
import 'package:build_runner_core/src/generate/build_phases.dart';
import 'package:build_runner_core/src/generate/options.dart';
import 'package:build_runner_core/src/package_graph/target_graph.dart';
import 'package:crypto/crypto.dart';
import 'package:shelf/shelf.dart';
import 'package:test/test.dart';

Expand Down Expand Up @@ -137,10 +138,9 @@ void main() {
AssetNode.generated(
AssetId('a', 'web/main.ddc.js'),
phaseNumber: 0,
pendingBuildAction: PendingBuildAction.none,
isHidden: false,
wasOutput: true,
isFailure: true,
digest: Digest([]),
result: false,
primaryInput: AssetId('a', 'web/main.dart'),
),
);
Expand Down
6 changes: 3 additions & 3 deletions build_runner/test/server/serve_handler_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import 'package:build_runner_core/src/generate/build_phases.dart';
import 'package:build_runner_core/src/generate/options.dart';
import 'package:build_runner_core/src/generate/performance_tracker.dart';
import 'package:build_runner_core/src/package_graph/target_graph.dart';
import 'package:crypto/crypto.dart';
import 'package:logging/logging.dart';
import 'package:shelf/shelf.dart';
import 'package:stream_channel/stream_channel.dart';
Expand Down Expand Up @@ -210,10 +211,9 @@ void main() {
AssetNode.generated(
AssetId('a', 'web/main.ddc.js'),
phaseNumber: 0,
pendingBuildAction: PendingBuildAction.none,
isHidden: false,
wasOutput: true,
isFailure: true,
digest: Digest([]),
result: false,
primaryInput: AssetId('a', 'web/main.dart'),
),
);
Expand Down
2 changes: 2 additions & 0 deletions build_runner_core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
- Compute outputs as needed instead of storing them in the asset graph.
- Check build options for changes in the phase setup instead of storing them
in the asset graph.
- Refactor invalidation to track current build progress in `Build` instead of
in the asset graph.

## 8.0.0

Expand Down
8 changes: 4 additions & 4 deletions build_runner_core/lib/src/asset/finalized_reader.dart
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ class FinalizedReader {

if (node.type == NodeType.generated) {
final nodeState = node.generatedNodeState!;
if (nodeState.isFailure) return UnreadableReason.failed;
if (!nodeState.wasOutput) return UnreadableReason.notOutput;
if (nodeState.result == false) return UnreadableReason.failed;
if (!node.wasOutput) return UnreadableReason.notOutput;
// No need to explicitly check readability for generated files, their
// readability is recorded in the node state.
return null;
Expand Down Expand Up @@ -120,10 +120,10 @@ class FinalizedReader {
/// Note that [id] must exist in the asset graph.
FutureOr<Digest> _ensureDigest(AssetId id) {
var node = _assetGraph.get(id)!;
if (node.lastKnownDigest != null) return node.lastKnownDigest!;
if (node.digest != null) return node.digest!;
return _delegate.digest(id).then((digest) {
_assetGraph.updateNode(id, (nodeBuilder) {
nodeBuilder.lastKnownDigest = digest;
nodeBuilder.digest = digest;
});
return digest;
});
Expand Down
Loading
Loading