diff --git a/sdk/bin/dart2js b/sdk/bin/dart2js index 96354cae4a7..2baaba762ff 100755 --- a/sdk/bin/dart2js +++ b/sdk/bin/dart2js @@ -41,9 +41,6 @@ unset EXTRA_VM_OPTIONS declare -a EXTRA_VM_OPTIONS if test -f "$SNAPSHOT"; then - # TODO(ahe): Remove the following line when we are relatively sure it works. - echo Using snapshot "$SNAPSHOT" 1>&2 - EXTRA_OPTIONS[${#EXTRA_OPTIONS[@]}]="--library-root=$SDK_DIR" fi diff --git a/sdk/bin/dart2js.bat b/sdk/bin/dart2js.bat index be0219f4cc4..aa6efb71da4 100644 --- a/sdk/bin/dart2js.bat +++ b/sdk/bin/dart2js.bat @@ -29,7 +29,6 @@ if _%DART2JS_DEVELOPER_MODE%_ == _1_ ( ) if exist "%SNAPSHOT%" ( - echo Using snapshot "%SNAPSHOT%" >&2 set EXTRA_OPTIONS=%EXTRA_OPTIONS% "--library-root=%SDK_DIR%" ) diff --git a/sdk/lib/_internal/compiler/implementation/dart2js.dart b/sdk/lib/_internal/compiler/implementation/dart2js.dart index 8d3c7da267d..c4242ca84a8 100644 --- a/sdk/lib/_internal/compiler/implementation/dart2js.dart +++ b/sdk/lib/_internal/compiler/implementation/dart2js.dart @@ -86,6 +86,7 @@ void compile(List argv) { List options = new List(); bool explicitOut = false; bool wantHelp = false; + bool wantVersion = false; String outputLanguage = 'JavaScript'; bool stripArgumentSet = false; bool analyzeOnly = false; @@ -197,6 +198,7 @@ void compile(List argv) { (_) => diagnosticHandler.showWarnings = false), new OptionHandler('--output-type=dart|--output-type=js', setOutputType), new OptionHandler('--verbose', setVerbose), + new OptionHandler('--version', (_) => wantVersion = true), new OptionHandler('--library-root=.+', setLibraryRoot), new OptionHandler('--out=.+|-o.+', setOutput), new OptionHandler('--allow-mock-compilation', passThrough), @@ -235,7 +237,9 @@ void compile(List argv) { ]; parseCommandLine(handlers, argv); - if (wantHelp) helpAndExit(diagnosticHandler.verbose); + if (wantHelp || wantVersion) { + helpAndExit(wantHelp, wantVersion, diagnosticHandler.verbose); + } if (outputLanguage != OUTPUT_LANGUAGE_DART && stripArgumentSet) { helpAndFail('Error: --force-strip may only be used with ' @@ -413,6 +417,9 @@ Supported options: -v, --verbose Display verbose information. + --version + Display version information. + -p, --package-root= Where to find packages, that is, "package:..." imports. @@ -487,11 +494,19 @@ be removed in a future version: '''.trim()); } -void helpAndExit(bool verbose) { - if (verbose) { - verboseHelp(); - } else { - help(); +void helpAndExit(bool wantHelp, bool wantVersion, bool verbose) { + if (wantVersion) { + var version = (BUILD_ID == null) + ? '' + : BUILD_ID; + print('Dart-to-JavaScript compiler (dart2js) version: $version'); + } + if (wantHelp) { + if (verbose) { + verboseHelp(); + } else { + help(); + } } exit(0); } diff --git a/sdk/lib/_internal/compiler/implementation/js_backend/emitter.dart b/sdk/lib/_internal/compiler/implementation/js_backend/emitter.dart index 6ecbfd5099e..d6c1b606222 100644 --- a/sdk/lib/_internal/compiler/implementation/js_backend/emitter.dart +++ b/sdk/lib/_internal/compiler/implementation/js_backend/emitter.dart @@ -2948,7 +2948,7 @@ if (typeof document !== "undefined" && document.readyState !== "complete") { computeNeededClasses(); - mainBuffer.add(GENERATED_BY); + mainBuffer.add(buildGeneratedBy()); addComment(HOOKS_API_USAGE, mainBuffer); mainBuffer.add('function ${namer.isolateName}()$_{}\n'); mainBuffer.add('init()$N$n'); @@ -3173,7 +3173,7 @@ if (typeof document !== "undefined" && document.readyState !== "complete") { void emitDeferredPreambleWhenEmpty(CodeBuffer buffer) { if (!buffer.isEmpty) return; - buffer.write(GENERATED_BY); + buffer.write(buildGeneratedBy()); buffer.write('var old${namer.CURRENT_ISOLATE}$_=' '$_${namer.CURRENT_ISOLATE}$N'); @@ -3186,6 +3186,12 @@ if (typeof document !== "undefined" && document.readyState !== "complete") { '$_${namer.isolateName}.prototype$N$n'); } + String buildGeneratedBy() { + var suffix = ''; + if (BUILD_ID != null) suffix = ' version: $BUILD_ID'; + return '// Generated by dart2js, the Dart to JavaScript compiler$suffix.\n'; + } + String buildSourceMap(CodeBuffer buffer, SourceFile compiledFile) { SourceMapBuilder sourceMapBuilder = new SourceMapBuilder(compiler.sourceMapUri); @@ -3214,10 +3220,6 @@ if (typeof document !== "undefined" && document.readyState !== "complete") { } } -const String GENERATED_BY = """ -// Generated by dart2js, the Dart to JavaScript compiler. -"""; - const String HOOKS_API_USAGE = """ // The code supports the following hooks: // dartPrint(message) - if this function is defined it is called diff --git a/sdk/lib/_internal/compiler/implementation/js_backend/js_backend.dart b/sdk/lib/_internal/compiler/implementation/js_backend/js_backend.dart index 4f7b4998cac..e5db0925c2d 100644 --- a/sdk/lib/_internal/compiler/implementation/js_backend/js_backend.dart +++ b/sdk/lib/_internal/compiler/implementation/js_backend/js_backend.dart @@ -13,6 +13,7 @@ import '../elements/modelx.dart' show FunctionElementX; // TODO(ahe): There seems to be a bug in the VM, so we have to hide "js". import '../dart2jslib.dart' hide Selector, TypedSelector, js; +import '../dart2js.dart' show BUILD_ID; import '../dart_types.dart'; import '../js/js.dart' as jsAst; import '../js/js.dart' show js; // TODO(ahe): VM bug, see above.