Skip to content

Commit acec47d

Browse files
committed
Fix GeneratedAssetNode bug (#102)
1 parent eb40dcc commit acec47d

File tree

5 files changed

+31
-3
lines changed

5 files changed

+31
-3
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## 0.3.0+1
4+
- Fix an AssetGraph bug where generated nodes might be created as non-generated
5+
nodes if they are attempted to be read from previous build steps.
6+
37
## 0.3.0
48
- **BREAKING** Renamed values of three enums to be lower-case:
59
`BuildType`, `BuildStatus`, and `PackageDependencyType`.

lib/src/generate/build_impl.dart

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -529,8 +529,13 @@ class BuildImpl {
529529
_assetGraph.addIfAbsent(input, () => new AssetNode(input));
530530
for (var output in expectedOutputs) {
531531
inputNode.outputs.add(output);
532-
_assetGraph.addIfAbsent(
533-
output, () => new GeneratedAssetNode(input, true, false, output));
532+
var existing = _assetGraph.get(output);
533+
/// If its null or of type [AssetNode], then insert a
534+
/// [GeneratedAssetNode].
535+
if (existing is! GeneratedAssetNode) {
536+
_assetGraph.remove(output);
537+
_assetGraph.add(new GeneratedAssetNode(input, true, false, output));
538+
}
534539
}
535540

536541
/// Skip the build step if none of the outputs need updating.

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: build
2-
version: 0.3.0
2+
version: 0.3.0+1
33
description: A build system for Dart.
44
author: Dart Team <[email protected]>
55
homepage: https://github.com/dart-lang/build

test/common/copy_builder.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ class CopyBuilder implements Builder {
2020
/// asset.
2121
final AssetId copyFromAsset;
2222

23+
/// Will touch this asset, so that it becomes a dependency.
24+
final AssetId touchAsset;
25+
2326
/// No `build` step will complete until this future completes. It may be
2427
/// re-assigned in between builds.
2528
Future blockUntil;
@@ -29,6 +32,7 @@ class CopyBuilder implements Builder {
2932
this.extension: 'copy',
3033
this.outputPackage,
3134
this.copyFromAsset,
35+
this.touchAsset,
3236
this.blockUntil});
3337

3438
@override
@@ -42,6 +46,8 @@ class CopyBuilder implements Builder {
4246
: await buildStep.readAsString(copyFromAsset);
4347
buildStep.writeAsString(new Asset(id, content));
4448
}
49+
50+
if (touchAsset != null) await buildStep.hasInput(touchAsset);
4551
}
4652

4753
@override

test/generate/build_test.dart

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,19 @@ void main() {
8282
'a|web/a.txt.clone.copy.1': 'a',
8383
});
8484
});
85+
86+
test('early step touches a not-yet-generated asset', () async {
87+
var phases = new PhaseGroup();
88+
phases.newPhase()
89+
..addAction(
90+
new CopyBuilder(touchAsset: new AssetId('a', 'lib/a.txt.copy')),
91+
new InputSet('a', ['lib/b.txt']));
92+
phases.newPhase()
93+
..addAction(new CopyBuilder(), new InputSet('a', ['lib/a.txt']));
94+
95+
await testPhases(phases, {'a|lib/a.txt': 'a', 'a|lib/b.txt': 'b',},
96+
outputs: {'a|lib/a.txt.copy': 'a', 'a|lib/b.txt.copy': 'b',});
97+
});
8598
});
8699

87100
group('inputs from other packages', () {

0 commit comments

Comments
 (0)