forked from envoyproxy/envoy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
protobuf.patch
150 lines (138 loc) · 4.81 KB
/
protobuf.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
# https://github.com/protocolbuffers/protobuf/pull/6720
diff --git a/third_party/BUILD b/third_party/BUILD
new file mode 100644
index 0000000000..b66101a39a
--- /dev/null
+++ b/third_party/BUILD
@@ -0,0 +1 @@
+exports_files(["six.BUILD", "zlib.BUILD"])
# https://github.com/protocolbuffers/protobuf/pull/6896
diff --git a/src/google/protobuf/stubs/strutil.cc b/src/google/protobuf/stubs/strutil.cc
index 62b3f0a871..bb3df47ccf 100644
--- a/src/google/protobuf/stubs/strutil.cc
+++ b/src/google/protobuf/stubs/strutil.cc
@@ -1435,32 +1435,44 @@ AlphaNum::AlphaNum(strings::Hex hex) {
// after the area just overwritten. It comes in multiple flavors to minimize
// call overhead.
static char *Append1(char *out, const AlphaNum &x) {
- memcpy(out, x.data(), x.size());
- return out + x.size();
+ if (x.size() > 0) {
+ memcpy(out, x.data(), x.size());
+ out += x.size();
+ }
+ return out;
}
static char *Append2(char *out, const AlphaNum &x1, const AlphaNum &x2) {
- memcpy(out, x1.data(), x1.size());
- out += x1.size();
-
- memcpy(out, x2.data(), x2.size());
- return out + x2.size();
+ if (x1.size() > 0) {
+ memcpy(out, x1.data(), x1.size());
+ out += x1.size();
+ }
+ if (x2.size() > 0) {
+ memcpy(out, x2.data(), x2.size());
+ out += x2.size();
+ }
+ return out;
}
-static char *Append4(char *out,
- const AlphaNum &x1, const AlphaNum &x2,
+static char *Append4(char *out, const AlphaNum &x1, const AlphaNum &x2,
const AlphaNum &x3, const AlphaNum &x4) {
- memcpy(out, x1.data(), x1.size());
- out += x1.size();
-
- memcpy(out, x2.data(), x2.size());
- out += x2.size();
-
- memcpy(out, x3.data(), x3.size());
- out += x3.size();
-
- memcpy(out, x4.data(), x4.size());
- return out + x4.size();
+ if (x1.size() > 0) {
+ memcpy(out, x1.data(), x1.size());
+ out += x1.size();
+ }
+ if (x2.size() > 0) {
+ memcpy(out, x2.data(), x2.size());
+ out += x2.size();
+ }
+ if (x3.size() > 0) {
+ memcpy(out, x3.data(), x3.size());
+ out += x3.size();
+ }
+ if (x4.size() > 0) {
+ memcpy(out, x4.data(), x4.size());
+ out += x4.size();
+ }
+ return out;
}
string StrCat(const AlphaNum &a, const AlphaNum &b) {
# patching for zlib binding
diff --git a/BUILD b/BUILD
index efc3d8e7f..746ad4851 100644
--- a/BUILD
+++ b/BUILD
@@ -24,7 +24,7 @@ config_setting(
# ZLIB configuration
################################################################################
-ZLIB_DEPS = ["@zlib//:zlib"]
+ZLIB_DEPS = ["//external:zlib"]
################################################################################
# Protobuf Runtime Library
diff --git a/protobuf.bzl b/protobuf.bzl
index 5fa5543b1..484bc41a7 100644
--- a/protobuf.bzl
+++ b/protobuf.bzl
@@ -75,18 +75,17 @@ def _RelativeOutputPath(path, include, dest = ""):
def _proto_gen_impl(ctx):
"""General implementation for generating protos"""
srcs = ctx.files.srcs
- deps = []
- deps += ctx.files.srcs
+ deps = depset(direct=ctx.files.srcs)
source_dir = _SourceDir(ctx)
gen_dir = _GenDir(ctx).rstrip("/")
if source_dir:
- import_flags = ["-I" + source_dir, "-I" + gen_dir]
+ import_flags = depset(direct=["-I" + source_dir, "-I" + gen_dir])
else:
- import_flags = ["-I."]
+ import_flags = depset(direct=["-I."])
for dep in ctx.attr.deps:
- import_flags += dep.proto.import_flags
- deps += dep.proto.deps
+ import_flags = depset(transitive=[import_flags, dep.proto.import_flags])
+ deps = depset(transitive=[deps, dep.proto.deps])
if not ctx.attr.gen_cc and not ctx.attr.gen_py and not ctx.executable.plugin:
return struct(
@@ -103,7 +102,7 @@ def _proto_gen_impl(ctx):
in_gen_dir = src.root.path == gen_dir
if in_gen_dir:
import_flags_real = []
- for f in depset(import_flags).to_list():
+ for f in import_flags.to_list():
path = f.replace("-I", "")
import_flags_real.append("-I$(realpath -s %s)" % path)
@@ -118,7 +117,7 @@ def _proto_gen_impl(ctx):
outs.extend(_PyOuts([src.basename], use_grpc_plugin = use_grpc_plugin))
outs = [ctx.actions.declare_file(out, sibling = src) for out in outs]
- inputs = [src] + deps
+ inputs = [src] + deps.to_list()
tools = [ctx.executable.protoc]
if ctx.executable.plugin:
plugin = ctx.executable.plugin
@@ -141,7 +140,7 @@ def _proto_gen_impl(ctx):
inputs = inputs,
tools = tools,
outputs = outs,
- arguments = args + import_flags + [src.path],
+ arguments = args + import_flags.to_list() + [src.path],
executable = ctx.executable.protoc,
mnemonic = "ProtoCompile",
use_default_shell_env = True,