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

Side by Side Diff: lib/src/barback/dart2js_transformer.dart

Issue 1228683003: Fix various pub issues. (Closed) Base URL: git@github.com:dart-lang/pub.git@master
Patch Set: Created 5 years, 5 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 | « no previous file | lib/src/command/list_package_dirs.dart » ('j') | lib/src/dart.dart » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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.dart2js_transformer; 5 library pub.dart2js_transformer;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:convert'; 8 import 'dart:convert';
9 9
10 import 'package:analyzer/analyzer.dart'; 10 import 'package:analyzer/analyzer.dart';
11 import 'package:barback/barback.dart'; 11 import 'package:barback/barback.dart';
12 import 'package:path/path.dart' as path; 12 import 'package:path/path.dart' as p;
13 import 'package:pool/pool.dart'; 13 import 'package:pool/pool.dart';
14 14
15 import 'package:compiler_unsupported/compiler.dart' as compiler; 15 import 'package:compiler_unsupported/compiler.dart' as compiler;
16 import 'package:compiler_unsupported/src/dart2js.dart' 16 import 'package:compiler_unsupported/src/dart2js.dart'
17 show AbortLeg; 17 show AbortLeg;
18 import 'package:compiler_unsupported/src/io/source_file.dart'; 18 import 'package:compiler_unsupported/src/io/source_file.dart';
19 import '../barback.dart'; 19 import '../barback.dart';
20 import '../dart.dart' as dart; 20 import '../dart.dart' as dart;
21 import '../utils.dart'; 21 import '../utils.dart';
22 import 'asset_environment.dart'; 22 import 'asset_environment.dart';
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 } 194 }
195 195
196 /// Defines an interface for dart2js to communicate with barback and pub. 196 /// Defines an interface for dart2js to communicate with barback and pub.
197 /// 197 ///
198 /// Note that most of the implementation of diagnostic handling here was 198 /// Note that most of the implementation of diagnostic handling here was
199 /// copied from [FormattingDiagnosticHandler] in dart2js. The primary 199 /// copied from [FormattingDiagnosticHandler] in dart2js. The primary
200 /// difference is that it uses barback's logging code and, more importantly, it 200 /// difference is that it uses barback's logging code and, more importantly, it
201 /// handles missing source files more gracefully. 201 /// handles missing source files more gracefully.
202 class _BarbackCompilerProvider implements dart.CompilerProvider { 202 class _BarbackCompilerProvider implements dart.CompilerProvider {
203 Uri get libraryRoot => 203 Uri get libraryRoot =>
204 Uri.parse("${path.toUri(path.absolute(_libraryRootPath))}/"); 204 Uri.parse("${p.toUri(p.normalize(p.absolute(_libraryRootPath)))}/");
205 205
206 final AssetEnvironment _environment; 206 final AssetEnvironment _environment;
207 final Transform _transform; 207 final Transform _transform;
208 String _libraryRootPath; 208 String _libraryRootPath;
209 209
210 /// The map of previously loaded files. 210 /// The map of previously loaded files.
211 /// 211 ///
212 /// Used to show where an error occurred in a source file. 212 /// Used to show where an error occurred in a source file.
213 final _sourceFiles = new Map<String, SourceFile>(); 213 final _sourceFiles = new Map<String, SourceFile>();
214 214
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 _libraryRootPath = _environment.rootPackage.path( 265 _libraryRootPath = _environment.rootPackage.path(
266 buildDir, "packages", r"$sdk"); 266 buildDir, "packages", r"$sdk");
267 } 267 }
268 268
269 /// A [CompilerInputProvider] for dart2js. 269 /// A [CompilerInputProvider] for dart2js.
270 Future<String> provideInput(Uri resourceUri) { 270 Future<String> provideInput(Uri resourceUri) {
271 // We only expect to get absolute "file:" URLs from dart2js. 271 // We only expect to get absolute "file:" URLs from dart2js.
272 assert(resourceUri.isAbsolute); 272 assert(resourceUri.isAbsolute);
273 assert(resourceUri.scheme == "file"); 273 assert(resourceUri.scheme == "file");
274 274
275 var sourcePath = path.fromUri(resourceUri); 275 var sourcePath = p.fromUri(resourceUri);
276 return _readResource(resourceUri).then((source) { 276 return _readResource(resourceUri).then((source) {
277 _sourceFiles[resourceUri.toString()] = 277 _sourceFiles[resourceUri.toString()] =
278 new StringSourceFile(resourceUri, path.relative(sourcePath), source); 278 new StringSourceFile(resourceUri, p.relative(sourcePath), source);
279 return source; 279 return source;
280 }); 280 });
281 } 281 }
282 282
283 /// A [CompilerOutputProvider] for dart2js. 283 /// A [CompilerOutputProvider] for dart2js.
284 EventSink<String> provideOutput(String name, String extension) { 284 EventSink<String> provideOutput(String name, String extension) {
285 // TODO(rnystrom): Do this more cleanly. See: #17403. 285 // TODO(rnystrom): Do this more cleanly. See: #17403.
286 if (!generateSourceMaps && extension.endsWith(".map")) { 286 if (!generateSourceMaps && extension.endsWith(".map")) {
287 return new NullSink<String>(); 287 return new NullSink<String>();
288 } 288 }
289 289
290 // TODO(nweiz): remove this special case when dart2js stops generating these 290 // TODO(nweiz): remove this special case when dart2js stops generating these
291 // files. 291 // files.
292 if (extension.endsWith(".precompiled.js")) return new NullSink<String>(); 292 if (extension.endsWith(".precompiled.js")) return new NullSink<String>();
293 293
294 var primaryId = _transform.primaryInput.id; 294 var primaryId = _transform.primaryInput.id;
295 295
296 // Dart2js uses an empty string for the name of the entrypoint library. 296 // Dart2js uses an empty string for the name of the entrypoint library.
297 // Otherwise, it's the name of a deferred library. 297 // Otherwise, it's the name of a deferred library.
298 var outPath; 298 var outPath;
299 if (name == "") { 299 if (name == "") {
300 outPath = _transform.primaryInput.id.path; 300 outPath = _transform.primaryInput.id.path;
301 } else { 301 } else {
302 var dirname = path.url.dirname(_transform.primaryInput.id.path); 302 var dirname = p.url.dirname(_transform.primaryInput.id.path);
303 outPath = path.url.join(dirname, name); 303 outPath = p.url.join(dirname, name);
304 } 304 }
305 305
306 var id = new AssetId(primaryId.package, "$outPath.$extension"); 306 var id = new AssetId(primaryId.package, "$outPath.$extension");
307 307
308 // Make a sink that dart2js can write to. 308 // Make a sink that dart2js can write to.
309 var sink = new StreamController<String>(); 309 var sink = new StreamController<String>();
310 310
311 // dart2js gives us strings, but stream assets expect byte lists. 311 // dart2js gives us strings, but stream assets expect byte lists.
312 var stream = UTF8.encoder.bind(sink.stream); 312 var stream = UTF8.encoder.bind(sink.stream);
313 313
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
392 } 392 }
393 393
394 AssetId _sourceUrlToId(Uri url) { 394 AssetId _sourceUrlToId(Uri url) {
395 // See if it's a package path. 395 // See if it's a package path.
396 var id = packagesUrlToId(url); 396 var id = packagesUrlToId(url);
397 if (id != null) return id; 397 if (id != null) return id;
398 398
399 // See if it's a path to a "public" asset within the root package. All 399 // See if it's a path to a "public" asset within the root package. All
400 // other files in the root package are not visible to transformers, so 400 // other files in the root package are not visible to transformers, so
401 // should be loaded directly from disk. 401 // should be loaded directly from disk.
402 var sourcePath = path.fromUri(url); 402 var sourcePath = p.fromUri(url);
403 if (_environment.containsPath(sourcePath)) { 403 if (_environment.containsPath(sourcePath)) {
404 var relative = path.toUri(_environment.rootPackage.relative(sourcePath)) 404 var relative = p.toUri(_environment.rootPackage.relative(sourcePath))
405 .toString(); 405 .toString();
406 406
407 return new AssetId(_environment.rootPackage.name, relative); 407 return new AssetId(_environment.rootPackage.name, relative);
408 } 408 }
409 409
410 return null; 410 return null;
411 } 411 }
412 } 412 }
413 413
414 /// An [EventSink] that discards all data. Provided to dart2js when we don't 414 /// An [EventSink] that discards all data. Provided to dart2js when we don't
415 /// want an actual output. 415 /// want an actual output.
416 class NullSink<T> implements EventSink<T> { 416 class NullSink<T> implements EventSink<T> {
417 void add(T event) {} 417 void add(T event) {}
418 void addError(errorEvent, [StackTrace stackTrace]) {} 418 void addError(errorEvent, [StackTrace stackTrace]) {}
419 void close() {} 419 void close() {}
420 } 420 }
OLDNEW
« no previous file with comments | « no previous file | lib/src/command/list_package_dirs.dart » ('j') | lib/src/dart.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698