Skip to content

Commit c2a9ce3

Browse files
compiler/cpp/src/main: Accept THRIFT_TYPES_PATH env variable
1 parent 8e95b25 commit c2a9ce3

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed

compiler/cpp/src/main.cc

+9-1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
*/
2929

3030
#include <cassert>
31+
#include <cstdlib>
3132
#include <stdlib.h>
3233
#include <stdio.h>
3334
#include <stdarg.h>
@@ -1053,7 +1054,13 @@ int main(int argc, char** argv) {
10531054
// Set the current path to a dummy value to make warning messages clearer.
10541055
g_curpath = "arguments";
10551056

1056-
g_incl_searchpath.push_back(THRIFT_TYPES_PATH);
1057+
std::string types_path = THRIFT_TYPES_PATH;
1058+
1059+
if (const char* env_path = std::getenv("THRIFT_TYPES_PATH")) {
1060+
types_path = std::string(env_path);
1061+
}
1062+
1063+
g_incl_searchpath.push_back(types_path);
10571064

10581065
// Hacky parameter handling... I didn't feel like using a library sorry!
10591066
for (i = 1; i < argc - 1; i++) {
@@ -1175,6 +1182,7 @@ int main(int argc, char** argv) {
11751182
}
11761183

11771184
program->set_include_prefix(include_prefix);
1185+
program->set_std_path(types_path);
11781186

11791187
// Initialize global types
11801188
g_type_void = new t_base_type("void", t_base_type::TYPE_VOID);

compiler/cpp/src/parse/t_program.h

+7-3
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,11 @@
5959
class t_program : public t_doc {
6060
public:
6161
t_program(std::string path, std::string name)
62-
: path_(path), name_(name), out_path_("./"), out_path_is_absolute_(false) {
62+
: path_(path), name_(name), out_path_("./"), out_path_is_absolute_(false), std_path_(THRIFT_TYPES_PATH) {
6363
scope_ = new t_scope();
6464
}
6565

66-
t_program(std::string path) : path_(path), out_path_("./"), out_path_is_absolute_(false) {
66+
t_program(std::string path) : path_(path), out_path_("./"), out_path_is_absolute_(false), std_path_(THRIFT_TYPES_PATH) {
6767
name_ = program_name(path);
6868
scope_ = new t_scope();
6969
}
@@ -76,7 +76,7 @@ class t_program : public t_doc {
7676
}
7777

7878
bool is_std_path() const {
79-
return path_.rfind(THRIFT_TYPES_NESTED_PATH, 0) == 0;
79+
return path_.rfind(std_path_ + "/types", 0) == 0;
8080
}
8181

8282
// Path accessor
@@ -126,6 +126,8 @@ class t_program : public t_doc {
126126
// Programs to include
127127
const std::vector<t_program*>& get_includes() const { return includes_; }
128128

129+
void set_std_path(std::string std_path) { std_path_ = std_path; }
130+
129131
void set_out_path(std::string out_path, bool out_path_is_absolute) {
130132
out_path_ = out_path;
131133
out_path_is_absolute_ = out_path_is_absolute;
@@ -367,6 +369,8 @@ class t_program : public t_doc {
367369
// Include prefix for this program, if any
368370
std::string include_prefix_;
369371

372+
std::string std_path_;
373+
370374
// Identifier lookup scope
371375
t_scope* scope_;
372376

compiler/cpp/version.h.in

-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
#define THRIFT_VERSION "@REPO_VERSION@"
22
#define THRIFT_TYPES_PATH "@TYPES_PREFIX@"
3-
#define THRIFT_TYPES_NESTED_PATH "@TYPES_PREFIX@/types"

0 commit comments

Comments
 (0)