Chromium Code Reviews| Index: sdk/lib/_internal/pub/lib/src/barback/dart2js_transformer.dart |
| diff --git a/sdk/lib/_internal/pub/lib/src/barback/dart2js_transformer.dart b/sdk/lib/_internal/pub/lib/src/barback/dart2js_transformer.dart |
| index 5af3b5c2b34aae3a20eed117b4e2e4d1d7e41f71..14f1240b39eb1872ba741c33017fe233b3f56e9f 100644 |
| --- a/sdk/lib/_internal/pub/lib/src/barback/dart2js_transformer.dart |
| +++ b/sdk/lib/_internal/pub/lib/src/barback/dart2js_transformer.dart |
| @@ -57,15 +57,78 @@ class Dart2JSTransformer extends Transformer implements LazyTransformer { |
| : this.withSettings(environment, new BarbackSettings({}, mode)); |
| /// Only ".dart" entrypoint files within a buildable directory are processed. |
| - Future<bool> isPrimary(Asset asset) { |
| - if (asset.id.extension != ".dart") return new Future.value(false); |
| + Future<bool> isPrimary(AssetId id) { |
| + if (id.extension != ".dart") return new Future.value(false); |
| // These should only contain libraries. For efficiency's sake, we don't |
| // look for entrypoints in there. |
| - if (["asset/", "lib/"].any(asset.id.path.startsWith)) { |
| - return new Future.value(false); |
| - } |
| + return new Future.value(!["asset/", "lib/"].any(id.path.startsWith)); |
| + } |
| + |
| + Future apply(Transform transform) { |
| + // TODO(nweiz): If/when barback starts reporting what assets were modified, |
|
Bob Nystrom
2014/04/03 22:28:29
Reference tracking bug.
nweiz
2014/04/03 23:03:50
Done.
|
| + // don't re-run the entrypoint detection logic unless the primary input was |
| + // actually modified. |
| + return _isEntrypoint(transform.primaryInput).then((isEntrypoint) { |
| + if (!isEntrypoint) return null; |
| + |
| + var stopwatch = new Stopwatch(); |
| + |
| + // Wait for any ongoing apply to finish first. |
| + return _pool.withResource(() { |
| + transform.logger.info("Compiling ${transform.primaryInput.id}..."); |
| + stopwatch.start(); |
| + |
| + var provider = new _BarbackCompilerProvider(_environment, transform, |
|
Bob Nystrom
2014/04/03 22:28:29
The indentation is a bit much here. How about brea
nweiz
2014/04/03 23:03:50
Done.
|
| + generateSourceMaps: _settings.mode != BarbackMode.RELEASE); |
| + |
| + // Create a "path" to the entrypoint script. The entrypoint may not |
| + // actually be on disk, but this gives dart2js a root to resolve |
| + // relative paths against. |
| + var id = transform.primaryInput.id; |
| + |
| + var entrypoint = path.join(_environment.graph.packages[id.package].dir, |
| + id.path); |
| + |
| + // TODO(rnystrom): Should have more sophisticated error-handling here. |
| + // Need to report compile errors to the user in an easily visible way. |
| + // Need to make sure paths in errors are mapped to the original source |
| + // path so they can understand them. |
| + return Chain.track(dart.compile( |
| + entrypoint, provider, |
| + commandLineOptions: _configCommandLineOptions, |
| + checked: _configBool('checked'), |
| + minify: _configBool( |
| + 'minify', defaultsTo: _settings.mode == BarbackMode.RELEASE), |
| + verbose: _configBool('verbose'), |
| + environment: _configEnvironment, |
| + packageRoot: path.join(_environment.rootPackage.dir, |
| + "packages"), |
|
Bob Nystrom
2014/04/03 22:28:29
Does this need to be wrapped?
nweiz
2014/04/03 23:03:50
Nope.
|
| + analyzeAll: _configBool('analyzeAll'), |
| + suppressWarnings: _configBool('suppressWarnings'), |
| + suppressHints: _configBool('suppressHints'), |
| + suppressPackageWarnings: _configBool( |
| + 'suppressPackageWarnings', defaultsTo: true), |
| + terse: _configBool('terse'), |
| + includeSourceMapUrls: _settings.mode != BarbackMode.RELEASE)) |
| + .then((_) { |
| + stopwatch.stop(); |
| + transform.logger.info("Took ${stopwatch.elapsed} to compile $id."); |
| + }); |
| + }); |
| + }); |
| + } |
| + |
| + Future declareOutputs(DeclaringTransform transform) { |
| + var primaryId = transform.primaryId; |
| + transform.declareOutput(primaryId.addExtension(".js")); |
| + transform.declareOutput(primaryId.addExtension(".js.map")); |
| + transform.declareOutput(primaryId.addExtension(".precompiled.js")); |
| + return new Future.value(); |
| + } |
| + /// Returns whether or not [asset] might be an entrypoint. |
| + Future<bool> _isEntrypoint(Asset asset) { |
| return asset.readAsString().then((code) { |
| try { |
| var name = asset.id.path; |
| @@ -83,61 +146,6 @@ class Dart2JSTransformer extends Transformer implements LazyTransformer { |
| }); |
| } |
| - Future apply(Transform transform) { |
| - var stopwatch = new Stopwatch(); |
| - |
| - // Wait for any ongoing apply to finish first. |
| - return _pool.withResource(() { |
| - transform.logger.info("Compiling ${transform.primaryInput.id}..."); |
| - stopwatch.start(); |
| - |
| - var provider = new _BarbackCompilerProvider(_environment, transform, |
| - generateSourceMaps: _settings.mode != BarbackMode.RELEASE); |
| - |
| - // Create a "path" to the entrypoint script. The entrypoint may not |
| - // actually be on disk, but this gives dart2js a root to resolve relative |
| - // paths against. |
| - var id = transform.primaryInput.id; |
| - |
| - var entrypoint = path.join(_environment.graph.packages[id.package].dir, |
| - id.path); |
| - |
| - // TODO(rnystrom): Should have more sophisticated error-handling here. |
| - // Need to report compile errors to the user in an easily visible way. |
| - // Need to make sure paths in errors are mapped to the original source |
| - // path so they can understand them. |
| - return Chain.track(dart.compile( |
| - entrypoint, provider, |
| - commandLineOptions: _configCommandLineOptions, |
| - checked: _configBool('checked'), |
| - minify: _configBool( |
| - 'minify', defaultsTo: _settings.mode == BarbackMode.RELEASE), |
| - verbose: _configBool('verbose'), |
| - environment: _configEnvironment, |
| - packageRoot: path.join(_environment.rootPackage.dir, |
| - "packages"), |
| - analyzeAll: _configBool('analyzeAll'), |
| - suppressWarnings: _configBool('suppressWarnings'), |
| - suppressHints: _configBool('suppressHints'), |
| - suppressPackageWarnings: _configBool( |
| - 'suppressPackageWarnings', defaultsTo: true), |
| - terse: _configBool('terse'), |
| - includeSourceMapUrls: _settings.mode != BarbackMode.RELEASE)) |
| - .then((_) { |
| - stopwatch.stop(); |
| - transform.logger.info("Took ${stopwatch.elapsed} to compile $id."); |
| - }); |
| - }); |
| - } |
| - |
| - Future declareOutputs(DeclaringTransform transform) { |
| - var primaryId = transform.primaryInput.id; |
| - transform.declareOutput(primaryId.addExtension(".js")); |
| - transform.declareOutput(primaryId.addExtension(".js.map")); |
| - transform.declareOutput(primaryId.addExtension(".precompiled.js")); |
| - return new Future.value(); |
| - } |
| - |
| /// Parses and returns the "commandLineOptions" configuration option. |
| List<String> get _configCommandLineOptions { |
| if (!_settings.configuration.containsKey('commandLineOptions')) return null; |