Skip to content

Commit

Permalink
Version 0.6.17.0 .
Browse files Browse the repository at this point in the history
svn merge -r 25973:25988  https://dart.googlecode.com/svn/branches/bleeding_edge trunk

git-svn-id: http://dart.googlecode.com/svn/trunk@25990 260f80e4-7a28-3924-810f-c04153c831b5
  • Loading branch information
dgrove committed May 27, 2015
2 parents e97cdf2 + d50c5b6 commit 61f7d41
Show file tree
Hide file tree
Showing 44 changed files with 1,333 additions and 403 deletions.
3 changes: 2 additions & 1 deletion pkg/barback/lib/barback.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ export 'src/build_result.dart';
export 'src/errors.dart';
export 'src/package_provider.dart';
export 'src/transform.dart' show Transform;
export 'src/transformer.dart';
export 'src/transform_logger.dart';
export 'src/transformer.dart';
7 changes: 7 additions & 0 deletions pkg/barback/lib/src/transform.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import 'asset_id.dart';
import 'asset_node.dart';
import 'asset_set.dart';
import 'errors.dart';
import 'transform_logger.dart';
import 'transform_node.dart';
import 'utils.dart';

Expand Down Expand Up @@ -45,6 +46,9 @@ class Transform {
/// would be secondary inputs.
AssetId get primaryId => _node.primary.id;

/// A logger so that the [Transformer] can report build details.
TransformLogger get logger => _logger;

/// Gets the asset for the primary input.
Future<Asset> get primaryInput => getInput(primaryId);

Expand All @@ -65,3 +69,6 @@ class Transform {
_outputs.add(output);
}
}

// TODO(sigmund,rnystrom): create a separate logger for each Transfom.
final TransformLogger _logger = new TransformLogger(true);
40 changes: 40 additions & 0 deletions pkg/barback/lib/src/transform_logger.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

library barback.transform_logger;

import 'package:source_maps/span.dart';

/// Object used to report warnings and errors encountered while running a
/// transformer.
class TransformLogger {

bool _shouldPrint;

TransformLogger(this._shouldPrint);

/// Logs a warning message.
///
/// If present, [span] indicates the location in the input asset that caused
/// the warning.
void warning(String message, [Span span]) {
_printMessage('warning', message, span);
}

/// Logs an error message.
///
/// If present, [span] indicates the location in the input asset that caused
/// the error.
// TODO(sigmund,nweiz): clarify when an error should be logged or thrown.
void error(String message, [Span span]) {
_printMessage('error', message, span);
}

// TODO(sigmund,rnystrom): do something better than printing.
_printMessage(String prefix, String message, Span span) {
if (!_shouldPrint) return;
print(span == null ? '$prefix $message'
: '$prefix ${span.getLocationMessage(message)}');
}
}
1 change: 1 addition & 0 deletions pkg/barback/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ description: >
responsiveness.
dependencies:
path: any
source_maps: any
stack_trace: any
dev_dependencies:
scheduled_test: any
Expand Down
50 changes: 12 additions & 38 deletions pkg/barback/test/package_graph/errors_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ main() {
expectAsset("app|foo.c", "foo.c");
buildShouldSucceed();

schedule(() => updateSources(["app|foo.b"]));
updateSources(["app|foo.b"]);
buildShouldFail([isAssetCollisionException("app|foo.c")]);
});

Expand All @@ -54,7 +54,7 @@ main() {

test("reports an error for an unprovided package", () {
initGraph();
expect(() => updateSources(["unknown|foo.txt"]), throwsArgumentError);
expect(() => updateSourcesSync(["unknown|foo.txt"]), throwsArgumentError);
});

test("reports an error for an unprovided source", () {
Expand All @@ -69,11 +69,9 @@ main() {
[new ManyToOneTransformer("txt")]
]});

buildShouldFail([isMissingInputException("app|a.inc")]);

updateSources(["app|a.txt"]);

expectNoAsset("app|a.out");
buildShouldFail([isMissingInputException("app|a.inc")]);
});

test("reports an error if a transformer emits an asset for another package",
Expand All @@ -82,9 +80,8 @@ main() {
"app": [[new CreateAssetTransformer("wrong|foo.txt")]]
});

buildShouldFail([isInvalidOutputException("app", "wrong|foo.txt")]);

updateSources(["app|foo.txt"]);
buildShouldFail([isInvalidOutputException("app", "wrong|foo.txt")]);
});

test("fails if a non-primary input is removed", () {
Expand All @@ -101,10 +98,7 @@ main() {
expectAsset("app|a.out", "abc");
buildShouldSucceed();

schedule(() {
removeSources(["app|b.inc"]);
});

removeSources(["app|b.inc"]);
buildShouldFail([isMissingInputException("app|b.inc")]);
expectNoAsset("app|a.out");
});
Expand All @@ -114,12 +108,8 @@ main() {
[new BadTransformer(["app|foo.out"])]
]});

schedule(() {
updateSources(["app|foo.txt"]);
});

updateSources(["app|foo.txt"]);
expectNoAsset("app|foo.out");

buildShouldFail([equals(BadTransformer.ERROR)]);
});

Expand All @@ -128,22 +118,15 @@ main() {
[new BadTransformer(["app|foo.txt"])]
]});

