Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(812)

Unified Diff: compiler/java/com/google/dart/compiler/DartCompiler.java

Issue 10825112: Issue 4262. Support for --version in dart_analyzer (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « compiler/java/com/google/dart/compiler/CommandLineOptions.java ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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;
+ }
}
« no previous file with comments | « compiler/java/com/google/dart/compiler/CommandLineOptions.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698