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

Unified Diff: sdk/lib/_internal/pub/lib/src/barback/load_transformers.dart

Issue 323263002: Load parallel transformers in the same isolate. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: fix a typo Created 6 years, 6 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/lib/src/barback/load_transformers.dart
diff --git a/sdk/lib/_internal/pub/lib/src/barback/load_transformers.dart b/sdk/lib/_internal/pub/lib/src/barback/load_transformers.dart
index 8b00d09816c61821282bcec57a07bff4bd0a4738..6315f5655770680642656117fc1e9dddbaf2e1b4 100644
--- a/sdk/lib/_internal/pub/lib/src/barback/load_transformers.dart
+++ b/sdk/lib/_internal/pub/lib/src/barback/load_transformers.dart
@@ -17,56 +17,71 @@ import 'asset_environment.dart';
import 'foreign_transformer.dart';
import 'barback_server.dart';
-/// Load and return all transformers and groups from the library identified by
-/// [id].
-Future<Set> loadTransformers(AssetEnvironment environment,
- BarbackServer transformerServer, TransformerId id) {
- return id.getAssetId(environment.barback).then((assetId) {
- var path = assetId.path.replaceFirst('lib/', '');
- // TODO(nweiz): load from a "package:" URI when issue 12474 is fixed.
-
+/// Load and return all transformers and groups from the libraries identified by
+/// [ids].
+///
+/// Returns a map from transformer ids to sets of transformer-like objects
+/// identified by these ids (these may be [Transformer]s,
+/// [AggregateTransformer]s, and/or [TransformerGroup]s).
+Future<Map<TransformerId, Set>> loadTransformers(AssetEnvironment environment,
+ BarbackServer transformerServer, List<TransformerId> ids) {
+ return listToMapAsync(ids, (id) => id, (id) {
+ return id.getAssetId(environment.barback);
+ }).then((idsToAssetIds) {
var baseUrl = transformerServer.url;
- var uri = baseUrl.resolve('packages/${id.package}/$path');
- var code = """
- import 'dart:isolate';
+ var idsToUrls = mapMap(idsToAssetIds, (id, _) => id, (id, assetId) {
+ var path = assetId.path.replaceFirst('lib/', '');
+ // TODO(nweiz): load from a "package:" URI when issue 12474 is fixed.
+ return baseUrl.resolve('packages/${id.package}/$path');
+ });
- import '$uri';
+ var code = new StringBuffer();
+ code.writeln("import 'dart:isolate';");
- import r'$baseUrl/packages/\$pub/transformer_isolate.dart';
+ for (var url in idsToUrls.values) {
+ code.writeln("import '$url';");
+ }
- void main(_, SendPort replyTo) => loadTransformers(replyTo);
- """;
- log.fine("Loading transformers from $assetId");
+ code.writeln("import r'$baseUrl/packages/\$pub/transformer_isolate.dart';");
+ code.writeln(
+ "void main(_, SendPort replyTo) => loadTransformers(replyTo);");
+
+ log.fine("Loading transformers from $ids");
var port = new ReceivePort();
- return dart.runInIsolate(code, port.sendPort)
+ return dart.runInIsolate(code.toString(), port.sendPort)
.then((_) => port.first)
.then((sendPort) {
- return call(sendPort, {
- 'library': uri.toString(),
- 'mode': environment.mode.name,
- // TODO(nweiz): support non-JSON-encodable configuration maps.
- 'configuration': JSON.encode(id.configuration)
- }).then((transformers) {
- transformers = transformers.map(
- (transformer) => deserializeTransformerLike(transformer, id))
- .toSet();
- log.fine("Transformers from $assetId: $transformers");
- return transformers;
+ return mapMapAsync(idsToAssetIds, (id, _) => id, (id, assetId) {
+ return call(sendPort, {
+ 'library': idsToUrls[id].toString(),
+ 'mode': environment.mode.name,
+ // TODO(nweiz): support non-JSON-encodable configuration maps.
+ 'configuration': JSON.encode(id.configuration)
+ }).then((transformers) {
+ transformers = transformers.map(
+ (transformer) => deserializeTransformerLike(transformer, id))
+ .toSet();
+ log.fine("Transformers from $assetId: $transformers");
+ return transformers;
+ });
});
}).catchError((error, stackTrace) {
if (error is! CrossIsolateException) throw error;
if (error.type != 'IsolateSpawnException') throw error;
+
// TODO(nweiz): don't parse this as a string once issues 12617 and 12689
// are fixed.
- if (!error.message.split('\n')[1].startsWith("Failure getting $uri:")) {
- throw error;
- }
+ var firstErrorLine = error.message.split('\n')[1];
+ var missingTransformer = idsToUrls.keys.firstWhere((id) =>
+ firstErrorLine.startsWith("Failure getting ${idsToUrls[id]}:"),
+ orElse: () => throw error);
+ var packageUri = idToPackageUri(idsToAssetIds[missingTransformer]);
// If there was an IsolateSpawnException and the import that actually
// failed was the one we were loading transformers from, throw an
// application exception with a more user-friendly message.
- fail('Transformer library "package:${id.package}/$path" not found.',
+ fail('Transformer library "$packageUri" not found.',
error, stackTrace);
});
});
« no previous file with comments | « sdk/lib/_internal/pub/lib/src/barback/load_all_transformers.dart ('k') | sdk/lib/_internal/pub/lib/src/utils.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698