THRIFT-1069. general: Add command line option to prevent thrift from inserting gen-* directories

This patch adds a -out switch that allows for an absolute path to be set for outputting generated code.

Patch: Jake Farrell

git-svn-id: https://svn.apache.org/repos/asf/thrift/trunk@1076000 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/compiler/cpp/src/generate/t_generator.h b/compiler/cpp/src/generate/t_generator.h
index 4de0568..24ac840 100644
--- a/compiler/cpp/src/generate/t_generator.h
+++ b/compiler/cpp/src/generate/t_generator.h
@@ -133,6 +133,10 @@
    * Get the current output directory
    */
   virtual std::string get_out_dir() const {
+    if (program_->is_out_path_absolute()) {
+      return program_->get_out_path() + "/";
+    }
+
     return program_->get_out_path() + out_dir_base_ + "/";
   }
 
diff --git a/compiler/cpp/src/main.cc b/compiler/cpp/src/main.cc
index 0c561b9..3e4a874 100644
--- a/compiler/cpp/src/main.cc
+++ b/compiler/cpp/src/main.cc
@@ -630,6 +630,8 @@
   fprintf(stderr, "  -version    Print the compiler version\n");
   fprintf(stderr, "  -o dir      Set the output directory for gen-* packages\n");
   fprintf(stderr, "               (default: current directory)\n");
+  fprintf(stderr, "  -out dir    Set the ouput location for generated files.\n");
+  fprintf(stderr,"               (no gen-* folder will be created)\n");
   fprintf(stderr, "  -I dir      Add a directory to the list of directories\n");
   fprintf(stderr, "                searched for include directives\n");
   fprintf(stderr, "  -nowarn     Suppress all compiler warnings (BAD!)\n");
@@ -881,7 +883,7 @@
     const vector<t_program*>& includes = program->get_includes();
     for (size_t i = 0; i < includes.size(); ++i) {
       // Propogate output path from parent to child programs
-      includes[i]->set_out_path(program->get_out_path());
+      includes[i]->set_out_path(program->get_out_path(), program->is_out_path_absolute());
 
       generate(includes[i], generator_strings);
     }
@@ -926,6 +928,7 @@
 int main(int argc, char** argv) {
   int i;
   std::string out_path;
+  bool out_path_is_absolute = false;
 
   // Setup time string
   time_t now = time(NULL);
@@ -1035,8 +1038,10 @@
           usage();
         }
         g_incl_searchpath.push_back(arg);
-      } else if (strcmp(arg, "-o") == 0) {
-        arg = argv[++i];
+      } else if ((strcmp(arg, "-o") == 0) || (strcmp(arg, "-out") == 0)) {
+        out_path_is_absolute = (strcmp(arg, "-out") == 0) ? true : false;
+		  
+		arg = argv[++i];
         if (arg == NULL) {
           fprintf(stderr, "-o: missing output directory\n");
           usage();
@@ -1174,7 +1179,7 @@
   // Instance of the global parse tree
   t_program* program = new t_program(input_file);
   if (out_path.size()) {
-    program->set_out_path(out_path);
+    program->set_out_path(out_path, out_path_is_absolute);
   }
 
   // Compute the cpp include prefix.
diff --git a/compiler/cpp/src/parse/t_program.h b/compiler/cpp/src/parse/t_program.h
index 440d151..0d05eed 100644
--- a/compiler/cpp/src/parse/t_program.h
+++ b/compiler/cpp/src/parse/t_program.h
@@ -60,13 +60,15 @@
   t_program(std::string path, std::string name) :
     path_(path),
     name_(name),
-    out_path_("./") {
+    out_path_("./"),
+    out_path_is_absolute_(false) {
     scope_ = new t_scope();
   }
 
   t_program(std::string path) :
     path_(path),
-    out_path_("./") {
+    out_path_("./"),
+    out_path_is_absolute_(false) {
     name_ = program_name(path);
     scope_ = new t_scope();
   }
@@ -77,6 +79,9 @@
   // Output path accessor
   const std::string& get_out_path() const { return out_path_; }
 
+  // Create gen-* dir accessor
+  bool is_out_path_absolute() { return out_path_is_absolute_; }
+
   // Name accessor
   const std::string& get_name() const { return name_; }
 
@@ -108,8 +113,9 @@
   // Programs to include
   const std::vector<t_program*>& get_includes() const { return includes_; }
 
-  void set_out_path(std::string out_path) {
+  void set_out_path(std::string out_path, bool out_path_is_absolute) {
     out_path_ = out_path;
+    out_path_is_absolute_ = out_path_is_absolute;
     // Ensure that it ends with a trailing '/' (or '\' for windows machines)
     char c = out_path_.at(out_path_.size() - 1);
     if (!(c == '/' || c == '\\')) {
@@ -228,6 +234,9 @@
   // Output directory
   std::string out_path_;
 
+  // Output directory is absolute location for generated source (no gen-*)
+  bool out_path_is_absolute_;
+
   // Namespace
   std::string namespace_;