Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(677)

Side by Side Diff: sdk/lib/_internal/compiler/implementation/dart2js.dart

Issue 15891015: Allow a space after -o in dart2js option parsing. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fix callback type. Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 import 'dart:collection' show Queue, LinkedHashMap; 8 import 'dart:collection' show Queue, LinkedHashMap;
9 import 'dart:io'; 9 import 'dart:io';
10 import 'dart:utf'; 10 import 'dart:utf';
(...skipping 11 matching lines...) Expand all
22 /** 22 /**
23 * A string to identify the revision or build. 23 * A string to identify the revision or build.
24 * 24 *
25 * This ID is displayed if the compiler crashes and in verbose mode, and is 25 * This ID is displayed if the compiler crashes and in verbose mode, and is
26 * an aid in reproducing bug reports. 26 * an aid in reproducing bug reports.
27 * 27 *
28 * The actual string is rewritten by a wrapper script when included in the sdk. 28 * The actual string is rewritten by a wrapper script when included in the sdk.
29 */ 29 */
30 String BUILD_ID = null; 30 String BUILD_ID = null;
31 31
32 typedef void HandleOption(String option); 32 /**
33 * The data passed to the [HandleOption] callback is either a single
34 * string argument, or the arguments iterator for multiple arguments
35 * handlers.
36 */
37 typedef void HandleOption(data);
33 38
34 class OptionHandler { 39 class OptionHandler {
35 String pattern; 40 final String pattern;
36 HandleOption handle; 41 final HandleOption handle;
42 final bool multipleArguments;
37 43
38 OptionHandler(this.pattern, this.handle); 44 OptionHandler(this.pattern, this.handle, {this.multipleArguments: false});
39 } 45 }
40 46
41 /** 47 /**
42 * Extract the parameter of an option. 48 * Extract the parameter of an option.
43 * 49 *
44 * For example, in ['--out=fisk.js'] and ['-ohest.js'], the parameters 50 * For example, in ['--out=fisk.js'] and ['-ohest.js'], the parameters
45 * are ['fisk.js'] and ['hest.js'], respectively. 51 * are ['fisk.js'] and ['hest.js'], respectively.
46 */ 52 */
47 String extractParameter(String argument) { 53 String extractParameter(String argument) {
48 // m[0] is the entire match (which will be equal to argument). m[1] 54 // m[0] is the entire match (which will be equal to argument). m[1]
49 // is something like "-o" or "--out=", and m[2] is the parameter. 55 // is something like "-o" or "--out=", and m[2] is the parameter.
50 Match m = new RegExp('^(-[a-z]|--.+=)(.*)').firstMatch(argument); 56 Match m = new RegExp('^(-[a-z]|--.+=)(.*)').firstMatch(argument);
51 if (m == null) helpAndFail('Error: Unknown option "$argument".'); 57 if (m == null) helpAndFail('Error: Unknown option "$argument".');
52 return m[2]; 58 return m[2];
53 } 59 }
54 60
55 String extractPath(String argument) { 61 String extractPath(String argument) {
56 String path = nativeToUriPath(extractParameter(argument)); 62 String path = nativeToUriPath(extractParameter(argument));
57 return path.endsWith("/") ? path : "$path/"; 63 return path.endsWith("/") ? path : "$path/";
58 } 64 }
59 65
60 void parseCommandLine(List<OptionHandler> handlers, List<String> argv) { 66 void parseCommandLine(List<OptionHandler> handlers, List<String> argv) {
61 // TODO(ahe): Use ../../args/args.dart for parsing options instead. 67 // TODO(ahe): Use ../../args/args.dart for parsing options instead.
62 var patterns = <String>[]; 68 var patterns = <String>[];
63 for (OptionHandler handler in handlers) { 69 for (OptionHandler handler in handlers) {
64 patterns.add(handler.pattern); 70 patterns.add(handler.pattern);
65 } 71 }
66 var pattern = new RegExp('^(${patterns.join(")\$|(")})\$'); 72 var pattern = new RegExp('^(${patterns.join(")\$|(")})\$');
67 OUTER: for (String argument in argv) { 73
74 Iterator<String> arguments = argv.iterator;
75 OUTER: while (arguments.moveNext()) {
76 String argument = arguments.current;
68 Match match = pattern.firstMatch(argument); 77 Match match = pattern.firstMatch(argument);
69 assert(match.groupCount == handlers.length); 78 assert(match.groupCount == handlers.length);
70 for (int i = 0; i < handlers.length; i++) { 79 for (int i = 0; i < handlers.length; i++) {
71 if (match[i + 1] != null) { 80 if (match[i + 1] != null) {
72 handlers[i].handle(argument); 81 OptionHandler handler = handlers[i];
82 if (handler.multipleArguments) {
83 handler.handle(arguments);
84 } else {
85 handler.handle(argument);
86 }
73 continue OUTER; 87 continue OUTER;
74 } 88 }
75 } 89 }
76 throw 'Internal error: "$argument" did not match'; 90 throw 'Internal error: "$argument" did not match';
77 } 91 }
78 } 92 }
79 93
80 void compile(List<String> argv) { 94 void compile(List<String> argv) {
81 bool isWindows = (Platform.operatingSystem == 'windows'); 95 bool isWindows = (Platform.operatingSystem == 'windows');
82 Uri libraryRoot = currentDirectory; 96 Uri libraryRoot = currentDirectory;
(...skipping 18 matching lines...) Expand all
101 } 115 }
102 116
103 setLibraryRoot(String argument) { 117 setLibraryRoot(String argument) {
104 libraryRoot = currentDirectory.resolve(extractPath(argument)); 118 libraryRoot = currentDirectory.resolve(extractPath(argument));
105 } 119 }
106 120
107 setPackageRoot(String argument) { 121 setPackageRoot(String argument) {
108 packageRoot = currentDirectory.resolve(extractPath(argument)); 122 packageRoot = currentDirectory.resolve(extractPath(argument));
109 } 123 }
110 124
111 setOutput(String argument) { 125 setOutput(Iterator<String> arguments) {
126 String path;
127 if (arguments.current == '-o') {
128 if (!arguments.moveNext()) {
129 helpAndFail('Error: Missing file after -o option.');
130 }
131 path = arguments.current;
132 } else {
133 path = extractParameter(arguments.current);
134 }
112 explicitOut = true; 135 explicitOut = true;
113 out = currentDirectory.resolve(nativeToUriPath(extractParameter(argument))); 136 out = currentDirectory.resolve(nativeToUriPath(path));
114 sourceMapOut = Uri.parse('$out.map'); 137 sourceMapOut = Uri.parse('$out.map');
115 } 138 }
116 139
117 setOutputType(String argument) { 140 setOutputType(String argument) {
118 if (argument == '--output-type=dart') { 141 if (argument == '--output-type=dart') {
119 outputLanguage = OUTPUT_LANGUAGE_DART; 142 outputLanguage = OUTPUT_LANGUAGE_DART;
120 if (!explicitOut) { 143 if (!explicitOut) {
121 out = currentDirectory.resolve('out.dart'); 144 out = currentDirectory.resolve('out.dart');
122 sourceMapOut = currentDirectory.resolve('out.dart.map'); 145 sourceMapOut = currentDirectory.resolve('out.dart.map');
123 } 146 }
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 List<OptionHandler> handlers = <OptionHandler>[ 224 List<OptionHandler> handlers = <OptionHandler>[
202 new OptionHandler('-[chv?]+', handleShortOptions), 225 new OptionHandler('-[chv?]+', handleShortOptions),
203 new OptionHandler('--throw-on-error', 226 new OptionHandler('--throw-on-error',
204 (_) => diagnosticHandler.throwOnError = true), 227 (_) => diagnosticHandler.throwOnError = true),
205 new OptionHandler('--suppress-warnings', 228 new OptionHandler('--suppress-warnings',
206 (_) => diagnosticHandler.showWarnings = false), 229 (_) => diagnosticHandler.showWarnings = false),
207 new OptionHandler('--output-type=dart|--output-type=js', setOutputType), 230 new OptionHandler('--output-type=dart|--output-type=js', setOutputType),
208 new OptionHandler('--verbose', setVerbose), 231 new OptionHandler('--verbose', setVerbose),
209 new OptionHandler('--version', (_) => wantVersion = true), 232 new OptionHandler('--version', (_) => wantVersion = true),
210 new OptionHandler('--library-root=.+', setLibraryRoot), 233 new OptionHandler('--library-root=.+', setLibraryRoot),
211 new OptionHandler('--out=.+|-o.+', setOutput), 234 new OptionHandler('--out=.+|-o.*', setOutput, multipleArguments: true),
212 new OptionHandler('--allow-mock-compilation', passThrough), 235 new OptionHandler('--allow-mock-compilation', passThrough),
213 new OptionHandler('--minify', passThrough), 236 new OptionHandler('--minify', passThrough),
214 new OptionHandler('--force-strip=.*', setStrip), 237 new OptionHandler('--force-strip=.*', setStrip),
215 // TODO(ahe): Remove the --no-colors option. 238 // TODO(ahe): Remove the --no-colors option.
216 new OptionHandler('--disable-diagnostic-colors', 239 new OptionHandler('--disable-diagnostic-colors',
217 (_) => diagnosticHandler.enableColors = false), 240 (_) => diagnosticHandler.enableColors = false),
218 new OptionHandler('--enable-diagnostic-colors', 241 new OptionHandler('--enable-diagnostic-colors',
219 (_) => diagnosticHandler.enableColors = true), 242 (_) => diagnosticHandler.enableColors = true),
220 new OptionHandler('--enable[_-]checked[_-]mode|--checked', 243 new OptionHandler('--enable[_-]checked[_-]mode|--checked',
221 (_) => passThrough('--enable-checked-mode')), 244 (_) => passThrough('--enable-checked-mode')),
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
395 // This message should be no longer than 20 lines. The default 418 // This message should be no longer than 20 lines. The default
396 // terminal size normally 80x24. Two lines are used for the prompts 419 // terminal size normally 80x24. Two lines are used for the prompts
397 // before and after running the compiler. Another two lines may be 420 // before and after running the compiler. Another two lines may be
398 // used to print an error message. 421 // used to print an error message.
399 print(''' 422 print('''
400 Usage: dart2js [options] dartfile 423 Usage: dart2js [options] dartfile
401 424
402 Compiles Dart to JavaScript. 425 Compiles Dart to JavaScript.
403 426
404 Common options: 427 Common options:
405 -o<file> Generate the output into <file>. 428 -o <file> Generate the output into <file>.
406 -c Insert runtime type checks and enable assertions (checked mode). 429 -c Insert runtime type checks and enable assertions (checked mode).
407 -h Display this message (add -v for information about all options).'''); 430 -h Display this message (add -v for information about all options).''') ;
408 } 431 }
409 432
410 void verboseHelp() { 433 void verboseHelp() {
411 print(r''' 434 print(r'''
412 Usage: dart2js [options] dartfile 435 Usage: dart2js [options] dartfile
413 436
414 Compiles Dart to JavaScript. 437 Compiles Dart to JavaScript.
415 438
416 Supported options: 439 Supported options:
417 -o<file>, --out=<file> 440 -o <file>, --out=<file>
418 Generate the output into <file>. 441 Generate the output into <file>.
419 442
420 -c, --enable-checked-mode, --checked 443 -c, --enable-checked-mode, --checked
421 Insert runtime type checks and enable assertions (checked mode). 444 Insert runtime type checks and enable assertions (checked mode).
422 445
423 -h, /h, /?, --help 446 -h, /h, /?, --help
424 Display this message (add -v for information about all options). 447 Display this message (add -v for information about all options).
425 448
426 -v, --verbose 449 -v, --verbose
427 Display verbose information. 450 Display verbose information.
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
544 print(trace); 567 print(trace);
545 } finally { 568 } finally {
546 exit(253); // 253 is recognized as a crash by our test scripts. 569 exit(253); // 253 is recognized as a crash by our test scripts.
547 } 570 }
548 } 571 }
549 } 572 }
550 573
551 void main() { 574 void main() {
552 mainWithErrorHandler(new Options()); 575 mainWithErrorHandler(new Options());
553 } 576 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698