Skip to content

Commit

Permalink
Fix GeneratedAssetNode bug (#102)
Browse files Browse the repository at this point in the history
  • Loading branch information
jakemac53 committed Apr 29, 2016
1 parent eb40dcc commit acec47d
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 0.3.0+1
- Fix an AssetGraph bug where generated nodes might be created as non-generated
nodes if they are attempted to be read from previous build steps.

## 0.3.0
- **BREAKING** Renamed values of three enums to be lower-case:
`BuildType`, `BuildStatus`, and `PackageDependencyType`.
Expand Down
9 changes: 7 additions & 2 deletions lib/src/generate/build_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -529,8 +529,13 @@ class BuildImpl {
_assetGraph.addIfAbsent(input, () => new AssetNode(input));
for (var output in expectedOutputs) {
inputNode.outputs.add(output);
_assetGraph.addIfAbsent(
output, () => new GeneratedAssetNode(input, true, false, output));
var existing = _assetGraph.get(output);
/// If its null or of type [AssetNode], then insert a
/// [GeneratedAssetNode].
if (existing is! GeneratedAssetNode) {
_assetGraph.remove(output);
_assetGraph.add(new GeneratedAssetNode(input, true, false, output));
}
}

/// Skip the build step if none of the outputs need updating.
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: build
version: 0.3.0
version: 0.3.0+1
description: A build system for Dart.
author: Dart Team <[email protected]>
homepage: https://github.com/dart-lang/build
Expand Down
6 changes: 6 additions & 0 deletions test/common/copy_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ class CopyBuilder implements Builder {
/// asset.
final AssetId copyFromAsset;

/// Will touch this asset, so that it becomes a dependency.
final AssetId touchAsset;

/// No `build` step will complete until this future completes. It may be
/// re-assigned in between builds.
Future blockUntil;
Expand All @@ -29,6 +32,7 @@ class CopyBuilder implements Builder {
this.extension: 'copy',
this.outputPackage,
this.copyFromAsset,
this.touchAsset,
this.blockUntil});

@override
Expand All @@ -42,6 +46,8 @@ class CopyBuilder implements Builder {
: await buildStep.readAsString(copyFromAsset);
buildStep.writeAsString(new Asset(id, content));
}

if (touchAsset != null) await buildStep.hasInput(touchAsset);
}

@override
Expand Down
13 changes: 13 additions & 0 deletions test/generate/build_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,19 @@ void main() {
'a|web/a.txt.clone.copy.1': 'a',
});
});

test('early step touches a not-yet-generated asset', () async {
var phases = new PhaseGroup();
phases.newPhase()
..addAction(
new CopyBuilder(touchAsset: new AssetId('a', 'lib/a.txt.copy')),
new InputSet('a', ['lib/b.txt']));
phases.newPhase()
..addAction(new CopyBuilder(), new InputSet('a', ['lib/a.txt']));

await testPhases(phases, {'a|lib/a.txt': 'a', 'a|lib/b.txt': 'b',},
outputs: {'a|lib/a.txt.copy': 'a', 'a|lib/b.txt.copy': 'b',});
});
});

group('inputs from other packages', () {
Expand Down

0 comments on commit acec47d

Please sign in to comment.