| 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 'dart:async' show runZoned; |
| 10 |
| 9 import 'package:kernel/target/targets.dart' | 11 import 'package:kernel/target/targets.dart' |
| 10 show Target, getTarget, TargetFlags, targets; | 12 show Target, getTarget, TargetFlags, targets; |
| 11 | 13 |
| 12 import 'command_line.dart' show CommandLine, deprecated_argumentError; | 14 import 'command_line.dart' show CommandLine, deprecated_argumentError; |
| 13 | 15 |
| 14 import 'compiler_context.dart' show CompilerContext; | 16 import 'compiler_context.dart' show CompilerContext, compilerContextKey; |
| 15 | 17 |
| 16 import 'command_line_reporting.dart' as command_line_reporting; | 18 import 'command_line_reporting.dart' as command_line_reporting; |
| 17 | 19 |
| 18 import 'fasta_codes.dart' | 20 import 'fasta_codes.dart' |
| 19 show | 21 show |
| 20 LocatedMessage, | 22 LocatedMessage, |
| 21 Message, | 23 Message, |
| 22 messageFastaUsageLong, | 24 messageFastaUsageLong, |
| 23 messageFastaUsageShort, | 25 messageFastaUsageShort, |
| 24 templateUnspecified; | 26 templateUnspecified; |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 return options["format"] ?? command_line_reporting.format; | 148 return options["format"] ?? command_line_reporting.format; |
| 147 } | 149 } |
| 148 | 150 |
| 149 String Function(Message, Severity) get formatWithoutLocation { | 151 String Function(Message, Severity) get formatWithoutLocation { |
| 150 return options["formatWithoutLocation"] ?? | 152 return options["formatWithoutLocation"] ?? |
| 151 command_line_reporting.formatWithoutLocation; | 153 command_line_reporting.formatWithoutLocation; |
| 152 } | 154 } |
| 153 | 155 |
| 154 static dynamic withGlobalOptions(String programName, List<String> arguments, | 156 static dynamic withGlobalOptions(String programName, List<String> arguments, |
| 155 dynamic f(CompilerContext context)) { | 157 dynamic f(CompilerContext context)) { |
| 156 return CompilerContext.withGlobalOptions( | 158 CompilerCommandLine cl = deprecated_withDefaultOptions( |
| 157 new CompilerCommandLine(programName, arguments), f); | 159 () => new CompilerCommandLine(programName, arguments)); |
| 160 return CompilerContext.withGlobalOptions(cl, f); |
| 158 } | 161 } |
| 159 | 162 |
| 160 static CompilerCommandLine forRootContext() { | 163 // TODO(sigmund, ahe): delete. We use this to wrap places where we require a |
| 161 return new CompilerCommandLine("", [""]); | 164 // context but we shoudln't. Right now this includes: |
| 165 // - constructor calls to CompilerCommandLine (because it is calling |
| 166 // [validate] which may report errors). This should be fixed by doing |
| 167 // validation after creating these objects. |
| 168 // - top-level try-catch in command-line tools that capture |
| 169 // deprecated_InputError, and then report errors using fasta's error |
| 170 // reporting mechanism. Those should be unnecessary once we get rid of all |
| 171 // deprecated_InputErrors. |
| 172 static dynamic deprecated_withDefaultOptions(dynamic f()) { |
| 173 var defaultContext = new CompilerContext(new CompilerCommandLine("", [""])); |
| 174 return runZoned(f, zoneValues: {compilerContextKey: defaultContext}); |
| 162 } | 175 } |
| 163 } | 176 } |
| 164 | 177 |
| 165 Message computeUsage(String programName, bool verbose) { | 178 Message computeUsage(String programName, bool verbose) { |
| 166 String basicUsage = "Usage: $programName [options] dartfile\n"; | 179 String basicUsage = "Usage: $programName [options] dartfile\n"; |
| 167 String summary; | 180 String summary; |
| 168 String options = | 181 String options = |
| 169 (verbose ? messageFastaUsageLong.message : messageFastaUsageShort.message) | 182 (verbose ? messageFastaUsageLong.message : messageFastaUsageShort.message) |
| 170 .trim(); | 183 .trim(); |
| 171 switch (programName) { | 184 switch (programName) { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 190 StringBuffer sb = new StringBuffer(basicUsage); | 203 StringBuffer sb = new StringBuffer(basicUsage); |
| 191 if (summary != null) { | 204 if (summary != null) { |
| 192 sb.writeln(); | 205 sb.writeln(); |
| 193 sb.writeln(summary); | 206 sb.writeln(summary); |
| 194 sb.writeln(); | 207 sb.writeln(); |
| 195 } | 208 } |
| 196 sb.write(options); | 209 sb.write(options); |
| 197 // TODO(ahe): Don't use [templateUnspecified]. | 210 // TODO(ahe): Don't use [templateUnspecified]. |
| 198 return templateUnspecified.withArguments("$sb"); | 211 return templateUnspecified.withArguments("$sb"); |
| 199 } | 212 } |
| OLD | NEW |