Skip to content

Commit d2be65b

Browse files
authored
Fix delete of transitive stale outputs. (#4130)
1 parent 72ef1de commit d2be65b

File tree

4 files changed

+11
-22
lines changed

4 files changed

+11
-22
lines changed

build_runner/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
- Remove interactive prompts for whether to delete files.
99
- Ignore `-d` flag: always delete files as if `-d` was passed.
1010
- Documentation revamp.
11+
- Bug fix: delete transitive generated outputs as well as direct generated
12+
outputs. So, a generated file now gets deleted if its input was a generated
13+
file that is no longer output.
1114

1215
## 2.6.1
1316

build_runner_core/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
- Add support for build.yaml `triggers`. See `build_runner` 2.7.0 for usage.
44
- Remove interactive prompts for whether to delete files.
55
- Ignore `-d` flag: always delete files as if `-d` was passed.
6+
- Bug fix: delete transitive generated outputs as well as direct generated
7+
outputs. So, a generated file now gets deleted if its input was a generated
8+
file that is no longer output.
69

710
## 9.2.1
811

build_runner_core/lib/src/generate/build.dart

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -784,8 +784,6 @@ class Build {
784784
void _markOutputsSkipped(Iterable<AssetId> outputs) {
785785
for (final output in outputs) {
786786
assetGraph.updateNode(output, (nodeBuilder) {
787-
// TODO(davidmorgan): deleting the file here may be the fix for
788-
// https://github.com/dart-lang/build/issues/3875.
789787
nodeBuilder.digest = null;
790788
nodeBuilder.generatedNodeState.result = null;
791789
});
@@ -797,8 +795,6 @@ class Build {
797795
Future<void> _markOutputsTransitivelyFailed(Iterable<AssetId> outputs) async {
798796
for (final output in outputs) {
799797
assetGraph.updateNode(output, (nodeBuilder) {
800-
// TODO(davidmorgan): deleting the file here may be the fix for
801-
// https://github.com/dart-lang/build/issues/3875.
802798
nodeBuilder.digest = null;
803799
nodeBuilder.generatedNodeState.result = false;
804800
nodeBuilder.generatedNodeState.errors.clear();
@@ -830,6 +826,7 @@ class Build {
830826
// If the primary input has been deleted, the build is skipped.
831827
if (deletedAssets.contains(primaryInput)) {
832828
if (primaryInputNode.type == NodeType.missingSource) {
829+
await _cleanUpStaleOutputs(outputs);
833830
_markOutputsSkipped(outputs);
834831
return false;
835832
}
@@ -846,6 +843,7 @@ class Build {
846843
// If the primary input succeeded but was not output, this build is
847844
// skipped.
848845
if (!primaryInputNode.wasOutput) {
846+
await _cleanUpStaleOutputs(outputs);
849847
_markOutputsSkipped(outputs);
850848
return false;
851849
}

build_runner_core/test/invalidation/primary_input_invalidation_test.dart

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -170,13 +170,7 @@ void main() {
170170
test('change a, on rebuild a.1 is not output, a.2 is deleted', () async {
171171
expect(await tester.build(), Result(written: ['a.1', 'a.2']));
172172
tester.skipOutput('a.1');
173-
expect(
174-
await tester.build(change: 'a'),
175-
// TODO(davidmorgan): this would be the correct result, see
176-
// https://github.com/dart-lang/build/issues/3875.
177-
// Result(deleted: ['a.1', 'a.2']),
178-
Result(deleted: ['a.1']),
179-
);
173+
expect(await tester.build(change: 'a'), Result(deleted: ['a.1', 'a.2']));
180174
});
181175
});
182176

@@ -221,13 +215,7 @@ void main() {
221215
test('change a, on rebuild a.1 is not output, a.2 is deleted', () async {
222216
expect(await tester.build(), Result(written: ['a.1', 'a.2']));
223217
tester.skipOutput('a.1');
224-
expect(
225-
await tester.build(change: 'a'),
226-
// TODO(davidmorgan): this would be the correct result, see
227-
// https://github.com/dart-lang/build/issues/3875.
228-
// Result(deleted: ['a.1', 'a.2']),
229-
Result(deleted: ['a.1']),
230-
);
218+
expect(await tester.build(change: 'a'), Result(deleted: ['a.1', 'a.2']));
231219
});
232220
});
233221

@@ -355,10 +343,7 @@ void main() {
355343
tester.skipOutput('a.2');
356344
expect(
357345
await tester.build(change: 'a'),
358-
// TODO(davidmorgan): this would be the correct result, see
359-
// https://github.com/dart-lang/build/issues/3875.
360-
// Result(written: ['a.1'], deleted: ['a.2', 'a.3', 'a.4']),
361-
Result(written: ['a.1'], deleted: ['a.2']),
346+
Result(written: ['a.1'], deleted: ['a.2', 'a.3', 'a.4']),
362347
);
363348
});
364349
});

0 commit comments

Comments
 (0)