| OLD | NEW |
| 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'; |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 /// Run the dart2js compiler. | 117 /// Run the dart2js compiler. |
| 118 Future _doCompilation(Transform transform) { | 118 Future _doCompilation(Transform transform) { |
| 119 var provider = new _BarbackCompilerProvider(_environment, transform, | 119 var provider = new _BarbackCompilerProvider(_environment, transform, |
| 120 generateSourceMaps: _generateSourceMaps); | 120 generateSourceMaps: _generateSourceMaps); |
| 121 | 121 |
| 122 // Create a "path" to the entrypoint script. The entrypoint may not actually | 122 // Create a "path" to the entrypoint script. The entrypoint may not actually |
| 123 // be on disk, but this gives dart2js a root to resolve relative paths | 123 // be on disk, but this gives dart2js a root to resolve relative paths |
| 124 // against. | 124 // against. |
| 125 var id = transform.primaryInput.id; | 125 var id = transform.primaryInput.id; |
| 126 | 126 |
| 127 var entrypoint = path.join(_environment.graph.packages[id.package].dir, | 127 var entrypoint = _environment.graph.packages[id.package].path(id.path); |
| 128 id.path); | |
| 129 | 128 |
| 130 // TODO(rnystrom): Should have more sophisticated error-handling here. Need | 129 // TODO(rnystrom): Should have more sophisticated error-handling here. Need |
| 131 // to report compile errors to the user in an easily visible way. Need to | 130 // to report compile errors to the user in an easily visible way. Need to |
| 132 // make sure paths in errors are mapped to the original source path so they | 131 // make sure paths in errors are mapped to the original source path so they |
| 133 // can understand them. | 132 // can understand them. |
| 134 return dart.compile( | 133 return dart.compile( |
| 135 entrypoint, provider, | 134 entrypoint, provider, |
| 136 commandLineOptions: _configCommandLineOptions, | 135 commandLineOptions: _configCommandLineOptions, |
| 137 csp: _configBool('csp'), | 136 csp: _configBool('csp'), |
| 138 checked: _configBool('checked'), | 137 checked: _configBool('checked'), |
| 139 minify: _configBool( | 138 minify: _configBool( |
| 140 'minify', defaultsTo: _settings.mode == BarbackMode.RELEASE), | 139 'minify', defaultsTo: _settings.mode == BarbackMode.RELEASE), |
| 141 verbose: _configBool('verbose'), | 140 verbose: _configBool('verbose'), |
| 142 environment: _configEnvironment, | 141 environment: _configEnvironment, |
| 143 packageRoot: path.join(_environment.rootPackage.dir, "packages"), | 142 packageRoot: _environment.rootPackage.path("packages"), |
| 144 analyzeAll: _configBool('analyzeAll'), | 143 analyzeAll: _configBool('analyzeAll'), |
| 145 suppressWarnings: _configBool('suppressWarnings'), | 144 suppressWarnings: _configBool('suppressWarnings'), |
| 146 suppressHints: _configBool('suppressHints'), | 145 suppressHints: _configBool('suppressHints'), |
| 147 suppressPackageWarnings: _configBool( | 146 suppressPackageWarnings: _configBool( |
| 148 'suppressPackageWarnings', defaultsTo: true), | 147 'suppressPackageWarnings', defaultsTo: true), |
| 149 terse: _configBool('terse'), | 148 terse: _configBool('terse'), |
| 150 includeSourceMapUrls: _settings.mode != BarbackMode.RELEASE); | 149 includeSourceMapUrls: _settings.mode != BarbackMode.RELEASE); |
| 151 } | 150 } |
| 152 | 151 |
| 153 /// Parses and returns the "commandLineOptions" configuration option. | 152 /// Parses and returns the "commandLineOptions" configuration option. |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 252 // | 251 // |
| 253 // /dev/myapp/web/sub/packages/$sdk/lib/ | 252 // /dev/myapp/web/sub/packages/$sdk/lib/ |
| 254 // | 253 // |
| 255 // This implies that the asset path for a file in the SDK is: | 254 // This implies that the asset path for a file in the SDK is: |
| 256 // | 255 // |
| 257 // $sdk|lib/lib/... | 256 // $sdk|lib/lib/... |
| 258 // | 257 // |
| 259 // TODO(rnystrom): Fix this if #17751 is fixed. | 258 // TODO(rnystrom): Fix this if #17751 is fixed. |
| 260 var buildDir = _environment.getSourceDirectoryContaining( | 259 var buildDir = _environment.getSourceDirectoryContaining( |
| 261 _transform.primaryInput.id.path); | 260 _transform.primaryInput.id.path); |
| 262 _libraryRootPath = path.join(_environment.rootPackage.dir, | 261 _libraryRootPath = _environment.rootPackage.path( |
| 263 buildDir, "packages", r"$sdk"); | 262 buildDir, "packages", r"$sdk"); |
| 264 } | 263 } |
| 265 | 264 |
| 266 /// A [CompilerInputProvider] for dart2js. | 265 /// A [CompilerInputProvider] for dart2js. |
| 267 Future<String> provideInput(Uri resourceUri) { | 266 Future<String> provideInput(Uri resourceUri) { |
| 268 // We only expect to get absolute "file:" URLs from dart2js. | 267 // We only expect to get absolute "file:" URLs from dart2js. |
| 269 assert(resourceUri.isAbsolute); | 268 assert(resourceUri.isAbsolute); |
| 270 assert(resourceUri.scheme == "file"); | 269 assert(resourceUri.scheme == "file"); |
| 271 | 270 |
| 272 var sourcePath = path.fromUri(resourceUri); | 271 var sourcePath = path.fromUri(resourceUri); |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 387 AssetId _sourceUrlToId(Uri url) { | 386 AssetId _sourceUrlToId(Uri url) { |
| 388 // See if it's a package path. | 387 // See if it's a package path. |
| 389 var id = packagesUrlToId(url); | 388 var id = packagesUrlToId(url); |
| 390 if (id != null) return id; | 389 if (id != null) return id; |
| 391 | 390 |
| 392 // See if it's a path to a "public" asset within the root package. All | 391 // See if it's a path to a "public" asset within the root package. All |
| 393 // other files in the root package are not visible to transformers, so | 392 // other files in the root package are not visible to transformers, so |
| 394 // should be loaded directly from disk. | 393 // should be loaded directly from disk. |
| 395 var sourcePath = path.fromUri(url); | 394 var sourcePath = path.fromUri(url); |
| 396 if (_environment.containsPath(sourcePath)) { | 395 if (_environment.containsPath(sourcePath)) { |
| 397 var relative = path.toUri(path.relative(sourcePath, | 396 var relative = path.toUri(_environment.rootPackage.relative(sourcePath)) |
| 398 from: _environment.rootPackage.dir)).toString(); | 397 .toString(); |
| 399 | 398 |
| 400 return new AssetId(_environment.rootPackage.name, relative); | 399 return new AssetId(_environment.rootPackage.name, relative); |
| 401 } | 400 } |
| 402 | 401 |
| 403 return null; | 402 return null; |
| 404 } | 403 } |
| 405 } | 404 } |
| 406 | 405 |
| 407 /// An [EventSink] that discards all data. Provided to dart2js when we don't | 406 /// An [EventSink] that discards all data. Provided to dart2js when we don't |
| 408 /// want an actual output. | 407 /// want an actual output. |
| 409 class NullSink<T> implements EventSink<T> { | 408 class NullSink<T> implements EventSink<T> { |
| 410 void add(T event) {} | 409 void add(T event) {} |
| 411 void addError(errorEvent, [StackTrace stackTrace]) {} | 410 void addError(errorEvent, [StackTrace stackTrace]) {} |
| 412 void close() {} | 411 void close() {} |
| 413 } | 412 } |
| OLD | NEW |