Skip to content

Commit 3d32057

Browse files
committed
Merge remote-tracking branch 'origin/master' into feature/1323
2 parents c9f521d + 5f6cda0 commit 3d32057

File tree

637 files changed

+21889
-13478
lines changed

Some content is hidden

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

637 files changed

+21889
-13478
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
.idea
44
.pub/
55
.settings/
6-
build/
6+
/build/
77
packages
88
/.packages
99
pubspec.lock

.travis.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
language: dart
2+
sudo: false
3+
4+
dart:
5+
- dev
6+
7+
dart_task:
8+
- test: --preset travis
9+
- dartfmt
10+
- dartanalyzer
11+
12+
# Create a snapshot to improve startup time. Tests will automatically use this
13+
# snapshot if it's available.
14+
before_script:
15+
- dart --no-checked --snapshot=bin/pub.dart.snapshot --snapshot-kind=app-jit bin/pub.dart --help
16+
17+
# Only building master means that we don't run two builds for each pull request.
18+
branches:
19+
only: [master, travis, features]
20+
21+
cache:
22+
directories:
23+
- $HOME/.pub-cache

README.md

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,7 @@ included in the repository as [Git submodules][]. To get them, run:
5959

6060
Changes to pub should be accompanied by one or more tests that exercise the new
6161
functionality. When adding a test, the best strategy is to find a similar test
62-
in `test/` and follow the same patterns. Note that pub makes wide use of the
63-
[scheduled_test] package in its tests, so it's usually important to be familiar
64-
with that when adding tests.
65-
66-
[scheduled_test]: http://pub.dartlang.org/packages/scheduled_test
62+
in `test/` and follow the same patterns.
6763

6864
Pub tests come in two basic forms. The first, which is usually used to unit test
6965
classes and libraries internal to pub, has many tests in a single file. This is

analysis_options.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
analyzer:
2+
strong-mode: true

dart_test.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
presets:
2+
travis:
3+
# Travis is sloooow.
4+
timeout: 3x
5+
6+
# Pub has a huge number of small suites, which means test is frequently
7+
# loading new ones. Keeping concurrency low helps limit load timeouts.
8+
concurrency: 4

