This is an automated email from the ASF dual-hosted git repository. dcelasun pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/thrift.git
View the commit online: https://github.com/apache/thrift/commit/f4475ff76fe3dcc1b3774d52bf28b333ab9acd01 The following commit(s) were added to refs/heads/master by this push: new f4475ff THRIFT-5019: Duplicate imports from multiple includes from a namespace f4475ff is described below commit f4475ff76fe3dcc1b3774d52bf28b333ab9acd01 Author: Duru Can Celasun <[email protected]> AuthorDate: Wed Nov 20 15:31:35 2019 +0000 THRIFT-5019: Duplicate imports from multiple includes from a namespace If a thrift file includes two files from the same namespace into a separate file, the generated Go code has duplicate imports for that namespace. This fixes that. Client: go --- compiler/cpp/src/thrift/generate/t_go_generator.cc | 5 +++++ lib/go/test/DuplicateImportsTest.thrift | 5 +++++ lib/go/test/Makefile.am | 7 +++++-- lib/go/test/common/a.thrift | 5 +++++ lib/go/test/common/b.thrift | 5 +++++ 5 files changed, 25 insertions(+), 2 deletions(-) diff --git a/compiler/cpp/src/thrift/generate/t_go_generator.cc b/compiler/cpp/src/thrift/generate/t_go_generator.cc index e153a78..2093841 100644 --- a/compiler/cpp/src/thrift/generate/t_go_generator.cc +++ b/compiler/cpp/src/thrift/generate/t_go_generator.cc @@ -777,11 +777,16 @@ string t_go_generator::render_included_programs(string& unused_prot) { const vector<t_program*>& includes = program_->get_includes(); string result = ""; string local_namespace = program_->get_namespace("go"); + std::set<std::string> included; for (auto include : includes) { if (!local_namespace.empty() && local_namespace == include->get_namespace("go")) { continue; } + if (!included.insert(include->get_namespace("go")).second) { + continue; + } + result += render_program_import(include, unused_prot); } return result; diff --git a/lib/go/test/DuplicateImportsTest.thrift b/lib/go/test/DuplicateImportsTest.thrift new file mode 100644 index 0000000..ffe1caf --- /dev/null +++ b/lib/go/test/DuplicateImportsTest.thrift @@ -0,0 +1,5 @@ +include "common/a.thrift" +include "common/b.thrift" + +typedef a.A A +typedef b.B B diff --git a/lib/go/test/Makefile.am b/lib/go/test/Makefile.am index 2a9d3f5..f5de26e 100644 --- a/lib/go/test/Makefile.am +++ b/lib/go/test/Makefile.am @@ -45,7 +45,8 @@ gopath: $(THRIFT) $(THRIFTTEST) \ ConflictNamespaceTestC.thrift \ ConflictNamespaceTestD.thrift \ ConflictNamespaceTestSuperThing.thrift \ - ConflictNamespaceServiceTest.thrift + ConflictNamespaceServiceTest.thrift \ + DuplicateImportsTest.thrift mkdir -p gopath/src grep -v list.*map.*list.*map $(THRIFTTEST) | grep -v 'set<Insanity>' > ThriftTest.thrift $(THRIFT) $(THRIFTARGS) -r IncludesTest.thrift @@ -71,6 +72,7 @@ gopath: $(THRIFT) $(THRIFTTEST) \ $(THRIFT) $(THRIFTARGS) ConflictNamespaceTestD.thrift $(THRIFT) $(THRIFTARGS) ConflictNamespaceTestSuperThing.thrift $(THRIFT) $(THRIFTARGS) ConflictNamespaceServiceTest.thrift + $(THRIFT) $(THRIFTARGS) -r DuplicateImportsTest.thrift GOPATH=`pwd`/gopath $(GO) get github.com/golang/mock/gomock || true sed -i 's/\"context\"/\"golang.org\/x\/net\/context\"/g' gopath/src/github.com/golang/mock/gomock/controller.go || true GOPATH=`pwd`/gopath $(GO) get github.com/golang/mock/gomock @@ -94,7 +96,8 @@ check: gopath unionbinarytest \ conflictnamespacetestsuperthing \ conflict/context/conflict_service-remote \ - servicestest/container_test-remote + servicestest/container_test-remote \ + duplicateimportstest GOPATH=`pwd`/gopath $(GO) test thrift tests dontexportrwtest clean-local: diff --git a/lib/go/test/common/a.thrift b/lib/go/test/common/a.thrift new file mode 100644 index 0000000..37e0e1c --- /dev/null +++ b/lib/go/test/common/a.thrift @@ -0,0 +1,5 @@ +namespace go common + +struct A { + 1: optional string a +} diff --git a/lib/go/test/common/b.thrift b/lib/go/test/common/b.thrift new file mode 100644 index 0000000..19930e7 --- /dev/null +++ b/lib/go/test/common/b.thrift @@ -0,0 +1,5 @@ +namespace go common + +struct B { + 1: optional string b +}
