Gentoo Archives: gentoo-commits

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