-
Notifications
You must be signed in to change notification settings - Fork 214
Split post process builder state out of the main graph. #3959
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
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ import 'package:build/src/internal.dart'; | |
import 'package:built_collection/built_collection.dart'; | ||
import 'package:crypto/crypto.dart'; | ||
import 'package:glob/glob.dart'; | ||
import 'package:meta/meta.dart'; | ||
import 'package:package_config/package_config.dart'; | ||
import 'package:watcher/watcher.dart'; | ||
|
||
|
@@ -23,6 +24,8 @@ import '../generate/phase.dart'; | |
import '../util/constants.dart'; | ||
import 'exceptions.dart'; | ||
import 'node.dart'; | ||
import 'post_process_build_step_id.dart'; | ||
import 'serializers.dart'; | ||
|
||
part 'serialization.dart'; | ||
|
||
|
@@ -46,6 +49,14 @@ class AssetGraph implements GeneratedAssetHider { | |
|
||
final BuiltMap<String, LanguageVersion?> packageLanguageVersions; | ||
|
||
/// All post process build steps outputs, indexed by package then | ||
/// [PostProcessBuildStepId]. | ||
/// | ||
/// Created with empty outputs at the start of the build if it's a new build | ||
/// step; or deserialized with previous build outputs if it has run before. | ||
final Map<String, Map<PostProcessBuildStepId, Set<AssetId>>> | ||
_postProcessBuildStepOutputs = {}; | ||
|
||
AssetGraph._( | ||
this.buildPhasesDigest, | ||
this.dartVersion, | ||
|
@@ -93,6 +104,10 @@ class AssetGraph implements GeneratedAssetHider { | |
|
||
List<int> serialize() => _AssetGraphSerializer(this).serialize(); | ||
|
||
@visibleForTesting | ||
Map<String, Map<PostProcessBuildStepId, Set<AssetId>>> | ||
get allPostProcessBuildStepOutputs => _postProcessBuildStepOutputs; | ||
|
||
/// Checks if [id] exists in the graph. | ||
bool contains(AssetId id) => | ||
_nodesByPackage[id.package]?.containsKey(id.path) ?? false; | ||
|
@@ -243,9 +258,6 @@ class AssetGraph implements GeneratedAssetHider { | |
var node = get(id); | ||
if (node == null) return removedIds; | ||
removedIds.add(id); | ||
for (var anchor in node.anchorOutputs.toList()) { | ||
_removeRecursive(anchor, removedIds: removedIds); | ||
} | ||
for (var output in node.primaryOutputs.toList()) { | ||
_removeRecursive(output, removedIds: removedIds); | ||
} | ||
|
@@ -290,6 +302,12 @@ class AssetGraph implements GeneratedAssetHider { | |
if (node.type != NodeType.missingSource) { | ||
_nodesByPackage[id.package]!.remove(id.path); | ||
} | ||
|
||
// Remove post build action applications with removed assets as inputs. | ||
for (final packageOutputs in _postProcessBuildStepOutputs.values) { | ||
packageOutputs.removeWhere((id, _) => removedIds!.contains(id.input)); | ||
} | ||
|
||
return removedIds; | ||
} | ||
|
||
|
@@ -301,6 +319,31 @@ class AssetGraph implements GeneratedAssetHider { | |
Iterable<AssetNode> packageNodes(String package) => | ||
_nodesByPackage[package]?.values ?? []; | ||
|
||
/// All the post process build steps for `package`. | ||
Iterable<PostProcessBuildStepId> postProcessBuildStepIds({ | ||
required String package, | ||
}) => _postProcessBuildStepOutputs[package]?.keys ?? const []; | ||
|
||
/// Creates or updates state for a [PostProcessBuildStepId]. | ||
void updatePostProcessBuildStep( | ||
PostProcessBuildStepId buildStepId, { | ||
required Set<AssetId> outputs, | ||
}) { | ||
_postProcessBuildStepOutputs.putIfAbsent( | ||
buildStepId.input.package, | ||
() => {}, | ||
)[buildStepId] = | ||
outputs; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you must just have forgotten to format it right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nope, this is the output :) |
||
} | ||
|
||
/// Gets outputs of a [PostProcessBuildStepId]. | ||
/// | ||
/// These are set using [updatePostProcessBuildStep] during the build, then | ||
/// used to clean up prior outputs in the next build. | ||
Iterable<AssetId> postProcessBuildStepOutputs(PostProcessBuildStepId action) { | ||
return _postProcessBuildStepOutputs[action.input.package]![action]!; | ||
} | ||
|
||
/// All the generated outputs in the graph. | ||
Iterable<AssetId> get outputs => | ||
allNodes.where((n) => n.type == NodeType.generated).map((n) => n.id); | ||
|
@@ -547,7 +590,7 @@ class AssetGraph implements GeneratedAssetHider { | |
), | ||
); | ||
} else if (phase is PostBuildPhase) { | ||
_addPostBuildPhaseAnchors(phase, allInputs); | ||
_addPostBuildActionApplications(phase, allInputs); | ||
} else { | ||
throw StateError('Unrecognized phase type $phase'); | ||
} | ||
|
@@ -600,27 +643,21 @@ class AssetGraph implements GeneratedAssetHider { | |
return phaseOutputs; | ||
} | ||
|
||
/// Adds all [AssetNode.postProcessAnchor]s for [phase] given [allInputs]; | ||
/// | ||
/// Does not return anything because [AssetNode.postProcessAnchor]s are | ||
/// synthetic and should not be treated as inputs. | ||
void _addPostBuildPhaseAnchors(PostBuildPhase phase, Set<AssetId> allInputs) { | ||
var actionNum = 0; | ||
/// Adds all [PostProcessBuildStepId]s for [phase] given [allInputs]; | ||
void _addPostBuildActionApplications( | ||
PostBuildPhase phase, | ||
Set<AssetId> allInputs, | ||
) { | ||
var actionNumber = 0; | ||
for (var action in phase.builderActions) { | ||
var inputs = allInputs.where((input) => _actionMatches(action, input)); | ||
for (var input in inputs) { | ||
var buildOptionsNodeId = builderOptionsIdForAction(action, actionNum); | ||
var anchor = AssetNode.postProcessAnchorForInputAndAction( | ||
input, | ||
actionNum, | ||
buildOptionsNodeId, | ||
updatePostProcessBuildStep( | ||
PostProcessBuildStepId(input: input, actionNumber: actionNumber), | ||
outputs: {}, | ||
); | ||
add(anchor); | ||
updateNode(input, (nodeBuilder) { | ||
nodeBuilder.anchorOutputs.add(anchor.id); | ||
}); | ||
} | ||
actionNum++; | ||
actionNumber++; | ||
} | ||
} | ||
|
||
|
@@ -762,11 +799,14 @@ class AssetGraph implements GeneratedAssetHider { | |
Digest computeBuilderOptionsDigest(BuilderOptions options) => | ||
md5.convert(utf8.encode(json.encode(options.config))); | ||
|
||
AssetId builderOptionsIdForAction(BuildAction action, int actionNum) { | ||
AssetId builderOptionsIdForAction(BuildAction action, int actionNumber) { | ||
if (action is InBuildPhase) { | ||
return AssetId(action.package, 'Phase$actionNum.builderOptions'); | ||
return AssetId(action.package, 'Phase$actionNumber.builderOptions'); | ||
} else if (action is PostBuildAction) { | ||
return AssetId(action.package, 'PostPhase$actionNum.builderOptions'); | ||
return PostProcessBuildStepId.builderOptionsIdFor( | ||
package: action.package, | ||
actionNumber: actionNumber, | ||
); | ||
} else { | ||
throw StateError('Unsupported action type $action'); | ||
} | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this really the indentation provided by
dart format
? (also below)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is ... formatting gets a bit surprising when there are very long identifiers.
There's a format presubmit :) that's checked before the tests run.