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' show Future, EventSink; |
8 show Future, EventSink; | |
9 import 'dart:convert' show UTF8, LineSplitter; | 8 import 'dart:convert' show UTF8, LineSplitter; |
10 import 'dart:io' | 9 import 'dart:io' |
11 show exit, File, FileMode, Platform, RandomAccessFile, FileSystemException, | 10 show |
12 stdin, stderr; | 11 exit, |
| 12 File, |
| 13 FileMode, |
| 14 Platform, |
| 15 RandomAccessFile, |
| 16 FileSystemException, |
| 17 stdin, |
| 18 stderr; |
13 | 19 |
14 import '../compiler.dart' as api; | 20 import '../compiler.dart' as api; |
15 import 'commandline_options.dart'; | 21 import 'commandline_options.dart'; |
16 import 'io/source_file.dart'; | 22 import 'io/source_file.dart'; |
17 import 'source_file_provider.dart'; | 23 import 'source_file_provider.dart'; |
18 import 'filenames.dart'; | 24 import 'filenames.dart'; |
19 import 'util/uri_extras.dart'; | 25 import 'util/uri_extras.dart'; |
20 import 'util/util.dart' show stackTraceFilePrefix; | 26 import 'util/util.dart' show stackTraceFilePrefix; |
21 import 'util/command_line.dart'; | 27 import 'util/command_line.dart'; |
22 import 'package:package_config/discovery.dart' show findPackages; | 28 import 'package:package_config/discovery.dart' show findPackages; |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 | 172 |
167 setOutputType(String argument) { | 173 setOutputType(String argument) { |
168 optionsImplyCompilation.add(argument); | 174 optionsImplyCompilation.add(argument); |
169 if (argument == '--output-type=dart' || | 175 if (argument == '--output-type=dart' || |
170 argument == '--output-type=dart-multi') { | 176 argument == '--output-type=dart-multi') { |
171 outputLanguage = OUTPUT_LANGUAGE_DART; | 177 outputLanguage = OUTPUT_LANGUAGE_DART; |
172 if (!explicitOut) { | 178 if (!explicitOut) { |
173 out = currentDirectory.resolve('out.dart'); | 179 out = currentDirectory.resolve('out.dart'); |
174 sourceMapOut = currentDirectory.resolve('out.dart.map'); | 180 sourceMapOut = currentDirectory.resolve('out.dart.map'); |
175 } | 181 } |
176 diagnosticHandler(null, null, null, | 182 diagnosticHandler( |
| 183 null, |
| 184 null, |
| 185 null, |
177 "--output-type=dart is deprecated. It will remain available " | 186 "--output-type=dart is deprecated. It will remain available " |
178 "in Dart 1.11, but will be removed in Dart 1.12.", | 187 "in Dart 1.11, but will be removed in Dart 1.12.", |
179 api.Diagnostic.WARNING); | 188 api.Diagnostic.WARNING); |
180 } | 189 } |
181 passThrough(argument); | 190 passThrough(argument); |
182 } | 191 } |
183 | 192 |
184 String getDepsOutput(Map<Uri, SourceFile> sourceFiles) { | 193 String getDepsOutput(Map<Uri, SourceFile> sourceFiles) { |
185 var filenames = sourceFiles.keys.map((uri) => '$uri').toList(); | 194 var filenames = sourceFiles.keys.map((uri) => '$uri').toList(); |
186 filenames.sort(); | 195 filenames.sort(); |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
250 } | 259 } |
251 | 260 |
252 setCategories(String argument) { | 261 setCategories(String argument) { |
253 List<String> categories = extractParameter(argument).split(','); | 262 List<String> categories = extractParameter(argument).split(','); |
254 if (categories.contains('all')) { | 263 if (categories.contains('all')) { |
255 categories = ["Client", "Server"]; | 264 categories = ["Client", "Server"]; |
256 } else { | 265 } else { |
257 for (String category in categories) { | 266 for (String category in categories) { |
258 if (!["Client", "Server"].contains(category)) { | 267 if (!["Client", "Server"].contains(category)) { |
259 fail('Unsupported library category "$category", ' | 268 fail('Unsupported library category "$category", ' |
260 'supported categories are: Client, Server, all'); | 269 'supported categories are: Client, Server, all'); |
261 } | 270 } |
262 } | 271 } |
263 } | 272 } |
264 passThrough('--categories=${categories.join(",")}'); | 273 passThrough('--categories=${categories.join(",")}'); |
265 } | 274 } |
266 | 275 |
267 void handleThrowOnError(String argument) { | 276 void handleThrowOnError(String argument) { |
268 diagnosticHandler.throwOnError = true; | 277 diagnosticHandler.throwOnError = true; |
269 String parameter = extractParameter(argument, isOptionalArgument: true); | 278 String parameter = extractParameter(argument, isOptionalArgument: true); |
270 if (parameter != null) { | 279 if (parameter != null) { |
(...skipping 26 matching lines...) Expand all Loading... |
297 | 306 |
298 List<String> arguments = <String>[]; | 307 List<String> arguments = <String>[]; |
299 List<OptionHandler> handlers = <OptionHandler>[ | 308 List<OptionHandler> handlers = <OptionHandler>[ |
300 new OptionHandler('-[chvm?]+', handleShortOptions), | 309 new OptionHandler('-[chvm?]+', handleShortOptions), |
301 new OptionHandler('--throw-on-error(?:=[0-9]+)?', handleThrowOnError), | 310 new OptionHandler('--throw-on-error(?:=[0-9]+)?', handleThrowOnError), |
302 new OptionHandler(Flags.suppressWarnings, (_) { | 311 new OptionHandler(Flags.suppressWarnings, (_) { |
303 diagnosticHandler.showWarnings = false; | 312 diagnosticHandler.showWarnings = false; |
304 passThrough(Flags.suppressWarnings); | 313 passThrough(Flags.suppressWarnings); |
305 }), | 314 }), |
306 new OptionHandler(Flags.fatalWarnings, passThrough), | 315 new OptionHandler(Flags.fatalWarnings, passThrough), |
307 new OptionHandler(Flags.suppressHints, | 316 new OptionHandler( |
308 (_) => diagnosticHandler.showHints = false), | 317 Flags.suppressHints, (_) => diagnosticHandler.showHints = false), |
309 new OptionHandler( | 318 new OptionHandler( |
310 '--output-type=dart|--output-type=dart-multi|--output-type=js', | 319 '--output-type=dart|--output-type=dart-multi|--output-type=js', |
311 setOutputType), | 320 setOutputType), |
312 new OptionHandler(Flags.useCpsIr, passThrough), | 321 new OptionHandler(Flags.useCpsIr, passThrough), |
313 new OptionHandler(Flags.noFrequencyBasedMinification, passThrough), | 322 new OptionHandler(Flags.noFrequencyBasedMinification, passThrough), |
314 new OptionHandler(Flags.verbose, setVerbose), | 323 new OptionHandler(Flags.verbose, setVerbose), |
315 new OptionHandler(Flags.version, (_) => wantVersion = true), | 324 new OptionHandler(Flags.version, (_) => wantVersion = true), |
316 new OptionHandler('--library-root=.+', setLibraryRoot), | 325 new OptionHandler('--library-root=.+', setLibraryRoot), |
317 new OptionHandler('--out=.+|-o.*', setOutput, multipleArguments: true), | 326 new OptionHandler('--out=.+|-o.*', setOutput, multipleArguments: true), |
318 new OptionHandler(Flags.allowMockCompilation, passThrough), | 327 new OptionHandler(Flags.allowMockCompilation, passThrough), |
319 new OptionHandler(Flags.fastStartup, passThrough), | 328 new OptionHandler(Flags.fastStartup, passThrough), |
320 new OptionHandler(Flags.conditionalDirectives, passThrough), | 329 new OptionHandler(Flags.conditionalDirectives, passThrough), |
321 new OptionHandler('${Flags.minify}|-m', implyCompilation), | 330 new OptionHandler('${Flags.minify}|-m', implyCompilation), |
322 new OptionHandler(Flags.preserveUris, passThrough), | 331 new OptionHandler(Flags.preserveUris, passThrough), |
323 new OptionHandler('--force-strip=.*', setStrip), | 332 new OptionHandler('--force-strip=.*', setStrip), |
324 new OptionHandler(Flags.disableDiagnosticColors, | 333 new OptionHandler(Flags.disableDiagnosticColors, |
325 (_) => diagnosticHandler.enableColors = false), | 334 (_) => diagnosticHandler.enableColors = false), |
326 new OptionHandler(Flags.enableDiagnosticColors, | 335 new OptionHandler(Flags.enableDiagnosticColors, |
327 (_) => diagnosticHandler.enableColors = true), | 336 (_) => diagnosticHandler.enableColors = true), |
328 new OptionHandler('--enable[_-]checked[_-]mode|--checked', | 337 new OptionHandler('--enable[_-]checked[_-]mode|--checked', |
329 (_) => setCheckedMode(Flags.enableCheckedMode)), | 338 (_) => setCheckedMode(Flags.enableCheckedMode)), |
330 new OptionHandler(Flags.trustTypeAnnotations, | 339 new OptionHandler(Flags.trustTypeAnnotations, |
331 (_) => setTrustTypeAnnotations( | 340 (_) => setTrustTypeAnnotations(Flags.trustTypeAnnotations)), |
332 Flags.trustTypeAnnotations)), | |
333 new OptionHandler(Flags.trustPrimitives, | 341 new OptionHandler(Flags.trustPrimitives, |
334 (_) => setTrustPrimitives( | 342 (_) => setTrustPrimitives(Flags.trustPrimitives)), |
335 Flags.trustPrimitives)), | 343 new OptionHandler( |
336 new OptionHandler(Flags.trustJSInteropTypeAnnotations, | 344 Flags.trustJSInteropTypeAnnotations, |
337 (_) => setTrustJSInteropTypeAnnotations( | 345 (_) => setTrustJSInteropTypeAnnotations( |
338 Flags.trustJSInteropTypeAnnotations)), | 346 Flags.trustJSInteropTypeAnnotations)), |
339 new OptionHandler(r'--help|/\?|/h', (_) => wantHelp = true), | 347 new OptionHandler(r'--help|/\?|/h', (_) => wantHelp = true), |
340 new OptionHandler('--packages=.+', setPackageConfig), | 348 new OptionHandler('--packages=.+', setPackageConfig), |
341 new OptionHandler('--package-root=.+|-p.+', setPackageRoot), | 349 new OptionHandler('--package-root=.+|-p.+', setPackageRoot), |
342 new OptionHandler(Flags.analyzeAll, setAnalyzeAll), | 350 new OptionHandler(Flags.analyzeAll, setAnalyzeAll), |
343 new OptionHandler(Flags.analyzeOnly, setAnalyzeOnly), | 351 new OptionHandler(Flags.analyzeOnly, setAnalyzeOnly), |
344 new OptionHandler(Flags.noSourceMaps, passThrough), | 352 new OptionHandler(Flags.noSourceMaps, passThrough), |
345 new OptionHandler(Flags.analyzeSignaturesOnly, setAnalyzeOnly), | 353 new OptionHandler(Flags.analyzeSignaturesOnly, setAnalyzeOnly), |
346 new OptionHandler(Flags.disableNativeLiveTypeAnalysis, passThrough), | 354 new OptionHandler(Flags.disableNativeLiveTypeAnalysis, passThrough), |
347 new OptionHandler('--categories=.*', setCategories), | 355 new OptionHandler('--categories=.*', setCategories), |
348 new OptionHandler(Flags.disableTypeInference, implyCompilation), | 356 new OptionHandler(Flags.disableTypeInference, implyCompilation), |
349 new OptionHandler(Flags.terse, passThrough), | 357 new OptionHandler(Flags.terse, passThrough), |
350 new OptionHandler('--deferred-map=.+', implyCompilation), | 358 new OptionHandler('--deferred-map=.+', implyCompilation), |
351 new OptionHandler(Flags.dumpInfo, setDumpInfo), | 359 new OptionHandler(Flags.dumpInfo, setDumpInfo), |
352 new OptionHandler('--disallow-unsafe-eval', | 360 new OptionHandler( |
353 (_) => hasDisallowUnsafeEval = true), | 361 '--disallow-unsafe-eval', (_) => hasDisallowUnsafeEval = true), |
354 new OptionHandler(Option.showPackageWarnings, passThrough), | 362 new OptionHandler(Option.showPackageWarnings, passThrough), |
355 new OptionHandler(Flags.useContentSecurityPolicy, passThrough), | 363 new OptionHandler(Flags.useContentSecurityPolicy, passThrough), |
356 new OptionHandler(Flags.enableExperimentalMirrors, passThrough), | 364 new OptionHandler(Flags.enableExperimentalMirrors, passThrough), |
357 new OptionHandler(Flags.enableAssertMessage, passThrough), | 365 new OptionHandler(Flags.enableAssertMessage, passThrough), |
358 new OptionHandler('--enable-async', (_) { | 366 new OptionHandler('--enable-async', (_) { |
359 diagnosticHandler.info( | 367 diagnosticHandler.info( |
360 "Option '--enable-async' is no longer needed. " | 368 "Option '--enable-async' is no longer needed. " |
361 "Async-await is supported by default.", | 369 "Async-await is supported by default.", |
362 api.Diagnostic.HINT); | 370 api.Diagnostic.HINT); |
363 }), | 371 }), |
364 new OptionHandler('--enable-null-aware-operators', (_) { | 372 new OptionHandler('--enable-null-aware-operators', (_) { |
365 diagnosticHandler.info( | 373 diagnosticHandler.info( |
366 "Option '--enable-null-aware-operators' is no longer needed. " | 374 "Option '--enable-null-aware-operators' is no longer needed. " |
367 "Null aware operators are supported by default.", | 375 "Null aware operators are supported by default.", |
368 api.Diagnostic.HINT); | 376 api.Diagnostic.HINT); |
369 }), | 377 }), |
370 new OptionHandler('--enable-enum', (_) { | 378 new OptionHandler('--enable-enum', (_) { |
371 diagnosticHandler.info( | 379 diagnosticHandler.info( |
372 "Option '--enable-enum' is no longer needed. " | 380 "Option '--enable-enum' is no longer needed. " |
373 "Enums are supported by default.", | 381 "Enums are supported by default.", |
374 api.Diagnostic.HINT); | 382 api.Diagnostic.HINT); |
(...skipping 11 matching lines...) Expand all Loading... |
386 arguments.add(nativeToUriPath(argument)); | 394 arguments.add(nativeToUriPath(argument)); |
387 }) | 395 }) |
388 ]; | 396 ]; |
389 | 397 |
390 parseCommandLine(handlers, argv); | 398 parseCommandLine(handlers, argv); |
391 if (wantHelp || wantVersion) { | 399 if (wantHelp || wantVersion) { |
392 helpAndExit(wantHelp, wantVersion, diagnosticHandler.verbose); | 400 helpAndExit(wantHelp, wantVersion, diagnosticHandler.verbose); |
393 } | 401 } |
394 | 402 |
395 if (hasDisallowUnsafeEval) { | 403 if (hasDisallowUnsafeEval) { |
396 String precompiledName = | 404 String precompiledName = relativize( |
397 relativize(currentDirectory, | 405 currentDirectory, |
398 RandomAccessFileOutputProvider.computePrecompiledUri(out), | 406 RandomAccessFileOutputProvider.computePrecompiledUri(out), |
399 Platform.isWindows); | 407 Platform.isWindows); |
400 helpAndFail("Option '--disallow-unsafe-eval' has been removed." | 408 helpAndFail("Option '--disallow-unsafe-eval' has been removed." |
401 " Instead, the compiler generates a file named" | 409 " Instead, the compiler generates a file named" |
402 " '$precompiledName'."); | 410 " '$precompiledName'."); |
403 } | 411 } |
404 | 412 |
405 if (outputLanguage != OUTPUT_LANGUAGE_DART && stripArgumentSet) { | 413 if (outputLanguage != OUTPUT_LANGUAGE_DART && stripArgumentSet) { |
406 helpAndFail("Option '--force-strip' may only be used with " | 414 helpAndFail("Option '--force-strip' may only be used with " |
407 "'--output-type=dart'."); | 415 "'--output-type=dart'."); |
408 } | 416 } |
409 if (arguments.isEmpty) { | 417 if (arguments.isEmpty) { |
410 helpAndFail('No Dart file specified.'); | 418 helpAndFail('No Dart file specified.'); |
411 } | 419 } |
412 if (arguments.length > 1) { | 420 if (arguments.length > 1) { |
413 var extra = arguments.sublist(1); | 421 var extra = arguments.sublist(1); |
414 helpAndFail('Extra arguments: ${extra.join(" ")}'); | 422 helpAndFail('Extra arguments: ${extra.join(" ")}'); |
415 } | 423 } |
416 | 424 |
417 if (checkedMode && trustTypeAnnotations) { | 425 if (checkedMode && trustTypeAnnotations) { |
418 helpAndFail("Option '${Flags.trustTypeAnnotations}' may not be used in " | 426 helpAndFail("Option '${Flags.trustTypeAnnotations}' may not be used in " |
419 "checked mode."); | 427 "checked mode."); |
420 } | 428 } |
421 | 429 |
422 if (packageRoot != null && packageConfig != null) { | 430 if (packageRoot != null && packageConfig != null) { |
423 helpAndFail("Cannot specify both '--package-root' and '--packages."); | 431 helpAndFail("Cannot specify both '--package-root' and '--packages."); |
424 } | 432 } |
425 | 433 |
426 if ((analyzeOnly || analyzeAll) && !optionsImplyCompilation.isEmpty) { | 434 if ((analyzeOnly || analyzeAll) && !optionsImplyCompilation.isEmpty) { |
427 if (!analyzeOnly) { | 435 if (!analyzeOnly) { |
428 diagnosticHandler.info( | 436 diagnosticHandler.info( |
429 "Option '${Flags.analyzeAll}' implies '${Flags.analyzeOnly}'.", | 437 "Option '${Flags.analyzeAll}' implies '${Flags.analyzeOnly}'.", |
430 api.Diagnostic.INFO); | 438 api.Diagnostic.INFO); |
431 } | 439 } |
432 diagnosticHandler.info( | 440 diagnosticHandler.info( |
433 "Options $optionsImplyCompilation indicate that output is expected, " | 441 "Options $optionsImplyCompilation indicate that output is expected, " |
434 "but compilation is turned off by the option '${Flags.analyzeOnly}'.", | 442 "but compilation is turned off by the option '${Flags.analyzeOnly}'.", |
435 api.Diagnostic.INFO); | 443 api.Diagnostic.INFO); |
436 } | 444 } |
437 if (analyzeAll) analyzeOnly = true; | 445 if (analyzeAll) analyzeOnly = true; |
438 if (!analyzeOnly) { | 446 if (!analyzeOnly) { |
439 if (allowNativeExtensions) { | 447 if (allowNativeExtensions) { |
440 helpAndFail("Option '${Flags.allowNativeExtensions}' is only supported " | 448 helpAndFail("Option '${Flags.allowNativeExtensions}' is only supported " |
441 "in combination with the '${Flags.analyzeOnly}' option."); | 449 "in combination with the '${Flags.analyzeOnly}' option."); |
442 } | 450 } |
443 } | 451 } |
444 if (dumpInfo && outputLanguage == OUTPUT_LANGUAGE_DART) { | 452 if (dumpInfo && outputLanguage == OUTPUT_LANGUAGE_DART) { |
445 helpAndFail("Option '${Flags.dumpInfo}' is not supported in " | 453 helpAndFail("Option '${Flags.dumpInfo}' is not supported in " |
446 "combination with the '--output-type=dart' option."); | 454 "combination with the '--output-type=dart' option."); |
447 } | 455 } |
448 | 456 |
449 options.add('--out=$out'); | 457 options.add('--out=$out'); |
450 options.add('--source-map=$sourceMapOut'); | 458 options.add('--source-map=$sourceMapOut'); |
451 | 459 |
452 RandomAccessFileOutputProvider outputProvider = | 460 RandomAccessFileOutputProvider outputProvider = |
453 new RandomAccessFileOutputProvider( | 461 new RandomAccessFileOutputProvider(out, sourceMapOut, |
454 out, sourceMapOut, onInfo: diagnosticHandler.info, onFailure: fail); | 462 onInfo: diagnosticHandler.info, onFailure: fail); |
455 | 463 |
456 api.CompilationResult compilationDone(api.CompilationResult result) { | 464 api.CompilationResult compilationDone(api.CompilationResult result) { |
457 if (analyzeOnly) return result; | 465 if (analyzeOnly) return result; |
458 if (!result.isSuccess) { | 466 if (!result.isSuccess) { |
459 fail('Compilation failed.'); | 467 fail('Compilation failed.'); |
460 } | 468 } |
461 writeString(Uri.parse('$out.deps'), | 469 writeString( |
462 getDepsOutput(inputProvider.sourceFiles)); | 470 Uri.parse('$out.deps'), getDepsOutput(inputProvider.sourceFiles)); |
463 diagnosticHandler.info( | 471 diagnosticHandler |
464 'Compiled ${inputProvider.dartCharactersRead} characters Dart ' | 472 .info('Compiled ${inputProvider.dartCharactersRead} characters Dart ' |
465 '-> ${outputProvider.totalCharactersWritten} characters ' | 473 '-> ${outputProvider.totalCharactersWritten} characters ' |
466 '$outputLanguage in ' | 474 '$outputLanguage in ' |
467 '${relativize(currentDirectory, out, Platform.isWindows)}'); | 475 '${relativize(currentDirectory, out, Platform.isWindows)}'); |
468 if (diagnosticHandler.verbose) { | 476 if (diagnosticHandler.verbose) { |
469 String input = uriPathToNative(arguments[0]); | 477 String input = uriPathToNative(arguments[0]); |
470 print('Dart file ($input) compiled to $outputLanguage.'); | 478 print('Dart file ($input) compiled to $outputLanguage.'); |
471 print('Wrote the following files:'); | 479 print('Wrote the following files:'); |
472 for (String filename in outputProvider.allOutputFiles) { | 480 for (String filename in outputProvider.allOutputFiles) { |
473 print(" $filename"); | 481 print(" $filename"); |
474 } | 482 } |
475 } else if (!explicitOut) { | 483 } else if (!explicitOut) { |
476 String input = uriPathToNative(arguments[0]); | 484 String input = uriPathToNative(arguments[0]); |
477 String output = relativize(currentDirectory, out, Platform.isWindows); | 485 String output = relativize(currentDirectory, out, Platform.isWindows); |
478 print('Dart file ($input) compiled to $outputLanguage: $output'); | 486 print('Dart file ($input) compiled to $outputLanguage: $output'); |
479 } | 487 } |
480 return result; | 488 return result; |
481 } | 489 } |
482 | 490 |
483 Uri uri = currentDirectory.resolve(arguments[0]); | 491 Uri uri = currentDirectory.resolve(arguments[0]); |
484 return compileFunc(uri, libraryRoot, packageRoot, inputProvider, | 492 return compileFunc( |
485 diagnosticHandler, options, outputProvider, environment, | 493 uri, |
486 packageConfig, findPackages) | 494 libraryRoot, |
487 .then(compilationDone); | 495 packageRoot, |
| 496 inputProvider, |
| 497 diagnosticHandler, |
| 498 options, |
| 499 outputProvider, |
| 500 environment, |
| 501 packageConfig, |
| 502 findPackages) |
| 503 .then(compilationDone); |
488 } | 504 } |
489 | 505 |
490 class AbortLeg { | 506 class AbortLeg { |
491 final message; | 507 final message; |
492 AbortLeg(this.message); | 508 AbortLeg(this.message); |
493 toString() => 'Aborted due to --throw-on-error: $message'; | 509 toString() => 'Aborted due to --throw-on-error: $message'; |
494 } | 510 } |
495 | 511 |
496 void writeString(Uri uri, String text) { | 512 void writeString(Uri uri, String text) { |
497 if (uri.scheme != 'file') { | 513 if (uri.scheme != 'file') { |
498 fail('Unhandled scheme ${uri.scheme}.'); | 514 fail('Unhandled scheme ${uri.scheme}.'); |
499 } | 515 } |
500 var file = new File(uri.toFilePath()).openSync(mode: FileMode.WRITE); | 516 var file = new File(uri.toFilePath()).openSync(mode: FileMode.WRITE); |
501 file.writeStringSync(text); | 517 file.writeStringSync(text); |
502 file.closeSync(); | 518 file.closeSync(); |
503 } | 519 } |
504 | 520 |
505 void fail(String message) { | 521 void fail(String message) { |
506 if (diagnosticHandler != null) { | 522 if (diagnosticHandler != null) { |
507 diagnosticHandler.report( | 523 diagnosticHandler.report(null, null, -1, -1, message, api.Diagnostic.ERROR); |
508 null, null, -1, -1, message, api.Diagnostic.ERROR); | |
509 } else { | 524 } else { |
510 print('Error: $message'); | 525 print('Error: $message'); |
511 } | 526 } |
512 exitFunc(1); | 527 exitFunc(1); |
513 } | 528 } |
514 | 529 |
515 Future<api.CompilationResult> compilerMain(List<String> arguments) { | 530 Future<api.CompilationResult> compilerMain(List<String> arguments) { |
516 var root = uriPathToNative("/$LIBRARY_ROOT"); | 531 var root = uriPathToNative("/$LIBRARY_ROOT"); |
517 arguments = <String>['--library-root=${Platform.script.toFilePath()}$root'] | 532 arguments = <String>['--library-root=${Platform.script.toFilePath()}$root'] |
518 ..addAll(arguments); | 533 ..addAll(arguments); |
519 return compile(arguments); | 534 return compile(arguments); |
520 } | 535 } |
521 | 536 |
522 void help() { | 537 void help() { |
523 // This message should be no longer than 20 lines. The default | 538 // This message should be no longer than 20 lines. The default |
524 // terminal size normally 80x24. Two lines are used for the prompts | 539 // terminal size normally 80x24. Two lines are used for the prompts |
525 // before and after running the compiler. Another two lines may be | 540 // before and after running the compiler. Another two lines may be |
526 // used to print an error message. | 541 // used to print an error message. |
527 print(''' | 542 print(''' |
528 Usage: dart2js [options] dartfile | 543 Usage: dart2js [options] dartfile |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
653 --generate-code-with-compile-time-errors | 668 --generate-code-with-compile-time-errors |
654 Generates output even if the program contains compile-time errors. Use the | 669 Generates output even if the program contains compile-time errors. Use the |
655 exit code to determine if compilation failed. | 670 exit code to determine if compilation failed. |
656 | 671 |
657 --use-cps-ir | 672 --use-cps-ir |
658 Experimental. Use the new CPS based backend for code generation. | 673 Experimental. Use the new CPS based backend for code generation. |
659 | 674 |
660 --no-frequency-based-minification | 675 --no-frequency-based-minification |
661 Experimental. Disabled the new frequency based minifying namer and use the | 676 Experimental. Disabled the new frequency based minifying namer and use the |
662 old namer instead. | 677 old namer instead. |
663 '''.trim()); | 678 ''' |
| 679 .trim()); |
664 } | 680 } |
665 | 681 |
666 void helpAndExit(bool wantHelp, bool wantVersion, bool verbose) { | 682 void helpAndExit(bool wantHelp, bool wantVersion, bool verbose) { |
667 if (wantVersion) { | 683 if (wantVersion) { |
668 var version = (BUILD_ID == null) | 684 var version = (BUILD_ID == null) ? '<non-SDK build>' : BUILD_ID; |
669 ? '<non-SDK build>' | |
670 : BUILD_ID; | |
671 print('Dart-to-JavaScript compiler (dart2js) version: $version'); | 685 print('Dart-to-JavaScript compiler (dart2js) version: $version'); |
672 } | 686 } |
673 if (wantHelp) { | 687 if (wantHelp) { |
674 if (verbose) { | 688 if (verbose) { |
675 verboseHelp(); | 689 verboseHelp(); |
676 } else { | 690 } else { |
677 help(); | 691 help(); |
678 } | 692 } |
679 } | 693 } |
680 exitFunc(0); | 694 exitFunc(0); |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
755 args.addAll(batchArguments); | 769 args.addAll(batchArguments); |
756 args.addAll(splitLine(line, windows: Platform.isWindows)); | 770 args.addAll(splitLine(line, windows: Platform.isWindows)); |
757 return internalMain(args); | 771 return internalMain(args); |
758 }).catchError((exception, trace) { | 772 }).catchError((exception, trace) { |
759 if (!identical(exception, _EXIT_SIGNAL)) { | 773 if (!identical(exception, _EXIT_SIGNAL)) { |
760 exitCode = 253; | 774 exitCode = 253; |
761 } | 775 } |
762 }).whenComplete(() { | 776 }).whenComplete(() { |
763 // The testing framework waits for a status line on stdout and | 777 // The testing framework waits for a status line on stdout and |
764 // stderr before moving to the next test. | 778 // stderr before moving to the next test. |
765 if (exitCode == 0){ | 779 if (exitCode == 0) { |
766 print(">>> TEST OK"); | 780 print(">>> TEST OK"); |
767 } else if (exitCode == 253) { | 781 } else if (exitCode == 253) { |
768 print(">>> TEST CRASH"); | 782 print(">>> TEST CRASH"); |
769 } else { | 783 } else { |
770 print(">>> TEST FAIL"); | 784 print(">>> TEST FAIL"); |
771 } | 785 } |
772 stderr.writeln(">>> EOF STDERR"); | 786 stderr.writeln(">>> EOF STDERR"); |
773 subscription.resume(); | 787 subscription.resume(); |
774 }); | 788 }); |
775 }); | 789 }); |
776 } | 790 } |
OLD | NEW |