OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 library pub.barback.build_environment; | 5 library pub.barback.build_environment; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 import 'dart:io'; | 8 import 'dart:io'; |
9 | 9 |
10 import 'package:barback/barback.dart'; | 10 import 'package:barback/barback.dart'; |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 .any((transformers) => transformers | 221 .any((transformers) => transformers |
222 .any((id) => id.package == '\$dart2js')); | 222 .any((id) => id.package == '\$dart2js')); |
223 | 223 |
224 if (!containsDart2JS && useDart2JS) { | 224 if (!containsDart2JS && useDart2JS) { |
225 _builtInTransformers.addAll([ | 225 _builtInTransformers.addAll([ |
226 new Dart2JSTransformer(this, mode), | 226 new Dart2JSTransformer(this, mode), |
227 new DartForwardingTransformer(mode) | 227 new DartForwardingTransformer(mode) |
228 ]); | 228 ]); |
229 } | 229 } |
230 | 230 |
| 231 // "$pub" is a psuedo-package that allows pub's transformer-loading |
| 232 // infrastructure to share code with pub proper. We provide it only during |
| 233 // the initial transformer loading process. |
| 234 var dartPath = assetPath('dart'); |
| 235 var pubSources = listDir(dartPath).map((library) { |
| 236 return new AssetId('\$pub', |
| 237 path.join('lib', path.relative(library, from: dartPath))); |
| 238 }); |
| 239 |
231 // Bind a server that we can use to load the transformers. | 240 // Bind a server that we can use to load the transformers. |
232 var transformerServer; | 241 var transformerServer; |
233 return BarbackServer.bind(this, _hostname, 0, null).then((server) { | 242 return BarbackServer.bind(this, _hostname, 0, null).then((server) { |
234 transformerServer = server; | 243 transformerServer = server; |
235 | 244 |
236 return log.progress("Loading source assets", _provideSources); | 245 return log.progress("Loading source assets", () { |
| 246 barback.updateSources(pubSources); |
| 247 return _provideSources(); |
| 248 }); |
237 }).then((_) { | 249 }).then((_) { |
238 log.fine("Provided sources."); | 250 log.fine("Provided sources."); |
239 var completer = new Completer(); | 251 var completer = new Completer(); |
240 | 252 |
241 // If any errors get emitted either by barback or by the transformer | 253 // If any errors get emitted either by barback or by the transformer |
242 // server, including non-programmatic barback errors, they should take | 254 // server, including non-programmatic barback errors, they should take |
243 // down the whole program. | 255 // down the whole program. |
244 var subscriptions = [ | 256 var subscriptions = [ |
245 barback.errors.listen((error) { | 257 barback.errors.listen((error) { |
246 if (error is TransformerException) { | 258 if (error is TransformerException) { |
(...skipping 28 matching lines...) Expand all Loading... |
275 if (!completer.isCompleted) { | 287 if (!completer.isCompleted) { |
276 completer.completeError(error, stackTrace); | 288 completer.completeError(error, stackTrace); |
277 } | 289 } |
278 }); | 290 }); |
279 | 291 |
280 return completer.future.whenComplete(() { | 292 return completer.future.whenComplete(() { |
281 for (var subscription in subscriptions) { | 293 for (var subscription in subscriptions) { |
282 subscription.cancel(); | 294 subscription.cancel(); |
283 } | 295 } |
284 }); | 296 }); |
285 }); | 297 }).then((_) => barback.removeSources(pubSources)); |
286 } | 298 } |
287 | 299 |
288 /// Provides all of the source assets in the environment to barback. | 300 /// Provides all of the source assets in the environment to barback. |
289 /// | 301 /// |
290 /// If [watcherType] is not [WatcherType.NONE], enables watching on them. | 302 /// If [watcherType] is not [WatcherType.NONE], enables watching on them. |
291 Future _provideSources() { | 303 Future _provideSources() { |
292 return Future.wait(graph.packages.values.map((package) { | 304 return Future.wait(graph.packages.values.map((package) { |
293 return Future.wait(_getPublicDirectories(package.name) | 305 return Future.wait(_getPublicDirectories(package.name) |
294 .map((dir) => _provideDirectorySources(package, dir))); | 306 .map((dir) => _provideDirectorySources(package, dir))); |
295 })); | 307 })); |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
510 String toString() => "polling"; | 522 String toString() => "polling"; |
511 } | 523 } |
512 | 524 |
513 class _NoneWatcherType implements WatcherType { | 525 class _NoneWatcherType implements WatcherType { |
514 const _NoneWatcherType(); | 526 const _NoneWatcherType(); |
515 | 527 |
516 DirectoryWatcher create(String directory) => null; | 528 DirectoryWatcher create(String directory) => null; |
517 | 529 |
518 String toString() => "none"; | 530 String toString() => "none"; |
519 } | 531 } |
OLD | NEW |