Skip to content

Commit 61f7d41

Browse files
committed
Version 0.6.17.0 .
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
2 parents e97cdf2 + d50c5b6 commit 61f7d41

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+1333
-403
lines changed

pkg/barback/lib/barback.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@ export 'src/build_result.dart';
1111
export 'src/errors.dart';
1212
export 'src/package_provider.dart';
1313
export 'src/transform.dart' show Transform;
14-
export 'src/transformer.dart';
14+
export 'src/transform_logger.dart';
15+
export 'src/transformer.dart';

pkg/barback/lib/src/transform.dart

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import 'asset_id.dart';
1111
import 'asset_node.dart';
1212
import 'asset_set.dart';
1313
import 'errors.dart';
14+
import 'transform_logger.dart';
1415
import 'transform_node.dart';
1516
import 'utils.dart';
1617

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

49+
/// A logger so that the [Transformer] can report build details.
50+
TransformLogger get logger => _logger;
51+
4852
/// Gets the asset for the primary input.
4953
Future<Asset> get primaryInput => getInput(primaryId);
5054

@@ -65,3 +69,6 @@ class Transform {
6569
_outputs.add(output);
6670
}
6771
}
72+
73+
// TODO(sigmund,rnystrom): create a separate logger for each Transfom.
74+
final TransformLogger _logger = new TransformLogger(true);
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
library barback.transform_logger;
6+
7+
import 'package:source_maps/span.dart';
8+
9+
/// Object used to report warnings and errors encountered while running a
10+
/// transformer.
11+
class TransformLogger {
12+
13+
bool _shouldPrint;
14+
15+
TransformLogger(this._shouldPrint);
16+
17+
/// Logs a warning message.
18+
///
19+
/// If present, [span] indicates the location in the input asset that caused
20+
/// the warning.
21+
void warning(String message, [Span span]) {
22+
_printMessage('warning', message, span);
23+
}
24+
25+
/// Logs an error message.
26+
///
27+
/// If present, [span] indicates the location in the input asset that caused
28+
/// the error.
29+
// TODO(sigmund,nweiz): clarify when an error should be logged or thrown.
30+
void error(String message, [Span span]) {
31+
_printMessage('error', message, span);
32+
}
33+
34+
// TODO(sigmund,rnystrom): do something better than printing.
35+
_printMessage(String prefix, String message, Span span) {
36+
if (!_shouldPrint) return;
37+
print(span == null ? '$prefix $message'
38+
: '$prefix ${span.getLocationMessage(message)}');
39+
}
40+
}

pkg/barback/pubspec.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ description: >
1313
responsiveness.
1414
dependencies:
1515
path: any
16+
source_maps: any
1617
stack_trace: any
1718
dev_dependencies:
1819
scheduled_test: any

pkg/barback/test/package_graph/errors_test.dart

Lines changed: 12 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ main() {
3838
expectAsset("app|foo.c", "foo.c");
3939
buildShouldSucceed();
4040

41-
schedule(() => updateSources(["app|foo.b"]));
41+
updateSources(["app|foo.b"]);
4242
buildShouldFail([isAssetCollisionException("app|foo.c")]);
4343
});
4444

@@ -54,7 +54,7 @@ main() {
5454

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

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

72-
buildShouldFail([isMissingInputException("app|a.inc")]);
73-
7472
updateSources(["app|a.txt"]);
75-
7673
expectNoAsset("app|a.out");
74+
buildShouldFail([isMissingInputException("app|a.inc")]);
7775
});
7876

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

85-
buildShouldFail([isInvalidOutputException("app", "wrong|foo.txt")]);
86-
8783
updateSources(["app|foo.txt"]);
84+
buildShouldFail([isInvalidOutputException("app", "wrong|foo.txt")]);
8885
});
8986

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

104-
schedule(() {
105-
removeSources(["app|b.inc"]);
106-
});
107-
101+
removeSources(["app|b.inc"]);
108102
buildShouldFail([isMissingInputException("app|b.inc")]);
109103
expectNoAsset("app|a.out");
110104
});
@@ -114,12 +108,8 @@ main() {
114108
[new BadTransformer(["app|foo.out"])]
115109
]});
116110

117-
schedule(() {
118-
updateSources(["app|foo.txt"]);
119-
});
120-
111+
updateSources(["app|foo.txt"]);
121112
expectNoAsset("app|foo.out");
122-
123113
buildShouldFail([equals(BadTransformer.ERROR)]);
124114
});
125115

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

131-
schedule(() {
132-
updateSources(["app|foo.txt"]);
133-
});
134-
121+
updateSources(["app|foo.txt"]);
135122
expectNoAsset("app|foo.txt");
136123
});
137124

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

141-
schedule(() {
142-
updateSources(["app|foo.txt"]);
143-
});
144-
128+
updateSources(["app|foo.txt"]);
145129
// Note: No asset requests here.
146-
147130
buildShouldFail([equals(BadTransformer.ERROR)]);
148131
});
149132

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

