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
This commit is contained in:
Bryan Duxbury 2011-03-01 19:53:07 +00:00
parent ef6cbfd1ab
commit bdca9f667f
3 changed files with 25 additions and 7 deletions

View File

@ -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_ + "/";
}

View File

@ -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<string>& generator_strings) {
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 @@ void generate(t_program* program, const vector<string>& 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,7 +1038,9 @@ int main(int argc, char** argv) {
usage();
}
g_incl_searchpath.push_back(arg);
} else if (strcmp(arg, "-o") == 0) {
} 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");
@ -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.

View File

@ -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<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 @@ 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_;