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

Side by Side Diff: lib/src/runner/browser/compiler_pool.dart

Issue 1295653003: Make source maps work in the browser. (Closed) Base URL: git@github.com:dart-lang/test@master
Patch Set: Code review changes Created 5 years, 4 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
« no previous file with comments | « CHANGELOG.md ('k') | lib/src/runner/browser/server.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, 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 test.util.compiler_pool; 5 library test.util.compiler_pool;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:convert'; 8 import 'dart:convert';
9 import 'dart:io'; 9 import 'dart:io';
10 10
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 _printOutputStream(process.stdout, buffer), 98 _printOutputStream(process.stdout, buffer),
99 _printOutputStream(process.stderr, buffer), 99 _printOutputStream(process.stderr, buffer),
100 ]); 100 ]);
101 101
102 var exitCode = await process.exitCode; 102 var exitCode = await process.exitCode;
103 _processes.remove(process); 103 _processes.remove(process);
104 if (_closed) return; 104 if (_closed) return;
105 105
106 if (buffer.isNotEmpty) print(buffer); 106 if (buffer.isNotEmpty) print(buffer);
107 107
108 if (exitCode != 0) { 108 if (exitCode != 0) throw new LoadException(dartPath, "dart2js failed.");
109 throw new LoadException(dartPath, "dart2js failed."); 109
110 } 110 _fixSourceMap(jsPath + '.map');
111 }); 111 });
112 }); 112 });
113 } 113 }
114 114
115 // TODO(nweiz): Remove this when sdk#17544 is fixed.
116 /// Fix up the source map at [mapPath] so that it points to absolute file:
117 /// URIs that are resolvable by the browser.
118 void _fixSourceMap(String mapPath) {
119 var map = JSON.decode(new File(mapPath).readAsStringSync());
120 var root = map['sourceRoot'];
121
122 map['sources'] = map['sources'].map((source) {
123 var url = Uri.parse(root + source);
124 if (url.scheme != '' && url.scheme != 'file') return source;
125 if (url.path.endsWith("/runInBrowser.dart")) return "";
126 return p.toUri(mapPath).resolveUri(url).toString();
127 }).toList();
128
129 new File(mapPath).writeAsStringSync(JSON.encode(map));
130 }
131
115 /// Sanitizes the bytes emitted by [stream], converts them to text, and writes 132 /// Sanitizes the bytes emitted by [stream], converts them to text, and writes
116 /// them to [buffer]. 133 /// them to [buffer].
117 Future _printOutputStream(Stream<List<int>> stream, StringBuffer buffer) { 134 Future _printOutputStream(Stream<List<int>> stream, StringBuffer buffer) {
118 return sanitizeForWindows(stream) 135 return sanitizeForWindows(stream)
119 .listen((data) => buffer.write(UTF8.decode(data))).asFuture(); 136 .listen((data) => buffer.write(UTF8.decode(data))).asFuture();
120 } 137 }
121 138
122 /// Closes the compiler pool. 139 /// Closes the compiler pool.
123 /// 140 ///
124 /// This kills all currently-running compilers and ensures that no more will 141 /// This kills all currently-running compilers and ensures that no more will
125 /// be started. It returns a [Future] that completes once all the compilers 142 /// be started. It returns a [Future] that completes once all the compilers
126 /// have been killed and all resources released. 143 /// have been killed and all resources released.
127 Future close() { 144 Future close() {
128 return _closeMemo.runOnce(() async { 145 return _closeMemo.runOnce(() async {
129 await Future.wait(_processes.map((process) async { 146 await Future.wait(_processes.map((process) async {
130 process.kill(); 147 process.kill();
131 await process.exitCode; 148 await process.exitCode;
132 })); 149 }));
133 }); 150 });
134 } 151 }
135 } 152 }
OLDNEW
« no previous file with comments | « CHANGELOG.md ('k') | lib/src/runner/browser/server.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698