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

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: 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..d9a216755cba09cd66a49d74ae45b03555aa623b 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].
Bob Nystrom 2014/06/11 20:33:36 Document the return value.
nweiz 2014/06/12 20:11:17 Done.
+Future<Map<TransformerId, Set>> loadTransformers(AssetEnvironment environment,
+ BarbackServer transformerServer, List<TransformerId> ids) {
+ return listToMapAsync(ids, (id) => id, (id) {
Bob Nystrom 2014/06/11 20:33:35 I think this would be easier to read if these were
nweiz 2014/06/12 20:11:17 Will do in a separate CL.
+ return id.getAssetId(environment.barback);
Bob Nystrom 2014/06/11 20:33:35 =>
nweiz 2014/06/12 20:11:17 I had it as that originally, but that followed by
+ }).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');
+ });
+
+ var code = new StringBuffer();
+ code.writeln("import 'dart:isolate';");
- import '$uri';
+ for (var url in idsToUrls.values) {
+ code.writeln("import '$url';");
+ }
- import r'$baseUrl/packages/\$pub/transformer_isolate.dart';
+ code.writeln("import r'$baseUrl/packages/\$pub/transformer_isolate.dart';");
+ code.writeln(
+ "void main(_, SendPort replyTo) => loadTransformers(replyTo);");
- void main(_, SendPort replyTo) => loadTransformers(replyTo);
- """;
- log.fine("Loading transformers from $assetId");
+ 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 missingTransformers = idsToUrls.keys.where((id) =>
+ firstErrorLine.startsWith("Failure getting ${idsToUrls[id]}:"));
Bob Nystrom 2014/06/11 20:33:36 Will this ever match more than one transformer?
nweiz 2014/06/12 20:11:17 I guess not. Changed.
+ if (missingTransformers.isEmpty) throw error;
+
+ var packageUris = toSentence(missingTransformers.map((id) =>
+ '"${idToPackageUri(idsToAssetIds[id])}"'));
+ var libraries = pluralize('library', missingTransformers.length,
+ plural: 'libraries');
// 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 $libraries $packageUris not found.',
error, stackTrace);
});
});

Powered by Google App Engine
This is Rietveld 408576698