Skip to content

Commit 280eab1

Browse files
authored
Refactor asset graph creation into BuildPlan (#4203)
* Refactor asset graph creation into `BuildPlan`. * Address review comments.
1 parent 79db21b commit 280eab1

File tree

17 files changed

+502
-1069
lines changed

17 files changed

+502
-1069
lines changed

build_runner/lib/src/build/asset_graph/build_definition.dart

Lines changed: 0 additions & 241 deletions
This file was deleted.

build_runner/lib/src/build/asset_graph/graph.dart

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,22 @@ class AssetGraph implements GeneratedAssetHider {
141141
previousPhasedAssetDeps: previousPhasedAssetDeps,
142142
);
143143

144+
/// Copies the graph prepared for the next build with [buildPhases].
145+
AssetGraph copyForNextBuild(BuildPhases buildPhases) {
146+
// TODO(davidmorgan): clean up so there is a way to copy safely without
147+
// serializing then deserializing.
148+
final result = AssetGraph.deserialize(serialize())!;
149+
result.previousInBuildPhasesOptionsDigests =
150+
result.inBuildPhasesOptionsDigests;
151+
result.inBuildPhasesOptionsDigests =
152+
buildPhases.inBuildPhasesOptionsDigests;
153+
result.previousPostBuildActionsOptionsDigests =
154+
result.postBuildActionsOptionsDigests;
155+
result.postBuildActionsOptionsDigests =
156+
buildPhases.postBuildActionsOptionsDigests;
157+
return result;
158+
}
159+
144160
/// Deserializes an [AssetGraph] from a [Map].
145161
///
146162
/// Returns `null` if deserialization fails.
@@ -719,20 +735,6 @@ class AssetGraph implements GeneratedAssetHider {
719735
return id;
720736
}
721737

722-
/// Deletes outputs that were written to the source tree.
723-
///
724-
/// Returns the assets that were deleted.
725-
Future<Iterable<AssetId>> deleteOutputs(
726-
PackageGraph packageGraph,
727-
ReaderWriter readerWriter,
728-
) async {
729-
final result = outputsToDelete(packageGraph);
730-
for (final id in outputsToDelete(packageGraph)) {
731-
await readerWriter.delete(id);
732-
}
733-
return result;
734-
}
735-
736738
/// Returns outputs that were written to the source tree.
737739
Iterable<AssetId> outputsToDelete(PackageGraph packageGraph) {
738740
final result = <AssetId>[];

build_runner/lib/src/build/build_series.dart

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import '../build_plan/build_plan.dart';
1515
import '../io/filesystem_cache.dart';
1616
import '../io/finalized_reader.dart';
1717
import '../io/reader_writer.dart';
18-
import 'asset_graph/build_definition.dart';
1918
import 'asset_graph/graph.dart';
2019
import 'build.dart';
2120
import 'build_result.dart';
@@ -47,7 +46,7 @@ class BuildSeries {
4746
///
4847
/// Null after the first build, or if there was no serialized build state, or
4948
/// if the serialized build state was discarded.
50-
Map<AssetId, ChangeType>? updatesFromLoad;
49+
BuiltMap<AssetId, ChangeType>? updatesFromLoad;
5150

5251
/// Whether the next build is the first build.
5352
bool firstBuild = true;
@@ -85,7 +84,7 @@ class BuildSeries {
8584
buildFilters ??= buildPlan.buildOptions.buildFilters;
8685
if (firstBuild) {
8786
if (updatesFromLoad != null) {
88-
updates = updatesFromLoad!..addAll(updates);
87+
updates = updatesFromLoad!.toMap()..addAll(updates);
8988
updatesFromLoad = null;
9089
}
9190
} else {
@@ -110,30 +109,20 @@ class BuildSeries {
110109
}
111110

112111
static Future<BuildSeries> create({required BuildPlan buildPlan}) async {
113-
final buildDefinition = await BuildDefinition.prepareWorkspace(
114-
assetGraph: buildPlan.takeAssetGraph(),
115-
packageGraph: buildPlan.packageGraph,
116-
targetGraph: buildPlan.targetGraph,
117-
readerWriter: buildPlan.readerWriter,
118-
buildPhases: buildPlan.buildPhases,
119-
skipBuildScriptCheck: buildPlan.buildOptions.skipBuildScriptCheck,
120-
);
121-
112+
final assetGraph = buildPlan.takeAssetGraph();
122113
final finalizedReader = FinalizedReader(
123-
buildPlan.readerWriter.copyWith(
124-
generatedAssetHider: buildDefinition.assetGraph,
125-
),
126-
buildDefinition.assetGraph,
114+
buildPlan.readerWriter.copyWith(generatedAssetHider: assetGraph),
115+
assetGraph,
127116
buildPlan.targetGraph,
128117
buildPlan.buildPhases,
129118
buildPlan.packageGraph.root.name,
130119
);
131120
final build = BuildSeries._(
132121
buildPlan,
133-
buildDefinition.assetGraph,
134-
buildDefinition.buildScriptUpdates,
122+
assetGraph,
123+
buildPlan.buildScriptUpdates,
135124
finalizedReader,
136-
buildDefinition.updates,
125+
buildPlan.updates,
137126
);
138127
return build;
139128
}

0 commit comments

Comments
 (0)