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