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 options; | 5 library options; |
6 | 6 |
7 import 'dart:io'; | 7 import 'dart:io'; |
8 | 8 |
9 import 'package:args/args.dart'; | 9 import 'package:args/args.dart'; |
10 | 10 |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 | 58 |
59 /** The source files to analyze */ | 59 /** The source files to analyze */ |
60 final List<String> sourceFiles; | 60 final List<String> sourceFiles; |
61 | 61 |
62 /** Whether to show both cold and hot performance statistics */ | 62 /** Whether to show both cold and hot performance statistics */ |
63 final bool warmPerf; | 63 final bool warmPerf; |
64 | 64 |
65 /** Whether to treat warnings as fatal */ | 65 /** Whether to treat warnings as fatal */ |
66 final bool warningsAreFatal; | 66 final bool warningsAreFatal; |
67 | 67 |
| 68 /** A table mapping library URIs to the file system path where the library |
| 69 * source is located. |
| 70 */ |
| 71 final Map<String, String> customUrlMappings; |
| 72 |
68 /** | 73 /** |
69 * Initialize options from the given parsed [args]. | 74 * Initialize options from the given parsed [args]. |
70 */ | 75 */ |
71 CommandLineOptions._fromArgs(ArgResults args, Map<String, | 76 CommandLineOptions._fromArgs(ArgResults args, Map<String, |
72 String> definedVariables) | 77 String> definedVariables, Map<String, String> customUrlMappings) |
73 : dartSdkPath = args['dart-sdk'], | 78 : dartSdkPath = args['dart-sdk'], |
74 this.definedVariables = definedVariables, | 79 this.definedVariables = definedVariables, |
75 disableHints = args['no-hints'], | 80 disableHints = args['no-hints'], |
76 displayVersion = args['version'], | 81 displayVersion = args['version'], |
77 enableTypeChecks = args['enable_type_checks'], | 82 enableTypeChecks = args['enable_type_checks'], |
78 ignoreUnrecognizedFlags = args['ignore-unrecognized-flags'], | 83 ignoreUnrecognizedFlags = args['ignore-unrecognized-flags'], |
79 log = args['log'], | 84 log = args['log'], |
80 machineFormat = args['machine'] || args['format'] == 'machine', | 85 machineFormat = args['machine'] || args['format'] == 'machine', |
81 packageRootPath = args['package-root'], | 86 packageRootPath = args['package-root'], |
82 perf = args['perf'], | 87 perf = args['perf'], |
83 shouldBatch = args['batch'], | 88 shouldBatch = args['batch'], |
84 showPackageWarnings = args['show-package-warnings'] || | 89 showPackageWarnings = args['show-package-warnings'] || |
85 args['package-warnings'], | 90 args['package-warnings'], |
86 showSdkWarnings = args['show-sdk-warnings'] || args['warnings'], | 91 showSdkWarnings = args['show-sdk-warnings'] || args['warnings'], |
87 sourceFiles = args.rest, | 92 sourceFiles = args.rest, |
88 warmPerf = args['warm-perf'], | 93 warmPerf = args['warm-perf'], |
89 warningsAreFatal = args['fatal-warnings']; | 94 warningsAreFatal = args['fatal-warnings'], |
| 95 this.customUrlMappings = customUrlMappings; |
90 | 96 |
91 /** | 97 /** |
92 * Parse [args] into [CommandLineOptions] describing the specified | 98 * Parse [args] into [CommandLineOptions] describing the specified |
93 * analyzer options. In case of a format error, prints error and exists. | 99 * analyzer options. In case of a format error, prints error and exists. |
94 */ | 100 */ |
95 static CommandLineOptions parse(List<String> args) { | 101 static CommandLineOptions parse(List<String> args) { |
96 CommandLineOptions options = _parse(args); | 102 CommandLineOptions options = _parse(args); |
97 // check SDK | 103 // check SDK |
98 { | 104 { |
99 var sdkPath = options.dartSdkPath; | 105 var sdkPath = options.dartSdkPath; |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 'show-sdk-warnings', | 198 'show-sdk-warnings', |
193 help: 'Show warnings from SDK imports (deprecated)', | 199 help: 'Show warnings from SDK imports (deprecated)', |
194 defaultsTo: false, | 200 defaultsTo: false, |
195 negatable: false) | 201 negatable: false) |
196 ..addFlag( | 202 ..addFlag( |
197 'help', | 203 'help', |
198 abbr: 'h', | 204 abbr: 'h', |
199 help: 'Display this help message', | 205 help: 'Display this help message', |
200 defaultsTo: false, | 206 defaultsTo: false, |
201 negatable: false) | 207 negatable: false) |
| 208 ..addOption( |
| 209 'url-mapping', |
| 210 help: '--url-mapping=libraryUri,/path/to/library.dart directs the ' |
| 211 'analyzer to use "library.dart" as the source for an import ' |
| 212 'of "libraryUri"', |
| 213 allowMultiple: true) |
202 // | 214 // |
203 // Hidden flags. | 215 // Hidden flags. |
204 // | 216 // |
205 ..addFlag( | 217 ..addFlag( |
206 'enable-async', | 218 'enable-async', |
207 help: 'Enable support for the proposed async feature', | 219 help: 'Enable support for the proposed async feature', |
208 defaultsTo: false, | 220 defaultsTo: false, |
209 negatable: false, | 221 negatable: false, |
210 hide: true) | 222 hide: true) |
211 ..addFlag( | 223 ..addFlag( |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
253 } | 265 } |
254 } else if (results['version']) { | 266 } else if (results['version']) { |
255 print('$_BINARY_NAME version ${_getVersion()}'); | 267 print('$_BINARY_NAME version ${_getVersion()}'); |
256 exit(0); | 268 exit(0); |
257 } else { | 269 } else { |
258 if (results.rest.isEmpty) { | 270 if (results.rest.isEmpty) { |
259 _showUsage(parser); | 271 _showUsage(parser); |
260 exit(15); | 272 exit(15); |
261 } | 273 } |
262 } | 274 } |
263 return new CommandLineOptions._fromArgs(results, definedVariables); | 275 Map<String, String> customUrlMappings = <String, String>{}; |
| 276 for (String mapping in results['url-mapping']) { |
| 277 List<String> splitMapping = mapping.split(','); |
| 278 if (splitMapping.length != 2) { |
| 279 _showUsage(parser); |
| 280 exit(15); |
| 281 } |
| 282 customUrlMappings[splitMapping[0]] = splitMapping[1]; |
| 283 } |
| 284 return new CommandLineOptions._fromArgs( |
| 285 results, definedVariables, customUrlMappings); |
264 } on FormatException catch (e) { | 286 } on FormatException catch (e) { |
265 print(e.message); | 287 print(e.message); |
266 _showUsage(parser); | 288 _showUsage(parser); |
267 exit(15); | 289 exit(15); |
268 } | 290 } |
269 | 291 |
270 } | 292 } |
271 | 293 |
272 static _showUsage(parser) { | 294 static _showUsage(parser) { |
273 print('Usage: $_BINARY_NAME [options...] <libraries to analyze...>'); | 295 print('Usage: $_BINARY_NAME [options...] <libraries to analyze...>'); |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
402 | 424 |
403 _getNextFlagIndex(args, i) { | 425 _getNextFlagIndex(args, i) { |
404 for ( ; i < args.length; ++i) { | 426 for ( ; i < args.length; ++i) { |
405 if (args[i].startsWith('--')) { | 427 if (args[i].startsWith('--')) { |
406 return i; | 428 return i; |
407 } | 429 } |
408 } | 430 } |
409 return i; | 431 return i; |
410 } | 432 } |
411 } | 433 } |
OLD | NEW |