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

Unified Diff: sdk/lib/_internal/pub_generated/lib/src/barback/load_all_transformers.dart

Issue 559833004: Cache snapshots of (mostly) immutable transformer phases. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 3 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 side-by-side diff with in-line comments
Download patch
Index: sdk/lib/_internal/pub_generated/lib/src/barback/load_all_transformers.dart
diff --git a/sdk/lib/_internal/pub_generated/lib/src/barback/load_all_transformers.dart b/sdk/lib/_internal/pub_generated/lib/src/barback/load_all_transformers.dart
index 94127b0d90324632258a29c8d1fe1884e825d5bb..d8fa10a8b67923b2b49d9814e4b4ec2909f7b440 100644
--- a/sdk/lib/_internal/pub_generated/lib/src/barback/load_all_transformers.dart
+++ b/sdk/lib/_internal/pub_generated/lib/src/barback/load_all_transformers.dart
@@ -1,17 +1,14 @@
library pub.load_all_transformers;
import 'dart:async';
-import 'package:barback/barback.dart';
import '../log.dart' as log;
import '../package_graph.dart';
import '../utils.dart';
import 'asset_environment.dart';
import 'barback_server.dart';
-import 'dart2js_transformer.dart';
-import 'excluding_transformer.dart';
import 'rewrite_import_transformer.dart';
-import 'transformer_config.dart';
+import 'transformer_cache.dart';
import 'transformer_id.dart';
-import 'transformer_isolate.dart';
+import 'transformer_loader.dart';
import 'transformers_needed_by_transformers.dart';
Future loadAllTransformers(AssetEnvironment environment,
BarbackServer transformerServer) {
@@ -30,14 +27,18 @@ Future loadAllTransformers(AssetEnvironment environment,
var phasedTransformers = _phaseTransformers(transformersNeededByTransformers);
var packagesThatUseTransformers =
_packagesThatUseTransformers(environment.graph);
- var loader = new _TransformerLoader(environment, transformerServer);
+ var loader = new TransformerLoader(environment, transformerServer);
var rewrite = new RewriteImportTransformer();
for (var package in environment.packages) {
environment.barback.updateTransformers(package, [[rewrite]]);
}
environment.barback.updateTransformers(r'$pub', [[rewrite]]);
+ var cache = new TransformerCache.load(environment);
+ var i = 0;
return Future.forEach(phasedTransformers, (phase) {
- return loader.load(phase).then((_) {
+ i++;
+ var snapshotPath = cache.snapshotPath(phase, i);
+ return loader.load(phase, snapshot: snapshotPath).then((_) {
var packagesToUpdate =
unionAll(phase.map((id) => packagesThatUseTransformers[id]));
return Future.wait(packagesToUpdate.map((packageName) {
@@ -50,6 +51,7 @@ Future loadAllTransformers(AssetEnvironment environment,
}));
});
}).then((_) {
+ cache.save();
return Future.wait(environment.graph.packages.values.map((package) {
return loader.transformersForPhases(
package.pubspec.transformers).then((phases) {
@@ -92,77 +94,3 @@ Map<TransformerId, Set<String>> _packagesThatUseTransformers(PackageGraph graph)
}
return results;
}
-class _TransformerLoader {
- final AssetEnvironment _environment;
- final BarbackServer _transformerServer;
- final _isolates = new Map<TransformerId, TransformerIsolate>();
- final _transformers = new Map<TransformerConfig, Set<Transformer>>();
- final _transformerUsers = new Map<TransformerId, Set<String>>();
- _TransformerLoader(this._environment, this._transformerServer) {
- for (var package in _environment.graph.packages.values) {
- for (var config in unionAll(package.pubspec.transformers)) {
- _transformerUsers.putIfAbsent(
- config.id,
- () => new Set<String>()).add(package.name);
- }
- }
- }
- Future load(Iterable<TransformerId> ids) {
- ids = ids.where((id) => !_isolates.containsKey(id)).toList();
- if (ids.isEmpty) return new Future.value();
- return log.progress("Loading ${toSentence(ids)} transformers", () {
- return TransformerIsolate.spawn(_environment, _transformerServer, ids);
- }).then((isolate) {
- for (var id in ids) {
- _isolates[id] = isolate;
- }
- });
- }
- Future<Set<Transformer>> transformersFor(TransformerConfig config) {
- if (_transformers.containsKey(config)) {
- return new Future.value(_transformers[config]);
- } else if (_isolates.containsKey(config.id)) {
- return _isolates[config.id].create(config).then((transformers) {
- if (transformers.isNotEmpty) {
- _transformers[config] = transformers;
- return transformers;
- }
- var message = "No transformers";
- if (config.configuration.isNotEmpty) {
- message += " that accept configuration";
- }
- var location;
- if (config.id.path == null) {
- location =
- 'package:${config.id.package}/transformer.dart or '
- 'package:${config.id.package}/${config.id.package}.dart';
- } else {
- location = 'package:$config.dart';
- }
- var users = toSentence(ordered(_transformerUsers[config.id]));
- fail("$message were defined in $location,\n" "required by $users.");
- });
- } else if (config.id.package != '\$dart2js') {
- return new Future.value(new Set());
- }
- var transformer;
- try {
- transformer = new Dart2JSTransformer.withSettings(
- _environment,
- new BarbackSettings(config.configuration, _environment.mode));
- } on FormatException catch (error, stackTrace) {
- fail(error.message, error, stackTrace);
- }
- _transformers[config] =
- new Set.from([ExcludingTransformer.wrap(transformer, config)]);
- return new Future.value(_transformers[config]);
- }
- Future<List<Set<Transformer>>>
- transformersForPhases(Iterable<Set<TransformerConfig>> phases) {
- return Future.wait(phases.map((phase) {
- return waitAndPrintErrors(phase.map(transformersFor)).then(unionAll);
- })).then((phases) {
- return phases.toList();
- });
- }
-}

Powered by Google App Engine
This is Rietveld 408576698