Chromium Code Reviews| 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 dart2js.cmdline; | 5 library dart2js.cmdline; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:io' | 8 import 'dart:io' |
| 9 show exit, File, FileMode, Platform, RandomAccessFile; | 9 show exit, File, FileMode, Platform, RandomAccessFile; |
| 10 import 'dart:math' as math; | 10 import 'dart:math' as math; |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 105 bool explicitOut = false; | 105 bool explicitOut = false; |
| 106 bool wantHelp = false; | 106 bool wantHelp = false; |
| 107 bool wantVersion = false; | 107 bool wantVersion = false; |
| 108 String outputLanguage = 'JavaScript'; | 108 String outputLanguage = 'JavaScript'; |
| 109 bool stripArgumentSet = false; | 109 bool stripArgumentSet = false; |
| 110 bool analyzeOnly = false; | 110 bool analyzeOnly = false; |
| 111 bool hasDisallowUnsafeEval = false; | 111 bool hasDisallowUnsafeEval = false; |
| 112 // TODO(johnniwinther): Measure time for reading files. | 112 // TODO(johnniwinther): Measure time for reading files. |
| 113 SourceFileProvider inputProvider = new CompilerSourceFileProvider(); | 113 SourceFileProvider inputProvider = new CompilerSourceFileProvider(); |
| 114 diagnosticHandler = new FormattingDiagnosticHandler(inputProvider); | 114 diagnosticHandler = new FormattingDiagnosticHandler(inputProvider); |
| 115 Map<String, dynamic> environment = new Map<String, dynamic>(); | |
| 115 | 116 |
| 116 passThrough(String argument) => options.add(argument); | 117 passThrough(String argument) => options.add(argument); |
| 117 | 118 |
| 118 if (BUILD_ID != null) { | 119 if (BUILD_ID != null) { |
| 119 passThrough("--build-id=$BUILD_ID"); | 120 passThrough("--build-id=$BUILD_ID"); |
| 120 } | 121 } |
| 121 | 122 |
| 122 setLibraryRoot(String argument) { | 123 setLibraryRoot(String argument) { |
| 123 libraryRoot = currentDirectory.resolve(extractPath(argument)); | 124 libraryRoot = currentDirectory.resolve(extractPath(argument)); |
| 124 } | 125 } |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 167 setAnalyzeOnly(String argument) { | 168 setAnalyzeOnly(String argument) { |
| 168 analyzeOnly = true; | 169 analyzeOnly = true; |
| 169 passThrough(argument); | 170 passThrough(argument); |
| 170 } | 171 } |
| 171 | 172 |
| 172 setVerbose(_) { | 173 setVerbose(_) { |
| 173 diagnosticHandler.verbose = true; | 174 diagnosticHandler.verbose = true; |
| 174 passThrough('--verbose'); | 175 passThrough('--verbose'); |
| 175 } | 176 } |
| 176 | 177 |
| 178 addInEnvironment(String argument) { | |
| 179 Match m = new RegExp('^-D(.+)=(.+)').firstMatch(argument); | |
|
ahe
2013/10/30 13:03:09
Terminate with $.
Lasse Reichstein Nielsen
2013/10/30 13:34:48
Terminating isn't necessary. The last capture is g
ngeoffray
2013/10/30 15:13:59
Done.
| |
| 180 String name = m[1]; | |
| 181 String value = m[2]; | |
| 182 if (value == 'true') { | |
| 183 environment[name] = true; | |
|
Lasse Reichstein Nielsen
2013/10/30 13:34:48
Why parse the arguments here?
Even if the value is
kasperl
2013/10/30 13:49:56
I agree with Lasse here. It seems cleaner to do th
ngeoffray
2013/10/30 15:13:59
Done.
| |
| 184 } else if (value == 'false') { | |
| 185 environment[name] = false; | |
| 186 } else { | |
| 187 int number = int.parse(value, onError: (_) => null); | |
| 188 if (number == null) { | |
| 189 environment[name] = value; | |
| 190 } else { | |
| 191 environment[name] = number; | |
| 192 } | |
| 193 } | |
| 194 } | |
| 195 | |
| 177 setCategories(String argument) { | 196 setCategories(String argument) { |
| 178 List<String> categories = extractParameter(argument).split(','); | 197 List<String> categories = extractParameter(argument).split(','); |
| 179 Set<String> allowedCategories = | 198 Set<String> allowedCategories = |
| 180 LIBRARIES.values.map((x) => x.category).toSet(); | 199 LIBRARIES.values.map((x) => x.category).toSet(); |
| 181 allowedCategories.remove('Shared'); | 200 allowedCategories.remove('Shared'); |
| 182 allowedCategories.remove('Internal'); | 201 allowedCategories.remove('Internal'); |
| 183 List<String> allowedCategoriesList = | 202 List<String> allowedCategoriesList = |
| 184 new List<String>.from(allowedCategories); | 203 new List<String>.from(allowedCategories); |
| 185 allowedCategoriesList.sort(); | 204 allowedCategoriesList.sort(); |
| 186 if (categories.contains('all')) { | 205 if (categories.contains('all')) { |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 268 new OptionHandler('--analyze-all', passThrough), | 287 new OptionHandler('--analyze-all', passThrough), |
| 269 new OptionHandler('--analyze-only', setAnalyzeOnly), | 288 new OptionHandler('--analyze-only', setAnalyzeOnly), |
| 270 new OptionHandler('--analyze-signatures-only', passThrough), | 289 new OptionHandler('--analyze-signatures-only', passThrough), |
| 271 new OptionHandler('--disable-native-live-type-analysis', passThrough), | 290 new OptionHandler('--disable-native-live-type-analysis', passThrough), |
| 272 new OptionHandler('--categories=.*', setCategories), | 291 new OptionHandler('--categories=.*', setCategories), |
| 273 new OptionHandler('--global-js-name=.*', checkGlobalName), | 292 new OptionHandler('--global-js-name=.*', checkGlobalName), |
| 274 new OptionHandler('--disable-type-inference', passThrough), | 293 new OptionHandler('--disable-type-inference', passThrough), |
| 275 new OptionHandler('--terse', passThrough), | 294 new OptionHandler('--terse', passThrough), |
| 276 new OptionHandler('--disallow-unsafe-eval', | 295 new OptionHandler('--disallow-unsafe-eval', |
| 277 (_) => hasDisallowUnsafeEval = true), | 296 (_) => hasDisallowUnsafeEval = true), |
| 297 new OptionHandler('-D.+=.+', addInEnvironment), | |
| 278 | 298 |
| 279 // The following two options must come last. | 299 // The following two options must come last. |
| 280 new OptionHandler('-.*', (String argument) { | 300 new OptionHandler('-.*', (String argument) { |
| 281 helpAndFail('Error: Unknown option "$argument".'); | 301 helpAndFail('Error: Unknown option "$argument".'); |
| 282 }), | 302 }), |
| 283 new OptionHandler('.*', (String argument) { | 303 new OptionHandler('.*', (String argument) { |
| 284 arguments.add(nativeToUriPath(argument)); | 304 arguments.add(nativeToUriPath(argument)); |
| 285 }) | 305 }) |
| 286 ]; | 306 ]; |
| 287 | 307 |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 404 if (isPrimaryOutput) { | 424 if (isPrimaryOutput) { |
| 405 totalCharactersWritten += charactersWritten; | 425 totalCharactersWritten += charactersWritten; |
| 406 } | 426 } |
| 407 } | 427 } |
| 408 | 428 |
| 409 return new EventSinkWrapper(writeStringSync, onDone); | 429 return new EventSinkWrapper(writeStringSync, onDone); |
| 410 } | 430 } |
| 411 | 431 |
| 412 return api.compile(uri, libraryRoot, packageRoot, | 432 return api.compile(uri, libraryRoot, packageRoot, |
| 413 inputProvider, diagnosticHandler, | 433 inputProvider, diagnosticHandler, |
| 414 options, outputProvider) | 434 options, outputProvider, environment) |
| 415 .then(compilationDone); | 435 .then(compilationDone); |
| 416 } | 436 } |
| 417 | 437 |
| 418 class EventSinkWrapper extends EventSink<String> { | 438 class EventSinkWrapper extends EventSink<String> { |
| 419 var onAdd, onClose; | 439 var onAdd, onClose; |
| 420 | 440 |
| 421 EventSinkWrapper(this.onAdd, this.onClose); | 441 EventSinkWrapper(this.onAdd, this.onClose); |
| 422 | 442 |
| 423 void add(String data) => onAdd(data); | 443 void add(String data) => onAdd(data); |
| 424 | 444 |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 474 -c Insert runtime type checks and enable assertions (checked mode). | 494 -c Insert runtime type checks and enable assertions (checked mode). |
| 475 -h Display this message (add -v for information about all options).''') ; | 495 -h Display this message (add -v for information about all options).''') ; |
| 476 } | 496 } |
| 477 | 497 |
| 478 void verboseHelp() { | 498 void verboseHelp() { |
| 479 print(r''' | 499 print(r''' |
| 480 Usage: dart2js [options] dartfile | 500 Usage: dart2js [options] dartfile |
| 481 | 501 |
| 482 Compiles Dart to JavaScript. | 502 Compiles Dart to JavaScript. |
| 483 | 503 |
| 484 Supported options: | 504 Supported options: |
|
ahe
2013/10/30 13:03:09
Please update the documentation.
ngeoffray
2013/10/30 15:13:59
Done.
| |
| 485 -o <file>, --out=<file> | 505 -o <file>, --out=<file> |
| 486 Generate the output into <file>. | 506 Generate the output into <file>. |
| 487 | 507 |
| 488 -c, --enable-checked-mode, --checked | 508 -c, --enable-checked-mode, --checked |
| 489 Insert runtime type checks and enable assertions (checked mode). | 509 Insert runtime type checks and enable assertions (checked mode). |
| 490 | 510 |
| 491 -h, /h, /?, --help | 511 -h, /h, /?, --help |
| 492 Display this message (add -v for information about all options). | 512 Display this message (add -v for information about all options). |
| 493 | 513 |
| 494 -v, --verbose | 514 -v, --verbose |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 600 try { | 620 try { |
| 601 var trace = getAttachedStackTrace(exception); | 621 var trace = getAttachedStackTrace(exception); |
| 602 if (trace != null) { | 622 if (trace != null) { |
| 603 print(trace); | 623 print(trace); |
| 604 } | 624 } |
| 605 } finally { | 625 } finally { |
| 606 exit(253); // 253 is recognized as a crash by our test scripts. | 626 exit(253); // 253 is recognized as a crash by our test scripts. |
| 607 } | 627 } |
| 608 }); | 628 }); |
| 609 } | 629 } |
| OLD | NEW |