| OLD | NEW |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 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 | 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 fasta.compiler_command_line; | 5 library fasta.compiler_command_line; |
| 6 | 6 |
| 7 import 'dart:io' show exit; | 7 import 'dart:io' show exit; |
| 8 | 8 |
| 9 import 'command_line.dart' show CommandLine, deprecated_argumentError; | 9 import 'command_line.dart' show CommandLine, deprecated_argumentError; |
| 10 | 10 |
| 11 import 'compiler_context.dart' show CompilerContext; | 11 import 'compiler_context.dart' show CompilerContext; |
| 12 | 12 |
| 13 import 'package:kernel/target/targets.dart' | 13 import 'package:kernel/target/targets.dart' |
| 14 show Target, getTarget, TargetFlags, targets; | 14 show Target, getTarget, TargetFlags, targets; |
| 15 | 15 |
| 16 import 'fasta_codes.dart' |
| 17 show FastaMessage, codeFastaUsageLong, codeFastaUsageShort, codeUnspecified; |
| 18 |
| 16 const Map<String, dynamic> optionSpecification = const <String, dynamic>{ | 19 const Map<String, dynamic> optionSpecification = const <String, dynamic>{ |
| 17 "--compile-sdk": Uri, | 20 "--compile-sdk": Uri, |
| 18 "--fatal": ",", | 21 "--fatal": ",", |
| 19 "--output": Uri, | 22 "--output": Uri, |
| 20 "-o": Uri, | 23 "-o": Uri, |
| 21 "--packages": Uri, | 24 "--packages": Uri, |
| 22 "--platform": Uri, | 25 "--platform": Uri, |
| 23 "--sdk": Uri, | 26 "--sdk": Uri, |
| 24 "--target": String, | 27 "--target": String, |
| 25 "-t": String, | 28 "-t": String, |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 dynamic f(CompilerContext context)) { | 124 dynamic f(CompilerContext context)) { |
| 122 return CompilerContext.withGlobalOptions( | 125 return CompilerContext.withGlobalOptions( |
| 123 new CompilerCommandLine(programName, arguments), f); | 126 new CompilerCommandLine(programName, arguments), f); |
| 124 } | 127 } |
| 125 | 128 |
| 126 static CompilerCommandLine forRootContext() { | 129 static CompilerCommandLine forRootContext() { |
| 127 return new CompilerCommandLine("", [""]); | 130 return new CompilerCommandLine("", [""]); |
| 128 } | 131 } |
| 129 } | 132 } |
| 130 | 133 |
| 131 String computeUsage(String programName, bool verbose) { | 134 FastaMessage computeUsage(String programName, bool verbose) { |
| 132 String basicUsage = "Usage: $programName [options] dartfile\n"; | 135 String basicUsage = "Usage: $programName [options] dartfile\n"; |
| 133 String summary; | 136 String summary; |
| 134 String options = (verbose ? allOptions : frequentOptions).trim(); | 137 String options = |
| 138 (verbose ? codeFastaUsageLong.template : codeFastaUsageShort.template) |
| 139 .trim(); |
| 135 switch (programName) { | 140 switch (programName) { |
| 136 case "outline": | 141 case "outline": |
| 137 summary = | 142 summary = |
| 138 "Creates an outline of a Dart program in the Dill/Kernel IR format."; | 143 "Creates an outline of a Dart program in the Dill/Kernel IR format."; |
| 139 break; | 144 break; |
| 140 | 145 |
| 141 case "compile": | 146 case "compile": |
| 142 summary = "Compiles a Dart program to the Dill/Kernel IR format."; | 147 summary = "Compiles a Dart program to the Dill/Kernel IR format."; |
| 143 break; | 148 break; |
| 144 | 149 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 156 basicUsage = "Usage: $programName [options] patched_sdk fullOutput " | 161 basicUsage = "Usage: $programName [options] patched_sdk fullOutput " |
| 157 "outlineOutput\n"; | 162 "outlineOutput\n"; |
| 158 } | 163 } |
| 159 StringBuffer sb = new StringBuffer(basicUsage); | 164 StringBuffer sb = new StringBuffer(basicUsage); |
| 160 if (summary != null) { | 165 if (summary != null) { |
| 161 sb.writeln(); | 166 sb.writeln(); |
| 162 sb.writeln(summary); | 167 sb.writeln(summary); |
| 163 sb.writeln(); | 168 sb.writeln(); |
| 164 } | 169 } |
| 165 sb.write(options); | 170 sb.write(options); |
| 166 return "$sb"; | 171 // TODO(ahe): Don't use [codeUnspecified]. |
| 172 return codeUnspecified.bind("$sb")(null, -1); |
| 167 } | 173 } |
| 168 | |
| 169 const String frequentOptions = """ | |
| 170 Frequently used options: | |
| 171 | |
| 172 -o <file> Generate the output into <file>. | |
| 173 -h Display this message (add -v for information about all options). | |
| 174 """; | |
| 175 | |
| 176 const String allOptions = """ | |
| 177 Supported options: | |
| 178 | |
| 179 -o <file>, --output=<file> | |
| 180 Generate the output into <file>. | |
| 181 | |
| 182 -h, /h, /?, --help | |
| 183 Display this message (add -v for information about all options). | |
| 184 | |
| 185 -v, --verbose | |
| 186 Display verbose information. | |
| 187 | |
| 188 -- | |
| 189 Stop option parsing, the rest of the command line is assumed to be | |
| 190 file names or arguments to the Dart program. | |
| 191 | |
| 192 --packages=<file> | |
| 193 Use package resolution configuration <file>, which should contain a mapping | |
| 194 of package names to paths. | |
| 195 | |
| 196 --platform=<file> | |
| 197 Read the SDK platform from <file>, which should be in Dill/Kernel IR format | |
| 198 and contain the Dart SDK. | |
| 199 | |
| 200 --target=none|vm|vmcc|vmreify|flutter | |
| 201 Specify the target configuration. | |
| 202 | |
| 203 --verify | |
| 204 Check that the generated output is free of various problems. This is mostly | |
| 205 useful for developers of this compiler or Kernel transformations. | |
| 206 | |
| 207 --dump-ir | |
| 208 Print compiled libraries in Kernel source notation. | |
| 209 | |
| 210 --exclude-source | |
| 211 Do not include source code in the dill file. | |
| 212 | |
| 213 --compile-sdk=<patched_sdk> | |
| 214 Compile the SDK from scratch instead of reading it from 'platform.dill'. | |
| 215 | |
| 216 --sdk=<patched_sdk> | |
| 217 Location of the SDK sources for use when compiling additional platform | |
| 218 libraries. | |
| 219 | |
| 220 --fatal=errors | |
| 221 --fatal=warnings | |
| 222 --fatal=nits | |
| 223 Makes messages of the given kinds fatal, that is, immediately stop the | |
| 224 compiler with a non-zero exit-code. In --verbose mode, also display an | |
| 225 internal stack trace from the compiler. Multiple kinds can be separated by | |
| 226 commas, for example, --fatal=errors,warnings. | |
| 227 """; | |
| OLD | NEW |