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

Side by Side Diff: sdk/lib/_internal/pub/asset/dart/transformer_isolate.dart

Issue 590393005: Pass a package root to spawned isolates in pub. (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.asset.transformer_isolate; 5 library pub.asset.transformer_isolate;
6 6
7 import 'dart:convert'; 7 import 'dart:convert';
8 import 'dart:isolate'; 8 import 'dart:isolate';
9 import 'dart:mirrors'; 9 import 'dart:mirrors';
10 10
11 import 'package:barback/barback.dart'; 11 import 'package:barback/barback.dart';
12 12
13 import 'serialize.dart'; 13 import 'serialize.dart';
14 14
15 /// The mirror system. 15 /// The mirror system.
16 /// 16 ///
17 /// Cached to avoid re-instantiating each time a transformer is initialized. 17 /// Cached to avoid re-instantiating each time a transformer is initialized.
18 final _mirrors = currentMirrorSystem(); 18 final _mirrors = currentMirrorSystem();
19 19
20 /// The URI of this library.
21 final _baseUri = _mirrors.findLibrary(
22 const Symbol('pub.asset.transformer_isolate')).uri;
23
24 /// Sets up the initial communication with the host isolate. 20 /// Sets up the initial communication with the host isolate.
25 void loadTransformers(SendPort replyTo) { 21 void loadTransformers(SendPort replyTo) {
26 var port = new ReceivePort(); 22 var port = new ReceivePort();
27 replyTo.send(port.sendPort); 23 replyTo.send(port.sendPort);
28 port.listen((wrappedMessage) { 24 port.listen((wrappedMessage) {
29 // TODO(nweiz): When issue 19228 is fixed, spin up a separate isolate for 25 // TODO(nweiz): When issue 19228 is fixed, spin up a separate isolate for
30 // libraries loaded beyond the first so they can run in parallel. 26 // libraries loaded beyond the first so they can run in parallel.
31 respond(wrappedMessage, (message) { 27 respond(wrappedMessage, (message) {
32 var configuration = JSON.decode(message['configuration']); 28 var configuration = JSON.decode(message['configuration']);
33 var mode = new BarbackMode(message['mode']); 29 var mode = new BarbackMode(message['mode']);
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 if (configuration.isNotEmpty) return null; 75 if (configuration.isNotEmpty) return null;
80 return classMirror.newInstance(const Symbol('asPlugin'), []).reflectee; 76 return classMirror.newInstance(const Symbol('asPlugin'), []).reflectee;
81 } 77 }
82 if (constructor.parameters.length != 1) return null; 78 if (constructor.parameters.length != 1) return null;
83 79
84 return classMirror.newInstance(const Symbol('asPlugin'), 80 return classMirror.newInstance(const Symbol('asPlugin'),
85 [new BarbackSettings(configuration, mode)]).reflectee; 81 [new BarbackSettings(configuration, mode)]).reflectee;
86 }).where((classMirror) => classMirror != null)); 82 }).where((classMirror) => classMirror != null));
87 } 83 }
88 84
89 loadFromLibrary(_mirrors.libraries[_baseUri.resolve(uri)]); 85 var library = _mirrors.libraries[Uri.parse(uri)];
86
87 // This should only happen if something's wrong with the logic in pub itself.
88 // If it were user error, the entire isolate would fail to load.
89 if (library == null) throw "Couldn't find library at $uri.";
90
91 loadFromLibrary(library);
90 return transformers; 92 return transformers;
91 } 93 }
92 94
93 // TODO(nweiz): clean this up when issue 13248 is fixed. 95 // TODO(nweiz): clean this up when issue 13248 is fixed.
94 MethodMirror _getConstructor(ClassMirror classMirror, String constructor) { 96 MethodMirror _getConstructor(ClassMirror classMirror, String constructor) {
95 var name = new Symbol("${MirrorSystem.getName(classMirror.simpleName)}" 97 var name = new Symbol("${MirrorSystem.getName(classMirror.simpleName)}"
96 ".$constructor"); 98 ".$constructor");
97 var candidate = classMirror.declarations[name]; 99 var candidate = classMirror.declarations[name];
98 if (candidate is MethodMirror && candidate.isConstructor) return candidate; 100 if (candidate is MethodMirror && candidate.isConstructor) return candidate;
99 return null; 101 return null;
100 } 102 }
101 103
102 // Older barbacks don't support [AggregateTransformer], and calling 104 // Older barbacks don't support [AggregateTransformer], and calling
103 // [reflectClass] on an undefined class will throw an error, so we just define a 105 // [reflectClass] on an undefined class will throw an error, so we just define a
104 // null getter for them. 106 // null getter for them.
105 //# if barback >=0.14.1 107 //# if barback >=0.14.1
106 ClassMirror get _aggregateTransformerClass => 108 ClassMirror get _aggregateTransformerClass =>
107 reflectClass(AggregateTransformer); 109 reflectClass(AggregateTransformer);
108 //# else 110 //# else
109 //> ClassMirror get _aggregateTransformerClass => null; 111 //> ClassMirror get _aggregateTransformerClass => null;
110 //# end 112 //# end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698