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 show Future, EventSink; | 8 show Future, EventSink; |
9 import 'dart:convert' show UTF8, LineSplitter; | 9 import 'dart:convert' show UTF8, LineSplitter; |
10 import 'dart:io' | 10 import 'dart:io' |
11 show exit, File, FileMode, Platform, RandomAccessFile, FileSystemException, | 11 show exit, File, FileMode, Platform, RandomAccessFile, FileSystemException, |
12 stdin, stderr; | 12 stdin, stderr; |
13 | 13 |
14 import '../compiler.dart' as api; | 14 import '../compiler.dart' as api; |
| 15 import 'commandline_options.dart'; |
15 import 'io/source_file.dart'; | 16 import 'io/source_file.dart'; |
16 import 'source_file_provider.dart'; | 17 import 'source_file_provider.dart'; |
17 import 'filenames.dart'; | 18 import 'filenames.dart'; |
18 import 'util/uri_extras.dart'; | 19 import 'util/uri_extras.dart'; |
19 import 'util/util.dart' show stackTraceFilePrefix; | 20 import 'util/util.dart' show stackTraceFilePrefix; |
20 import 'util/command_line.dart'; | 21 import 'util/command_line.dart'; |
21 import 'package:sdk_library_metadata/libraries.dart'; | 22 import 'package:sdk_library_metadata/libraries.dart'; |
22 import 'package:package_config/discovery.dart' show findPackages; | 23 import 'package:package_config/discovery.dart' show findPackages; |
23 | 24 |
24 const String LIBRARY_ROOT = '../../../../../sdk'; | 25 const String LIBRARY_ROOT = '../../../../../sdk'; |
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
279 for (var shortOption in shortOptions) { | 280 for (var shortOption in shortOptions) { |
280 switch (shortOption) { | 281 switch (shortOption) { |
281 case 'v': | 282 case 'v': |
282 setVerbose(null); | 283 setVerbose(null); |
283 break; | 284 break; |
284 case 'h': | 285 case 'h': |
285 case '?': | 286 case '?': |
286 wantHelp = true; | 287 wantHelp = true; |
287 break; | 288 break; |
288 case 'c': | 289 case 'c': |
289 setCheckedMode('--enable-checked-mode'); | 290 setCheckedMode(Flags.enableCheckedMode); |
290 break; | 291 break; |
291 case 'm': | 292 case 'm': |
292 implyCompilation('--minify'); | 293 implyCompilation(Flags.minify); |
293 break; | 294 break; |
294 default: | 295 default: |
295 throw 'Internal error: "$shortOption" did not match'; | 296 throw 'Internal error: "$shortOption" did not match'; |
296 } | 297 } |
297 } | 298 } |
298 } | 299 } |
299 | 300 |
300 List<String> arguments = <String>[]; | 301 List<String> arguments = <String>[]; |
301 List<OptionHandler> handlers = <OptionHandler>[ | 302 List<OptionHandler> handlers = <OptionHandler>[ |
302 new OptionHandler('-[chvm?]+', handleShortOptions), | 303 new OptionHandler('-[chvm?]+', handleShortOptions), |
303 new OptionHandler('--throw-on-error(?:=[0-9]+)?', handleThrowOnError), | 304 new OptionHandler('--throw-on-error(?:=[0-9]+)?', handleThrowOnError), |
304 new OptionHandler('--suppress-warnings', (_) { | 305 new OptionHandler(Flags.suppressWarnings, (_) { |
305 diagnosticHandler.showWarnings = false; | 306 diagnosticHandler.showWarnings = false; |
306 passThrough('--suppress-warnings'); | 307 passThrough(Flags.suppressWarnings); |
307 }), | 308 }), |
308 new OptionHandler('--fatal-warnings', passThrough), | 309 new OptionHandler(Flags.fatalWarnings, passThrough), |
309 new OptionHandler('--suppress-hints', | 310 new OptionHandler(Flags.suppressHints, |
310 (_) => diagnosticHandler.showHints = false), | 311 (_) => diagnosticHandler.showHints = false), |
311 new OptionHandler( | 312 new OptionHandler( |
312 '--output-type=dart|--output-type=dart-multi|--output-type=js', | 313 '--output-type=dart|--output-type=dart-multi|--output-type=js', |
313 setOutputType), | 314 setOutputType), |
314 new OptionHandler('--use-cps-ir', passThrough), | 315 new OptionHandler(Flags.useCpsIr, passThrough), |
315 new OptionHandler('--no-frequency-based-minification', passThrough), | 316 new OptionHandler(Flags.noFrequencyBasedMinification, passThrough), |
316 new OptionHandler('--verbose', setVerbose), | 317 new OptionHandler(Flags.verbose, setVerbose), |
317 new OptionHandler('--version', (_) => wantVersion = true), | 318 new OptionHandler(Flags.version, (_) => wantVersion = true), |
318 new OptionHandler('--library-root=.+', setLibraryRoot), | 319 new OptionHandler('--library-root=.+', setLibraryRoot), |
319 new OptionHandler('--out=.+|-o.*', setOutput, multipleArguments: true), | 320 new OptionHandler('--out=.+|-o.*', setOutput, multipleArguments: true), |
320 new OptionHandler('--allow-mock-compilation', passThrough), | 321 new OptionHandler(Flags.allowMockCompilation, passThrough), |
321 new OptionHandler('--fast-startup', passThrough), | 322 new OptionHandler(Flags.fastStartup, passThrough), |
322 new OptionHandler('--minify|-m', implyCompilation), | 323 new OptionHandler('${Flags.minify}|-m', implyCompilation), |
323 new OptionHandler('--preserve-uris', passThrough), | 324 new OptionHandler(Flags.preserveUris, passThrough), |
324 new OptionHandler('--force-strip=.*', setStrip), | 325 new OptionHandler('--force-strip=.*', setStrip), |
325 new OptionHandler('--disable-diagnostic-colors', | 326 new OptionHandler(Flags.disableDiagnosticColors, |
326 (_) => diagnosticHandler.enableColors = false), | 327 (_) => diagnosticHandler.enableColors = false), |
327 new OptionHandler('--enable-diagnostic-colors', | 328 new OptionHandler(Flags.enableDiagnosticColors, |
328 (_) => diagnosticHandler.enableColors = true), | 329 (_) => diagnosticHandler.enableColors = true), |
329 new OptionHandler('--enable[_-]checked[_-]mode|--checked', | 330 new OptionHandler('--enable[_-]checked[_-]mode|--checked', |
330 (_) => setCheckedMode('--enable-checked-mode')), | 331 (_) => setCheckedMode(Flags.enableCheckedMode)), |
331 new OptionHandler('--enable-concrete-type-inference', | 332 new OptionHandler(Flags.enableConcreteTypeInference, |
332 (_) => implyCompilation( | 333 (_) => implyCompilation( |
333 '--enable-concrete-type-inference')), | 334 Flags.enableConcreteTypeInference)), |
334 new OptionHandler('--trust-type-annotations', | 335 new OptionHandler(Flags.trustTypeAnnotations, |
335 (_) => setTrustTypeAnnotations( | 336 (_) => setTrustTypeAnnotations( |
336 '--trust-type-annotations')), | 337 Flags.trustTypeAnnotations)), |
337 new OptionHandler('--trust-primitives', | 338 new OptionHandler(Flags.trustPrimitives, |
338 (_) => setTrustPrimitives( | 339 (_) => setTrustPrimitives( |
339 '--trust-primitives')), | 340 Flags.trustPrimitives)), |
340 new OptionHandler(r'--help|/\?|/h', (_) => wantHelp = true), | 341 new OptionHandler(r'--help|/\?|/h', (_) => wantHelp = true), |
341 new OptionHandler('--packages=.+', setPackageConfig), | 342 new OptionHandler('--packages=.+', setPackageConfig), |
342 new OptionHandler('--package-root=.+|-p.+', setPackageRoot), | 343 new OptionHandler('--package-root=.+|-p.+', setPackageRoot), |
343 new OptionHandler('--analyze-all', setAnalyzeAll), | 344 new OptionHandler(Flags.analyzeAll, setAnalyzeAll), |
344 new OptionHandler('--analyze-only', setAnalyzeOnly), | 345 new OptionHandler(Flags.analyzeOnly, setAnalyzeOnly), |
345 new OptionHandler('--no-source-maps', passThrough), | 346 new OptionHandler(Flags.noSourceMaps, passThrough), |
346 new OptionHandler('--analyze-signatures-only', setAnalyzeOnly), | 347 new OptionHandler(Flags.analyzeSignaturesOnly, setAnalyzeOnly), |
347 new OptionHandler('--disable-native-live-type-analysis', passThrough), | 348 new OptionHandler(Flags.disableNativeLiveTypeAnalysis, passThrough), |
348 new OptionHandler('--categories=.*', setCategories), | 349 new OptionHandler('--categories=.*', setCategories), |
349 new OptionHandler('--disable-type-inference', implyCompilation), | 350 new OptionHandler(Flags.disableTypeInference, implyCompilation), |
350 new OptionHandler('--terse', passThrough), | 351 new OptionHandler(Flags.terse, passThrough), |
351 new OptionHandler('--deferred-map=.+', implyCompilation), | 352 new OptionHandler('--deferred-map=.+', implyCompilation), |
352 new OptionHandler('--dump-info', setDumpInfo), | 353 new OptionHandler(Flags.dumpInfo, setDumpInfo), |
353 new OptionHandler('--disallow-unsafe-eval', | 354 new OptionHandler('--disallow-unsafe-eval', |
354 (_) => hasDisallowUnsafeEval = true), | 355 (_) => hasDisallowUnsafeEval = true), |
355 new OptionHandler('--show-package-warnings', passThrough), | 356 new OptionHandler(Flags.showPackageWarnings, passThrough), |
356 new OptionHandler('--csp', passThrough), | 357 new OptionHandler(Flags.useContentSecurityPolicy, passThrough), |
357 new OptionHandler('--enable-experimental-mirrors', passThrough), | 358 new OptionHandler(Flags.enableExperimentalMirrors, passThrough), |
358 new OptionHandler('--enable-async', (_) { | 359 new OptionHandler('--enable-async', (_) { |
359 diagnosticHandler.info( | 360 diagnosticHandler.info( |
360 "Option '--enable-async' is no longer needed. " | 361 "Option '--enable-async' is no longer needed. " |
361 "Async-await is supported by default.", | 362 "Async-await is supported by default.", |
362 api.Diagnostic.HINT); | 363 api.Diagnostic.HINT); |
363 }), | 364 }), |
364 new OptionHandler('--enable-null-aware-operators', (_) { | 365 new OptionHandler('--enable-null-aware-operators', (_) { |
365 diagnosticHandler.info( | 366 diagnosticHandler.info( |
366 "Option '--enable-null-aware-operators' is no longer needed. " | 367 "Option '--enable-null-aware-operators' is no longer needed. " |
367 "Null aware operators are supported by default.", | 368 "Null aware operators are supported by default.", |
368 api.Diagnostic.HINT); | 369 api.Diagnostic.HINT); |
369 }), | 370 }), |
370 new OptionHandler('--enable-enum', (_) { | 371 new OptionHandler('--enable-enum', (_) { |
371 diagnosticHandler.info( | 372 diagnosticHandler.info( |
372 "Option '--enable-enum' is no longer needed. " | 373 "Option '--enable-enum' is no longer needed. " |
373 "Enums are supported by default.", | 374 "Enums are supported by default.", |
374 api.Diagnostic.HINT); | 375 api.Diagnostic.HINT); |
375 }), | 376 }), |
376 new OptionHandler('--allow-native-extensions', setAllowNativeExtensions), | 377 new OptionHandler(Flags.allowNativeExtensions, setAllowNativeExtensions), |
377 new OptionHandler('--generate-code-with-compile-time-errors', passThrough), | 378 new OptionHandler(Flags.generateCodeWithCompileTimeErrors, passThrough), |
378 new OptionHandler('--test-mode', passThrough), | 379 new OptionHandler(Flags.testMode, passThrough), |
379 | 380 |
380 // The following three options must come last. | 381 // The following three options must come last. |
381 new OptionHandler('-D.+=.*', addInEnvironment), | 382 new OptionHandler('-D.+=.*', addInEnvironment), |
382 new OptionHandler('-.*', (String argument) { | 383 new OptionHandler('-.*', (String argument) { |
383 helpAndFail("Unknown option '$argument'."); | 384 helpAndFail("Unknown option '$argument'."); |
384 }), | 385 }), |
385 new OptionHandler('.*', (String argument) { | 386 new OptionHandler('.*', (String argument) { |
386 arguments.add(nativeToUriPath(argument)); | 387 arguments.add(nativeToUriPath(argument)); |
387 }) | 388 }) |
388 ]; | 389 ]; |
(...skipping 19 matching lines...) Expand all Loading... |
408 } | 409 } |
409 if (arguments.isEmpty) { | 410 if (arguments.isEmpty) { |
410 helpAndFail('No Dart file specified.'); | 411 helpAndFail('No Dart file specified.'); |
411 } | 412 } |
412 if (arguments.length > 1) { | 413 if (arguments.length > 1) { |
413 var extra = arguments.sublist(1); | 414 var extra = arguments.sublist(1); |
414 helpAndFail('Extra arguments: ${extra.join(" ")}'); | 415 helpAndFail('Extra arguments: ${extra.join(" ")}'); |
415 } | 416 } |
416 | 417 |
417 if (checkedMode && trustTypeAnnotations) { | 418 if (checkedMode && trustTypeAnnotations) { |
418 helpAndFail("Option '--trust-type-annotations' may not be used in " | 419 helpAndFail("Option '${Flags.trustTypeAnnotations}' may not be used in " |
419 "checked mode."); | 420 "checked mode."); |
420 } | 421 } |
421 | 422 |
422 if (packageRoot != null && packageConfig != null) { | 423 if (packageRoot != null && packageConfig != null) { |
423 helpAndFail("Cannot specify both '--package-root' and '--packages."); | 424 helpAndFail("Cannot specify both '--package-root' and '--packages."); |
424 } | 425 } |
425 | 426 |
426 if ((analyzeOnly || analyzeAll) && !optionsImplyCompilation.isEmpty) { | 427 if ((analyzeOnly || analyzeAll) && !optionsImplyCompilation.isEmpty) { |
427 if (!analyzeOnly) { | 428 if (!analyzeOnly) { |
428 diagnosticHandler.info( | 429 diagnosticHandler.info( |
429 "Option '--analyze-all' implies '--analyze-only'.", | 430 "Option '${Flags.analyzeAll}' implies '${Flags.analyzeOnly}'.", |
430 api.Diagnostic.INFO); | 431 api.Diagnostic.INFO); |
431 } | 432 } |
432 diagnosticHandler.info( | 433 diagnosticHandler.info( |
433 "Options $optionsImplyCompilation indicate that output is expected, " | 434 "Options $optionsImplyCompilation indicate that output is expected, " |
434 "but compilation is turned off by the option '--analyze-only'.", | 435 "but compilation is turned off by the option '${Flags.analyzeOnly}'.", |
435 api.Diagnostic.INFO); | 436 api.Diagnostic.INFO); |
436 } | 437 } |
437 if (analyzeAll) analyzeOnly = true; | 438 if (analyzeAll) analyzeOnly = true; |
438 if (!analyzeOnly) { | 439 if (!analyzeOnly) { |
439 if (allowNativeExtensions) { | 440 if (allowNativeExtensions) { |
440 helpAndFail("Option '--allow-native-extensions' is only supported in " | 441 helpAndFail("Option '${Flags.allowNativeExtensions}' is only supported " |
441 "combination with the '--analyze-only' option."); | 442 "in combination with the '${Flags.analyzeOnly}' option."); |
442 } | 443 } |
443 } | 444 } |
444 if (dumpInfo && outputLanguage == OUTPUT_LANGUAGE_DART) { | 445 if (dumpInfo && outputLanguage == OUTPUT_LANGUAGE_DART) { |
445 helpAndFail("Option '--dump-info' is not supported in " | 446 helpAndFail("Option '${Flags.dumpInfo}' is not supported in " |
446 "combination with the '--output-type=dart' option."); | 447 "combination with the '--output-type=dart' option."); |
447 } | 448 } |
448 | 449 |
449 options.add('--out=$out'); | 450 options.add('--out=$out'); |
450 options.add('--source-map=$sourceMapOut'); | 451 options.add('--source-map=$sourceMapOut'); |
451 | 452 |
452 RandomAccessFileOutputProvider outputProvider = | 453 RandomAccessFileOutputProvider outputProvider = |
453 new RandomAccessFileOutputProvider( | 454 new RandomAccessFileOutputProvider( |
454 out, sourceMapOut, onInfo: diagnosticHandler.info, onFailure: fail); | 455 out, sourceMapOut, onInfo: diagnosticHandler.info, onFailure: fail); |
455 | 456 |
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
767 } else if (exitCode == 253) { | 768 } else if (exitCode == 253) { |
768 print(">>> TEST CRASH"); | 769 print(">>> TEST CRASH"); |
769 } else { | 770 } else { |
770 print(">>> TEST FAIL"); | 771 print(">>> TEST FAIL"); |
771 } | 772 } |
772 stderr.writeln(">>> EOF STDERR"); | 773 stderr.writeln(">>> EOF STDERR"); |
773 subscription.resume(); | 774 subscription.resume(); |
774 }); | 775 }); |
775 }); | 776 }); |
776 } | 777 } |
OLD | NEW |