Gentoo Archives: gentoo-commits

From: Sam James <sam@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] repo/gentoo:master commit in: dev-libs/glib/files/, dev-libs/glib/
Date: Thu, 16 Mar 2023 23:51:16
Message-Id: 1679010633.494fdf6d476ec4dfa6b6c801b66709765bdce45a.sam@gentoo
1 commit: 494fdf6d476ec4dfa6b6c801b66709765bdce45a
2 Author: Sam James <sam <AT> gentoo <DOT> org>
3 AuthorDate: Thu Mar 16 23:47:33 2023 +0000
4 Commit: Sam James <sam <AT> gentoo <DOT> org>
5 CommitDate: Thu Mar 16 23:50:33 2023 +0000
6 URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=494fdf6d
7
8 dev-libs/glib: backport fix for building C++ applications
9
10 Closes: https://bugs.gentoo.org/901211
11 Closes: https://bugs.gentoo.org/901035
12 Signed-off-by: Sam James <sam <AT> gentoo.org>
13
14 dev-libs/glib/files/glib-2.76.0-g_strdup-c++.patch | 132 ++++++++++
15 dev-libs/glib/glib-2.76.0-r1.ebuild | 284 +++++++++++++++++++++
16 2 files changed, 416 insertions(+)
17
18 diff --git a/dev-libs/glib/files/glib-2.76.0-g_strdup-c++.patch b/dev-libs/glib/files/glib-2.76.0-g_strdup-c++.patch
19 new file mode 100644
20 index 000000000000..23b0a1b641c1
21 --- /dev/null
22 +++ b/dev-libs/glib/files/glib-2.76.0-g_strdup-c++.patch
23 @@ -0,0 +1,132 @@
24 +https://bugs.gentoo.org/901035
25 +https://gitlab.gnome.org/GNOME/glib/-/merge_requests/3322
26 +https://gitlab.gnome.org/GNOME/glib/-/commit/cc7f2f81cc59751fcc689731dcd60af5da5723ba
27 +
28 +From cc7f2f81cc59751fcc689731dcd60af5da5723ba Mon Sep 17 00:00:00 2001
29 +From: Xi Ruoyao <xry111@××××××.site>
30 +Date: Mon, 13 Mar 2023 16:23:37 +0800
31 +Subject: [PATCH] gstrfuncs: Improve inline version of g_strdup() to avoid
32 + breaking C++ code
33 +
34 +Wrap the logic into a G_ALWAYS_INLINE function, instead of using a
35 +complex statement-expression which is not allowed in braced initializer
36 +lists and expanded into some bad thing when it's used as
37 +`::g_strdup(...)`.
38 +
39 +We cannot use `__builtin_constant_p (str)` because GCC documentation
40 +clearly states that it always produces 0 when str is a const char *
41 +argument of an inline function. But `__builtin_constant_p (!str)`,
42 +`__builtin_constant_p (!!str)`, and
43 +`__builtin_constant_p (strlen (str))` functions properly with `-O1` or
44 +above enabled.
45 +
46 +Fixes #2936.
47 +--- a/glib/gstrfuncs.h
48 ++++ b/glib/gstrfuncs.h
49 +@@ -204,23 +204,6 @@ gboolean (g_str_has_prefix) (const gchar *str,
50 + (g_str_has_suffix) (STR, SUFFIX) \
51 + )
52 +
53 +-#define g_strdup(STR) \
54 +- (__builtin_constant_p ((STR)) ? \
55 +- (G_LIKELY ((STR) != NULL) ? \
56 +- G_GNUC_EXTENSION ({ \
57 +- const char *const ___str = ((STR)); \
58 +- const char *const __str = _G_STR_NONNULL (___str); \
59 +- const size_t __str_len = strlen (__str) + 1; \
60 +- char *__dup_str = (char *) g_malloc (__str_len); \
61 +- (char *) memcpy (__dup_str, __str, __str_len); \
62 +- }) \
63 +- : \
64 +- (char *) (NULL) \
65 +- ) \
66 +- : \
67 +- (g_strdup) ((STR)) \
68 +- )
69 +-
70 + #endif /* !defined (__GI_SCANNER__) */
71 + #endif /* !defined (__GTK_DOC_IGNORE__) */
72 + #endif /* G_GNUC_CHECK_VERSION (2, 0) */
73 +@@ -318,6 +301,32 @@ GLIB_AVAILABLE_IN_ALL
74 + gchar* g_strjoin (const gchar *separator,
75 + ...) G_GNUC_MALLOC G_GNUC_NULL_TERMINATED;
76 +
77 ++#if G_GNUC_CHECK_VERSION(2, 0)
78 ++#ifndef __GTK_DOC_IGNORE__
79 ++#ifndef __GI_SCANNER__
80 ++
81 ++G_ALWAYS_INLINE static inline char *
82 ++g_strdup_inline (const char *str)
83 ++{
84 ++ if (__builtin_constant_p (!str) && !str)
85 ++ return NULL;
86 ++
87 ++ if (__builtin_constant_p (!!str) && !!str && __builtin_constant_p (strlen (str)))
88 ++ {
89 ++ const size_t len = strlen (str) + 1;
90 ++ char *dup_str = (char *) g_malloc (len);
91 ++ return (char *) memcpy (dup_str, str, len);
92 ++ }
93 ++
94 ++ return g_strdup (str);
95 ++}
96 ++
97 ++#define g_strdup(x) g_strdup_inline (x)
98 ++
99 ++#endif /* !defined (__GI_SCANNER__) */
100 ++#endif /* !defined (__GTK_DOC_IGNORE__) */
101 ++#endif /* G_GNUC_CHECK_VERSION (2, 0) */
102 ++
103 + /* Make a copy of a string interpreting C string -style escape
104 + * sequences. Inverse of g_strescape. The recognized sequences are \b
105 + * \f \n \r \t \\ \" and the octal format.
106 +--- a/glib/tests/cxx.cpp
107 ++++ b/glib/tests/cxx.cpp
108 +@@ -349,6 +349,36 @@ test_strdup_macro (void)
109 + g_free (str);
110 + }
111 +
112 ++static void
113 ++test_strdup_macro_qualified (void)
114 ++{
115 ++ gchar *str;
116 ++
117 ++ g_assert_null (::g_strdup (NULL));
118 ++
119 ++ str = ::g_strdup ("C++ is cool too!");
120 ++ g_assert_nonnull (str);
121 ++ g_assert_cmpstr (str, ==, "C++ is cool too!");
122 ++ g_free (str);
123 ++}
124 ++
125 ++static void
126 ++test_strdup_macro_nested_initializer (void)
127 ++{
128 ++ struct
129 ++ {
130 ++ char *p, *q;
131 ++ } strings = {
132 ++ g_strdup (NULL),
133 ++ g_strdup ("C++ is cool too!"),
134 ++ };
135 ++
136 ++ g_assert_null (strings.p);
137 ++ g_assert_nonnull (strings.q);
138 ++ g_assert_cmpstr (strings.q, ==, "C++ is cool too!");
139 ++ g_free (strings.q);
140 ++}
141 ++
142 + static void
143 + test_str_has_prefix (void)
144 + {
145 +@@ -527,6 +557,8 @@ main (int argc, char *argv[])
146 + g_test_add_func ("/C++/str-equal", test_str_equal);
147 + g_test_add_func ("/C++/strdup", test_strdup);
148 + g_test_add_func ("/C++/strdup/macro", test_strdup_macro);
149 ++ g_test_add_func ("/C++/strdup/macro/qualified", test_strdup_macro_qualified);
150 ++ g_test_add_func ("/C++/strdup/macro/nested-initializer", test_strdup_macro_nested_initializer);
151 + g_test_add_func ("/C++/str-has-prefix", test_str_has_prefix);
152 + g_test_add_func ("/C++/str-has-prefix/macro", test_str_has_prefix_macro);
153 + g_test_add_func ("/C++/str-has-suffix", test_str_has_suffix);
154 +--
155 +GitLab
156
157 diff --git a/dev-libs/glib/glib-2.76.0-r1.ebuild b/dev-libs/glib/glib-2.76.0-r1.ebuild
158 new file mode 100644
159 index 000000000000..56112f34dd89
160 --- /dev/null
161 +++ b/dev-libs/glib/glib-2.76.0-r1.ebuild
162 @@ -0,0 +1,284 @@
163 +# Copyright 1999-2023 Gentoo Authors
164 +# Distributed under the terms of the GNU General Public License v2
165 +
166 +EAPI=8
167 +PYTHON_REQ_USE="xml(+)"
168 +PYTHON_COMPAT=( python3_{9..11} )
169 +
170 +inherit gnome.org gnome2-utils linux-info meson-multilib multilib python-any-r1 toolchain-funcs xdg
171 +
172 +DESCRIPTION="The GLib library of C routines"
173 +HOMEPAGE="https://www.gtk.org/"
174 +
175 +LICENSE="LGPL-2.1+"
176 +SLOT="2"
177 +IUSE="dbus debug +elf gtk-doc +mime selinux static-libs sysprof systemtap test utils xattr"
178 +RESTRICT="!test? ( test )"
179 +REQUIRED_USE="gtk-doc? ( test )" # Bug #777636
180 +
181 +KEYWORDS="~alpha ~amd64 ~arm ~arm64 ~hppa ~ia64 ~loong ~m68k ~mips ~ppc ~ppc64 ~riscv ~s390 ~sparc ~x86 ~amd64-linux ~x86-linux"
182 +
183 +# * elfutils (via libelf) does not build on Windows. gresources are not embedded
184 +# within ELF binaries on that platform anyway and inspecting ELF binaries from
185 +# other platforms is not that useful so exclude the dependency in this case.
186 +# * Technically static-libs is needed on zlib, util-linux and perhaps more, but
187 +# these are used by GIO, which glib[static-libs] consumers don't really seem
188 +# to need at all, thus not imposing the deps for now and once some consumers
189 +# are actually found to static link libgio-2.0.a, we can revisit and either add
190 +# them or just put the (build) deps in that rare consumer instead of recursive
191 +# RDEPEND here (due to lack of recursive DEPEND).
192 +RDEPEND="
193 + !<dev-util/gdbus-codegen-${PV}
194 + >=virtual/libiconv-0-r1[${MULTILIB_USEDEP}]
195 + >=dev-libs/libpcre2-10.32:0=[${MULTILIB_USEDEP},unicode(+),static-libs?]
196 + >=dev-libs/libffi-3.0.13-r1:=[${MULTILIB_USEDEP}]
197 + >=sys-libs/zlib-1.2.8-r1[${MULTILIB_USEDEP}]
198 + >=virtual/libintl-0-r2[${MULTILIB_USEDEP}]
199 + kernel_linux? ( >=sys-apps/util-linux-2.23[${MULTILIB_USEDEP}] )
200 + selinux? ( >=sys-libs/libselinux-2.2.2-r5[${MULTILIB_USEDEP}] )
201 + xattr? ( !elibc_glibc? ( >=sys-apps/attr-2.4.47-r1[${MULTILIB_USEDEP}] ) )
202 + elf? ( virtual/libelf:0= )
203 + sysprof? ( >=dev-util/sysprof-capture-3.40.1:4[${MULTILIB_USEDEP}] )
204 +"
205 +DEPEND="${RDEPEND}"
206 +# libxml2 used for optional tests that get automatically skipped
207 +BDEPEND="
208 + app-text/docbook-xsl-stylesheets
209 + dev-libs/libxslt
210 + >=sys-devel/gettext-0.19.8
211 + gtk-doc? ( >=dev-util/gtk-doc-1.33
212 + app-text/docbook-xml-dtd:4.2
213 + app-text/docbook-xml-dtd:4.5 )
214 + systemtap? ( >=dev-util/systemtap-1.3 )
215 + ${PYTHON_DEPS}
216 + test? ( >=sys-apps/dbus-1.2.14 )
217 + virtual/pkgconfig
218 +"
219 +# TODO: >=dev-util/gdbus-codegen-${PV} test dep once we modify gio/tests/meson.build to use external gdbus-codegen
220 +
221 +PDEPEND="
222 + dbus? ( gnome-base/dconf )
223 + mime? ( x11-misc/shared-mime-info )
224 +"
225 +# shared-mime-info needed for gio/xdgmime, bug #409481
226 +# dconf is needed to be able to save settings, bug #498436
227 +
228 +MULTILIB_CHOST_TOOLS=(
229 + /usr/bin/gio-querymodules$(get_exeext)
230 +)
231 +
232 +PATCHES=(
233 + "${FILESDIR}"/${PN}-2.64.1-mark-gdbus-server-auth-test-flaky.patch
234 + "${FILESDIR}"/${PN}-2.76.0-g_strdup-c++.patch
235 +)
236 +
237 +pkg_setup() {
238 + if use kernel_linux ; then
239 + CONFIG_CHECK="~INOTIFY_USER"
240 + if use test ; then
241 + CONFIG_CHECK="~IPV6"
242 + WARNING_IPV6="Your kernel needs IPV6 support for running some tests, skipping them."
243 + fi
244 + linux-info_pkg_setup
245 + fi
246 + python-any-r1_pkg_setup
247 +}
248 +
249 +src_prepare() {
250 + if use test; then
251 + # TODO: Review the test exclusions, especially now with meson
252 + # Disable tests requiring dev-util/desktop-file-utils when not installed, bug #286629, upstream bug #629163
253 + if ! has_version dev-util/desktop-file-utils ; then
254 + ewarn "Some tests will be skipped due dev-util/desktop-file-utils not being present on your system,"
255 + ewarn "think on installing it to get these tests run."
256 + sed -i -e "/appinfo\/associations/d" gio/tests/appinfo.c || die
257 + sed -i -e "/g_test_add_func/d" gio/tests/desktop-app-info.c || die
258 + fi
259 +
260 + # gdesktopappinfo requires existing terminal (gnome-terminal or any
261 + # other), falling back to xterm if one doesn't exist
262 + #if ! has_version x11-terms/xterm && ! has_version x11-terms/gnome-terminal ; then
263 + # ewarn "Some tests will be skipped due to missing terminal program"
264 + # These tests seem to sometimes fail even with a terminal; skip for now and reevulate with meson
265 + # Also try https://gitlab.gnome.org/GNOME/glib/issues/1601 once ready for backport (or in a bump) and file new issue if still fails
266 + sed -i -e "/appinfo\/launch/d" gio/tests/appinfo.c || die
267 + # desktop-app-info/launch* might fail similarly
268 + sed -i -e "/desktop-app-info\/launch-as-manager/d" gio/tests/desktop-app-info.c || die
269 + #fi
270 +
271 + # https://bugzilla.gnome.org/show_bug.cgi?id=722604
272 + sed -i -e "/timer\/stop/d" glib/tests/timer.c || die
273 + sed -i -e "/timer\/basic/d" glib/tests/timer.c || die
274 +
275 + ewarn "Tests for search-utils have been skipped"
276 + sed -i -e "/search-utils/d" glib/tests/meson.build || die
277 +
278 + # Play nice with network-sandbox, but this approach would defeat the purpose of the test
279 + #sed -i -e "s/localhost/127.0.0.1/g" gio/tests/gsocketclient-slow.c || die
280 + else
281 + # Don't build tests, also prevents extra deps, bug #512022
282 + sed -i -e '/subdir.*tests/d' {.,gio,glib}/meson.build || die
283 + fi
284 +
285 + # Don't build fuzzing binaries - not used
286 + sed -i -e '/subdir.*fuzzing/d' meson.build || die
287 +
288 + # gdbus-codegen is a separate package
289 + sed -i -e '/install_dir/d' gio/gdbus-2.0/codegen/meson.build || die
290 +
291 + # Same kind of meson-0.50 issue with some installed-tests files; will likely be fixed upstream soon
292 + sed -i -e '/install_dir/d' gio/tests/meson.build || die
293 +
294 + cat > "${T}/glib-test-ld-wrapper" <<-EOF
295 + #!/usr/bin/env sh
296 + exec \${LD:-ld} "\$@"
297 + EOF
298 + chmod a+x "${T}/glib-test-ld-wrapper" || die
299 + sed -i -e "s|'ld'|'${T}/glib-test-ld-wrapper'|g" gio/tests/meson.build || die
300 +
301 + default
302 + gnome2_environment_reset
303 + # TODO: python_name sedding for correct python shebang? Might be relevant mainly for glib-utils only
304 +}
305 +
306 +multilib_src_configure() {
307 + # TODO: figure a way to pass appropriate values for all cross properties that glib uses (search for get_cross_property)
308 + #if tc-is-cross-compiler ; then
309 + # https://bugzilla.gnome.org/show_bug.cgi?id=756473
310 + # TODO-meson: This should be in meson cross file as 'growing_stack' property; and more, look at get_cross_property
311 + #case ${CHOST} in
312 + #hppa*|metag*) export glib_cv_stack_grows=yes ;;
313 + #*) export glib_cv_stack_grows=no ;;
314 + #esac
315 + #fi
316 +
317 + local emesonargs=(
318 + --buildtype $(usex debug debug plain)
319 + -Ddefault_library=$(usex static-libs both shared)
320 + -Druntime_dir="${EPREFIX}"/run
321 + $(meson_feature selinux)
322 + $(meson_use xattr)
323 + -Dlibmount=enabled # only used if host_system == 'linux'
324 + -Dman=true
325 + $(meson_use systemtap dtrace)
326 + $(meson_use systemtap)
327 + $(meson_feature sysprof)
328 + $(meson_native_use_bool gtk-doc gtk_doc)
329 + $(meson_use test tests)
330 + -Dinstalled_tests=false
331 + -Dnls=enabled
332 + -Doss_fuzz=disabled
333 + $(meson_native_use_feature elf libelf)
334 + -Dmultiarch=false
335 + )
336 + meson_src_configure
337 +}
338 +
339 +multilib_src_test() {
340 + export XDG_CONFIG_DIRS=/etc/xdg
341 + export XDG_DATA_DIRS=/usr/local/share:/usr/share
342 + export G_DBUS_COOKIE_SHA1_KEYRING_DIR="${T}/temp"
343 + export LC_TIME=C # bug #411967
344 + export TZ=UTC
345 + unset GSETTINGS_BACKEND # bug #596380
346 + python_setup
347 +
348 + # https://bugs.gentoo.org/839807
349 + local -x SANDBOX_PREDICT=${SANDBOX_PREDICT}
350 + addpredict /usr/b
351 +
352 + # Related test is a bit nitpicking
353 + mkdir "$G_DBUS_COOKIE_SHA1_KEYRING_DIR"
354 + chmod 0700 "$G_DBUS_COOKIE_SHA1_KEYRING_DIR"
355 +
356 + meson_src_test --timeout-multiplier 2 --no-suite flaky
357 +}
358 +
359 +multilib_src_install() {
360 + meson_src_install
361 + keepdir /usr/$(get_libdir)/gio/modules
362 +}
363 +
364 +multilib_src_install_all() {
365 + # These are installed by dev-util/glib-utils
366 + # TODO: With patching we might be able to get rid of the python-any deps and removals, and test depend on glib-utils instead; revisit now with meson
367 + rm "${ED}/usr/bin/glib-genmarshal" || die
368 + rm "${ED}/usr/share/man/man1/glib-genmarshal.1" || die
369 + rm "${ED}/usr/bin/glib-mkenums" || die
370 + rm "${ED}/usr/share/man/man1/glib-mkenums.1" || die
371 + rm "${ED}/usr/bin/gtester-report" || die
372 + rm "${ED}/usr/share/man/man1/gtester-report.1" || die
373 + # gdbus-codegen manpage installed by dev-util/gdbus-codegen
374 + rm "${ED}/usr/share/man/man1/gdbus-codegen.1" || die
375 +}
376 +
377 +pkg_preinst() {
378 + xdg_pkg_preinst
379 +
380 + # Make gschemas.compiled belong to glib alone
381 + local cache="/usr/share/glib-2.0/schemas/gschemas.compiled"
382 +
383 + if [[ -e ${EROOT}${cache} ]]; then
384 + cp "${EROOT}"${cache} "${ED}"/${cache} || die
385 + else
386 + touch "${ED}"${cache} || die
387 + fi
388 +
389 + multilib_pkg_preinst() {
390 + # Make giomodule.cache belong to glib alone
391 + local cache="/usr/$(get_libdir)/gio/modules/giomodule.cache"
392 +
393 + if [[ -e ${EROOT}${cache} ]]; then
394 + cp "${EROOT}"${cache} "${ED}"${cache} || die
395 + else
396 + touch "${ED}"${cache} || die
397 + fi
398 + }
399 +
400 + # Don't run the cache ownership when cross-compiling, as it would end up with an empty cache
401 + # file due to inability to create it and GIO might not look at any of the modules there
402 + if ! tc-is-cross-compiler ; then
403 + multilib_foreach_abi multilib_pkg_preinst
404 + fi
405 +}
406 +
407 +pkg_postinst() {
408 + xdg_pkg_postinst
409 + # glib installs no schemas itself, but we force update for fresh install in case
410 + # something has dropped in a schemas file without direct glib dep; and for upgrades
411 + # in case the compiled schema format could have changed
412 + gnome2_schemas_update
413 +
414 + multilib_pkg_postinst() {
415 + gnome2_giomodule_cache_update \
416 + || die "Update GIO modules cache failed (for ${ABI})"
417 + }
418 + if ! tc-is-cross-compiler ; then
419 + multilib_foreach_abi multilib_pkg_postinst
420 + else
421 + ewarn "Updating of GIO modules cache skipped due to cross-compilation."
422 + ewarn "You might want to run gio-querymodules manually on the target for"
423 + ewarn "your final image for performance reasons and re-run it when packages"
424 + ewarn "installing GIO modules get upgraded or added to the image."
425 + fi
426 +
427 + for v in ${REPLACING_VERSIONS}; do
428 + if ver_test "$v" "-lt" "2.63.6"; then
429 + ewarn "glib no longer installs the gio-launch-desktop binary. You may need"
430 + ewarn "to restart your session for \"Open With\" dialogs to work."
431 + fi
432 + done
433 +}
434 +
435 +pkg_postrm() {
436 + xdg_pkg_postrm
437 + gnome2_schemas_update
438 +
439 + if [[ -z ${REPLACED_BY_VERSION} ]]; then
440 + multilib_pkg_postrm() {
441 + rm -f "${EROOT}"/usr/$(get_libdir)/gio/modules/giomodule.cache
442 + }
443 + multilib_foreach_abi multilib_pkg_postrm
444 + rm -f "${EROOT}"/usr/share/glib-2.0/schemas/gschemas.compiled
445 + fi
446 +}