Skip to content

Commit faf8af1

Browse files
authored
Merge pull request #41 from qiwzhang/remove_pb
Use official cc_proto_library
2 parents 8285079 + 80a9c5d commit faf8af1

9 files changed

+71
-70
lines changed

repositories.bzl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ def protobuf_repositories(bind=True):
109109
)
110110

111111
http_archive(
112-
name = "protobuf_git",
112+
name = "com_google_protobuf",
113113
strip_prefix = "protobuf-" + PROTOBUF_COMMIT,
114114
url = "https://github.com/google/protobuf/archive/v" + PROTOBUF_COMMIT + ".tar.gz",
115115
sha256 = PROTOBUF_SHA256,
@@ -118,32 +118,32 @@ def protobuf_repositories(bind=True):
118118
if bind:
119119
native.bind(
120120
name = "protoc",
121-
actual = "@protobuf_git//:protoc",
121+
actual = "@com_google_protobuf//:protoc",
122122
)
123123

124124
native.bind(
125125
name = "protobuf",
126-
actual = "@protobuf_git//:protobuf",
126+
actual = "@com_google_protobuf//:protobuf",
127127
)
128128

129129
native.bind(
130130
name = "cc_wkt_protos",
131-
actual = "@protobuf_git//:cc_wkt_protos",
131+
actual = "@com_google_protobuf//:cc_wkt_protos",
132132
)
133133

134134
native.bind(
135135
name = "cc_wkt_protos_genproto",
136-
actual = "@protobuf_git//:cc_wkt_protos_genproto",
136+
actual = "@com_google_protobuf//:cc_wkt_protos_genproto",
137137
)
138138

139139
native.bind(
140140
name = "protobuf_compiler",
141-
actual = "@protobuf_git//:protoc_lib",
141+
actual = "@com_google_protobuf//:protoc_lib",
142142
)
143143

144144
native.bind(
145145
name = "protobuf_clib",
146-
actual = "@protobuf_git//:protoc_lib",
146+
actual = "@com_google_protobuf//:protoc_lib",
147147
)
148148

149149
GOOGLETEST_COMMIT = "43863938377a9ea1399c0596269e0890b5c5515a"
@@ -238,7 +238,7 @@ cc_library(
238238
GOOGLEAPIS_COMMIT = "32a10f69e2c9ce15bba13ab1ff928bacebb25160" # May 20, 2019
239239
GOOGLEAPIS_SHA256 = "6861efa8619579e06e70dd4765cdf6cef1ecad6a1a2026ad750541e99552bf71"
240240

241-
def googleapis_repositories(protobuf_repo="@protobuf_git//", bind=True):
241+
def googleapis_repositories(protobuf_repo="@com_google_protobuf//", bind=True):
242242
BUILD = """
243243
# Copyright 2016 Google Inc. All Rights Reserved.
244244
#

src/request_message_translator.cc

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@
2424
#include "grpc_transcoding/prefix_writer.h"
2525
#include "grpc_transcoding/request_weaver.h"
2626

27-
namespace pb = ::google::protobuf;
28-
namespace pbutil = ::google::protobuf::util;
2927
namespace pbconv = ::google::protobuf::util::converter;
3028

3129
namespace google {

src/type_helper.cc

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
#include <string>
2626
#include <unordered_map>
2727

28-
namespace pb = ::google::protobuf;
2928
namespace pbutil = ::google::protobuf::util;
3029
namespace pbconv = ::google::protobuf::util::converter;
3130
namespace pberr = ::google::protobuf::util::error;
@@ -41,21 +40,22 @@ class SimpleTypeResolver : public pbutil::TypeResolver {
4140
public:
4241
SimpleTypeResolver() : url_prefix_(DEFAULT_URL_PREFIX) {}
4342

44-
void AddType(const pb::Type& t) {
43+
void AddType(const google::protobuf::Type& t) {
4544
type_map_.emplace(url_prefix_ + t.name(), &t);
4645
// A temporary workaround for service configs that use
4746
// "proto2.MessageOptions.*" options.
48-
ReplaceProto2WithGoogleProtobufInOptionNames(const_cast<pb::Type*>(&t));
47+
ReplaceProto2WithGoogleProtobufInOptionNames(
48+
const_cast<google::protobuf::Type*>(&t));
4949
}
5050

51-
void AddEnum(const pb::Enum& e) {
51+
void AddEnum(const google::protobuf::Enum& e) {
5252
enum_map_.emplace(url_prefix_ + e.name(), &e);
5353
}
5454

5555
// TypeResolver implementation
5656
// Resolves a type url for a message type.
57-
virtual pbutil::Status ResolveMessageType(const std::string& type_url,
58-
pb::Type* type) override {
57+
virtual pbutil::Status ResolveMessageType(
58+
const std::string& type_url, google::protobuf::Type* type) override {
5959
auto i = type_map_.find(type_url);
6060
if (end(type_map_) != i) {
6161
if (nullptr != type) {
@@ -69,8 +69,8 @@ class SimpleTypeResolver : public pbutil::TypeResolver {
6969
}
7070

7171
// Resolves a type url for an enum type.
72-
virtual pbutil::Status ResolveEnumType(const std::string& type_url,
73-
pb::Enum* enum_type) override {
72+
virtual pbutil::Status ResolveEnumType(
73+
const std::string& type_url, google::protobuf::Enum* enum_type) override {
7474
auto i = enum_map_.find(type_url);
7575
if (end(enum_map_) != i) {
7676
if (nullptr != enum_type) {
@@ -84,7 +84,8 @@ class SimpleTypeResolver : public pbutil::TypeResolver {
8484
}
8585

8686
private:
87-
void ReplaceProto2WithGoogleProtobufInOptionNames(pb::Type* type) {
87+
void ReplaceProto2WithGoogleProtobufInOptionNames(
88+
google::protobuf::Type* type) {
8889
// As a temporary workaround for service configs that use
8990
// "proto2.MessageOptions.*" options instead of
9091
// "google.protobuf.MessageOptions.*", we replace the option names to make
@@ -101,8 +102,8 @@ class SimpleTypeResolver : public pbutil::TypeResolver {
101102
}
102103

103104
std::string url_prefix_;
104-
std::unordered_map<std::string, const pb::Type*> type_map_;
105-
std::unordered_map<std::string, const pb::Enum*> enum_map_;
105+
std::unordered_map<std::string, const google::protobuf::Type*> type_map_;
106+
std::unordered_map<std::string, const google::protobuf::Enum*> enum_map_;
106107

107108
SimpleTypeResolver(const SimpleTypeResolver&) = delete;
108109
SimpleTypeResolver& operator=(const SimpleTypeResolver&) = delete;
@@ -126,32 +127,33 @@ void TypeHelper::Initialize() {
126127
type_info_.reset(pbconv::TypeInfo::NewTypeInfo(type_resolver_));
127128
}
128129

129-
void TypeHelper::AddType(const pb::Type& t) {
130+
void TypeHelper::AddType(const google::protobuf::Type& t) {
130131
reinterpret_cast<SimpleTypeResolver*>(type_resolver_)->AddType(t);
131132
}
132133

133-
void TypeHelper::AddEnum(const pb::Enum& e) {
134+
void TypeHelper::AddEnum(const google::protobuf::Enum& e) {
134135
reinterpret_cast<SimpleTypeResolver*>(type_resolver_)->AddEnum(e);
135136
}
136137

137138
pbutil::Status TypeHelper::ResolveFieldPath(
138-
const pb::Type& type, const std::string& field_path_str,
139-
std::vector<const pb::Field*>* field_path_out) const {
139+
const google::protobuf::Type& type, const std::string& field_path_str,
140+
std::vector<const google::protobuf::Field*>* field_path_out) const {
140141
// Split the field names & call ResolveFieldPath()
141142
const std::vector<std::string> field_names =
142143
absl::StrSplit(field_path_str, '.', absl::SkipEmpty());
143144
return ResolveFieldPath(type, field_names, field_path_out);
144145
}
145146

146147
pbutil::Status TypeHelper::ResolveFieldPath(
147-
const pb::Type& type, const std::vector<std::string>& field_names,
148-
std::vector<const pb::Field*>* field_path_out) const {
148+
const google::protobuf::Type& type,
149+
const std::vector<std::string>& field_names,
150+
std::vector<const google::protobuf::Field*>* field_path_out) const {
149151
// The type of the current message being processed (initially the type of the
150152
// top level message)
151153
auto current_type = &type;
152154

153155
// The resulting field path
154-
std::vector<const pb::Field*> field_path;
156+
std::vector<const google::protobuf::Field*> field_path;
155157

156158
for (size_t i = 0; i < field_names.size(); ++i) {
157159
// Find the field by name in the current type
@@ -166,7 +168,7 @@ pbutil::Status TypeHelper::ResolveFieldPath(
166168

167169
if (i < field_names.size() - 1) {
168170
// If this is not the last field in the path, it must be a message
169-
if (pb::Field::TYPE_MESSAGE != field->kind()) {
171+
if (google::protobuf::Field::TYPE_MESSAGE != field->kind()) {
170172
return pbutil::Status(
171173
pberr::INVALID_ARGUMENT,
172174
"Encountered a non-leaf field \"" + field->name() +

test/BUILD

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
#
1515
################################################################################
1616
#
17-
package(default_visibility = ["//visibility:public"])
17+
load("@com_google_protobuf//:protobuf.bzl", "py_proto_library")
1818

19-
load("@protobuf_git//:protobuf.bzl", "cc_proto_library")
19+
package(default_visibility = ["//visibility:public"])
2020

2121
cc_test(
2222
name = "http_template_test",
@@ -82,16 +82,16 @@ cc_test(
8282
],
8383
)
8484

85-
cc_proto_library(
86-
name = "bookstore_test_proto",
85+
proto_library(
86+
name = "bookstore_proto",
8787
testonly = 1,
8888
srcs = ["bookstore.proto"],
89-
include = ".",
90-
default_runtime = "//external:protobuf",
91-
protoc = "//external:protoc",
92-
deps = [
93-
"//external:cc_wkt_protos",
94-
],
89+
)
90+
91+
cc_proto_library(
92+
name = "bookstore_cc_proto",
93+
testonly = 1,
94+
deps = [":bookstore_proto"],
9595
)
9696

9797
cc_test(
@@ -136,7 +136,7 @@ cc_library(
136136
"request_translator_test_base.h",
137137
],
138138
deps = [
139-
":bookstore_test_proto",
139+
":bookstore_cc_proto",
140140
":test_common",
141141
"//external:googletest",
142142
"//external:protobuf",
@@ -156,7 +156,7 @@ cc_test(
156156
"testdata/bookstore_service.pb.txt",
157157
],
158158
deps = [
159-
":bookstore_test_proto",
159+
":bookstore_cc_proto",
160160
":request_translator_test_base",
161161
":test_common",
162162
"//external:googletest_main",
@@ -174,7 +174,7 @@ cc_test(
174174
"testdata/bookstore_service.pb.txt",
175175
],
176176
deps = [
177-
":bookstore_test_proto",
177+
":bookstore_cc_proto",
178178
":request_translator_test_base",
179179
"//external:googletest_main",
180180
"//src:request_stream_translator",
@@ -191,7 +191,7 @@ cc_test(
191191
"testdata/bookstore_service.pb.txt",
192192
],
193193
deps = [
194-
":bookstore_test_proto",
194+
":bookstore_cc_proto",
195195
":request_translator_test_base",
196196
":test_common",
197197
"//external:googletest_main",
@@ -222,7 +222,7 @@ cc_test(
222222
"testdata/bookstore_service.pb.txt",
223223
],
224224
deps = [
225-
":bookstore_test_proto",
225+
":bookstore_cc_proto",
226226
":test_common",
227227
"//external:googletest_main",
228228
"//src:message_reader",

test/json_request_translator_test.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@
2020
#include <string>
2121
#include <vector>
2222

23-
#include "bookstore.pb.h"
2423
#include "google/protobuf/io/zero_copy_stream.h"
2524
#include "gtest/gtest.h"
2625
#include "proto_stream_tester.h"
2726
#include "request_translator_test_base.h"
27+
#include "test/bookstore.pb.h"
2828
#include "test_common.h"
2929

3030
namespace google {

test/request_message_translator_test.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@
1919
#include <memory>
2020
#include <string>
2121

22-
#include "bookstore.pb.h"
2322
#include "google/protobuf/struct.pb.h"
2423
#include "google/protobuf/type.pb.h"
2524
#include "gtest/gtest.h"
2625
#include "request_translator_test_base.h"
26+
#include "test/bookstore.pb.h"
2727
#include "test_common.h"
2828

2929
namespace google {

test/request_stream_translator_test.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@
1919
#include <memory>
2020
#include <string>
2121

22-
#include "bookstore.pb.h"
2322
#include "google/protobuf/type.pb.h"
2423
#include "gtest/gtest.h"
2524
#include "request_translator_test_base.h"
25+
#include "test/bookstore.pb.h"
2626

2727
namespace google {
2828
namespace grpc {

test/response_to_json_translator_test.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@
2121
#include <string>
2222
#include <vector>
2323

24-
#include "bookstore.pb.h"
2524
#include "google/protobuf/io/zero_copy_stream.h"
2625
#include "google/protobuf/text_format.h"
2726
#include "grpc_transcoding/type_helper.h"
2827
#include "gtest/gtest.h"
28+
#include "test/bookstore.pb.h"
2929
#include "test_common.h"
3030

3131
namespace google {

0 commit comments

Comments
 (0)