Permalink
Browse files

Merge pull request #44 from matttproud/refactor_makefile_improvements

Refactorings of Makefiles to Decouple Thrift Version Expectations
  • Loading branch information...
2 parents 81acaa3 + 600e491 commit e2c739e7012a1e64fe9d5993d309e81bc8269d47 @pomack committed Oct 11, 2012
View
@@ -1,3 +1,5 @@
+include Makefile.environment
+
SUB_DIRECTORIES = lib tests
CLEAN_DIRECTORIES = $(SUB_DIRECTORIES:%=clean-%)
TEST_DIRECTORIES = $(SUB_DIRECTORIES:%=test-%)
View
@@ -0,0 +1 @@
+export THRIFT_VERSION = 0.8.0
@@ -928,9 +928,9 @@ void t_go_generator::generate_go_struct_definition(ofstream& out,
indent_up();
for (m_iter = members.begin(); m_iter != members.end(); ++m_iter) {
- string thrift_name((*m_iter)->get_name());
+ const string thrift_name = escape_string((*m_iter)->get_name());
out <<
- indent() << "thrift.NewTField(\"" << escape_string(thrift_name) << "\", " << type_to_enum((*m_iter)->get_type()) << ", " << (*m_iter)->get_key() << ")," << endl;
+ indent() << "thrift.NewTField(\"" << thrift_name << "\", " << type_to_enum((*m_iter)->get_type()) << ", " << (*m_iter)->get_key() << ")," << endl;
}
out <<
@@ -943,18 +943,19 @@ void t_go_generator::generate_go_struct_definition(ofstream& out,
for (m_iter = members.begin(); m_iter != members.end(); ++m_iter) {
// Initialize fields
- //t_type* type = (*m_iter)->get_type();
- string fieldName(publicize((*m_iter)->get_name()));
- string fullFieldName = "output." + fieldName;
- t_type* type = get_true_type((*m_iter)->get_type());
+ const string base_field_name = (*m_iter)->get_name();
+ const string escaped_field_name = escape_string(base_field_name);
+ const string go_safe_name = variable_name_to_go_name(escaped_field_name);
+ const string publicized_name = publicize(go_safe_name);
+ const string full_field_name = "output." + publicized_name;
+ const t_type* type = get_true_type((*m_iter)->get_type());
+ const bool has_default_value = (*m_iter)->get_value() != NULL;
+ const bool type_is_enum = type->is_enum();
- if (type->is_enum() && (*m_iter)->get_value() == NULL) {
- out <<
- indent() << fullFieldName << " = math.MinInt32 - 1" << endl;
- } else if ((*m_iter)->get_value() != NULL) {
- out <<
- indent() << fullFieldName << " = " <<
- render_field_default_value(*m_iter, fullFieldName) << endl;
+ if (has_default_value) {
+ out << indent() << full_field_name << " = " << render_field_default_value(*m_iter, base_field_name) << endl;
+ } else if (type_is_enum) {
+ out << indent() << full_field_name << " = math.MinInt32 - 1" << endl;
}
}
@@ -1005,7 +1006,10 @@ void t_go_generator::generate_go_struct_definition(ofstream& out,
indent_up();
for (m_iter = members.begin(); m_iter != members.end(); ++m_iter) {
- string field_name(publicize(variable_name_to_go_name((*m_iter)->get_name())));
+ const string base_field_name = (*m_iter)->get_name();
+ const string escaped_field_name = escape_string(base_field_name);
+ const string go_safe_name = variable_name_to_go_name(escaped_field_name);
+ const string field_name = publicize(go_safe_name);
out <<
indent() << "case " << (*m_iter)->get_key() << ": return p." << field_name << endl;
}
@@ -1051,7 +1055,7 @@ void t_go_generator::generate_isset_helpers(ofstream& out,
t_type* type = get_true_type((*f_iter)->get_type());
if ((*f_iter)->get_req() == t_field::T_OPTIONAL || type->is_enum()) {
- const string field_name(publicize((*f_iter)->get_name()));
+ const string field_name(publicize(variable_name_to_go_name(escape_string((*f_iter)->get_name()))));
t_const_value* field_default_value = (*f_iter)->get_value();
out <<
indent() << "func (p *" << tstruct_name << ") IsSet" << field_name << "() bool {" << endl;
View
@@ -1,4 +1,4 @@
-SUB_DIRECTORIES = generation interoperability merge
+SUB_DIRECTORIES = cassandra-1.0.11 cassandra-1.1.4 generation interoperability merge
CLEAN_DIRECTORIES = $(SUB_DIRECTORIES:%=%-clean)
TEST_STAMPS = $(SUB_DIRECTORIES:%=%-stamp)
TEST_ARTIFACTS =$(TEST_STAMPS)
@@ -7,6 +7,18 @@ all: test
test: $(SUB_DIRECTORIES)
+cassandra-1.0.11: cassandra-1.0.11-stamp
+
+cassandra-1.0.11-stamp: interoperability-stamp
+ $(MAKE) -C cassandra-1.0.11 test
+ touch $@
+
+cassandra-1.1.4: cassandra-1.1.4-stamp
+
+cassandra-1.1.4-stamp: interoperability-stamp
+ $(MAKE) -C cassandra-1.1.4 test
+ touch $@
+
generation: generation-stamp
generation-stamp: merge-stamp
@@ -0,0 +1,30 @@
+export GOPATH = $(CURDIR)/../../lib/go
+
+TEST_ARTIFACTS = \
+ gen-go \
+ test-compile-stamp \
+ test-generation-stamp \
+ test-stamp
+
+THRIFT = $(CURDIR)/../merge/thrift-$(THRIFT_VERSION)/compiler/cpp/thrift
+IDL = $(CURDIR)/cassandra.thrift
+
+all: test
+
+test: test-stamp
+
+test-stamp: test-compile-stamp
+ touch $@
+
+test-compile-stamp: test-generation-stamp
+ cd gen-go/cassandra && go build -v -x .
+ touch $@
+
+test-generation-stamp:
+ "$(THRIFT)" --gen go "$(IDL)"
+ touch $@
+
+clean:
+ rm -rf $(TEST_ARTIFACTS)
+
+.PHONY: test
Oops, something went wrong.

0 comments on commit e2c739e

Please sign in to comment.