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 'io/source_file.dart'; | 15 import 'io/source_file.dart'; |
16 import 'source_file_provider.dart'; | 16 import 'source_file_provider.dart'; |
17 import 'filenames.dart'; | 17 import 'filenames.dart'; |
18 import 'util/uri_extras.dart'; | 18 import 'util/uri_extras.dart'; |
19 import 'util/util.dart' show stackTraceFilePrefix; | 19 import 'util/util.dart' show stackTraceFilePrefix; |
20 import 'util/command_line.dart'; | 20 import 'util/command_line.dart'; |
21 import 'package:_internal/libraries.dart'; | 21 import 'package:_internal/libraries.dart'; |
22 import 'package:package_config/discovery.dart' show findPackages; | |
23 | 22 |
24 const String LIBRARY_ROOT = '../../../../../sdk'; | 23 const String LIBRARY_ROOT = '../../../../../sdk'; |
25 const String OUTPUT_LANGUAGE_DART = 'Dart'; | 24 const String OUTPUT_LANGUAGE_DART = 'Dart'; |
26 | 25 |
27 /** | 26 /** |
28 * A string to identify the revision or build. | 27 * A string to identify the revision or build. |
29 * | 28 * |
30 * This ID is displayed if the compiler crashes and in verbose mode, and is | 29 * This ID is displayed if the compiler crashes and in verbose mode, and is |
31 * an aid in reproducing bug reports. | 30 * an aid in reproducing bug reports. |
32 * | 31 * |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 } | 98 } |
100 } | 99 } |
101 | 100 |
102 FormattingDiagnosticHandler diagnosticHandler; | 101 FormattingDiagnosticHandler diagnosticHandler; |
103 | 102 |
104 Future<api.CompilationResult> compile(List<String> argv) { | 103 Future<api.CompilationResult> compile(List<String> argv) { |
105 stackTraceFilePrefix = '$currentDirectory'; | 104 stackTraceFilePrefix = '$currentDirectory'; |
106 Uri libraryRoot = currentDirectory; | 105 Uri libraryRoot = currentDirectory; |
107 Uri out = currentDirectory.resolve('out.js'); | 106 Uri out = currentDirectory.resolve('out.js'); |
108 Uri sourceMapOut = currentDirectory.resolve('out.js.map'); | 107 Uri sourceMapOut = currentDirectory.resolve('out.js.map'); |
109 Uri packageConfig = null; | |
110 Uri packageRoot = null; | 108 Uri packageRoot = null; |
111 List<String> options = new List<String>(); | 109 List<String> options = new List<String>(); |
112 bool explicitOut = false; | 110 bool explicitOut = false; |
113 bool wantHelp = false; | 111 bool wantHelp = false; |
114 bool wantVersion = false; | 112 bool wantVersion = false; |
115 String outputLanguage = 'JavaScript'; | 113 String outputLanguage = 'JavaScript'; |
116 bool stripArgumentSet = false; | 114 bool stripArgumentSet = false; |
117 bool analyzeOnly = false; | 115 bool analyzeOnly = false; |
118 bool analyzeAll = false; | 116 bool analyzeAll = false; |
119 bool dumpInfo = false; | 117 bool dumpInfo = false; |
(...skipping 15 matching lines...) Expand all Loading... |
135 } | 133 } |
136 | 134 |
137 setLibraryRoot(String argument) { | 135 setLibraryRoot(String argument) { |
138 libraryRoot = currentDirectory.resolve(extractPath(argument)); | 136 libraryRoot = currentDirectory.resolve(extractPath(argument)); |
139 } | 137 } |
140 | 138 |
141 setPackageRoot(String argument) { | 139 setPackageRoot(String argument) { |
142 packageRoot = currentDirectory.resolve(extractPath(argument)); | 140 packageRoot = currentDirectory.resolve(extractPath(argument)); |
143 } | 141 } |
144 | 142 |
145 setPackageConfig(String argument) { | |
146 packageConfig = currentDirectory.resolve(extractPath(argument)); | |
147 } | |
148 | |
149 setOutput(Iterator<String> arguments) { | 143 setOutput(Iterator<String> arguments) { |
150 optionsImplyCompilation.add(arguments.current); | 144 optionsImplyCompilation.add(arguments.current); |
151 String path; | 145 String path; |
152 if (arguments.current == '-o') { | 146 if (arguments.current == '-o') { |
153 if (!arguments.moveNext()) { | 147 if (!arguments.moveNext()) { |
154 helpAndFail('Error: Missing file after -o option.'); | 148 helpAndFail('Error: Missing file after -o option.'); |
155 } | 149 } |
156 path = arguments.current; | 150 path = arguments.current; |
157 } else { | 151 } else { |
158 path = extractParameter(arguments.current); | 152 path = extractParameter(arguments.current); |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
328 new OptionHandler('--enable-concrete-type-inference', | 322 new OptionHandler('--enable-concrete-type-inference', |
329 (_) => implyCompilation( | 323 (_) => implyCompilation( |
330 '--enable-concrete-type-inference')), | 324 '--enable-concrete-type-inference')), |
331 new OptionHandler('--trust-type-annotations', | 325 new OptionHandler('--trust-type-annotations', |
332 (_) => setTrustTypeAnnotations( | 326 (_) => setTrustTypeAnnotations( |
333 '--trust-type-annotations')), | 327 '--trust-type-annotations')), |
334 new OptionHandler('--trust-primitives', | 328 new OptionHandler('--trust-primitives', |
335 (_) => setTrustPrimitives( | 329 (_) => setTrustPrimitives( |
336 '--trust-primitives')), | 330 '--trust-primitives')), |
337 new OptionHandler(r'--help|/\?|/h', (_) => wantHelp = true), | 331 new OptionHandler(r'--help|/\?|/h', (_) => wantHelp = true), |
338 new OptionHandler('--packages=.+', setPackageConfig), | |
339 new OptionHandler('--package-root=.+|-p.+', setPackageRoot), | 332 new OptionHandler('--package-root=.+|-p.+', setPackageRoot), |
340 new OptionHandler('--analyze-all', setAnalyzeAll), | 333 new OptionHandler('--analyze-all', setAnalyzeAll), |
341 new OptionHandler('--analyze-only', setAnalyzeOnly), | 334 new OptionHandler('--analyze-only', setAnalyzeOnly), |
342 new OptionHandler('--no-source-maps', passThrough), | 335 new OptionHandler('--no-source-maps', passThrough), |
343 new OptionHandler('--analyze-signatures-only', setAnalyzeOnly), | 336 new OptionHandler('--analyze-signatures-only', setAnalyzeOnly), |
344 new OptionHandler('--disable-native-live-type-analysis', passThrough), | 337 new OptionHandler('--disable-native-live-type-analysis', passThrough), |
345 new OptionHandler('--categories=.*', setCategories), | 338 new OptionHandler('--categories=.*', setCategories), |
346 new OptionHandler('--disable-type-inference', implyCompilation), | 339 new OptionHandler('--disable-type-inference', implyCompilation), |
347 new OptionHandler('--terse', passThrough), | 340 new OptionHandler('--terse', passThrough), |
348 new OptionHandler('--deferred-map=.+', implyCompilation), | 341 new OptionHandler('--deferred-map=.+', implyCompilation), |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
403 if (arguments.length > 1) { | 396 if (arguments.length > 1) { |
404 var extra = arguments.sublist(1); | 397 var extra = arguments.sublist(1); |
405 helpAndFail('Extra arguments: ${extra.join(" ")}'); | 398 helpAndFail('Extra arguments: ${extra.join(" ")}'); |
406 } | 399 } |
407 | 400 |
408 if (checkedMode && trustTypeAnnotations) { | 401 if (checkedMode && trustTypeAnnotations) { |
409 helpAndFail("Option '--trust-type-annotations' may not be used in " | 402 helpAndFail("Option '--trust-type-annotations' may not be used in " |
410 "checked mode."); | 403 "checked mode."); |
411 } | 404 } |
412 | 405 |
413 if (packageRoot != null && packageConfig != null) { | 406 Uri uri = currentDirectory.resolve(arguments[0]); |
414 helpAndFail("Cannot specify both '--package-root' and '--packages."); | 407 if (packageRoot == null) { |
| 408 packageRoot = uri.resolve('./packages/'); |
415 } | 409 } |
416 | 410 |
417 if ((analyzeOnly || analyzeAll) && !optionsImplyCompilation.isEmpty) { | 411 if ((analyzeOnly || analyzeAll) && !optionsImplyCompilation.isEmpty) { |
418 if (!analyzeOnly) { | 412 if (!analyzeOnly) { |
419 diagnosticHandler.info( | 413 diagnosticHandler.info( |
420 "Option '--analyze-all' implies '--analyze-only'.", | 414 "Option '--analyze-all' implies '--analyze-only'.", |
421 api.Diagnostic.INFO); | 415 api.Diagnostic.INFO); |
422 } | 416 } |
423 diagnosticHandler.info( | 417 diagnosticHandler.info( |
424 "Options $optionsImplyCompilation indicate that output is expected, " | 418 "Options $optionsImplyCompilation indicate that output is expected, " |
425 "but compilation is turned off by the option '--analyze-only'.", | 419 "but compilation is turned off by the option '--analyze-only'.", |
426 api.Diagnostic.INFO); | 420 api.Diagnostic.INFO); |
427 } | 421 } |
428 if (analyzeAll) analyzeOnly = true; | 422 if (analyzeAll) analyzeOnly = true; |
429 if (!analyzeOnly) { | 423 if (!analyzeOnly) { |
430 if (allowNativeExtensions) { | 424 if (allowNativeExtensions) { |
431 helpAndFail("Option '--allow-native-extensions' is only supported in " | 425 helpAndFail("Option '--allow-native-extensions' is only supported in " |
432 "combination with the '--analyze-only' option."); | 426 "combination with the '--analyze-only' option."); |
433 } | 427 } |
434 } | 428 } |
435 if (dumpInfo && outputLanguage == OUTPUT_LANGUAGE_DART) { | 429 if (dumpInfo && outputLanguage == OUTPUT_LANGUAGE_DART) { |
436 helpAndFail("Option '--dump-info' is not supported in " | 430 helpAndFail("Option '--dump-info' is not supported in " |
437 "combination with the '--output-type=dart' option."); | 431 "combination with the '--output-type=dart' option."); |
438 } | 432 } |
439 | 433 |
| 434 diagnosticHandler.info('Package root is $packageRoot'); |
| 435 |
440 options.add('--out=$out'); | 436 options.add('--out=$out'); |
441 options.add('--source-map=$sourceMapOut'); | 437 options.add('--source-map=$sourceMapOut'); |
442 | 438 |
443 RandomAccessFileOutputProvider outputProvider = | 439 RandomAccessFileOutputProvider outputProvider = |
444 new RandomAccessFileOutputProvider( | 440 new RandomAccessFileOutputProvider( |
445 out, sourceMapOut, onInfo: diagnosticHandler.info, onFailure: fail); | 441 out, sourceMapOut, onInfo: diagnosticHandler.info, onFailure: fail); |
446 | 442 |
447 api.CompilationResult compilationDone(api.CompilationResult result) { | 443 api.CompilationResult compilationDone(api.CompilationResult result) { |
448 if (analyzeOnly) return result; | 444 if (analyzeOnly) return result; |
449 if (!result.isSuccess) { | 445 if (!result.isSuccess) { |
(...skipping 14 matching lines...) Expand all Loading... |
464 print(" $filename"); | 460 print(" $filename"); |
465 } | 461 } |
466 } else if (!explicitOut) { | 462 } else if (!explicitOut) { |
467 String input = uriPathToNative(arguments[0]); | 463 String input = uriPathToNative(arguments[0]); |
468 String output = relativize(currentDirectory, out, Platform.isWindows); | 464 String output = relativize(currentDirectory, out, Platform.isWindows); |
469 print('Dart file ($input) compiled to $outputLanguage: $output'); | 465 print('Dart file ($input) compiled to $outputLanguage: $output'); |
470 } | 466 } |
471 return result; | 467 return result; |
472 } | 468 } |
473 | 469 |
474 Uri uri = currentDirectory.resolve(arguments[0]); | 470 return compileFunc(uri, libraryRoot, packageRoot, |
475 return compileFunc(uri, libraryRoot, packageRoot, inputProvider, | 471 inputProvider, diagnosticHandler, |
476 diagnosticHandler, options, outputProvider, environment, | 472 options, outputProvider, environment) |
477 packageConfig, findPackages) | |
478 .then(compilationDone); | 473 .then(compilationDone); |
479 } | 474 } |
480 | 475 |
481 class AbortLeg { | 476 class AbortLeg { |
482 final message; | 477 final message; |
483 AbortLeg(this.message); | 478 AbortLeg(this.message); |
484 toString() => 'Aborted due to --throw-on-error: $message'; | 479 toString() => 'Aborted due to --throw-on-error: $message'; |
485 } | 480 } |
486 | 481 |
487 void writeString(Uri uri, String text) { | 482 void writeString(Uri uri, String text) { |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
549 -v, --verbose | 544 -v, --verbose |
550 Display verbose information. | 545 Display verbose information. |
551 | 546 |
552 -D<name>=<value> | 547 -D<name>=<value> |
553 Define an environment variable. | 548 Define an environment variable. |
554 | 549 |
555 --version | 550 --version |
556 Display version information. | 551 Display version information. |
557 | 552 |
558 -p<path>, --package-root=<path> | 553 -p<path>, --package-root=<path> |
559 Where to find packages, that is, "package:..." imports. This option cannot | 554 Where to find packages, that is, "package:..." imports. |
560 be used with --packages. | |
561 | |
562 --packages=<path> | |
563 Path to the package resolution configuration file, which supplies a mapping | |
564 of package names to paths. This option cannot be used with --package-root. | |
565 | 555 |
566 --analyze-all | 556 --analyze-all |
567 Analyze all code. Without this option, the compiler only analyzes | 557 Analyze all code. Without this option, the compiler only analyzes |
568 code that is reachable from [main]. This option implies --analyze-only. | 558 code that is reachable from [main]. This option implies --analyze-only. |
569 | 559 |
570 --analyze-only | 560 --analyze-only |
571 Analyze but do not generate code. | 561 Analyze but do not generate code. |
572 | 562 |
573 --analyze-signatures-only | 563 --analyze-signatures-only |
574 Skip analysis of method bodies and field initializers. This option implies | 564 Skip analysis of method bodies and field initializers. This option implies |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
754 } else if (exitCode == 253) { | 744 } else if (exitCode == 253) { |
755 print(">>> TEST CRASH"); | 745 print(">>> TEST CRASH"); |
756 } else { | 746 } else { |
757 print(">>> TEST FAIL"); | 747 print(">>> TEST FAIL"); |
758 } | 748 } |
759 stderr.writeln(">>> EOF STDERR"); | 749 stderr.writeln(">>> EOF STDERR"); |
760 subscription.resume(); | 750 subscription.resume(); |
761 }); | 751 }); |
762 }); | 752 }); |
763 } | 753 } |
OLD | NEW |