Skip to content

Commit d652b79

Browse files
committed
Cleanup.
1 parent e1b08b6 commit d652b79

File tree

1 file changed

+55
-118
lines changed

1 file changed

+55
-118
lines changed

build_runner_core/lib/src/generate/build.dart

Lines changed: 55 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
// ignore_for_file: lines_longer_than_80_chars
6-
75
import 'dart:async';
86
import 'dart:collection';
97
import 'dart:convert';
@@ -110,8 +108,6 @@ class Build {
110108
/// checked against the digest from the previous build.
111109
final Set<AssetId> changedOutputs = {};
112110

113-
static final debugging = true;
114-
115111
Build({
116112
required this.environment,
117113
required this.options,
@@ -127,13 +123,7 @@ class Build {
127123
options.trackPerformance
128124
? BuildPerformanceTracker()
129125
: BuildPerformanceTracker.noOp(),
130-
logFine = _logger.level <= Level.FINE || debugging {
131-
if (debugging) {
132-
Logger.root.level = Level.FINE;
133-
/*Logger.root.onRecord.listen((record) {
134-
print('${record.message} ');
135-
});*/
136-
}
126+
logFine = _logger.level <= Level.FINE {
137127
hungActionsHeartbeat = HungActionsHeartbeat(() {
138128
final message = StringBuffer();
139129
const actionsToLogMax = 5;
@@ -166,20 +156,10 @@ class Build {
166156
buildPhases,
167157
);
168158
if (result.status == BuildStatus.success) {
169-
/*if (logFine) {
170-
_logger.fine('Failed? $processedAssets');
171-
_logger.fine(
172-
'Failed?? ${processedAssets.map((id) => assetGraph.get(id)!).where((node) => node.type == NodeType.generated).map((node) => node.id)}',
173-
);
174-
_logger.fine(
175-
'Failed??? ${processedAssets.map((id) => assetGraph.get(id)!).where((node) => node.type == NodeType.generated && node.generatedNodeState!.result == false).map((node) => node.id)}',
176-
);
177-
}*/
178159
final failures = processedOutputs
179160
.map((id) => assetGraph.get(id)!)
180161
.where((node) => node.type == NodeType.generated)
181-
.where((node) => node.generatedNodeState!.result == false)
182-
/*.where((node) => optionalOutputTracker.isRequired(node.id))*/;
162+
.where((node) => node.generatedNodeState!.result == false);
183163
if (failures.isNotEmpty) {
184164
await failureReporter.reportErrors(failures);
185165
result = BuildResult(
@@ -235,7 +215,6 @@ class Build {
235215
readerWriter,
236216
);
237217
deletedAssets.addAll(deleted);
238-
// if (debugging) print(assetGraph);
239218
await readerWriter.cache.invalidate(changedInputs);
240219
});
241220
}
@@ -310,7 +289,6 @@ class Build {
310289
},
311290
(e, st) {
312291
if (!done.isCompleted) {
313-
if (debugging) print('Unhandled build failure! $e $st');
314292
_logger.severe('Unhandled build failure! $e $st', e, st);
315293
done.complete(BuildResult(BuildStatus.failure, []));
316294
}
@@ -504,22 +482,7 @@ class Build {
504482
phase.builderLabel,
505483
);
506484
return tracker.track(() async {
507-
var builderOutputs = expectedOutputs(builder, input);
508-
509-
// Add `builderOutputs` to the primary outputs of the input.
510-
var inputNode = assetGraph.get(input)!;
511-
assert(
512-
inputNode.primaryOutputs.containsAll(builderOutputs),
513-
// ignore: prefer_interpolation_to_compose_strings
514-
'input $input with builder $builder missing primary outputs: \n'
515-
'Got ${inputNode.primaryOutputs.join(', ')} '
516-
'which was missing:\n' +
517-
builderOutputs
518-
.where((id) => !inputNode.primaryOutputs.contains(id))
519-
.join(', '),
520-
);
521-
522-
var readerWriter = SingleStepReaderWriter(
485+
final readerWriter = SingleStepReaderWriter(
523486
runningBuild: RunningBuild(
524487
packageGraph: options.packageGraph,
525488
targetGraph: options.targetGraph,
@@ -538,6 +501,7 @@ class Build {
538501
assetsWritten: {},
539502
);
540503

504+
final builderOutputs = expectedOutputs(builder, input);
541505
if (!await tracker.trackStage(
542506
'Setup',
543507
() => _buildShouldRun(phaseNumber, input, builderOutputs, readerWriter),
@@ -551,19 +515,19 @@ class Build {
551515
// Clear input tracking accumulated during `_buildShouldRun`.
552516
readerWriter.inputTracker.clear();
553517

554-
var actionDescription = _actionLoggerName(
518+
final actionDescription = _actionLoggerName(
555519
phase,
556520
input,
557521
options.packageGraph.root.name,
558522
);
559-
var logger = BuildForInputLogger(Logger(actionDescription));
523+
final logger = BuildForInputLogger(Logger(actionDescription));
560524

561525
actionsStartedCount++;
562526
pendingActions
563527
.putIfAbsent(phaseNumber, () => <String>{})
564528
.add(actionDescription);
565529

566-
var unusedAssets = <AssetId>{};
530+
final unusedAssets = <AssetId>{};
567531
void reportUnusedAssetsForInput(AssetId input, Iterable<AssetId> assets) {
568532
options.reportUnusedAssetsForInput?.call(input, assets);
569533
unusedAssets.addAll(assets);
@@ -816,8 +780,8 @@ class Build {
816780
if (primaryInputNode.type == NodeType.missingSource) {
817781
if (logFine) {
818782
_logger.fine(
819-
'Skip ${renderer.build(primaryInput, outputs)} because $primaryInput '
820-
' was deleted.',
783+
'Skip ${renderer.build(primaryInput, outputs)} because '
784+
'$primaryInput was deleted.',
821785
);
822786
}
823787
_markOutputsSkipped(outputs);
@@ -831,35 +795,36 @@ class Build {
831795
if (primaryInputNode.generatedNodeState!.result == false) {
832796
if (logFine) {
833797
_logger.fine(
834-
'Skip ${renderer.build(primaryInput, outputs)} because $primaryInput is '
835-
'a generated file that failed.',
798+
'Skip ${renderer.build(primaryInput, outputs)} because '
799+
'$primaryInput is a generated file that failed.',
836800
);
837801
}
838802
await _markOutputsTransitivelyFailed(outputs);
839803
return false;
840804
}
841805

842-
// If the primary input succeeded but was not output, this build is skipped.
806+
// If the primary input succeeded but was not output, this build is
807+
// skipped.
843808
if (!primaryInputNode.wasOutput) {
844809
if (logFine) {
845810
_logger.fine(
846-
'Skip ${renderer.build(primaryInput, outputs)} because $primaryInput is a '
847-
' generated file that was not output.',
811+
'Skip ${renderer.build(primaryInput, outputs)} because '
812+
'$primaryInput is a generated file that was not output.',
848813
);
849814
}
850815
_markOutputsSkipped(outputs);
851816
return false;
852817
}
853818
}
854819

855-
// The primary input has been checked and is valid, from here builds will run unless there
856-
// is valid output already on disk.
820+
// The primary input has been checked and is valid, from here builds will
821+
// run unless there is valid output already on disk.
857822

858823
if (assetGraph.cleanBuild) {
859824
if (logFine) {
860825
_logger.fine(
861-
'Build ${renderer.build(primaryInput, outputs)} because this is a clean '
862-
'build.',
826+
'Build ${renderer.build(primaryInput, outputs)} because this is a '
827+
'clean build.',
863828
);
864829
}
865830
return true;
@@ -869,8 +834,8 @@ class Build {
869834
assetGraph.inBuildPhasesOptionsDigests[phaseNumber]) {
870835
if (logFine) {
871836
_logger.fine(
872-
'Build ${renderer.build(primaryInput, outputs)} because builder options '
873-
'changed.',
837+
'Build ${renderer.build(primaryInput, outputs)} because builder '
838+
'options changed.',
874839
);
875840
}
876841
return true;
@@ -879,8 +844,8 @@ class Build {
879844
if (newPrimaryInputs.contains(primaryInput)) {
880845
if (logFine) {
881846
_logger.fine(
882-
'Build ${renderer.build(primaryInput, outputs)} because $primaryInput '
883-
'was created.',
847+
'Build ${renderer.build(primaryInput, outputs)} because '
848+
'$primaryInput was created.',
884849
);
885850
}
886851
return true;
@@ -898,15 +863,16 @@ class Build {
898863
}
899864
}
900865

901-
// Build results are the same across outputs, so just check the first output.
866+
// Build results are the same across outputs, so just check the first
867+
// output.
902868
var firstOutput = assetGraph.get(outputs.first)!;
903869
final firstOutputState = firstOutput.generatedNodeState!;
904870

905871
if (firstOutputState.result == null) {
906872
if (logFine) {
907873
_logger.fine(
908-
'Build ${renderer.build(primaryInput, outputs)} the outputs are optional outputs '
909-
'than have become needed.',
874+
'Build ${renderer.build(primaryInput, outputs)} the outputs are '
875+
'optional outputs than have become needed.',
910876
);
911877
}
912878
return true;
@@ -1118,11 +1084,11 @@ class Build {
11181084

11191085
/// Sets the state for all [outputs] of a build step, by:
11201086
///
1121-
/// - Setting `needsUpdate` to `false` for each output
1122-
/// - Setting `wasOutput` based on `writer.assetsWritten`.
1123-
/// - Setting `isFailed` based on action success.
1124-
/// - Adding `outputs` as outputs to all `reader.assetsRead`.
1087+
/// - Setting `digest` based on what was written.
1088+
/// - Setting `result` based on action success.
1089+
/// - Setting `inputs` based on `inputTracker` and `unusedAssets`.
11251090
/// - Storing the error message with the [failureReporter].
1091+
/// - Updating `newPrimaryInputs` and `changedOutputs` as needed.
11261092
Future<void> _setOutputsState(
11271093
AssetId input,
11281094
Iterable<AssetId> outputs,
@@ -1141,69 +1107,40 @@ class Build {
11411107
final result = errors.isEmpty;
11421108

11431109
await this.readerWriter.cache.invalidate(outputs);
1144-
for (var output in outputs) {
1145-
var wasOutput = readerWriter.assetsWritten.contains(output);
1146-
var digest = wasOutput ? await this.readerWriter.digest(output) : null;
1110+
for (final output in outputs) {
1111+
final wasOutput = readerWriter.assetsWritten.contains(output);
1112+
final digest = wasOutput ? await this.readerWriter.digest(output) : null;
1113+
var outputNode = assetGraph.get(output)!;
1114+
1115+
// A transition from (missing or failed) to (written and not failed) is
1116+
// a new primary input that triggers generation even if no content
1117+
// changed.
1118+
if ((outputNode.digest == null ||
1119+
outputNode.generatedNodeState!.result == false) &&
1120+
(digest != null && result)) {
1121+
newPrimaryInputs.add(output);
1122+
}
1123+
// Only a change to content matters for non-primary inputs.
1124+
if (outputNode.digest != digest) {
1125+
changedOutputs.add(output);
1126+
}
11471127

1148-
processedOutputs.add(output);
1149-
assetGraph.updateNode(output, (nodeBuilder) {
1150-
/*_logger.fine(
1151-
'Generated output $output, digest ${nodeBuilder.lastKnownDigest} '
1152-
'-> $digest',
1153-
);*/
1154-
// A transition from (missing or failed) to (written and not failed) is
1155-
// a new primary input that triggers generation even if no content changed.
1156-
if ((nodeBuilder.digest == null ||
1157-
nodeBuilder.generatedNodeState.result == false) &&
1158-
(digest != null && result)) {
1159-
newPrimaryInputs.add(output);
1160-
}
1161-
if (nodeBuilder.digest != digest ||
1162-
nodeBuilder.generatedNodeState.result != result) {
1163-
_logger.fine('Changed output $output');
1164-
changedOutputs.add(output);
1165-
} else {
1166-
_logger.fine('Unchanged output $output');
1167-
}
1128+
outputNode = assetGraph.updateNode(output, (nodeBuilder) {
11681129
nodeBuilder.generatedNodeState
11691130
..inputs.replace(usedInputs)
11701131
..result = result;
11711132
nodeBuilder.digest = digest;
11721133
});
11731134

11741135
if (!result) {
1175-
_logger.fine('Failed: $input->$output');
1136+
await failureReporter.markReported(
1137+
actionDescription,
1138+
outputNode,
1139+
errors,
1140+
);
11761141
}
11771142

1178-
if (!result) {
1179-
final node = assetGraph.get(output)!;
1180-
await failureReporter.markReported(actionDescription, node, errors);
1181-
} /*
1182-
var needsMarkAsFailure = Queue.of(node.primaryOutputs);
1183-
var allSkippedFailures = <AssetId>[];
1184-
while (needsMarkAsFailure.isNotEmpty) {
1185-
var output = needsMarkAsFailure.removeLast();
1186-
builtAssets.add(output);
1187-
assetGraph.updateNode(output, (nodeBuilder) {
1188-
if (nodeBuilder.digest != null) {
1189-
changedOutputs.add(output);
1190-
}
1191-
nodeBuilder.generatedNodeState.result = false;
1192-
nodeBuilder.digest = null;
1193-
});
1194-
allSkippedFailures.add(output);
1195-
needsMarkAsFailure.addAll(assetGraph.get(output)!.primaryOutputs);
1196-
1197-
// Make sure output invalidation follows primary outputs for builds
1198-
// that won't run.
1199-
assetGraph.updateNode(output, (nodeBuilder) {
1200-
nodeBuilder.generatedNodeState.inputs.add(node.id);
1201-
});
1202-
}
1203-
await failureReporter.markSkipped(
1204-
allSkippedFailures.map((id) => assetGraph.get(id)!),
1205-
);
1206-
}*/
1143+
processedOutputs.add(output);
12071144
}
12081145
}
12091146

0 commit comments

Comments
 (0)