lib/src/ascii_tree.dart

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,13 @@ import 'utils.dart';
6060
/// will have their contents truncated. Defaults to `false`.
6161
String fromFiles(List<String> files, {String baseDir, bool showAllChildren}) {
6262
// Parse out the files into a tree of nested maps.
63-
var root = {};
63+
var root = <String, Map>{};
6464
for (var file in files) {
6565
if (baseDir != null) file = path.relative(file, from: baseDir);
6666
var directory = root;
6767
for (var part in path.split(file)) {
68-
directory = directory.putIfAbsent(part, () => {});
68+
directory = directory.putIfAbsent(part, () => <String, Map>{})
69+
as Map<String, Map>;
6970
}
7071
}
7172

@@ -97,14 +98,14 @@ String fromFiles(List<String> files, {String baseDir, bool showAllChildren}) {
9798
///
9899
/// If [showAllChildren] is `false`, then directories with more than ten items
99100
/// will have their contents truncated. Defaults to `false`.
100-
String fromMap(Map map, {bool showAllChildren}) {
101+
String fromMap(Map<String, Map> map, {bool showAllChildren}) {
101102
var buffer = new StringBuffer();
102103
_draw(buffer, "", null, map, showAllChildren: showAllChildren);
103104
return buffer.toString();
104105
}
105106

106-
void _drawLine(StringBuffer buffer, String prefix, bool isLastChild,
107-
String name) {
107+
void _drawLine(
108+
StringBuffer buffer, String prefix, bool isLastChild, String name) {
108109
// Print lines.
109110
buffer.write(prefix);
110111
if (name != null) {
@@ -125,8 +126,9 @@ String _getPrefix(bool isRoot, bool isLast) {
125126
return log.gray("| ");
126127
}
127128

128-
void _draw(StringBuffer buffer, String prefix, String name, Map children,
129-
{bool showAllChildren, bool isLast: false}) {
129+
void _draw(
130+
StringBuffer buffer, String prefix, String name, Map<String, Map> children,
131+
{bool showAllChildren, bool isLast: false}) {
130132
if (showAllChildren == null) showAllChildren = false;
131133

132134
// Don't draw a line for the root node.
@@ -137,7 +139,8 @@ void _draw(StringBuffer buffer, String prefix, String name, Map children,
137139

138140
drawChild(bool isLastChild, String child) {
139141
var childPrefix = _getPrefix(name == null, isLast);
140-
_draw(buffer, '$prefix$childPrefix', child, children[child],
142+
_draw(buffer, '$prefix$childPrefix', child,
143+
children[child] as Map<String, Map>,
141144
showAllChildren: showAllChildren, isLast: isLastChild);
142145
}
143146

lib/src/asset/dart/serialize.dart

Lines changed: 21 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55
import 'dart:async';
66
import 'dart:isolate';
77

8+
import 'package:async/async.dart';
89
import 'package:barback/barback.dart';
910

1011
//# if source_span
1112
import 'package:source_span/source_span.dart';
1213
//# end
1314

1415
import 'serialize/exception.dart';
15-
import 'utils.dart';
1616

1717
export 'serialize/aggregate_transform.dart';
1818
export 'serialize/exception.dart';
@@ -41,10 +41,8 @@ Map serializeSpan(span) {
4141

4242
/// Converts a serializable map into a [SourceSpan].
4343
SourceSpan deserializeSpan(Map span) {
44-
return new SourceSpan(
45-
deserializeLocation(span['start']),
46-
deserializeLocation(span['end']),
47-
span['text']);
44+
return new SourceSpan(deserializeLocation(span['start']),
45+
deserializeLocation(span['end']), span['text']);
4846
}
4947

5048
/// Converts [location] into a serializable map.
@@ -77,22 +75,17 @@ SourceLocation deserializeLocation(Map location) {
7775
/// Converts [stream] into a serializable map.
7876
///
7977
/// [serializeEvent] is used to serialize each event from the stream.
80-
Map serializeStream(Stream stream, serializeEvent(event)) {
78+
Map serializeStream/*<T>*/(Stream/*<T>*/ stream, serializeEvent(/*=T*/ event)) {
8179
var receivePort = new ReceivePort();
8280
var map = {'replyTo': receivePort.sendPort};
8381

8482
receivePort.first.then((message) {
8583
var sendPort = message['replyTo'];
8684
stream.listen((event) {
87-
sendPort.send({
88-
'type': 'event',
89-
'value': serializeEvent(event)
90-
});
85+
sendPort.send({'type': 'event', 'value': serializeEvent(event)});
9186
}, onError: (error, stackTrace) {
92-
sendPort.send({
93-
'type': 'error',
94-
'error': serializeException(error, stackTrace)
95-
});
87+
sendPort.send(
88+
{'type': 'error', 'error': serializeException(error, stackTrace)});
9689
}, onDone: () => sendPort.send({'type': 'done'}));
9790
});
9891

@@ -102,12 +95,14 @@ Map serializeStream(Stream stream, serializeEvent(event)) {
10295
/// Converts a serializable map into a [Stream].
10396
///
10497
/// [deserializeEvent] is used to deserialize each event from the stream.
105-
Stream deserializeStream(Map stream, deserializeEvent(event)) {
106-
return callbackStream(() {
98+
Stream/*<T>*/ deserializeStream/*<T>*/(
99+
Map stream,
100+
/*=T*/ deserializeEvent(event)) {
101+
return new LazyStream(() {
107102
var receivePort = new ReceivePort();
108103
stream['replyTo'].send({'replyTo': receivePort.sendPort});
109104

110-
var controller = new StreamController(sync: true);
105+
var controller = new StreamController<T>(sync: true);
111106
receivePort.listen((event) {
112107
switch (event['type']) {
113108
case 'event':
@@ -133,15 +128,15 @@ Stream deserializeStream(Map stream, deserializeEvent(event)) {
133128
///
134129
/// The returned Future will complete to the value or error returned by
135130
/// [respond].
136-
Future call(SendPort port, message) {
131+
Future/*<T>*/ call/*<T>*/(SendPort port, message) {
137132
var receivePort = new ReceivePort();
138-
port.send({
139-
'message': message,
140-
'replyTo': receivePort.sendPort
141-
});
133+
port.send({'message': message, 'replyTo': receivePort.sendPort});
142134

143-
return receivePort.first.then((response) {
144-
if (response['type'] == 'success') return response['value'];
135+
return new Future.sync(() async {
136+
var response = await receivePort.first;
137+
if (response['type'] == 'success') {
138+
return response['value'] as dynamic/*=T*/;
139+
}
145140
assert(response['type'] == 'error');
146141
var exception = deserializeException(response['error']);
147142
return new Future.error(exception, exception.stackTrace);
@@ -159,9 +154,7 @@ void respond(wrappedMessage, callback(message)) {
159154
new Future.sync(() => callback(wrappedMessage['message']))
160155
.then((result) => replyTo.send({'type': 'success', 'value': result}))
161156
.catchError((error, stackTrace) {
162-
replyTo.send({
163-
'type': 'error',
164-
'error': serializeException(error, stackTrace)
165-
});
157+
replyTo.send(
158+
{'type': 'error', 'error': serializeException(error, stackTrace)});
166159
});
167160
}

lib/src/asset/dart/serialize/aggregate_transform.dart

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ import 'get_input_transform.dart';
1919
/// serialized transform. [methodHandlers] is a set of additional methods. Each
2020
/// value should take a JSON message and return the response (which may be a
2121
/// Future).
22-
Map _serializeBaseAggregateTransform(transform, Map additionalFields,
22+
Map _serializeBaseAggregateTransform(
23+
transform,
24+
Map<String, dynamic> additionalFields,
2325
Map<String, Function> methodHandlers) {
2426
var receivePort = new ReceivePort();
2527
receivePort.listen((wrappedMessage) {
@@ -41,10 +43,10 @@ Map _serializeBaseAggregateTransform(transform, Map additionalFields,
4143
}[message['level']];
4244
assert(method != null);
4345

44-
var assetId = message['assetId'] == null ? null :
45-
deserializeId(message['assetId']);
46-
var span = message['span'] == null ? null :
47-
deserializeSpan(message['span']);
46+
var assetId =
47+
message['assetId'] == null ? null : deserializeId(message['assetId']);
48+
var span =
49+
message['span'] == null ? null : deserializeSpan(message['span']);
4850
method(message['message'], asset: assetId, span: span);
4951
});
5052
});
@@ -61,7 +63,8 @@ Map serializeAggregateTransform(AggregateTransform transform) {
6163
return _serializeBaseAggregateTransform(transform, {
6264
'primaryInputs': serializeStream(transform.primaryInputs, serializeAsset)
6365
}, {
64-
'getInput': (message) => transform.getInput(deserializeId(message['id']))
66+
'getInput': (message) => transform
67+
.getInput(deserializeId(message['id']))
6568
.then((asset) => serializeAsset(asset)),
6669
'addOutput': (message) =>
6770
transform.addOutput(deserializeAsset(message['output']))
@@ -123,46 +126,37 @@ class _ForeignBaseAggregateTransform {
123126
///
124127
/// This retrieves inputs from and sends outputs and logs to the host isolate.
125128
class ForeignAggregateTransform extends _ForeignBaseAggregateTransform
126-
with GetInputTransform implements AggregateTransform {
129+
with GetInputTransform
130+
implements AggregateTransform {
127131
final Stream<Asset> primaryInputs;
128132

129133
/// Creates a transform from a serialized map sent from the host isolate.
130134
ForeignAggregateTransform(Map transform)
131-
: primaryInputs = deserializeStream(
132-
transform['primaryInputs'], deserializeAsset),
135+
: primaryInputs =
136+
deserializeStream(transform['primaryInputs'], deserializeAsset),
133137
super(transform);
134138

135139
Future<Asset> getInput(AssetId id) {
136-
return call(_port, {
137-
'type': 'getInput',
138-
'id': serializeId(id)
139-
}).then(deserializeAsset);
140+
return call(_port, {'type': 'getInput', 'id': serializeId(id)})
141+
.then(deserializeAsset);
140142
}
141143

142144
void addOutput(Asset output) {
143-
call(_port, {
144-
'type': 'addOutput',
145-
'output': serializeAsset(output)
146-
});
145+
call(_port, {'type': 'addOutput', 'output': serializeAsset(output)});
147146
}
148147
}
149148

150149
/// A wrapper for a [DeclaringAggregateTransform] that's in the host isolate.
151-
class ForeignDeclaringAggregateTransform
152-
extends _ForeignBaseAggregateTransform
150+
class ForeignDeclaringAggregateTransform extends _ForeignBaseAggregateTransform
153151
implements DeclaringAggregateTransform {
154152
final Stream<AssetId> primaryIds;
155153

156154
/// Creates a transform from a serializable map sent from the host isolate.
157155
ForeignDeclaringAggregateTransform(Map transform)
158-
: primaryIds = deserializeStream(
159-
transform['primaryIds'], deserializeId),
156+
: primaryIds = deserializeStream(transform['primaryIds'], deserializeId),
160157
super(transform);
161158

162159
void declareOutput(AssetId id) {
163-
call(_port, {
164-
'type': 'declareOutput',
165-
'output': serializeId(id)
166-
});
160+
call(_port, {'type': 'declareOutput', 'output': serializeId(id)});
167161
}
168162
}

lib/src/asset/dart/serialize/exception.dart

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ class CrossIsolateException implements Exception {
2020

2121
/// The exception's message, or its [toString] if it didn't expose a `message`
2222
/// property.
23-
final String message;
23+
String get message => _message;
24+
final String _message;
2425

2526
/// The exception's stack chain, or `null` if no stack chain was available.
2627
final Chain stackTrace;
@@ -30,9 +31,9 @@ class CrossIsolateException implements Exception {
3031
/// [error] should be the result of [CrossIsolateException.serialize].
3132
CrossIsolateException.deserialize(Map error)
3233
: type = error['type'],
33-
message = error['message'],
34-
stackTrace = error['stack'] == null ? null :
35-
new Chain.parse(error['stack']);
34+
_message = error['message'],
35+
stackTrace =
36+
error['stack'] == null ? null : new Chain.parse(error['stack']);
3637

3738
/// Serializes [error] to an object that can safely be passed across isolate
3839
/// boundaries.
@@ -48,7 +49,7 @@ class CrossIsolateException implements Exception {
4849
String toString() => "$message\n$stackTrace";
4950
}
5051

51-
/// An [AssetNotFoundException] that was originally raised in another isolate.
52+
/// An [AssetNotFoundException] that was originally raised in another isolate.
5253
class _CrossIsolateAssetNotFoundException extends CrossIsolateException
5354
implements AssetNotFoundException {
5455
final AssetId id;

lib/src/asset/dart/serialize/get_input_transform.dart

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,29 @@
55
import 'dart:async';
66
import 'dart:convert';
77

8+
import 'package:async/async.dart';
89
import 'package:barback/barback.dart';
910

10-
import '../utils.dart';
11-
1211
/// A mixin for transforms that support [getInput] and the associated suite of
1312
/// methods.
1413
abstract class GetInputTransform {
1514
Future<Asset> getInput(AssetId id);
1615

1716
Future<String> readInputAsString(AssetId id, {Encoding encoding}) {
1817
if (encoding == null) encoding = UTF8;
19-
return getInput(id).then((input) =>
20-
input.readAsString(encoding: encoding));
18+
return getInput(id).then((input) => input.readAsString(encoding: encoding));
2119
}
2220

2321
Stream<List<int>> readInput(AssetId id) =>
24-
futureStream(getInput(id).then((input) => input.read()));
22+
StreamCompleter.fromFuture(getInput(id).then((input) => input.read()));
2523

26-
Future<bool> hasInput(AssetId id) {
27-
return getInput(id).then((_) => true).catchError((error) {
28-
if (error is AssetNotFoundException && error.id == id) return false;
29-
throw error;
30-
});
24+
Future<bool> hasInput(AssetId id) async {
25+
try {
26+
await getInput(id);
27+
return true;
28+
} on AssetNotFoundException catch (error) {
29+
if (error.id == id) return false;
30+
rethrow;
31+
}
3132
}
3233
}

0 commit comments

Comments
 (0)