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

Side by Side Diff: pkg/polymer/lib/builder.dart

Issue 29823005: fixes to polymer, gets tests back to a stable state (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 2 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) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 /** 5 /**
6 * Common logic to make it easy to run the polymer linter and deploy tool. 6 * Common logic to make it easy to run the polymer linter and deploy tool.
7 * 7 *
8 * The functions in this library are designed to make it easier to create 8 * The functions in this library are designed to make it easier to create
9 * `build.dart` files. A `build.dart` file is a Dart script that can be invoked 9 * `build.dart` files. A `build.dart` file is a Dart script that can be invoked
10 * from the command line, but that can also invoked automatically by the Dart 10 * from the command line, but that can also invoked automatically by the Dart
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 * passing the [options] argument. 137 * passing the [options] argument.
138 * 138 *
139 * The linter needs to know the name of the [currentPackage] and the location 139 * The linter needs to know the name of the [currentPackage] and the location
140 * where to find the code for any package it depends on ([packageDirs]). This is 140 * where to find the code for any package it depends on ([packageDirs]). This is
141 * inferred automatically, but can be overriden if those arguments are provided. 141 * inferred automatically, but can be overriden if those arguments are provided.
142 */ 142 */
143 Future lint({List<String> entryPoints, CommandLineOptions options, 143 Future lint({List<String> entryPoints, CommandLineOptions options,
144 String currentPackage, Map<String, String> packageDirs}) { 144 String currentPackage, Map<String, String> packageDirs}) {
145 if (options == null) options = _options; 145 if (options == null) options = _options;
146 if (currentPackage == null) currentPackage = readCurrentPackageFromPubspec(); 146 if (currentPackage == null) currentPackage = readCurrentPackageFromPubspec();
147 var linterOptions = new TransformOptions(entryPoints); 147 var linterOptions = new TransformOptions(entryPoints: entryPoints);
148 var formatter = options.machineFormat ? jsonFormatter : consoleFormatter; 148 var formatter = options.machineFormat ? jsonFormatter : consoleFormatter;
149 var linter = new Linter(linterOptions, formatter); 149 var linter = new Linter(linterOptions, formatter);
150 return runBarback(new BarbackOptions([[linter]], null, 150 return runBarback(new BarbackOptions([[linter]], null,
151 currentPackage: currentPackage, packageDirs: packageDirs)).then((assets) { 151 currentPackage: currentPackage, packageDirs: packageDirs)).then((assets) {
152 var messages = {}; 152 var messages = {};
153 var futures = []; 153 var futures = [];
154 for (var asset in assets) { 154 for (var asset in assets) {
155 var id = asset.id; 155 var id = asset.id;
156 if (id.package == currentPackage && id.path.endsWith('.messages')) { 156 if (id.package == currentPackage && id.path.endsWith('.messages')) {
157 futures.add(asset.readAsString().then((content) { 157 futures.add(asset.readAsString().then((content) {
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 * 193 *
194 * The deploy step needs to know the name of the [currentPackage] and the 194 * The deploy step needs to know the name of the [currentPackage] and the
195 * location where to find the code for any package it depends on 195 * location where to find the code for any package it depends on
196 * ([packageDirs]). This is inferred automatically, but can be overriden if 196 * ([packageDirs]). This is inferred automatically, but can be overriden if
197 * those arguments are provided. 197 * those arguments are provided.
198 */ 198 */
199 Future deploy({List<String> entryPoints, CommandLineOptions options, 199 Future deploy({List<String> entryPoints, CommandLineOptions options,
200 String currentPackage, Map<String, String> packageDirs}) { 200 String currentPackage, Map<String, String> packageDirs}) {
201 if (options == null) options = _options; 201 if (options == null) options = _options;
202 if (currentPackage == null) currentPackage = readCurrentPackageFromPubspec(); 202 if (currentPackage == null) currentPackage = readCurrentPackageFromPubspec();
203
204 var transformOptions = new TransformOptions(
205 entryPoints: entryPoints,
206 directlyIncludeJS: options.directlyIncludeJS,
207 contentSecurityPolicy: options.contentSecurityPolicy);
208
203 var barbackOptions = new BarbackOptions( 209 var barbackOptions = new BarbackOptions(
204 (new PolymerTransformerGroup(new TransformOptions(entryPoints))).phases, 210 new PolymerTransformerGroup(transformOptions).phases,
205 options.outDir, currentPackage: currentPackage, 211 options.outDir, currentPackage: currentPackage,
206 packageDirs: packageDirs); 212 packageDirs: packageDirs);
207 return runBarback(barbackOptions) 213 return runBarback(barbackOptions)
208 .then((_) => print('Done! All files written to "${options.outDir}"')); 214 .then((_) => print('Done! All files written to "${options.outDir}"'));
209 } 215 }
210 216
211 217
212 /** 218 /**
213 * Options that may be used either in build.dart or by the linter and deploy 219 * Options that may be used either in build.dart or by the linter and deploy
214 * tools. 220 * tools.
(...skipping 13 matching lines...) Expand all
228 234
229 /** Whether to print results using a machine parseable format. */ 235 /** Whether to print results using a machine parseable format. */
230 final bool machineFormat; 236 final bool machineFormat;
231 237
232 /** Whether the force deploy option was passed in the command line. */ 238 /** Whether the force deploy option was passed in the command line. */
233 final bool forceDeploy; 239 final bool forceDeploy;
234 240
235 /** Location where to generate output files. */ 241 /** Location where to generate output files. */
236 final String outDir; 242 final String outDir;
237 243
244 /** True to use the CSP-compliant JS file. */
245 final bool contentSecurityPolicy;
246
247 /**
248 * True to include the JS script tag directly, with the
Siggi Cherem (dart-lang) 2013/10/21 21:07:42 with -> without?
Jennifer Messerly 2013/10/21 21:42:56 Done.
249 * "packages/browser/dart.js" trampoline.
250 */
251 final bool directlyIncludeJS;
252
238 CommandLineOptions(this.changedFiles, this.removedFiles, this.clean, 253 CommandLineOptions(this.changedFiles, this.removedFiles, this.clean,
239 this.full, this.machineFormat, this.forceDeploy, this.outDir); 254 this.full, this.machineFormat, this.forceDeploy, this.outDir,
255 this.directlyIncludeJS, this.contentSecurityPolicy);
240 } 256 }
241 257
242 /** Options parsed directly from the command line arguments. */ 258 /** Options parsed directly from the command line arguments. */
243 CommandLineOptions _options = parseOptions(); 259 CommandLineOptions _options = parseOptions();
244 260
245 /** 261 /**
246 * Parse command-line arguments and return a [CommandLineOptions] object. The 262 * Parse command-line arguments and return a [CommandLineOptions] object. The
247 * following flags are parsed by this method. 263 * following flags are parsed by this method.
248 * 264 *
249 * * `--changed file-path`: notify of a file change. 265 * * `--changed file-path`: notify of a file change.
250 * * `--removed file-path`: notify that a file was removed. 266 * * `--removed file-path`: notify that a file was removed.
251 * * `--clean`: remove temporary artifacts (if any) 267 * * `--clean`: remove temporary artifacts (if any)
252 * * `--full`: build everything, similar to marking every file as changed 268 * * `--full`: build everything, similar to marking every file as changed
253 * * `--machine`: produce output that can be parsed by tools, such as the Dart 269 * * `--machine`: produce output that can be parsed by tools, such as the Dart
254 * Editor. 270 * Editor.
255 * * `--deploy`: force deploy. 271 * * `--deploy`: force deploy.
272 * * `--no-js`: deploy replaces *.dart scripts with *.dart.js. This
Siggi Cherem (dart-lang) 2013/10/21 21:07:42 remove 'no-'
blois 2013/10/21 21:08:12 comment is out of sync with code (--no-js vs --js)
Siggi Cherem (dart-lang) 2013/10/21 21:32:24 OK - after re-reading I understand this better. Fe
Jennifer Messerly 2013/10/21 21:42:56 the "--no-" prefix is from args.dart. it's how you
273 * flag leaves "packages/browser/dart.js" to do the replacement at runtime.
274 * * `--csp`: replaces *.dart with *.dart.precompiled.js to comply with
275 * Content Security Policy restrictions.
256 * * `--help`: print documentation for each option and exit. 276 * * `--help`: print documentation for each option and exit.
257 * 277 *
258 * Currently not all the flags are used by [lint] or [deploy] above, but they 278 * Currently not all the flags are used by [lint] or [deploy] above, but they
259 * are available so they can be used from your `build.dart`. For instance, see 279 * are available so they can be used from your `build.dart`. For instance, see
260 * the top-level library documentation for an example that uses the force-deploy 280 * the top-level library documentation for an example that uses the force-deploy
261 * option to conditionally call [deploy]. 281 * option to conditionally call [deploy].
262 * 282 *
263 * If this documentation becomes out of date, the best way to discover which 283 * If this documentation becomes out of date, the best way to discover which
264 * flags are supported is to invoke this function from your build.dart, and run 284 * flags are supported is to invoke this function from your build.dart, and run
265 * it with the `--help` command-line flag. 285 * it with the `--help` command-line flag.
266 */ 286 */
267 CommandLineOptions parseOptions([List<String> args]) { 287 CommandLineOptions parseOptions([List<String> args]) {
268 var parser = new ArgParser() 288 var parser = new ArgParser()
269 ..addOption('changed', help: 'The file has changed since the last build.', 289 ..addOption('changed', help: 'The file has changed since the last build.',
270 allowMultiple: true) 290 allowMultiple: true)
271 ..addOption('removed', help: 'The file was removed since the last build.', 291 ..addOption('removed', help: 'The file was removed since the last build.',
272 allowMultiple: true) 292 allowMultiple: true)
273 ..addFlag('clean', negatable: false, 293 ..addFlag('clean', negatable: false,
274 help: 'Remove any build artifacts (if any).') 294 help: 'Remove any build artifacts (if any).')
275 ..addFlag('full', negatable: false, help: 'perform a full build') 295 ..addFlag('full', negatable: false, help: 'perform a full build')
276 ..addFlag('machine', negatable: false, 296 ..addFlag('machine', negatable: false,
277 help: 'Produce warnings in a machine parseable format.') 297 help: 'Produce warnings in a machine parseable format.')
278 ..addFlag('deploy', negatable: false, 298 ..addFlag('deploy', negatable: false,
279 help: 'Whether to force deploying.') 299 help: 'Whether to force deploying.')
280 ..addOption('out', abbr: 'o', help: 'Directory to generate files into.', 300 ..addOption('out', abbr: 'o', help: 'Directory to generate files into.',
281 defaultsTo: 'out') 301 defaultsTo: 'out')
302 ..addFlag('js', help:
303 'deploy replaces *.dart scripts with *.dart.js. This flag \n'
304 'leaves "packages/browser/dart.js" to do the replacement at runtime.'
305 defaultsTo: true)
Siggi Cherem (dart-lang) 2013/10/21 21:07:42 eventually I agree that should be the default. I w
Jennifer Messerly 2013/10/21 21:42:56 it should. browser/dart.js needs to go away for 1.
306 ..addFlag('csp', help:
307 'replaces *.dart with *.dart.precompiled.js to comply with \n'
308 'Content Security Policy restrictions.');
282 ..addFlag('help', abbr: 'h', 309 ..addFlag('help', abbr: 'h',
283 negatable: false, help: 'Displays this help and exit.'); 310 negatable: false, help: 'Displays this help and exit.');
284 var res = parser.parse(args == null ? new Options().arguments : args); 311 var res = parser.parse(args == null ? new Options().arguments : args);
285 if (res['help']) { 312 if (res['help']) {
286 print('A build script that invokes the polymer linter and deploy tools.'); 313 print('A build script that invokes the polymer linter and deploy tools.');
287 print('Usage: dart build.dart [options]'); 314 print('Usage: dart build.dart [options]');
288 print('\nThese are valid options expected by build.dart:'); 315 print('\nThese are valid options expected by build.dart:');
289 print(parser.getUsage()); 316 print(parser.getUsage());
290 exit(0); 317 exit(0);
291 } 318 }
292 return new CommandLineOptions(res['changed'], res['removed'], res['clean'], 319 return new CommandLineOptions(res['changed'], res['removed'], res['clean'],
293 res['full'], res['machine'], res['deploy'], res['out']); 320 res['full'], res['machine'], res['deploy'], res['out'], res['js'],
321 res['csp']);
294 } 322 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698