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