schedule(() {
updateSources(["app|foo.txt"]);
});

updateSources(["app|foo.txt"]);
expectNoAsset("app|foo.txt");
});

test("catches errors even if nothing is waiting for process results", () {
initGraph(["app|foo.txt"], {"app": [[new BadTransformer([])]]});

schedule(() {
updateSources(["app|foo.txt"]);
});

updateSources(["app|foo.txt"]);
// Note: No asset requests here.

buildShouldFail([equals(BadTransformer.ERROR)]);
});

Expand All @@ -152,21 +135,15 @@ main() {
[new BadTransformer(["a.out", "b.out"])]
]});

schedule(() {
updateSources(["app|foo.txt"]);
});

updateSources(["app|foo.txt"]);
expectNoAsset("app|a.out");
});

test("fails if only one package fails", () {
initGraph(["pkg1|foo.txt", "pkg2|foo.txt"],
{"pkg1": [[new BadTransformer([])]]});

schedule(() {
updateSources(["pkg1|foo.txt", "pkg2|foo.txt"]);
});

updateSources(["pkg1|foo.txt", "pkg2|foo.txt"]);
expectAsset("pkg2|foo.txt", "foo");
buildShouldFail([equals(BadTransformer.ERROR)]);
});
Expand All @@ -177,10 +154,7 @@ main() {
"pkg2": [[new BadTransformer([])]]
});

schedule(() {
updateSources(["pkg1|foo.txt", "pkg2|foo.txt"]);
});

updateSources(["pkg1|foo.txt", "pkg2|foo.txt"]);
buildShouldFail([
equals(BadTransformer.ERROR),
equals(BadTransformer.ERROR)
Expand All @@ -191,7 +165,7 @@ main() {
initGraph(["app|foo.txt"]);

setAssetError("app|foo.txt");
schedule(() => updateSources(["app|foo.txt"]));
updateSources(["app|foo.txt"]);
expectNoAsset("app|foo.txt");
buildShouldFail([isMockLoadException("app|foo.txt")]);
});
Expand Down
56 changes: 21 additions & 35 deletions pkg/barback/test/package_graph/source_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,7 @@ main() {
expectAsset("app|foo.txt");
buildShouldSucceed();

schedule(() {
removeSources(["app|foo.txt"]);
});

removeSources(["app|foo.txt"]);
expectNoAsset("app|foo.txt");
buildShouldSucceed();
});
Expand All @@ -75,26 +72,24 @@ main() {

schedule(() {
// Make a bunch of synchronous update calls.
updateSources(["app|foo.blub"]);
updateSources(["app|foo.blub"]);
updateSources(["app|foo.blub"]);
updateSources(["app|foo.blub"]);
updateSourcesSync(["app|foo.blub"]);
updateSourcesSync(["app|foo.blub"]);
updateSourcesSync(["app|foo.blub"]);
updateSourcesSync(["app|foo.blub"]);
});

expectAsset("app|foo.blab", "foo.blab");
buildShouldSucceed();

schedule(() {
expect(transformer.numRuns, equals(1));
});
expect(transformer.numRuns, completion(equals(1)));
});

test("a removal cancels out an update", () {
initGraph(["app|foo.txt"]);

schedule(() {
updateSources(["app|foo.txt"]);
removeSources(["app|foo.txt"]);
updateSourcesSync(["app|foo.txt"]);
removeSourcesSync(["app|foo.txt"]);
});

expectNoAsset("app|foo.txt");
Expand All @@ -105,8 +100,8 @@ main() {
initGraph(["app|foo.txt"]);

schedule(() {
removeSources(["app|foo.txt"]);
updateSources(["app|foo.txt"]);
removeSourcesSync(["app|foo.txt"]);
updateSourcesSync(["app|foo.txt"]);
});

expectAsset("app|foo.txt");
Expand All @@ -117,14 +112,12 @@ main() {
initGraph({"app|foo.txt": "foo"});

pauseProvider();
schedule(() {
// The mock provider synchronously loads the value of the assets, so this
// will kick off two loads with different values. The second one should
// win.
updateSources(["app|foo.txt"]);
modifyAsset("app|foo.txt", "bar");
updateSources(["app|foo.txt"]);
});
// The mock provider synchronously loads the value of the assets, so this
// will kick off two loads with different values. The second one should
// win.
updateSources(["app|foo.txt"]);
modifyAsset("app|foo.txt", "bar");
updateSources(["app|foo.txt"]);

resumeProvider();
expectAsset("app|foo.txt", "bar");
Expand All @@ -145,23 +138,16 @@ main() {
// Make the provider slow to load a source.
pauseProvider();

schedule(() {
// Update an asset that doesn't trigger any transformers.
updateSources(["app|other.bar"]);
});
// Update an asset that doesn't trigger any transformers.
updateSources(["app|other.bar"]);

schedule(() {
// Now update an asset that does trigger a transformer.
updateSources(["app|foo.txt"]);
});
// Now update an asset that does trigger a transformer.
updateSources(["app|foo.txt"]);

resumeProvider();

buildShouldSucceed();
waitForBuild();

schedule(() {
expect(transformer.numRuns, equals(2));
});
expect(transformer.numRuns, completion(equals(2)));
});
}
Loading

0 comments on commit 61f7d41

Please sign in to comment.