Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / tools / gn / gn_main.cc
index 9c86ab5..05291e9 100644 (file)
@@ -8,6 +8,15 @@
 #include "tools/gn/commands.h"
 #include "tools/gn/err.h"
 #include "tools/gn/location.h"
+#include "tools/gn/standard_out.h"
+
+// Only the GN-generated build makes this header for now.
+// TODO(brettw) consider adding this if we need it in GYP.
+#if defined(GN_BUILD)
+#include "tools/gn/last_commit_position.h"
+#else
+#define LAST_COMMIT_POSITION "UNKNOWN"
+#endif
 
 namespace {
 
@@ -36,11 +45,19 @@ int main(int argc, char** argv) {
   std::vector<std::string> args = GetArgs(cmdline);
 
   std::string command;
-  if (cmdline.HasSwitch("help")) {
-    // Make "--help" default to help command.
+  if (cmdline.HasSwitch("help") || cmdline.HasSwitch("h")) {
+    // Make "-h" and "--help" default to help command.
     command = commands::kHelp;
+  } else if (cmdline.HasSwitch("version")) {
+    // Make "--version" print the version and exit.
+    OutputString(std::string(LAST_COMMIT_POSITION) + "\n");
+    exit(0);
   } else if (args.empty()) {
-    command = commands::kGen;
+    // No command, print error and exit.
+    Err(Location(), "No command specified.",
+        "Most commonly you want \"gn gen <out_dir>\" to make a build dir.\n"
+        "Or try \"gn help\" for more commands.").PrintToStdout();
+    return 1;
   } else {
     command = args[0];
     args.erase(args.begin());
@@ -61,5 +78,4 @@ int main(int argc, char** argv) {
   }
 
   exit(retval);  // Don't free memory, it can be really slow!
-  return retval;
 }