From bdca9f667fb2d76b4085a4426636f4be129d1cfa Mon Sep 17 00:00:00 2001 From: Bryan Duxbury Date: Tue, 1 Mar 2011 19:53:07 +0000 Subject: [PATCH] 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 --- compiler/cpp/src/generate/t_generator.h | 4 ++++ compiler/cpp/src/main.cc | 13 +++++++++---- compiler/cpp/src/parse/t_program.h | 15 ++++++++++++--- 3 files changed, 25 insertions(+), 7 deletions(-) diff --git a/compiler/cpp/src/generate/t_generator.h b/compiler/cpp/src/generate/t_generator.h index 4de05688..24ac8401 100644 --- a/compiler/cpp/src/generate/t_generator.h +++ b/compiler/cpp/src/generate/t_generator.h @@ -133,6 +133,10 @@ class t_generator { * 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 0c561b9c..3e4a8744 100644 --- a/compiler/cpp/src/main.cc +++ b/compiler/cpp/src/main.cc @@ -630,6 +630,8 @@ void usage() { 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 @@ void generate(t_program* program, const vector& generator_strings) { const vector& 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 @@ void generate(t_program* program, const vector& generator_strings) { 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 @@ int main(int argc, char** argv) { 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 @@ int main(int argc, char** argv) { // 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 440d151e..0d05eede 100644 --- a/compiler/cpp/src/parse/t_program.h +++ b/compiler/cpp/src/parse/t_program.h @@ -60,13 +60,15 @@ class t_program : public t_doc { 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 @@ class t_program : public t_doc { // 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 @@ class t_program : public t_doc { // Programs to include const std::vector& 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 @@ class t_program : public t_doc { // 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_; -- 2.17.1