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

Side by Side Diff: sdk/lib/_internal/pub/lib/src/barback/dart2js_transformer.dart

Issue 223553008: Only pass an AssetId to isPrimary and declareOutputs. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: fixes Created 6 years, 8 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) 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 import 'dart:io'; 9 import 'dart:io';
10 10
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 50
51 throw new FormatException("Unrecognized dart2js " 51 throw new FormatException("Unrecognized dart2js "
52 "${pluralize('option', invalidOptions.length)} " 52 "${pluralize('option', invalidOptions.length)} "
53 "${toSentence(invalidOptions.map((option) => '"$option"'))}."); 53 "${toSentence(invalidOptions.map((option) => '"$option"'))}.");
54 } 54 }
55 55
56 Dart2JSTransformer(BuildEnvironment environment, BarbackMode mode) 56 Dart2JSTransformer(BuildEnvironment environment, BarbackMode mode)
57 : this.withSettings(environment, new BarbackSettings({}, mode)); 57 : this.withSettings(environment, new BarbackSettings({}, mode));
58 58
59 /// Only ".dart" entrypoint files within a buildable directory are processed. 59 /// Only ".dart" entrypoint files within a buildable directory are processed.
60 Future<bool> isPrimary(Asset asset) { 60 Future<bool> isPrimary(AssetId id) {
61 if (asset.id.extension != ".dart") return new Future.value(false); 61 if (id.extension != ".dart") return new Future.value(false);
62 62
63 // These should only contain libraries. For efficiency's sake, we don't 63 // These should only contain libraries. For efficiency's sake, we don't
64 // look for entrypoints in there. 64 // look for entrypoints in there.
65 if (["asset/", "lib/"].any(asset.id.path.startsWith)) { 65 return new Future.value(!["asset/", "lib/"].any(id.path.startsWith));
66 return new Future.value(false); 66 }
67 }
68 67
68 Future apply(Transform transform) {
69 // 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.
70 // don't re-run the entrypoint detection logic unless the primary input was
71 // actually modified.
72 return _isEntrypoint(transform.primaryInput).then((isEntrypoint) {
73 if (!isEntrypoint) return null;
74
75 var stopwatch = new Stopwatch();
76
77 // Wait for any ongoing apply to finish first.
78 return _pool.withResource(() {
79 transform.logger.info("Compiling ${transform.primaryInput.id}...");
80 stopwatch.start();
81
82 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.
83 generateSourceMaps: _settings.mode != BarbackMode.RELEASE);
84
85 // Create a "path" to the entrypoint script. The entrypoint may not
86 // actually be on disk, but this gives dart2js a root to resolve
87 // relative paths against.
88 var id = transform.primaryInput.id;
89
90 var entrypoint = path.join(_environment.graph.packages[id.package].dir,
91 id.path);
92
93 // TODO(rnystrom): Should have more sophisticated error-handling here.
94 // Need to report compile errors to the user in an easily visible way.
95 // Need to make sure paths in errors are mapped to the original source
96 // path so they can understand them.
97 return Chain.track(dart.compile(
98 entrypoint, provider,
99 commandLineOptions: _configCommandLineOptions,
100 checked: _configBool('checked'),
101 minify: _configBool(
102 'minify', defaultsTo: _settings.mode == BarbackMode.RELEASE),
103 verbose: _configBool('verbose'),
104 environment: _configEnvironment,
105 packageRoot: path.join(_environment.rootPackage.dir,
106 "packages"),
Bob Nystrom 2014/04/03 22:28:29 Does this need to be wrapped?
nweiz 2014/04/03 23:03:50 Nope.
107 analyzeAll: _configBool('analyzeAll'),
108 suppressWarnings: _configBool('suppressWarnings'),
109 suppressHints: _configBool('suppressHints'),
110 suppressPackageWarnings: _configBool(
111 'suppressPackageWarnings', defaultsTo: true),
112 terse: _configBool('terse'),
113 includeSourceMapUrls: _settings.mode != BarbackMode.RELEASE))
114 .then((_) {
115 stopwatch.stop();
116 transform.logger.info("Took ${stopwatch.elapsed} to compile $id.");
117 });
118 });
119 });
120 }
121
122 Future declareOutputs(DeclaringTransform transform) {
123 var primaryId = transform.primaryId;
124 transform.declareOutput(primaryId.addExtension(".js"));
125 transform.declareOutput(primaryId.addExtension(".js.map"));
126 transform.declareOutput(primaryId.addExtension(".precompiled.js"));
127 return new Future.value();
128 }
129
130 /// Returns whether or not [asset] might be an entrypoint.
131 Future<bool> _isEntrypoint(Asset asset) {
69 return asset.readAsString().then((code) { 132 return asset.readAsString().then((code) {
70 try { 133 try {
71 var name = asset.id.path; 134 var name = asset.id.path;
72 if (asset.id.package != _environment.rootPackage.name) { 135 if (asset.id.package != _environment.rootPackage.name) {
73 name += " in ${asset.id.package}"; 136 name += " in ${asset.id.package}";
74 } 137 }
75 138
76 var parsed = parseCompilationUnit(code, name: name); 139 var parsed = parseCompilationUnit(code, name: name);
77 return dart.isEntrypoint(parsed); 140 return dart.isEntrypoint(parsed);
78 } on AnalyzerErrorGroup catch (e) { 141 } on AnalyzerErrorGroup catch (e) {
79 // If we get a parse error, consider the asset primary so we report 142 // If we get a parse error, consider the asset primary so we report
80 // dart2js's more detailed error message instead. 143 // dart2js's more detailed error message instead.
81 return true; 144 return true;
82 } 145 }
83 }); 146 });
84 } 147 }
85 148
86 Future apply(Transform transform) {
87 var stopwatch = new Stopwatch();
88
89 // Wait for any ongoing apply to finish first.
90 return _pool.withResource(() {
91 transform.logger.info("Compiling ${transform.primaryInput.id}...");
92 stopwatch.start();
93
94 var provider = new _BarbackCompilerProvider(_environment, transform,
95 generateSourceMaps: _settings.mode != BarbackMode.RELEASE);
96
97 // Create a "path" to the entrypoint script. The entrypoint may not
98 // actually be on disk, but this gives dart2js a root to resolve relative
99 // paths against.
100 var id = transform.primaryInput.id;
101
102 var entrypoint = path.join(_environment.graph.packages[id.package].dir,
103 id.path);
104
105 // TODO(rnystrom): Should have more sophisticated error-handling here.
106 // Need to report compile errors to the user in an easily visible way.
107 // Need to make sure paths in errors are mapped to the original source
108 // path so they can understand them.
109 return Chain.track(dart.compile(
110 entrypoint, provider,
111 commandLineOptions: _configCommandLineOptions,
112 checked: _configBool('checked'),
113 minify: _configBool(
114 'minify', defaultsTo: _settings.mode == BarbackMode.RELEASE),
115 verbose: _configBool('verbose'),
116 environment: _configEnvironment,
117 packageRoot: path.join(_environment.rootPackage.dir,
118 "packages"),
119 analyzeAll: _configBool('analyzeAll'),
120 suppressWarnings: _configBool('suppressWarnings'),
121 suppressHints: _configBool('suppressHints'),
122 suppressPackageWarnings: _configBool(
123 'suppressPackageWarnings', defaultsTo: true),
124 terse: _configBool('terse'),
125 includeSourceMapUrls: _settings.mode != BarbackMode.RELEASE))
126 .then((_) {
127 stopwatch.stop();
128 transform.logger.info("Took ${stopwatch.elapsed} to compile $id.");
129 });
130 });
131 }
132
133 Future declareOutputs(DeclaringTransform transform) {
134 var primaryId = transform.primaryInput.id;
135 transform.declareOutput(primaryId.addExtension(".js"));
136 transform.declareOutput(primaryId.addExtension(".js.map"));
137 transform.declareOutput(primaryId.addExtension(".precompiled.js"));
138 return new Future.value();
139 }
140
141 /// Parses and returns the "commandLineOptions" configuration option. 149 /// Parses and returns the "commandLineOptions" configuration option.
142 List<String> get _configCommandLineOptions { 150 List<String> get _configCommandLineOptions {
143 if (!_settings.configuration.containsKey('commandLineOptions')) return null; 151 if (!_settings.configuration.containsKey('commandLineOptions')) return null;
144 152
145 var options = _settings.configuration['commandLineOptions']; 153 var options = _settings.configuration['commandLineOptions'];
146 if (options is List && options.every((option) => option is String)) { 154 if (options is List && options.every((option) => option is String)) {
147 return options; 155 return options;
148 } 156 }
149 157
150 throw new FormatException('Invalid value for ' 158 throw new FormatException('Invalid value for '
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
387 } 395 }
388 } 396 }
389 397
390 /// An [EventSink] that discards all data. Provided to dart2js when we don't 398 /// An [EventSink] that discards all data. Provided to dart2js when we don't
391 /// want an actual output. 399 /// want an actual output.
392 class NullSink<T> implements EventSink<T> { 400 class NullSink<T> implements EventSink<T> {
393 void add(T event) {} 401 void add(T event) {}
394 void addError(errorEvent, [StackTrace stackTrace]) {} 402 void addError(errorEvent, [StackTrace stackTrace]) {}
395 void close() {} 403 void close() {}
396 } 404 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698