1 |
commit: 78245b85a8d6b58f97f27a0bdb9526f2052fa7d0 |
2 |
Author: Arfrever Frehtes Taifersar Arahesis <Arfrever <AT> Apache <DOT> Org> |
3 |
AuthorDate: Thu Apr 18 19:16:35 2019 +0000 |
4 |
Commit: Mike Gilbert <floppym <AT> gentoo <DOT> org> |
5 |
CommitDate: Fri Apr 19 16:39:07 2019 +0000 |
6 |
URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=78245b85 |
7 |
|
8 |
dev-libs/protobuf: Add live ebuild. |
9 |
|
10 |
Signed-off-by: Arfrever Frehtes Taifersar Arahesis <Arfrever <AT> Apache.Org> |
11 |
Signed-off-by: Mike Gilbert <floppym <AT> gentoo.org> |
12 |
|
13 |
.../protobuf-3.8.0-protoc_input_output_files.patch | 262 +++++++++++++++++++++ |
14 |
dev-libs/protobuf/protobuf-9999.ebuild | 118 ++++++++++ |
15 |
2 files changed, 380 insertions(+) |
16 |
|
17 |
diff --git a/dev-libs/protobuf/files/protobuf-3.8.0-protoc_input_output_files.patch b/dev-libs/protobuf/files/protobuf-3.8.0-protoc_input_output_files.patch |
18 |
new file mode 100644 |
19 |
index 00000000000..a60bd74f39a |
20 |
--- /dev/null |
21 |
+++ b/dev-libs/protobuf/files/protobuf-3.8.0-protoc_input_output_files.patch |
22 |
@@ -0,0 +1,262 @@ |
23 |
+https://github.com/protocolbuffers/protobuf/pull/235 |
24 |
+ |
25 |
+--- /src/google/protobuf/compiler/command_line_interface.cc |
26 |
++++ /src/google/protobuf/compiler/command_line_interface.cc |
27 |
+@@ -949,6 +949,28 @@ |
28 |
+ } |
29 |
+ |
30 |
+ if (mode_ == MODE_ENCODE || mode_ == MODE_DECODE) { |
31 |
++ bool success = false; |
32 |
++ int in_fd = STDIN_FILENO; |
33 |
++ int out_fd = STDOUT_FILENO; |
34 |
++ |
35 |
++ if (!protobuf_in_path_.empty()) { |
36 |
++ in_fd = open(protobuf_in_path_.c_str(), O_RDONLY); |
37 |
++ if (in_fd == -1) { |
38 |
++ std::cerr << protobuf_in_path_ << ": error: failed to open file." << std::endl; |
39 |
++ return 1; |
40 |
++ } |
41 |
++ } |
42 |
++ if (!protobuf_out_path_.empty()) { |
43 |
++ out_fd = open(protobuf_out_path_.c_str(), |
44 |
++ O_WRONLY | O_CREAT | O_TRUNC, |
45 |
++ 0644); |
46 |
++ if (out_fd == -1) { |
47 |
++ std::cerr << protobuf_out_path_ << ": error: failed to open file." << std::endl; |
48 |
++ close(in_fd); |
49 |
++ return 1; |
50 |
++ } |
51 |
++ } |
52 |
++ |
53 |
+ if (codec_type_.empty()) { |
54 |
+ // HACK: Define an EmptyMessage type to use for decoding. |
55 |
+ DescriptorPool pool; |
56 |
+@@ -957,13 +979,20 @@ |
57 |
+ file.add_message_type()->set_name("EmptyMessage"); |
58 |
+ GOOGLE_CHECK(pool.BuildFile(file) != NULL); |
59 |
+ codec_type_ = "EmptyMessage"; |
60 |
+- if (!EncodeOrDecode(&pool)) { |
61 |
+- return 1; |
62 |
+- } |
63 |
++ success = EncodeOrDecode(&pool, in_fd, out_fd); |
64 |
+ } else { |
65 |
+- if (!EncodeOrDecode(descriptor_pool.get())) { |
66 |
+- return 1; |
67 |
+- } |
68 |
++ success = EncodeOrDecode(descriptor_pool.get(), in_fd, out_fd); |
69 |
++ } |
70 |
++ |
71 |
++ if (in_fd != STDIN_FILENO) { |
72 |
++ close(in_fd); |
73 |
++ } |
74 |
++ if (out_fd != STDOUT_FILENO) { |
75 |
++ close(out_fd); |
76 |
++ } |
77 |
++ |
78 |
++ if (!success) { |
79 |
++ return 1; |
80 |
+ } |
81 |
+ } |
82 |
+ |
83 |
+@@ -1001,6 +1030,11 @@ |
84 |
+ for (int i = 0; i < proto_path_.size(); i++) { |
85 |
+ source_tree->MapPath(proto_path_[i].first, proto_path_[i].second); |
86 |
+ } |
87 |
++ if (mode_ == MODE_COMPILE && |
88 |
++ (!protobuf_in_path_.empty() || !protobuf_out_path_.empty())) { |
89 |
++ std::cerr << "--protobuf_in and --protobuf_out are only valid with " |
90 |
++ << "decode operations. Ignoring."; |
91 |
++ } |
92 |
+ |
93 |
+ // Map input files to virtual paths if possible. |
94 |
+ if (!MakeInputsBeProtoPathRelative(source_tree, fallback_database)) { |
95 |
+@@ -1627,6 +1661,12 @@ |
96 |
+ |
97 |
+ codec_type_ = value; |
98 |
+ |
99 |
++ } else if (name == "--protobuf_in") { |
100 |
++ protobuf_in_path_ = value; |
101 |
++ |
102 |
++ } else if (name == "--protobuf_out") { |
103 |
++ protobuf_out_path_ = value; |
104 |
++ |
105 |
+ } else if (name == "--error_format") { |
106 |
+ if (value == "gcc") { |
107 |
+ error_format_ = ERROR_FORMAT_GCC; |
108 |
+@@ -1763,29 +1803,50 @@ |
109 |
+ " -h, --help Show this text and exit.\n" |
110 |
+ " --encode=MESSAGE_TYPE Read a text-format message of the " |
111 |
+ "given type\n" |
112 |
+- " from standard input and write it in " |
113 |
+- "binary\n" |
114 |
+- " to standard output. The message type " |
115 |
+- "must\n" |
116 |
++ " and write it in binary. The message " |
117 |
++ "type must\n" |
118 |
+ " be defined in PROTO_FILES or their " |
119 |
+ "imports.\n" |
120 |
++ " The input/output protobuf files are " |
121 |
++ "specified\n" |
122 |
++ " using the --protobuf_in and " |
123 |
++ "--protobuf_out\n" |
124 |
++ " command line flags.\n" |
125 |
+ " --decode=MESSAGE_TYPE Read a binary message of the given " |
126 |
+- "type from\n" |
127 |
+- " standard input and write it in text " |
128 |
+- "format\n" |
129 |
+- " to standard output. The message type " |
130 |
+- "must\n" |
131 |
+- " be defined in PROTO_FILES or their " |
132 |
+- "imports.\n" |
133 |
++ "type and\n" |
134 |
++ " write it in text format. The message " |
135 |
++ "type\n" |
136 |
++ " must be defined in PROTO_FILES or " |
137 |
++ "their imports.\n" |
138 |
++ " The input/output protobuf files are " |
139 |
++ "specified\n" |
140 |
++ " using the --protobuf_in and " |
141 |
++ "--protobuf_out\n" |
142 |
++ " command line flags.\n" |
143 |
+ " --decode_raw Read an arbitrary protocol message " |
144 |
+- "from\n" |
145 |
+- " standard input and write the raw " |
146 |
+- "tag/value\n" |
147 |
+- " pairs in text format to standard " |
148 |
+- "output. No\n" |
149 |
++ "and write\n" |
150 |
++ " the raw tag/value pairs in text format." |
151 |
++ " No\n" |
152 |
+ " PROTO_FILES should be given when using " |
153 |
+ "this\n" |
154 |
+- " flag.\n" |
155 |
++ " flag. The input/output protobuf files " |
156 |
++ "are\n" |
157 |
++ " specified using the --protobuf_in and\n" |
158 |
++ " --protobuf_out command line flags.\n" |
159 |
++ " --protobuf_in=FILE Absolute path to the protobuf file " |
160 |
++ "from which\n" |
161 |
++ " input of encoding/decoding operation " |
162 |
++ "will be\n" |
163 |
++ " read. If omitted, input will be read " |
164 |
++ "from\n" |
165 |
++ " standard input.\n" |
166 |
++ " --protobuf_out=FILE Absolute path to the protobuf file " |
167 |
++ "to which\n" |
168 |
++ " output of encoding/decoding operation " |
169 |
++ "will be\n" |
170 |
++ " written. If omitted, output will be " |
171 |
++ "written to\n" |
172 |
++ " standard output.\n" |
173 |
+ " --descriptor_set_in=FILES Specifies a delimited list of FILES\n" |
174 |
+ " each containing a FileDescriptorSet " |
175 |
+ "(a\n" |
176 |
+@@ -2101,7 +2162,9 @@ |
177 |
+ return true; |
178 |
+ } |
179 |
+ |
180 |
+-bool CommandLineInterface::EncodeOrDecode(const DescriptorPool* pool) { |
181 |
++bool CommandLineInterface::EncodeOrDecode(const DescriptorPool* pool, |
182 |
++ int in_fd, |
183 |
++ int out_fd) { |
184 |
+ // Look up the type. |
185 |
+ const Descriptor* type = pool->FindMessageTypeByName(codec_type_); |
186 |
+ if (type == NULL) { |
187 |
+@@ -2113,15 +2176,15 @@ |
188 |
+ std::unique_ptr<Message> message(dynamic_factory.GetPrototype(type)->New()); |
189 |
+ |
190 |
+ if (mode_ == MODE_ENCODE) { |
191 |
+- SetFdToTextMode(STDIN_FILENO); |
192 |
+- SetFdToBinaryMode(STDOUT_FILENO); |
193 |
++ SetFdToTextMode(in_fd); |
194 |
++ SetFdToBinaryMode(out_fd); |
195 |
+ } else { |
196 |
+- SetFdToBinaryMode(STDIN_FILENO); |
197 |
+- SetFdToTextMode(STDOUT_FILENO); |
198 |
++ SetFdToBinaryMode(in_fd); |
199 |
++ SetFdToTextMode(out_fd); |
200 |
+ } |
201 |
+ |
202 |
+- io::FileInputStream in(STDIN_FILENO); |
203 |
+- io::FileOutputStream out(STDOUT_FILENO); |
204 |
++ io::FileInputStream in(in_fd); |
205 |
++ io::FileOutputStream out(out_fd); |
206 |
+ |
207 |
+ if (mode_ == MODE_ENCODE) { |
208 |
+ // Input is text. |
209 |
+--- /src/google/protobuf/compiler/command_line_interface.h |
210 |
++++ /src/google/protobuf/compiler/command_line_interface.h |
211 |
+@@ -286,7 +286,9 @@ |
212 |
+ GeneratorContext* generator_context, std::string* error); |
213 |
+ |
214 |
+ // Implements --encode and --decode. |
215 |
+- bool EncodeOrDecode(const DescriptorPool* pool); |
216 |
++ bool EncodeOrDecode(const DescriptorPool* pool, |
217 |
++ int in_fd, |
218 |
++ int out_fd); |
219 |
+ |
220 |
+ // Implements the --descriptor_set_out option. |
221 |
+ bool WriteDescriptorSet( |
222 |
+@@ -418,6 +420,13 @@ |
223 |
+ // parsed FileDescriptorSets to be used for loading protos. Otherwise, empty. |
224 |
+ std::vector<std::string> descriptor_set_in_names_; |
225 |
+ |
226 |
++ // When using --encode / --decode / --decode_raw absolute path to the output |
227 |
++ // file. (Empty string indicates write to STDOUT). |
228 |
++ std::string protobuf_out_path_; |
229 |
++ // When using --encode / --decode / --decode_raw, absolute path to the input |
230 |
++ // file. (Empty string indicates read from STDIN). |
231 |
++ std::string protobuf_in_path_; |
232 |
++ |
233 |
+ // If --descriptor_set_out was given, this is the filename to which the |
234 |
+ // FileDescriptorSet should be written. Otherwise, empty. |
235 |
+ std::string descriptor_set_out_name_; |
236 |
+--- /src/google/protobuf/compiler/command_line_interface_unittest.cc |
237 |
++++ /src/google/protobuf/compiler/command_line_interface_unittest.cc |
238 |
+@@ -95,7 +95,7 @@ |
239 |
+ virtual void SetUp(); |
240 |
+ virtual void TearDown(); |
241 |
+ |
242 |
+- // Runs the CommandLineInterface with the given command line. The |
243 |
++ // Run the CommandLineInterface with the given command line. The |
244 |
+ // command is automatically split on spaces, and the string "$tmpdir" |
245 |
+ // is replaced with TestTempDir(). |
246 |
+ void Run(const std::string& command); |
247 |
+@@ -2337,6 +2337,17 @@ |
248 |
+ EXPECT_EQ(StripCR(expected_text), StripCR(captured_stderr_)); |
249 |
+ } |
250 |
+ |
251 |
++ void ExpectBinaryFilesMatch(const string &expected_file, |
252 |
++ const string &actual_file) { |
253 |
++ string expected_output, actual_output; |
254 |
++ ASSERT_TRUE(File::ReadFileToString(expected_file, &expected_output)); |
255 |
++ ASSERT_TRUE(File::ReadFileToString(actual_file, &actual_output)); |
256 |
++ |
257 |
++ // Don't use EXPECT_EQ because we don't want to print raw binary data to |
258 |
++ // stdout on failure. |
259 |
++ EXPECT_TRUE(expected_output == actual_output); |
260 |
++ } |
261 |
++ |
262 |
+ private: |
263 |
+ void WriteUnittestProtoDescriptorSet() { |
264 |
+ unittest_proto_descriptor_set_filename_ = |
265 |
+@@ -2431,6 +2442,19 @@ |
266 |
+ "net/proto2/internal/no_such_file.proto: No such file or directory\n"); |
267 |
+ } |
268 |
+ |
269 |
++TEST_P(EncodeDecodeTest, RedirectInputOutput) { |
270 |
++ string out_file = TestTempDir() + "/golden_message_out.pbf"; |
271 |
++ EXPECT_TRUE( |
272 |
++ Run(TestUtil::MaybeTranslatePath("net/proto2/internal/unittest.proto") + |
273 |
++ " --encode=protobuf_unittest.TestAllTypes" + |
274 |
++ " --protobuf_in=" + TestUtil::GetTestDataPath( |
275 |
++ "net/proto2/internal/" |
276 |
++ "testdata/text_format_unittest_data_oneof_implemented.txt") + |
277 |
++ " --protobuf_out=" + out_file)); |
278 |
++ ExpectBinaryFilesMatch(out_file, TestUtil::GetTestDataPath( |
279 |
++ "net/proto2/internal/testdata/golden_message_oneof_implemented")); |
280 |
++} |
281 |
++ |
282 |
+ INSTANTIATE_TEST_SUITE_P(FileDescriptorSetSource, EncodeDecodeTest, |
283 |
+ testing::Values(PROTO_PATH, DESCRIPTOR_SET_IN)); |
284 |
+ } // anonymous namespace |
285 |
|
286 |
diff --git a/dev-libs/protobuf/protobuf-9999.ebuild b/dev-libs/protobuf/protobuf-9999.ebuild |
287 |
new file mode 100644 |
288 |
index 00000000000..ab63263883b |
289 |
--- /dev/null |
290 |
+++ b/dev-libs/protobuf/protobuf-9999.ebuild |
291 |
@@ -0,0 +1,118 @@ |
292 |
+# Copyright 2008-2019 Arfrever Frehtes Taifersar Arahesis and others |
293 |
+# Distributed under the terms of the GNU General Public License v2 |
294 |
+ |
295 |
+EAPI="7" |
296 |
+ |
297 |
+inherit autotools elisp-common flag-o-matic multilib-minimal toolchain-funcs |
298 |
+ |
299 |
+if [[ "${PV}" == "9999" ]]; then |
300 |
+ inherit git-r3 |
301 |
+ |
302 |
+ EGIT_REPO_URI="https://github.com/protocolbuffers/protobuf" |
303 |
+ EGIT_SUBMODULES=() |
304 |
+fi |
305 |
+ |
306 |
+DESCRIPTION="Google's Protocol Buffers - Extensible mechanism for serializing structured data" |
307 |
+HOMEPAGE="https://developers.google.com/protocol-buffers/ https://github.com/protocolbuffers/protobuf" |
308 |
+if [[ "${PV}" == "9999" ]]; then |
309 |
+ SRC_URI="" |
310 |
+else |
311 |
+ SRC_URI="https://github.com/protocolbuffers/${PN}/archive/v${PV}.tar.gz -> ${P}.tar.gz" |
312 |
+fi |
313 |
+ |
314 |
+LICENSE="BSD" |
315 |
+SLOT="0/18" |
316 |
+KEYWORDS="" |
317 |
+IUSE="emacs examples static-libs test zlib" |
318 |
+RESTRICT="!test? ( test )" |
319 |
+ |
320 |
+BDEPEND="emacs? ( virtual/emacs )" |
321 |
+DEPEND="test? ( >=dev-cpp/gtest-1.8.0[${MULTILIB_USEDEP}] ) |
322 |
+ zlib? ( sys-libs/zlib[${MULTILIB_USEDEP}] )" |
323 |
+RDEPEND="emacs? ( virtual/emacs ) |
324 |
+ zlib? ( sys-libs/zlib[${MULTILIB_USEDEP}] )" |
325 |
+ |
326 |
+PATCHES=( |
327 |
+ "${FILESDIR}/${PN}-3.7.0-disable_no-warning-test.patch" |
328 |
+ "${FILESDIR}/${PN}-3.7.1-system_libraries.patch" |
329 |
+ "${FILESDIR}/${PN}-3.8.0-protoc_input_output_files.patch" |
330 |
+) |
331 |
+ |
332 |
+DOCS=(CHANGES.txt CONTRIBUTORS.txt README.md) |
333 |
+ |
334 |
+src_prepare() { |
335 |
+ default |
336 |
+ eautoreconf |
337 |
+} |
338 |
+ |
339 |
+src_configure() { |
340 |
+ append-cppflags -DGOOGLE_PROTOBUF_NO_RTTI |
341 |
+ multilib-minimal_src_configure |
342 |
+} |
343 |
+ |
344 |
+multilib_src_configure() { |
345 |
+ local options=( |
346 |
+ $(use_enable static-libs static) |
347 |
+ $(use_with zlib) |
348 |
+ ) |
349 |
+ |
350 |
+ if tc-is-cross-compiler; then |
351 |
+ # Build system uses protoc when building, so protoc copy runnable on host is needed. |
352 |
+ mkdir -p "${WORKDIR}/build" || die |
353 |
+ pushd "${WORKDIR}/build" > /dev/null || die |
354 |
+ ECONF_SOURCE="${S}" econf_build "${options[@]}" |
355 |
+ options+=(--with-protoc="$(pwd)/src/protoc") |
356 |
+ popd > /dev/null || die |
357 |
+ fi |
358 |
+ |
359 |
+ ECONF_SOURCE="${S}" econf "${options[@]}" |
360 |
+} |
361 |
+ |
362 |
+src_compile() { |
363 |
+ multilib-minimal_src_compile |
364 |
+ |
365 |
+ if use emacs; then |
366 |
+ elisp-compile editors/protobuf-mode.el |
367 |
+ fi |
368 |
+} |
369 |
+ |
370 |
+multilib_src_compile() { |
371 |
+ if tc-is-cross-compiler; then |
372 |
+ emake -C "${WORKDIR}/build/src" protoc |
373 |
+ fi |
374 |
+ |
375 |
+ default |
376 |
+} |
377 |
+ |
378 |
+multilib_src_test() { |
379 |
+ emake check |
380 |
+} |
381 |
+ |
382 |
+multilib_src_install_all() { |
383 |
+ find "${D}" -name "*.la" -delete || die |
384 |
+ |
385 |
+ insinto /usr/share/vim/vimfiles/syntax |
386 |
+ doins editors/proto.vim |
387 |
+ insinto /usr/share/vim/vimfiles/ftdetect |
388 |
+ doins "${FILESDIR}/proto.vim" |
389 |
+ |
390 |
+ if use emacs; then |
391 |
+ elisp-install ${PN} editors/protobuf-mode.el* |
392 |
+ elisp-site-file-install "${FILESDIR}/70${PN}-gentoo.el" |
393 |
+ fi |
394 |
+ |
395 |
+ if use examples; then |
396 |
+ DOCS+=(examples) |
397 |
+ docompress -x /usr/share/doc/${PF}/examples |
398 |
+ fi |
399 |
+ |
400 |
+ einstalldocs |
401 |
+} |
402 |
+ |
403 |
+pkg_postinst() { |
404 |
+ use emacs && elisp-site-regen |
405 |
+} |
406 |
+ |
407 |
+pkg_postrm() { |
408 |
+ use emacs && elisp-site-regen |
409 |
+} |