Skip to content

Commit

Permalink
Hacking.
Browse files Browse the repository at this point in the history
  • Loading branch information
davidmorgan committed Mar 4, 2025
1 parent 734b793 commit 969ee33
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 32 deletions.
30 changes: 3 additions & 27 deletions build_runner_core/lib/src/asset_graph/graph.dart
Original file line number Diff line number Diff line change
Expand Up @@ -276,32 +276,6 @@ class AssetGraph {
Iterable<AssetId> get sources =>
allNodes.whereType<SourceAssetNode>().map((n) => n.id);

Future<Map<AssetId, ChangeType>> checkForChanges(
List<BuildPhase> buildPhases,
String rootPackage,
Future Function(AssetId id) delete,
AssetReader digestReader,
) async {
final result = <AssetId, ChangeType>{};
for (final node in allNodes) {
print('Check $node');
final oldDigest = node.lastKnownDigest;
await digestReader.cache.invalidate([node.id]);
if (await digestReader.canRead(node.id)) {
print(' readable');
final newDigest = await digestReader.digest(node.id);
print(' $oldDigest -> $newDigest');
if (oldDigest != newDigest) {
result[node.id] = ChangeType.MODIFY;
}
} else {
print(' not readable');
result[node.id] = ChangeType.REMOVE;
}
}
return result;
}

/// Updates graph structure, invalidating and deleting any outputs that were
/// affected.
///
Expand All @@ -313,7 +287,7 @@ class AssetGraph {
Future Function(AssetId id) delete,
AssetReader digestReader,
) async {
print('Updating graph! ${StackTrace.current}');
print('Updating graph! ${StackTrace.current} from $updates');
var newIds = <AssetId>{};
var modifyIds = <AssetId>{};
var removeIds = <AssetId>{};
Expand Down Expand Up @@ -429,6 +403,8 @@ class AssetGraph {
_removeRecursive(id);
}

print('Returning: $invalidatedIds');

return invalidatedIds;
}

Expand Down
9 changes: 6 additions & 3 deletions build_runner_core/lib/src/generate/build_definition.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ final _logger = Logger('BuildDefinition');

class BuildDefinition {
final AssetGraph assetGraph;
final Map<AssetId, ChangeType>? updates;
Map<AssetId, ChangeType>? updates;
final TargetGraph targetGraph;

final AssetReader reader;
Expand Down Expand Up @@ -134,6 +134,7 @@ class AssetTracker {
Set<AssetId> internalSources,
AssetGraph assetGraph,
) async {
print('compute source updates');
final allSources =
<AssetId>{}
..addAll(inputSources)
Expand Down Expand Up @@ -173,6 +174,7 @@ class AssetTracker {
if (originalDigest == null) return;
await _reader.cache.invalidate([id]);
var currentDigest = await _reader.digest(id);
print('$id $originalDigest -> $currentDigest');
if (currentDigest != originalDigest) {
updates[id] = ChangeType.MODIFY;
}
Expand Down Expand Up @@ -554,7 +556,8 @@ class _Loader {
assetGraph,
);
updates.addAll(_computeBuilderOptionsUpdates(assetGraph, buildPhases));
await assetGraph.updateAndInvalidate(
// build_impl also wants to do this, and uses the results
/*await assetGraph.updateAndInvalidate(
_buildPhases,
updates,
_options.packageGraph.root.name,
Expand All @@ -566,7 +569,7 @@ class _Loader {
_environment.reader,
assetGraph,
),
);
);*/
return updates;
}

Expand Down
12 changes: 10 additions & 2 deletions build_runner_core/lib/src/generate/build_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,9 @@ class BuildImpl {
_resourceManager = buildDefinition.resourceManager,
_environment = buildDefinition.environment,
_trackPerformance = options.trackPerformance,
_logPerformanceDir = options.logPerformanceDir;
_logPerformanceDir = options.logPerformanceDir {
buildDefinition.updates = null;
}

Future<BuildResult> run(
Map<AssetId, ChangeType> updates, {
Expand Down Expand Up @@ -827,7 +829,10 @@ class _SingleBuild {
final inputs = firstNode.inputs;

void compareResult(bool expectedResult) {
final myResult = invalidated == null || invalidated.any(inputs.contains);
final reallyInvalidated = invalidated!.difference(
unchangedGeneratedNodes,
);
final myResult = reallyInvalidated.any(inputs.contains);
print('''
_buildShouldRun $inputs -> $outputs
Expand Down Expand Up @@ -982,6 +987,8 @@ invalidated: $invalidated
return Digest(combinedBytes);
}

Set<AssetId> unchangedGeneratedNodes = {};

/// Sets the state for all [outputs] of a build step, by:
///
/// - Setting `needsUpdate` to `false` for each output
Expand Down Expand Up @@ -1026,6 +1033,7 @@ invalidated: $invalidated
// time a node might not be in a valid state.
_removeOldInputs(node, usedInputs);
_addNewInputs(node, usedInputs);
if (node.lastKnownDigest == digest) unchangedGeneratedNodes.add(node.id);
node
..state = NodeState.upToDate
..wasOutput = wasOutput
Expand Down

0 comments on commit 969ee33

Please sign in to comment.