155-
schedule(() {
156-
updateSources(["app|foo.txt"]);
157-
});
158-
138+
updateSources(["app|foo.txt"]);
159139
expectNoAsset("app|a.out");
160140
});
161141

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

166-
schedule(() {
167-
updateSources(["pkg1|foo.txt", "pkg2|foo.txt"]);
168-
});
169-
146+
updateSources(["pkg1|foo.txt", "pkg2|foo.txt"]);
170147
expectAsset("pkg2|foo.txt", "foo");
171148
buildShouldFail([equals(BadTransformer.ERROR)]);
172149
});
@@ -177,10 +154,7 @@ main() {
177154
"pkg2": [[new BadTransformer([])]]
178155
});
179156

180-
schedule(() {
181-
updateSources(["pkg1|foo.txt", "pkg2|foo.txt"]);
182-
});
183-
157+
updateSources(["pkg1|foo.txt", "pkg2|foo.txt"]);
184158
buildShouldFail([
185159
equals(BadTransformer.ERROR),
186160
equals(BadTransformer.ERROR)
@@ -191,7 +165,7 @@ main() {
191165
initGraph(["app|foo.txt"]);
192166

193167
setAssetError("app|foo.txt");
194-
schedule(() => updateSources(["app|foo.txt"]));
168+
updateSources(["app|foo.txt"]);
195169
expectNoAsset("app|foo.txt");
196170
buildShouldFail([isMockLoadException("app|foo.txt")]);
197171
});

pkg/barback/test/package_graph/source_test.dart

Lines changed: 21 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,7 @@ main() {
6161
expectAsset("app|foo.txt");
6262
buildShouldSucceed();
6363

64-
schedule(() {
65-
removeSources(["app|foo.txt"]);
66-
});
67-
64+
removeSources(["app|foo.txt"]);
6865
expectNoAsset("app|foo.txt");
6966
buildShouldSucceed();
7067
});
@@ -75,26 +72,24 @@ main() {
7572

7673
schedule(() {
7774
// Make a bunch of synchronous update calls.
78-
updateSources(["app|foo.blub"]);
79-
updateSources(["app|foo.blub"]);
80-
updateSources(["app|foo.blub"]);
81-
updateSources(["app|foo.blub"]);
75+
updateSourcesSync(["app|foo.blub"]);
76+
updateSourcesSync(["app|foo.blub"]);
77+
updateSourcesSync(["app|foo.blub"]);
78+
updateSourcesSync(["app|foo.blub"]);
8279
});
8380

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

87-
schedule(() {
88-
expect(transformer.numRuns, equals(1));
89-
});
84+
expect(transformer.numRuns, completion(equals(1)));
9085
});
9186

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

9590
schedule(() {
96-
updateSources(["app|foo.txt"]);
97-
removeSources(["app|foo.txt"]);
91+
updateSourcesSync(["app|foo.txt"]);
92+
removeSourcesSync(["app|foo.txt"]);
9893
});
9994

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

107102
schedule(() {
108-
removeSources(["app|foo.txt"]);
109-
updateSources(["app|foo.txt"]);
103+
removeSourcesSync(["app|foo.txt"]);
104+
updateSourcesSync(["app|foo.txt"]);
110105
});
111106

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

119114
pauseProvider();
120-
schedule(() {
121-
// The mock provider synchronously loads the value of the assets, so this
122-
// will kick off two loads with different values. The second one should
123-
// win.
124-
updateSources(["app|foo.txt"]);
125-
modifyAsset("app|foo.txt", "bar");
126-
updateSources(["app|foo.txt"]);
127-
});
115+
// The mock provider synchronously loads the value of the assets, so this
116+
// will kick off two loads with different values. The second one should
117+
// win.
118+
updateSources(["app|foo.txt"]);
119+
modifyAsset("app|foo.txt", "bar");
120+
updateSources(["app|foo.txt"]);
128121

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

148-
schedule(() {
149-
// Update an asset that doesn't trigger any transformers.
150-
updateSources(["app|other.bar"]);
151-
});
141+
// Update an asset that doesn't trigger any transformers.
142+
updateSources(["app|other.bar"]);
152143

153-
schedule(() {
154-
// Now update an asset that does trigger a transformer.
155-
updateSources(["app|foo.txt"]);
156-
});
144+
// Now update an asset that does trigger a transformer.
145+
updateSources(["app|foo.txt"]);
157146

158147
resumeProvider();
159148

160149
buildShouldSucceed();
161-
waitForBuild();
162150

163-
schedule(() {
164-
expect(transformer.numRuns, equals(2));
165-
});
151+
expect(transformer.numRuns, completion(equals(2)));
166152
});
167153
}

0 commit comments

Comments
 (0)