Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(683)

Side by Side Diff: sdk/lib/_internal/pub/lib/src/barback/asset_environment.dart

Issue 599993004: Don't load transformers that aren't going to be used for an executable. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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.asset_environment; 5 library pub.barback.asset_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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 /// 49 ///
50 /// This will only add the root package's "lib" directory to the environment. 50 /// This will only add the root package's "lib" directory to the environment.
51 /// Other directories can be added to the environment using [serveDirectory]. 51 /// Other directories can be added to the environment using [serveDirectory].
52 /// 52 ///
53 /// If [watcherType] is not [WatcherType.NONE] (the default), watches source 53 /// If [watcherType] is not [WatcherType.NONE] (the default), watches source
54 /// assets for modification. 54 /// assets for modification.
55 /// 55 ///
56 /// If [packages] is passed, only those packages' assets will be loaded and 56 /// If [packages] is passed, only those packages' assets will be loaded and
57 /// served. 57 /// served.
58 /// 58 ///
59 /// If [entrypoints] is passed, only transformers necessary to run those
60 /// entrypoints will be loaded. Each entrypoint is expected to refer to a Dart
Bob Nystrom 2014/09/24 23:42:47 "will be" -> "are". It took me a while to break m
nweiz 2014/09/25 00:13:15 Done.
61 /// library.
62 ///
59 /// Returns a [Future] that completes to the environment once the inputs, 63 /// Returns a [Future] that completes to the environment once the inputs,
60 /// transformers, and server are loaded and ready. 64 /// transformers, and server are loaded and ready.
61 static Future<AssetEnvironment> create(Entrypoint entrypoint, 65 static Future<AssetEnvironment> create(Entrypoint entrypoint,
62 BarbackMode mode, {WatcherType watcherType, String hostname, int basePort, 66 BarbackMode mode, {WatcherType watcherType, String hostname, int basePort,
63 Iterable<String> packages, bool useDart2JS: true}) { 67 Iterable<String> packages, Iterable<AssetId> entrypoints,
68 bool useDart2JS: true}) {
64 if (watcherType == null) watcherType = WatcherType.NONE; 69 if (watcherType == null) watcherType = WatcherType.NONE;
65 if (hostname == null) hostname = "localhost"; 70 if (hostname == null) hostname = "localhost";
66 if (basePort == null) basePort = 0; 71 if (basePort == null) basePort = 0;
67 72
68 return entrypoint.loadPackageGraph().then((graph) { 73 return entrypoint.loadPackageGraph().then((graph) {
69 log.fine("Loaded package graph."); 74 log.fine("Loaded package graph.");
70 graph = _adjustPackageGraph(graph, mode, packages); 75 graph = _adjustPackageGraph(graph, mode, packages);
71 var barback = new Barback(new PubPackageProvider(graph)); 76 var barback = new Barback(new PubPackageProvider(graph));
72 barback.log.listen(_log); 77 barback.log.listen(_log);
73 78
74 var environment = new AssetEnvironment._(graph, barback, mode, 79 var environment = new AssetEnvironment._(graph, barback, mode,
75 watcherType, hostname, basePort); 80 watcherType, hostname, basePort);
76 81
77 return environment._load(useDart2JS: useDart2JS) 82 return environment._load(entrypoints: entrypoints, useDart2JS: useDart2JS)
78 .then((_) => environment); 83 .then((_) => environment);
79 }); 84 });
80 } 85 }
81 86
82 /// Return a version of [graph] that's restricted to [packages] (if passed) 87 /// Return a version of [graph] that's restricted to [packages] (if passed)
83 /// and loads cached packages (if [mode] is [BarbackMode.DEBUG]). 88 /// and loads cached packages (if [mode] is [BarbackMode.DEBUG]).
84 static PackageGraph _adjustPackageGraph(PackageGraph graph, 89 static PackageGraph _adjustPackageGraph(PackageGraph graph,
85 BarbackMode mode, Iterable<String> packages) { 90 BarbackMode mode, Iterable<String> packages) {
86 if (mode != BarbackMode.DEBUG && packages == null) return graph; 91 if (mode != BarbackMode.DEBUG && packages == null) return graph;
87 packages = (packages == null ? graph.packages.keys : packages).toSet(); 92 packages = (packages == null ? graph.packages.keys : packages).toSet();
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after
438 /// Loads the assets and transformers for this environment. 443 /// Loads the assets and transformers for this environment.
439 /// 444 ///
440 /// This transforms and serves all library and asset files in all packages in 445 /// This transforms and serves all library and asset files in all packages in
441 /// the environment's package graph. It loads any transformer plugins defined 446 /// the environment's package graph. It loads any transformer plugins defined
442 /// in packages in [graph] and re-runs them as necessary when any input files 447 /// in packages in [graph] and re-runs them as necessary when any input files
443 /// change. 448 /// change.
444 /// 449 ///
445 /// If [useDart2JS] is `true`, then the [Dart2JSTransformer] is implicitly 450 /// If [useDart2JS] is `true`, then the [Dart2JSTransformer] is implicitly
446 /// added to end of the root package's transformer phases. 451 /// added to end of the root package's transformer phases.
447 /// 452 ///
453 /// If [entrypoints] is passed, only transformers necessary to run those
454 /// entrypoints will be loaded.
455 ///
448 /// Returns a [Future] that completes once all inputs and transformers are 456 /// Returns a [Future] that completes once all inputs and transformers are
449 /// loaded. 457 /// loaded.
450 Future _load({bool useDart2JS}) { 458 Future _load({Iterable<AssetId> entrypoints, bool useDart2JS}) {
451 return log.progress("Initializing barback", () { 459 return log.progress("Initializing barback", () {
452 // If the entrypoint package manually configures the dart2js 460 // If the entrypoint package manually configures the dart2js
453 // transformer, don't include it in the built-in transformer list. 461 // transformer, don't include it in the built-in transformer list.
454 // 462 //
455 // TODO(nweiz): if/when we support more built-in transformers, make 463 // TODO(nweiz): if/when we support more built-in transformers, make
456 // this more general. 464 // this more general.
457 var containsDart2JS = graph.entrypoint.root.pubspec.transformers 465 var containsDart2JS = graph.entrypoint.root.pubspec.transformers
458 .any((transformers) => 466 .any((transformers) =>
459 transformers.any((config) => config.id.package == '\$dart2js')); 467 transformers.any((config) => config.id.package == '\$dart2js'));
460 468
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
497 if (error.stackTrace != null) { 505 if (error.stackTrace != null) {
498 message += "\n" + error.stackTrace.terse.toString(); 506 message += "\n" + error.stackTrace.terse.toString();
499 } 507 }
500 508
501 _log(new LogEntry(error.transform, error.transform.primaryId, 509 _log(new LogEntry(error.transform, error.transform.primaryId,
502 LogLevel.ERROR, message, null)); 510 LogLevel.ERROR, message, null));
503 }); 511 });
504 512
505 return _withStreamErrors(() { 513 return _withStreamErrors(() {
506 return log.progress("Loading transformers", () { 514 return log.progress("Loading transformers", () {
507 return loadAllTransformers(this, transformerServer) 515 return loadAllTransformers(this, transformerServer,
516 entrypoints: entrypoints)
508 .then((_) => transformerServer.close()); 517 .then((_) => transformerServer.close());
Bob Nystrom 2014/09/24 23:42:47 Whole lotta indentation here. How about using awai
nweiz 2014/09/25 00:13:15 Done.
509 }, fine: true); 518 }, fine: true);
510 }, [errorStream, barback.results, transformerServer.results]); 519 }, [errorStream, barback.results, transformerServer.results]);
511 }); 520 });
512 }, fine: true); 521 }, fine: true);
513 } 522 }
514 523
515 /// Provides the public source assets in the environment to barback. 524 /// Provides the public source assets in the environment to barback.
516 /// 525 ///
517 /// If [watcherType] is not [WatcherType.NONE], enables watching on them. 526 /// If [watcherType] is not [WatcherType.NONE], enables watching on them.
518 Future _provideSources() async { 527 Future _provideSources() async {
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after
783 String toString() => "polling"; 792 String toString() => "polling";
784 } 793 }
785 794
786 class _NoneWatcherType implements WatcherType { 795 class _NoneWatcherType implements WatcherType {
787 const _NoneWatcherType(); 796 const _NoneWatcherType();
788 797
789 DirectoryWatcher create(String directory) => null; 798 DirectoryWatcher create(String directory) => null;
790 799
791 String toString() => "none"; 800 String toString() => "none";
792 } 801 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698