Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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'); | 5 #library('dart2js'); |
| 6 | 6 |
| 7 #import('dart:io'); | 7 #import('dart:io'); |
| 8 #import('dart:uri'); | 8 #import('dart:uri'); |
| 9 #import('dart:utf'); | 9 #import('dart:utf'); |
| 10 | 10 |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 72 bool verbose = false; | 72 bool verbose = false; |
| 73 Uri libraryRoot = cwd; | 73 Uri libraryRoot = cwd; |
| 74 Uri out = cwd.resolve('out.js'); | 74 Uri out = cwd.resolve('out.js'); |
| 75 Uri sourceMapOut = cwd.resolve('out.js.map'); | 75 Uri sourceMapOut = cwd.resolve('out.js.map'); |
| 76 Uri packageRoot = null; | 76 Uri packageRoot = null; |
| 77 List<String> options = new List<String>(); | 77 List<String> options = new List<String>(); |
| 78 bool explicitOut = false; | 78 bool explicitOut = false; |
| 79 bool wantHelp = false; | 79 bool wantHelp = false; |
| 80 bool enableColors = false; | 80 bool enableColors = false; |
| 81 String outputLanguage = 'JavaScript'; | 81 String outputLanguage = 'JavaScript'; |
| 82 bool stripArgumentSet = false; | |
| 82 | 83 |
| 83 passThrough(String argument) => options.add(argument); | 84 passThrough(String argument) => options.add(argument); |
| 84 | 85 |
| 85 setLibraryRoot(String argument) { | 86 setLibraryRoot(String argument) { |
| 86 libraryRoot = cwd.resolve(extractPath(argument)); | 87 libraryRoot = cwd.resolve(extractPath(argument)); |
| 87 } | 88 } |
| 88 | 89 |
| 89 setPackageRoot(String argument) { | 90 setPackageRoot(String argument) { |
| 90 packageRoot = cwd.resolve(extractPath(argument)); | 91 packageRoot = cwd.resolve(extractPath(argument)); |
| 91 } | 92 } |
| 92 | 93 |
| 93 setOutput(String argument) { | 94 setOutput(String argument) { |
| 94 explicitOut = true; | 95 explicitOut = true; |
| 95 out = cwd.resolve(nativeToUriPath(extractParameter(argument))); | 96 out = cwd.resolve(nativeToUriPath(extractParameter(argument))); |
| 96 sourceMapOut = new Uri.fromString('$out.map'); | 97 sourceMapOut = new Uri.fromString('$out.map'); |
| 97 } | 98 } |
| 98 | 99 |
| 99 setOutputType(String argument) { | 100 setOutputType(String argument) { |
| 100 if (argument == '--output-type=dart') { | 101 if (argument == '--output-type=dart') { |
| 101 outputLanguage = 'Dart'; | 102 outputLanguage = 'Dart'; |
| 102 if (!explicitOut) { | 103 if (!explicitOut) { |
| 103 out = cwd.resolve('out.dart'); | 104 out = cwd.resolve('out.dart'); |
| 104 sourceMapOut = cwd.resolve('out.dart.map'); | 105 sourceMapOut = cwd.resolve('out.dart.map'); |
| 105 } | 106 } |
| 106 } | 107 } |
| 107 passThrough(argument); | 108 passThrough(argument); |
| 108 } | 109 } |
| 109 | 110 |
| 111 setStrip(String argument) { | |
| 112 stripArgumentSet = true; | |
| 113 passThrough(argument); | |
| 114 } | |
| 115 | |
| 110 handleShortOptions(String argument) { | 116 handleShortOptions(String argument) { |
| 111 var shortOptions = argument.substring(1).splitChars(); | 117 var shortOptions = argument.substring(1).splitChars(); |
| 112 for (var shortOption in shortOptions) { | 118 for (var shortOption in shortOptions) { |
| 113 switch (shortOption) { | 119 switch (shortOption) { |
| 114 case 'v': | 120 case 'v': |
| 115 verbose = true; | 121 verbose = true; |
| 116 break; | 122 break; |
| 117 case 'h': | 123 case 'h': |
| 118 case '?': | 124 case '?': |
| 119 wantHelp = true; | 125 wantHelp = true; |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 131 List<OptionHandler> handlers = <OptionHandler>[ | 137 List<OptionHandler> handlers = <OptionHandler>[ |
| 132 new OptionHandler('-[chv?]+', handleShortOptions), | 138 new OptionHandler('-[chv?]+', handleShortOptions), |
| 133 new OptionHandler('--throw-on-error', (_) => throwOnError = true), | 139 new OptionHandler('--throw-on-error', (_) => throwOnError = true), |
| 134 new OptionHandler('--suppress-warnings', (_) => showWarnings = false), | 140 new OptionHandler('--suppress-warnings', (_) => showWarnings = false), |
| 135 new OptionHandler('--output-type=dart|--output-type=js', setOutputType), | 141 new OptionHandler('--output-type=dart|--output-type=js', setOutputType), |
| 136 new OptionHandler('--verbose', (_) => verbose = true), | 142 new OptionHandler('--verbose', (_) => verbose = true), |
| 137 new OptionHandler('--library-root=.+', setLibraryRoot), | 143 new OptionHandler('--library-root=.+', setLibraryRoot), |
| 138 new OptionHandler('--out=.+|-o.+', setOutput), | 144 new OptionHandler('--out=.+|-o.+', setOutput), |
| 139 new OptionHandler('--allow-mock-compilation', passThrough), | 145 new OptionHandler('--allow-mock-compilation', passThrough), |
| 140 new OptionHandler('--minify', passThrough), | 146 new OptionHandler('--minify', passThrough), |
| 141 new OptionHandler('--force-cut-declaration-types', passThrough), | 147 new OptionHandler('--force-strip=.*', setStrip), |
| 142 // TODO(ahe): Remove the --no-colors option. | 148 // TODO(ahe): Remove the --no-colors option. |
| 143 new OptionHandler('--disable-diagnostic-colors', (_) => enableColors = false ), | 149 new OptionHandler('--disable-diagnostic-colors', (_) => enableColors = false ), |
| 144 new OptionHandler('--enable-diagnostic-colors', (_) => enableColors = true), | 150 new OptionHandler('--enable-diagnostic-colors', (_) => enableColors = true), |
| 145 new OptionHandler('--enable[_-]checked[_-]mode|--checked', | 151 new OptionHandler('--enable[_-]checked[_-]mode|--checked', |
| 146 (_) => passThrough('--enable-checked-mode')), | 152 (_) => passThrough('--enable-checked-mode')), |
| 147 new OptionHandler(r'--help|/\?|/h', (_) => wantHelp = true), | 153 new OptionHandler(r'--help|/\?|/h', (_) => wantHelp = true), |
| 148 new OptionHandler(r'--package-root=.+|-p.+', setPackageRoot), | 154 new OptionHandler(r'--package-root=.+|-p.+', setPackageRoot), |
| 149 // The following two options must come last. | 155 // The following two options must come last. |
| 150 new OptionHandler('-.*', (String argument) { | 156 new OptionHandler('-.*', (String argument) { |
| 151 helpAndFail('Error: Unknown option "$argument".'); | 157 helpAndFail('Error: Unknown option "$argument".'); |
| 152 }), | 158 }), |
| 153 new OptionHandler('.*', (String argument) { | 159 new OptionHandler('.*', (String argument) { |
| 154 arguments.add(nativeToUriPath(argument)); | 160 arguments.add(nativeToUriPath(argument)); |
| 155 }) | 161 }) |
| 156 ]; | 162 ]; |
| 157 | 163 |
| 158 parseCommandLine(handlers, argv); | 164 parseCommandLine(handlers, argv); |
| 159 | |
| 160 if (wantHelp) helpAndExit(verbose); | 165 if (wantHelp) helpAndExit(verbose); |
| 161 | 166 |
| 167 if (outputLanguage != 'Dart' && stripArgumentSet) { | |
|
ahe
2012/10/01 10:19:22
I like this check!
| |
| 168 helpAndFail('Error: --force-strip may only be used with ' | |
| 169 '--output-type=dart'); | |
| 170 } | |
| 162 if (arguments.isEmpty()) { | 171 if (arguments.isEmpty()) { |
| 163 helpAndFail('Error: No Dart file specified.'); | 172 helpAndFail('Error: No Dart file specified.'); |
| 164 } | 173 } |
| 165 if (arguments.length > 1) { | 174 if (arguments.length > 1) { |
| 166 var extra = arguments.getRange(1, arguments.length - 1); | 175 var extra = arguments.getRange(1, arguments.length - 1); |
| 167 helpAndFail('Error: Extra arguments: ${Strings.join(extra, " ")}'); | 176 helpAndFail('Error: Extra arguments: ${Strings.join(extra, " ")}'); |
| 168 } | 177 } |
| 169 | 178 |
| 170 Map<String, SourceFile> sourceFiles = <String, SourceFile>{}; | 179 Map<String, SourceFile> sourceFiles = <String, SourceFile>{}; |
| 171 int dartBytesRead = 0; | 180 int dartBytesRead = 0; |
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 400 } catch (ignored) { | 409 } catch (ignored) { |
| 401 print('Internal error: error while printing exception'); | 410 print('Internal error: error while printing exception'); |
| 402 } | 411 } |
| 403 try { | 412 try { |
| 404 print(trace); | 413 print(trace); |
| 405 } finally { | 414 } finally { |
| 406 exit(253); // 253 is recognized as a crash by our test scripts. | 415 exit(253); // 253 is recognized as a crash by our test scripts. |
| 407 } | 416 } |
| 408 } | 417 } |
| 409 } | 418 } |
| OLD | NEW |