Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions compiler/cpp/src/thrift/generate/t_go_generator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,19 @@ void t_go_generator::init_generator() {
package_dir_ = get_out_dir();
last_const_block_ = 0;

// The -remote stub's main() declares these local variables. An imported package with one of
// these names would be shadowed by them, so reserve them before any import is rendered; such a
// package is then imported under an alias in every file of this program.
if (!skip_remote_) {
for (const char* local :
{"cfg", "client", "cmd", "err", "framed", "headers",
"host", "httptrans", "iprot", "m", "oprot", "parsedUrl",
"parts", "port", "portStr", "protocol", "protocolFactory", "trans",
"urlString", "useHttp"}) {
package_identifiers_set_.insert(local);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

package_identifiers_set_ is actually global so this impacts more than the -remote code? do we have a way to only do this for the -remote part?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also the hardcoded list here doesn't seem maintainable, like it's easy to get out of sync with the actual local variables used in main inside -remote, but that part haven't changed in a long time though.

}
}

// This set is taken from https://github.com/golang/lint/blob/master/lint.go#L692
commonInitialisms.insert("API");
commonInitialisms.insert("ASCII");
Expand Down
13 changes: 11 additions & 2 deletions lib/go/test/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,10 @@ gopath: $(THRIFT) $(THRIFTTEST) \
ValidateTest.thrift \
ForwardType.thrift \
StringParseAllocationTest.thrift \
DocCommentTest.thrift
DocCommentTest.thrift \
RemoteShadowClient.thrift \
RemoteShadowHost.thrift \
RemoteShadowTest.thrift
mkdir -p gopath/src
grep -v 'set<Insanity>' $(THRIFTTEST) > ThriftTest.thrift
$(THRIFT) $(THRIFTARGS) $(RECURSIVE)
Expand Down Expand Up @@ -115,6 +118,7 @@ gopath: $(THRIFT) $(THRIFTTEST) \
$(THRIFT) $(THRIFTARGS) ForwardType.thrift
$(THRIFT) $(THRIFTARGS) StringParseAllocationTest.thrift
$(THRIFT) $(THRIFTARGS) DocCommentTest.thrift
$(THRIFT) $(THRIFTARGS) -r RemoteShadowTest.thrift
ln -nfs ../../tests gopath/src/tests
cp -r ./dontexportrwtest gopath/src
touch gopath
Expand Down Expand Up @@ -149,7 +153,9 @@ check: gopath
./gopath/src/processormiddlewaretest \
./gopath/src/clientmiddlewareexceptiontest \
./gopath/src/validatetest \
./gopath/src/forwardtypetest
./gopath/src/forwardtypetest \
./gopath/src/remoteshadowtest \
./gopath/src/remoteshadowtest/shadow_service-remote
$(GO) test github.com/apache/thrift/lib/go/thrift
$(GO) test ./gopath/src/tests ./gopath/src/dontexportrwtest

Expand Down Expand Up @@ -200,6 +206,9 @@ EXTRA_DIST = \
OptionalFieldsTest.thrift \
ProcessorMiddlewareTest.thrift \
RefAnnotationFieldsTest.thrift \
RemoteShadowClient.thrift \
RemoteShadowHost.thrift \
RemoteShadowTest.thrift \
RequiredFieldTest.thrift \
ServicesTest.thrift \
StringParseAllocationTest.thrift \
Expand Down
25 changes: 25 additions & 0 deletions lib/go/test/RemoteShadowClient.thrift
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#

// Its Go package is named like a local variable of the generated -remote stub.
namespace go client

struct Info {
1: i32 x
}
25 changes: 25 additions & 0 deletions lib/go/test/RemoteShadowHost.thrift
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#

// Its Go package is named like a local variable of the generated -remote stub.
namespace go host

struct Addr {
1: string name
}
29 changes: 29 additions & 0 deletions lib/go/test/RemoteShadowTest.thrift
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#

// The -remote stub declares local variables such as client and host; packages
// with those names, used by the arguments below, must not be shadowed by them.
namespace go remoteshadowtest

include "RemoteShadowClient.thrift"
include "RemoteShadowHost.thrift"

service ShadowService {
void f(1: RemoteShadowClient.Info info, 2: RemoteShadowHost.Addr addr)
}
Loading