Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | |
| 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. | |
| 4 | |
| 5 library fasta.compiler_command_line; | |
| 6 | |
| 7 import 'dart:io' show | |
| 8 exit; | |
| 9 | |
| 10 import 'command_line.dart' show | |
| 11 CommandLine, | |
| 12 argumentError; | |
| 13 | |
| 14 const Map<String, dynamic> optionSpecification = const <String, dynamic>{ | |
| 15 "-o": Uri, | |
| 16 "--output": Uri, | |
| 17 "--platform": Uri, | |
| 18 "--packages": Uri, | |
| 19 }; | |
| 20 | |
| 21 class CompilerCommandLine extends CommandLine { | |
| 22 final String programName; | |
| 23 | |
| 24 CompilerCommandLine(String programName, List<String> arguments) | |
| 25 : programName = programName, | |
| 26 super(arguments, specification: optionSpecification, | |
| 27 usage: computeUsage(programName, false)); | |
| 28 | |
| 29 bool get verify => options.containsKey("--verify"); | |
| 30 | |
| 31 bool get dumpIr => options.containsKey("--dump-ir"); | |
| 32 | |
| 33 bool get help { | |
| 34 return options.containsKey("--help") || | |
| 35 options.containsKey("-h") || | |
| 36 options.containsKey("/h") || | |
| 37 options.containsKey("/?"); | |
| 38 } | |
| 39 | |
| 40 void validate() { | |
| 41 if (help) { | |
| 42 print(computeUsage(programName, verbose)); | |
| 43 exit(0); | |
| 44 } | |
| 45 | |
| 46 if (options.containsKey("-o") && options.containsKey("--output")) { | |
| 47 return argumentError(usage, "Can't specify both '-o' and '--output'."); | |
| 48 } | |
| 49 if (options.containsKey("--packages")) { | |
| 50 return argumentError(usage, "Option '--packages' isn't supported yet."); | |
| 51 } | |
| 52 if (arguments.isEmpty) { | |
| 53 return argumentError(usage, "No Dart file specified."); | |
| 54 } | |
| 55 } | |
| 56 | |
| 57 Uri get output { | |
| 58 return options["-o"] ?? options["-o"] ?? defaultOutput; | |
|
Johnni Winther
2017/01/16 09:47:46
Second `options["-o"]` should be `options["--outpu
ahe
2017/01/16 12:07:04
Done.
| |
| 59 } | |
| 60 | |
| 61 Uri get defaultOutput => Uri.base.resolve("${arguments.first}.dill"); | |
| 62 | |
| 63 Uri get platform { | |
| 64 return options["--platform"] ?? Uri.base.resolve("platform.dill"); | |
| 65 } | |
| 66 } | |
| 67 | |
| 68 String computeUsage(String programName, bool verbose) { | |
| 69 String basicUsage = "Usage: $programName [options] dartfile\n"; | |
| 70 String summary; | |
| 71 String options = (verbose ? allOptions : frequentOptions).trim(); | |
| 72 switch (programName) { | |
| 73 case "outline": | |
| 74 summary = | |
| 75 "Creates an outline of a Dart program in the Dill/Kernel IR format."; | |
| 76 break; | |
| 77 | |
| 78 case "compile": | |
| 79 summary = "Compiles a Dart program to the Dill/Kernel IR format."; | |
| 80 break; | |
| 81 | |
| 82 case "kompile": | |
| 83 summary = | |
| 84 "Compiles a Dart program to the Dill/Kernel IR format via dartk."; | |
| 85 break; | |
| 86 | |
| 87 case "run": | |
| 88 summary = "Runs a Dart program."; | |
|
Johnni Winther
2017/01/16 09:47:46
'Compiles and runs' or 'Runs from .dill' or ... ?
ahe
2017/01/16 12:07:04
It compiles and run. But is it important for a usa
| |
| 89 break; | |
| 90 } | |
| 91 StringBuffer sb = new StringBuffer(basicUsage); | |
| 92 if (summary != null) { | |
| 93 sb.writeln(); | |
| 94 sb.writeln(summary); | |
| 95 sb.writeln(); | |
| 96 } | |
| 97 sb.write(options); | |
| 98 return "$sb"; | |
| 99 } | |
| 100 | |
| 101 const String frequentOptions = """ | |
| 102 Frequently used options: | |
| 103 | |
| 104 -o <file> Generate the output into <file>. | |
| 105 -h Display this message (add -v for information about all options). | |
| 106 """; | |
| 107 | |
| 108 const String allOptions = """ | |
| 109 Supported options: | |
| 110 | |
| 111 -o <file>, --out=<file> | |
| 112 Generate the output into <file>. | |
| 113 | |
| 114 -h, /h, /?, --help | |
| 115 Display this message (add -v for information about all options). | |
| 116 | |
| 117 -v, --verbose | |
| 118 Display verbose information. | |
| 119 | |
| 120 -- | |
| 121 Stop option parsing, the rest of the command line is assumed to be | |
| 122 arguments. | |
|
Johnni Winther
2017/01/16 09:47:46
Arguments for what?
ahe
2017/01/16 12:07:04
Changed to: ... is assumed to be file names or arg
| |
| 123 | |
| 124 --packages=<file> | |
| 125 Use package resolution configuration <file>, which should contain a mapping | |
| 126 of package names to paths. | |
| 127 | |
| 128 --platform=<file> | |
| 129 Read the SDK platform from <file>, which should be in Dill/Kernel IR format | |
| 130 and contain the Dart SDK. | |
| 131 | |
| 132 --verify | |
| 133 Check that the generated output is free of various problems. This is mostly | |
| 134 useful for developers of this compiler or Kernel transformations. | |
| 135 | |
| 136 --dump-ir | |
| 137 Print compiled libraries in Kernel source notation. | |
| 138 """; | |
| OLD | NEW |