Chromium Code Reviews| Index: compiler/java/com/google/dart/compiler/DartCompiler.java |
| diff --git a/compiler/java/com/google/dart/compiler/DartCompiler.java b/compiler/java/com/google/dart/compiler/DartCompiler.java |
| index 48e5fdec066c0f1700121d7f8a7ff3b1e70c3b8c..8fad02679dc5736f059fdc7c3b121232d5e070fe 100644 |
| --- a/compiler/java/com/google/dart/compiler/DartCompiler.java |
| +++ b/compiler/java/com/google/dart/compiler/DartCompiler.java |
| @@ -48,7 +48,9 @@ import com.google.dart.compiler.util.DefaultTextOutput; |
| import org.kohsuke.args4j.CmdLineException; |
| import org.kohsuke.args4j.CmdLineParser; |
| +import java.io.BufferedReader; |
| import java.io.File; |
| +import java.io.FileReader; |
| import java.io.IOException; |
| import java.io.PrintStream; |
| import java.io.Reader; |
| @@ -969,6 +971,10 @@ public class DartCompiler { |
| CompilerOptions topCompilerOptions = processCommandLineOptions(topArgs); |
| boolean result = false; |
| try { |
| + if (topCompilerOptions.showVersion()) { |
| + showVersion(topCompilerOptions); |
| + System.exit(0); |
| + } |
| if (topCompilerOptions.shouldBatch()) { |
| if (topArgs.length > 1) { |
| System.err.println("(Extra arguments specified with -batch ignored.)"); |
| @@ -1016,14 +1022,14 @@ public class DartCompiler { |
| public static boolean compilerMain(CompilerOptions compilerOptions) throws IOException { |
| List<String> sourceFiles = compilerOptions.getSourceFiles(); |
| if (sourceFiles.size() == 0) { |
| - System.err.println("dartc: no source files were specified."); |
| + System.err.println("dart_analyzer: no source files were specified."); |
| showUsage(null, System.err); |
| return false; |
| } |
| File sourceFile = new File(sourceFiles.get(0)); |
| if (!sourceFile.exists()) { |
| - System.err.println("dartc: file not found: " + sourceFile); |
| + System.err.println("dart_analyzer: file not found: " + sourceFile); |
| showUsage(null, System.err); |
| return false; |
| } |
| @@ -1063,7 +1069,7 @@ public class DartCompiler { |
| } |
| private static void showUsage(CmdLineParser cmdLineParser, PrintStream out) { |
| - out.println("Usage: dartc [<options>] <dart-script> [script-arguments]"); |
| + out.println("Usage: dart_analyzer [<options>] <dart-script> [script-arguments]"); |
| out.println("Available options:"); |
| if (cmdLineParser == null) { |
| cmdLineParser = new CmdLineParser(new CompilerOptions()); |
| @@ -1347,4 +1353,32 @@ public class DartCompiler { |
| public static LibraryUnit getCoreLib(LibraryUnit libraryUnit) { |
| return findLibrary(libraryUnit, "dart:core", new HashSet<LibraryElement>()); |
| } |
| + |
| + private static void showVersion(CompilerOptions options) { |
| + String revision = getSdkRevision(options); |
| + if (revision == null) { |
| + revision = "<unkown>"; |
| + } |
| + System.out.println("dart_analyzer #" + revision); |
|
Brian Wilkerson
2012/07/31 19:28:25
I think it would be better to have a message like:
scheglov
2012/07/31 19:39:06
OK
|
| + } |
| + |
| + /** |
| + * @return the numeric revision of SDK, may be <code>null</code> if can not find. |
|
Brian Wilkerson
2012/07/31 19:28:25
nit: "can not" --> "cannot"
scheglov
2012/07/31 19:39:06
Done.
|
| + */ |
| + private static String getSdkRevision(CompilerOptions options) { |
| + try { |
| + File sdkPath = options.getDartSdkPath(); |
| + File revisionFile = new File(sdkPath, "revision"); |
| + if (revisionFile.exists() && revisionFile.isFile()) { |
| + BufferedReader br = new BufferedReader(new FileReader(revisionFile)); |
| + try { |
| + return br.readLine(); |
| + } finally { |
| + br.close(); |
| + } |
| + } |
| + } catch (Throwable e) { |
| + } |
| + return null; |
| + } |
| } |