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

Side by Side Diff: sdk/lib/_internal/compiler/implementation/dart2js.dart

Issue 16114013: Reland "Add --version option to dart2js and add version information (if available) to generated cod… (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fix formatting. Created 7 years, 6 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 dart2js.cmdline; 5 library dart2js.cmdline;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:collection' show Queue, LinkedHashMap; 8 import 'dart:collection' show Queue, LinkedHashMap;
9 import 'dart:io'; 9 import 'dart:io';
10 import 'dart:utf'; 10 import 'dart:utf';
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 79
80 void compile(List<String> argv) { 80 void compile(List<String> argv) {
81 bool isWindows = (Platform.operatingSystem == 'windows'); 81 bool isWindows = (Platform.operatingSystem == 'windows');
82 Uri libraryRoot = currentDirectory; 82 Uri libraryRoot = currentDirectory;
83 Uri out = currentDirectory.resolve('out.js'); 83 Uri out = currentDirectory.resolve('out.js');
84 Uri sourceMapOut = currentDirectory.resolve('out.js.map'); 84 Uri sourceMapOut = currentDirectory.resolve('out.js.map');
85 Uri packageRoot = null; 85 Uri packageRoot = null;
86 List<String> options = new List<String>(); 86 List<String> options = new List<String>();
87 bool explicitOut = false; 87 bool explicitOut = false;
88 bool wantHelp = false; 88 bool wantHelp = false;
89 bool wantVersion = false;
89 String outputLanguage = 'JavaScript'; 90 String outputLanguage = 'JavaScript';
90 bool stripArgumentSet = false; 91 bool stripArgumentSet = false;
91 bool analyzeOnly = false; 92 bool analyzeOnly = false;
92 SourceFileProvider inputProvider = new SourceFileProvider(); 93 SourceFileProvider inputProvider = new SourceFileProvider();
93 FormattingDiagnosticHandler diagnosticHandler = 94 FormattingDiagnosticHandler diagnosticHandler =
94 new FormattingDiagnosticHandler(inputProvider); 95 new FormattingDiagnosticHandler(inputProvider);
95 96
96 passThrough(String argument) => options.add(argument); 97 passThrough(String argument) => options.add(argument);
97 98
98 if (BUILD_ID != null) { 99 if (BUILD_ID != null) {
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 191
191 List<String> arguments = <String>[]; 192 List<String> arguments = <String>[];
192 List<OptionHandler> handlers = <OptionHandler>[ 193 List<OptionHandler> handlers = <OptionHandler>[
193 new OptionHandler('-[chv?]+', handleShortOptions), 194 new OptionHandler('-[chv?]+', handleShortOptions),
194 new OptionHandler('--throw-on-error', 195 new OptionHandler('--throw-on-error',
195 (_) => diagnosticHandler.throwOnError = true), 196 (_) => diagnosticHandler.throwOnError = true),
196 new OptionHandler('--suppress-warnings', 197 new OptionHandler('--suppress-warnings',
197 (_) => diagnosticHandler.showWarnings = false), 198 (_) => diagnosticHandler.showWarnings = false),
198 new OptionHandler('--output-type=dart|--output-type=js', setOutputType), 199 new OptionHandler('--output-type=dart|--output-type=js', setOutputType),
199 new OptionHandler('--verbose', setVerbose), 200 new OptionHandler('--verbose', setVerbose),
201 new OptionHandler('--version', (_) => wantVersion = true),
200 new OptionHandler('--library-root=.+', setLibraryRoot), 202 new OptionHandler('--library-root=.+', setLibraryRoot),
201 new OptionHandler('--out=.+|-o.+', setOutput), 203 new OptionHandler('--out=.+|-o.+', setOutput),
202 new OptionHandler('--allow-mock-compilation', passThrough), 204 new OptionHandler('--allow-mock-compilation', passThrough),
203 new OptionHandler('--minify', passThrough), 205 new OptionHandler('--minify', passThrough),
204 new OptionHandler('--force-strip=.*', setStrip), 206 new OptionHandler('--force-strip=.*', setStrip),
205 // TODO(ahe): Remove the --no-colors option. 207 // TODO(ahe): Remove the --no-colors option.
206 new OptionHandler('--disable-diagnostic-colors', 208 new OptionHandler('--disable-diagnostic-colors',
207 (_) => diagnosticHandler.enableColors = false), 209 (_) => diagnosticHandler.enableColors = false),
208 new OptionHandler('--enable-diagnostic-colors', 210 new OptionHandler('--enable-diagnostic-colors',
209 (_) => diagnosticHandler.enableColors = true), 211 (_) => diagnosticHandler.enableColors = true),
(...skipping 18 matching lines...) Expand all
228 // The following two options must come last. 230 // The following two options must come last.
229 new OptionHandler('-.*', (String argument) { 231 new OptionHandler('-.*', (String argument) {
230 helpAndFail('Error: Unknown option "$argument".'); 232 helpAndFail('Error: Unknown option "$argument".');
231 }), 233 }),
232 new OptionHandler('.*', (String argument) { 234 new OptionHandler('.*', (String argument) {
233 arguments.add(nativeToUriPath(argument)); 235 arguments.add(nativeToUriPath(argument));
234 }) 236 })
235 ]; 237 ];
236 238
237 parseCommandLine(handlers, argv); 239 parseCommandLine(handlers, argv);
238 if (wantHelp) helpAndExit(diagnosticHandler.verbose); 240 if (wantHelp || wantVersion) {
241 helpAndExit(wantHelp, wantVersion, diagnosticHandler.verbose);
242 }
239 243
240 if (outputLanguage != OUTPUT_LANGUAGE_DART && stripArgumentSet) { 244 if (outputLanguage != OUTPUT_LANGUAGE_DART && stripArgumentSet) {
241 helpAndFail('Error: --force-strip may only be used with ' 245 helpAndFail('Error: --force-strip may only be used with '
242 '--output-type=dart'); 246 '--output-type=dart');
243 } 247 }
244 if (arguments.isEmpty) { 248 if (arguments.isEmpty) {
245 helpAndFail('Error: No Dart file specified.'); 249 helpAndFail('Error: No Dart file specified.');
246 } 250 }
247 if (arguments.length > 1) { 251 if (arguments.length > 1) {
248 var extra = arguments.sublist(1); 252 var extra = arguments.sublist(1);
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
406 410
407 -c, --enable-checked-mode, --checked 411 -c, --enable-checked-mode, --checked
408 Insert runtime type checks and enable assertions (checked mode). 412 Insert runtime type checks and enable assertions (checked mode).
409 413
410 -h, /h, /?, --help 414 -h, /h, /?, --help
411 Display this message (add -v for information about all options). 415 Display this message (add -v for information about all options).
412 416
413 -v, --verbose 417 -v, --verbose
414 Display verbose information. 418 Display verbose information.
415 419
420 --version
421 Display version information.
422
416 -p<path>, --package-root=<path> 423 -p<path>, --package-root=<path>
417 Where to find packages, that is, "package:..." imports. 424 Where to find packages, that is, "package:..." imports.
418 425
419 --analyze-all 426 --analyze-all
420 Analyze all code. Without this option, the compiler only analyzes 427 Analyze all code. Without this option, the compiler only analyzes
421 code that is reachable from [main]. This option is useful for 428 code that is reachable from [main]. This option is useful for
422 finding errors in libraries, but using it can result in bigger and 429 finding errors in libraries, but using it can result in bigger and
423 slower output. 430 slower output.
424 431
425 --analyze-only 432 --analyze-only
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
480 487
481 --categories=<categories> 488 --categories=<categories>
482 A comma separated list of allowed library categories. The default 489 A comma separated list of allowed library categories. The default
483 is "Client". Possible categories can be seen by providing an 490 is "Client". Possible categories can be seen by providing an
484 unsupported category, for example, --categories=help. To enable 491 unsupported category, for example, --categories=help. To enable
485 all categories, use --categories=all. 492 all categories, use --categories=all.
486 493
487 '''.trim()); 494 '''.trim());
488 } 495 }
489 496
490 void helpAndExit(bool verbose) { 497 void helpAndExit(bool wantHelp, bool wantVersion, bool verbose) {
491 if (verbose) { 498 if (wantVersion) {
492 verboseHelp(); 499 var version = (BUILD_ID == null)
493 } else { 500 ? '<non-SDK build>'
494 help(); 501 : BUILD_ID;
502 print('Dart-to-JavaScript compiler (dart2js) version: $version');
503 }
504 if (wantHelp) {
505 if (verbose) {
506 verboseHelp();
507 } else {
508 help();
509 }
495 } 510 }
496 exit(0); 511 exit(0);
497 } 512 }
498 513
499 void helpAndFail(String message) { 514 void helpAndFail(String message) {
500 help(); 515 help();
501 print(''); 516 print('');
502 fail(message); 517 fail(message);
503 } 518 }
504 519
(...skipping 10 matching lines...) Expand all
515 print(trace); 530 print(trace);
516 } finally { 531 } finally {
517 exit(253); // 253 is recognized as a crash by our test scripts. 532 exit(253); // 253 is recognized as a crash by our test scripts.
518 } 533 }
519 } 534 }
520 } 535 }
521 536
522 void main() { 537 void main() {
523 mainWithErrorHandler(new Options()); 538 mainWithErrorHandler(new Options());
524 } 539 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698