| 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: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:uri'; | 10 import 'dart:uri'; |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 Uri cwd = getCurrentDirectory(); | 72 Uri cwd = getCurrentDirectory(); |
| 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 String outputLanguage = 'JavaScript'; | 80 String outputLanguage = 'JavaScript'; |
| 81 bool stripArgumentSet = false; | 81 bool stripArgumentSet = false; |
| 82 bool analyzeOnly = false; | |
| 83 SourceFileProvider inputProvider = new SourceFileProvider(); | 82 SourceFileProvider inputProvider = new SourceFileProvider(); |
| 84 FormattingDiagnosticHandler diagnosticHandler = | 83 FormattingDiagnosticHandler diagnosticHandler = |
| 85 new FormattingDiagnosticHandler(inputProvider); | 84 new FormattingDiagnosticHandler(inputProvider); |
| 86 | 85 |
| 87 passThrough(String argument) => options.add(argument); | 86 passThrough(String argument) => options.add(argument); |
| 88 | 87 |
| 89 setLibraryRoot(String argument) { | 88 setLibraryRoot(String argument) { |
| 90 libraryRoot = cwd.resolve(extractPath(argument)); | 89 libraryRoot = cwd.resolve(extractPath(argument)); |
| 91 } | 90 } |
| 92 | 91 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 115 var filenames = new List.from(sourceFiles.keys); | 114 var filenames = new List.from(sourceFiles.keys); |
| 116 filenames.sort(); | 115 filenames.sort(); |
| 117 return Strings.join(filenames, "\n"); | 116 return Strings.join(filenames, "\n"); |
| 118 } | 117 } |
| 119 | 118 |
| 120 setStrip(String argument) { | 119 setStrip(String argument) { |
| 121 stripArgumentSet = true; | 120 stripArgumentSet = true; |
| 122 passThrough(argument); | 121 passThrough(argument); |
| 123 } | 122 } |
| 124 | 123 |
| 125 setAnalyzeOnly(String argument) { | |
| 126 analyzeOnly = true; | |
| 127 passThrough(argument); | |
| 128 } | |
| 129 | |
| 130 handleShortOptions(String argument) { | 124 handleShortOptions(String argument) { |
| 131 var shortOptions = argument.substring(1).splitChars(); | 125 var shortOptions = argument.substring(1).splitChars(); |
| 132 for (var shortOption in shortOptions) { | 126 for (var shortOption in shortOptions) { |
| 133 switch (shortOption) { | 127 switch (shortOption) { |
| 134 case 'v': | 128 case 'v': |
| 135 diagnosticHandler.verbose = true; | 129 diagnosticHandler.verbose = true; |
| 136 break; | 130 break; |
| 137 case 'h': | 131 case 'h': |
| 138 case '?': | 132 case '?': |
| 139 wantHelp = true; | 133 wantHelp = true; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 167 new OptionHandler('--enable-diagnostic-colors', | 161 new OptionHandler('--enable-diagnostic-colors', |
| 168 (_) => diagnosticHandler.enableColors = true), | 162 (_) => diagnosticHandler.enableColors = true), |
| 169 new OptionHandler('--enable[_-]checked[_-]mode|--checked', | 163 new OptionHandler('--enable[_-]checked[_-]mode|--checked', |
| 170 (_) => passThrough('--enable-checked-mode')), | 164 (_) => passThrough('--enable-checked-mode')), |
| 171 new OptionHandler('--enable-concrete-type-inference', | 165 new OptionHandler('--enable-concrete-type-inference', |
| 172 (_) => passThrough('--enable-concrete-type-inference')), | 166 (_) => passThrough('--enable-concrete-type-inference')), |
| 173 new OptionHandler(r'--help|/\?|/h', (_) => wantHelp = true), | 167 new OptionHandler(r'--help|/\?|/h', (_) => wantHelp = true), |
| 174 new OptionHandler('--package-root=.+|-p.+', setPackageRoot), | 168 new OptionHandler('--package-root=.+|-p.+', setPackageRoot), |
| 175 new OptionHandler('--disallow-unsafe-eval', passThrough), | 169 new OptionHandler('--disallow-unsafe-eval', passThrough), |
| 176 new OptionHandler('--analyze-all', passThrough), | 170 new OptionHandler('--analyze-all', passThrough), |
| 177 new OptionHandler('--analyze-only', setAnalyzeOnly), | |
| 178 new OptionHandler('--disable-native-live-type-analysis', passThrough), | 171 new OptionHandler('--disable-native-live-type-analysis', passThrough), |
| 179 new OptionHandler('--enable-native-live-type-analysis', passThrough), | 172 new OptionHandler('--enable-native-live-type-analysis', passThrough), |
| 180 new OptionHandler('--reject-deprecated-language-features', passThrough), | 173 new OptionHandler('--reject-deprecated-language-features', passThrough), |
| 181 new OptionHandler('--report-sdk-use-of-deprecated-language-features', | 174 new OptionHandler('--report-sdk-use-of-deprecated-language-features', |
| 182 passThrough), | 175 passThrough), |
| 183 | 176 |
| 184 // The following two options must come last. | 177 // The following two options must come last. |
| 185 new OptionHandler('-.*', (String argument) { | 178 new OptionHandler('-.*', (String argument) { |
| 186 helpAndFail('Error: Unknown option "$argument".'); | 179 helpAndFail('Error: Unknown option "$argument".'); |
| 187 }), | 180 }), |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 223 | 216 |
| 224 diagnosticHandler.info('package root is $packageRoot'); | 217 diagnosticHandler.info('package root is $packageRoot'); |
| 225 | 218 |
| 226 // TODO(ahe): We expect the future to be complete and call value | 219 // TODO(ahe): We expect the future to be complete and call value |
| 227 // directly. In effect, we don't support truly asynchronous API. | 220 // directly. In effect, we don't support truly asynchronous API. |
| 228 String code = deprecatedFutureValue( | 221 String code = deprecatedFutureValue( |
| 229 api.compile(uri, libraryRoot, packageRoot, | 222 api.compile(uri, libraryRoot, packageRoot, |
| 230 inputProvider.readStringFromUri, | 223 inputProvider.readStringFromUri, |
| 231 handler, | 224 handler, |
| 232 options)); | 225 options)); |
| 233 if (analyzeOnly) return; | |
| 234 | |
| 235 if (code == null) { | 226 if (code == null) { |
| 236 fail('Error: Compilation failed.'); | 227 fail('Error: Compilation failed.'); |
| 237 } | 228 } |
| 238 String sourceMapFileName = | 229 String sourceMapFileName = |
| 239 sourceMapOut.path.substring(sourceMapOut.path.lastIndexOf('/') + 1); | 230 sourceMapOut.path.substring(sourceMapOut.path.lastIndexOf('/') + 1); |
| 240 code = '$code\n//@ sourceMappingURL=${sourceMapFileName}'; | 231 code = '$code\n//@ sourceMappingURL=${sourceMapFileName}'; |
| 241 writeString(out, code); | 232 writeString(out, code); |
| 242 writeString(new Uri.fromString('$out.deps'), | 233 writeString(new Uri.fromString('$out.deps'), |
| 243 getDepsOutput(inputProvider.sourceFiles)); | 234 getDepsOutput(inputProvider.sourceFiles)); |
| 244 int dartBytesRead = inputProvider.dartBytesRead; | 235 int dartBytesRead = inputProvider.dartBytesRead; |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 317 | 308 |
| 318 -p<path>, --package-root=<path> | 309 -p<path>, --package-root=<path> |
| 319 Where to find packages, that is, "package:..." imports. | 310 Where to find packages, that is, "package:..." imports. |
| 320 | 311 |
| 321 --analyze-all | 312 --analyze-all |
| 322 Analyze all code. Without this option, the compiler only analyzes | 313 Analyze all code. Without this option, the compiler only analyzes |
| 323 code that is reachable from [main]. This option is useful for | 314 code that is reachable from [main]. This option is useful for |
| 324 finding errors in libraries, but using it can result in bigger and | 315 finding errors in libraries, but using it can result in bigger and |
| 325 slower output. | 316 slower output. |
| 326 | 317 |
| 327 --analyze-only | |
| 328 Analyze but do not generate code. | |
| 329 | |
| 330 --minify | 318 --minify |
| 331 Generate minified output. | 319 Generate minified output. |
| 332 | 320 |
| 333 --suppress-warnings | 321 --suppress-warnings |
| 334 Do not display any warnings. | 322 Do not display any warnings. |
| 335 | 323 |
| 336 --enable-diagnostic-colors | 324 --enable-diagnostic-colors |
| 337 Add colors to diagnostic messages. | 325 Add colors to diagnostic messages. |
| 338 | 326 |
| 339 The following options are only used for compiler development and may | 327 The following options are only used for compiler development and may |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 405 } catch (ignored) { | 393 } catch (ignored) { |
| 406 print('Internal error: error while printing exception'); | 394 print('Internal error: error while printing exception'); |
| 407 } | 395 } |
| 408 try { | 396 try { |
| 409 print(trace); | 397 print(trace); |
| 410 } finally { | 398 } finally { |
| 411 exit(253); // 253 is recognized as a crash by our test scripts. | 399 exit(253); // 253 is recognized as a crash by our test scripts. |
| 412 } | 400 } |
| 413 } | 401 } |
| 414 } | 402 } |
| OLD | NEW |