Gentoo Archives: gentoo-dev

From: "Haelwenn (lanodan) Monnier" <contact@×××××××××.me>
To: gentoo-dev@l.g.o
Cc: "Haelwenn (lanodan) Monnier" <contact@×××××××××.me>
Subject: [gentoo-dev] [PATCH v2] gstreamer-meson.eclass: New eclass required for gstreamer-1.18.0+
Date: Tue, 23 Mar 2021 12:45:07
Message-Id: 20210323124458.17993-1-contact@hacktivis.me
In Reply to: [gentoo-dev] [PATCH] gstreamer-meson.eclass: New eclass required for gstreamer-1.18.0+ by "Haelwenn (lanodan) Monnier"
1 Gstreamer switched to meson in 1.16.0 and removed autotools support in 1.18.0,
2 this eclass is an update of gstreamer.eclass.
3
4 One significant change between autotools and meson is that in the latter we
5 don't have easily extractable semantics in the buildsystem to get a list
6 of plugins with extraneous dependencies that we currently split in other
7 packages.
8 Hence the rather ugly but currently required GST_PLUGINS_DISABLED block.
9 The gstreamer_system_link function also got lost in translation.
10
11 Differences from version 1:
12 - Move to EAPI-7, including moving deps from DEPEND to BDEPEND when appropriate
13 - Port python script to perl, this allows to avoid having to add PYTHON_COMPAT
14 into a python-unrelated eclass
15 - Drop errorneous MULTILIB_USEDEP on virtual/pkgconfig
16 - Fix running tests: defining multilib_src_test, media-libs/gstreamer[test] dep
17 - Fix ebuild emesonargs being ignored
18 - Remove legacy prune_libtool_files
19 - virtualx wrapped for testing
20
21 Fixes: https://bugs.gentoo.org/690468
22
23 Signed-off-by: Haelwenn (lanodan) Monnier <contact@×××××××××.me>
24 ---
25 eclass/gstreamer-meson.eclass | 320 ++++++++++++++++++++++++++++++++++
26 1 file changed, 320 insertions(+)
27 create mode 100644 eclass/gstreamer-meson.eclass
28
29 diff --git a/eclass/gstreamer-meson.eclass b/eclass/gstreamer-meson.eclass
30 new file mode 100644
31 index 00000000000..14a825f76b5
32 --- /dev/null
33 +++ b/eclass/gstreamer-meson.eclass
34 @@ -0,0 +1,320 @@
35 +# Copyright 1999-2021 Gentoo Authors
36 +# Distributed under the terms of the GNU General Public License v2
37 +
38 +# @ECLASS: gstreamer-meson.eclass
39 +# @MAINTAINER:
40 +# gstreamer@g.o
41 +# @AUTHOR:
42 +# Michał Górny <mgorny@g.o>
43 +# Gilles Dartiguelongue <eva@g.o>
44 +# Saleem Abdulrasool <compnerd@g.o>
45 +# foser <foser@g.o>
46 +# zaheerm <zaheerm@g.o>
47 +# Steven Newbury
48 +# Haelwenn (lanodan) Monnier <contact@×××××××××.me>
49 +# @SUPPORTED_EAPIS: 7
50 +# @BLURB: Helps building core & split gstreamer plugins.
51 +# @DESCRIPTION:
52 +# Eclass to make external gst-plugins emergable on a per-plugin basis
53 +# and to solve the problem with gst-plugins generating far too much
54 +# unneeded dependencies.
55 +#
56 +# GStreamer consuming applications should depend on the specific plugins
57 +# they need as defined in their source code. Usually you can find that
58 +# out by grepping the source tree for 'factory_make'. If it uses playbin
59 +# plugin, consider adding media-plugins/gst-plugins-meta dependency, but
60 +# also list any packages that provide explicitly requested plugins.
61 +
62 +inherit multilib virtualx meson toolchain-funcs xdg-utils multilib-minimal
63 +
64 +case "${EAPI:-0}" in
65 + 7)
66 + ;;
67 + *)
68 + die "EAPI=\"${EAPI}\" is not supported"
69 + ;;
70 +esac
71 +
72 +# @ECLASS-VARIABLE: GST_PLUGINS_ENABLED
73 +# @DESCRIPTION:
74 +# Defines the plugins to be built.
75 +# May be set by an ebuild and contain more than one indentifier, space
76 +# seperated (only src_configure can handle mutiple plugins at this time).
77 +: ${GST_PLUGINS_ENABLED:=${PN/gst-plugins-/}}
78 +
79 +# @ECLASS-VARIABLE: GST_PLUGINS_DISABLED
80 +# @DESCRIPTION:
81 +# Defines the plugins to not be built, GST_PLUGINS_ENABLED overrides it.
82 +# May be set by an ebuild and contain more than one indentifier, space
83 +# seperated (only src_configure can handle mutiple plugins at this time).
84 +case "${GST_ORG_MODULE}" in
85 + # copied GST_PLUGINS_DISABLED from media-libs/${GST_ORG_MODULE} then added GST_PLUGINS_ENABLED
86 + gst-plugins-bad)
87 + # removed from list: shm ipcpipeline gl
88 + GST_PLUGINS_DISABLED="aom avtp androidmedia applemedia assrender bluez bs2b bz2 chromaprint closedcaption colormanagement curl curl-ssh2 d3dvideosink d3d11 dash dc1394 decklink directfb directsound dtls dts dvb faac faad fbdev fdkaac flite fluidsynth gme gsm iqa kate kms ladspa libde265 libmms lv2 mediafoundation microdns modplug mpeg2enc mplex msdk musepack neon nvcodec ofa openal openexr openh264 openjpeg openmpt openni2 opensles opus resindvd rsvg rtmp sbc sctp smoothstreaming sndfile soundtouch spandsp srt srtp svthevcenc teletext tinyalsa transcode ttml uvch264 va voaacenc voamrwbenc vulkan wasapi wasapi2 webp webrtc webrtcdsp wildmidi winks winscreencap x265 zbar zxing wpe magicleap v4l2codecs hls opencv"
89 + GST_PLUGINS_DISABLED="${GST_PLUGINS_DISABLED} accurip adpcmdec adpcmenc aiff asfmux audiobuffersplit audiofxbad audiolatency audiomixmatrix audiovisualizers autoconvert bayer camerabin2 coloreffects deb ugutils dvbsubenc dvbsuboverlay dvdspu faceoverlay festival fieldanalysis freeverb frei0r gaudieffects gdp geometrictransform id3tag inter interlace ivfpars e ivtc jp2kdecimator jpegformat librfb midi mpegdemux mpegpsmux mpegtsdemux mpegtsmux mxf netsim onvif pcapparse pnm proxy rawparse removesilence rist rtmp2 rtp sdp segmentclip siren smooth speed subenc switchbin timecode videofilters videoframe_audiolevel videoparsers videosignal vmnc y4m"
90 + ;;
91 + gst-plugins-base)
92 + GST_PLUGINS_DISABLED="cdparanoia libvisual opus tremor"
93 + GST_PLUGINS_DISABLED="${GST_PLUGINS_DISABLED} adder app audioconvert audiomixer audiorate audioresample audiotestsrc compositor encoding gio gio-typefinder overlaycomposition pbtypes playback rawparse subparse tcp typefind videoconvert videorate videoscale videotestsrc volume"
94 + ;;
95 + gst-plugins-good)
96 + GST_PLUGINS_DISABLED="aalib cairo directsound dv dv1394 flac gdk-pixbuf gtk3 jack jpeg lame libcaca mpg123 oss oss4 osxaudio osxvideo png pulse qt5 shout2 soup speex taglib twolame vpx waveform wavpack rpicamsrc ximagesrc v4l2"
97 + GST_PLUGINS_DISABLED="${GST_PLUGINS_DISABLED} alpha apetag audiofx audioparsers auparse autodetect avi cutter debugutils deinterlace dtmf effectv equalizer flv flx goom goom2k1 icydemux id3demux imagefreeze interleave isomp4 law level matroska monoscope multifile multipart replaygain rtp rtpmanager rtsp shapewipe smpte spectrum udp videobox videocrop videofilter videomixer wavenc wavparse y4m"
98 + ;;
99 + gst-plugins-ugly)
100 + GST_PLUGINS_DISABLED="a52dec amrnb amrwbdec cdio dvdread mpeg2dec sidplay x264"
101 + GST_PLUGINS_DISABLED="${GST_PLUGINS_DISABLED} asfdemux dvdlpcmdec dvdsub realmedia xingmux"
102 + ;;
103 +esac
104 +
105 +# @ECLASS-VARIABLE: GST_PLUGINS_BUILD_DIR
106 +# @DESCRIPTION:
107 +# Actual build directories of the plugins.
108 +# Most often the same as the configure switch name.
109 +# FIXME: Change into a bash array
110 +: ${GST_PLUGINS_BUILD_DIR:=${PN/gst-plugins-/}}
111 +
112 +# @ECLASS-VARIABLE: GST_TARBALL_SUFFIX
113 +# @DESCRIPTION:
114 +# Most projects hosted on gstreamer.freedesktop.org mirrors provide
115 +# tarballs as tar.bz2 or tar.xz. This eclass defaults to xz. This is
116 +# because the gstreamer mirrors are moving to only have xz tarballs for
117 +# new releases.
118 +: ${GST_TARBALL_SUFFIX:="xz"}
119 +
120 +# Even though xz-utils are in @system, they must still be added to BDEPEND; see
121 +# https://archives.gentoo.org/gentoo-dev/msg_a0d4833eb314d1be5d5802a3b710e0a4.xml
122 +if [[ ${GST_TARBALL_SUFFIX} == "xz" ]]; then
123 + BDEPEND="${BDEPEND} app-arch/xz-utils"
124 +fi
125 +
126 +# @ECLASS-VARIABLE: GST_ORG_MODULE
127 +# @DESCRIPTION:
128 +# Name of the module as hosted on gstreamer.freedesktop.org mirrors.
129 +# Leave unset if package name matches module name.
130 +: ${GST_ORG_MODULE:=$PN}
131 +
132 +# @ECLASS-VARIABLE: GST_ORG_PVP
133 +# @INTERNAL
134 +# @DESCRIPTION:
135 +# Major and minor numbers of the version number.
136 +: ${GST_ORG_PVP:=$(ver_cut 1-2)}
137 +
138 +
139 +DESCRIPTION="${BUILD_GST_PLUGINS} plugin for gstreamer"
140 +HOMEPAGE="https://gstreamer.freedesktop.org/"
141 +SRC_URI="https://gstreamer.freedesktop.org/src/${GST_ORG_MODULE}/${GST_ORG_MODULE}-${PV}.tar.${GST_TARBALL_SUFFIX}"
142 +
143 +LICENSE="GPL-2"
144 +case ${GST_ORG_PVP} in
145 + 1.*) SLOT="1.0"; GST_MIN_PV="1.2.4-r1" ;;
146 + *) die "Unkown gstreamer release."
147 +esac
148 +
149 +S="${WORKDIR}/${GST_ORG_MODULE}-${PV}"
150 +
151 +RDEPEND="
152 + >=dev-libs/glib-2.40.0:2[${MULTILIB_USEDEP}]
153 + >=media-libs/gstreamer-${GST_MIN_PV}:${SLOT}[${MULTILIB_USEDEP}]
154 +"
155 +BDEPEND="
156 + >=sys-apps/sed-4
157 + virtual/pkgconfig
158 + virtual/perl-JSON-PP
159 +"
160 +
161 +# Export common multilib phases.
162 +multilib_src_configure() { gstreamer_multilib_src_configure; }
163 +
164 +if [[ ${PN} != ${GST_ORG_MODULE} ]]; then
165 + # Do not run test phase for invididual plugin ebuilds.
166 + RESTRICT="test"
167 + RDEPEND="${RDEPEND}
168 + >=media-libs/${GST_ORG_MODULE}-${PV}:${SLOT}[${MULTILIB_USEDEP}]"
169 +
170 + # Export multilib phases used for split builds.
171 + multilib_src_compile() { gstreamer_multilib_src_compile; }
172 + multilib_src_install() { gstreamer_multilib_src_install; }
173 + multilib_src_install_all() { gstreamer_multilib_src_install_all; }
174 +else
175 + IUSE="nls test"
176 + RESTRICT="!test? ( test )"
177 + BDEPEND="${DEPEND}
178 + nls? ( >=sys-devel/gettext-0.17 )
179 + test? ( media-libs/gstreamer[test] )
180 + "
181 +
182 + multilib_src_compile() { eninja; }
183 + multilib_src_test() { gstreamer_multilib_src_test; }
184 + multilib_src_install() { DESTDIR="${D}" eninja install; }
185 +fi
186 +
187 +DEPEND="${DEPEND} ${RDEPEND}"
188 +
189 +# @FUNCTION: gstreamer_environment_reset
190 +# @INTERNAL
191 +# @DESCRIPTION:
192 +# Clean up environment for clean builds.
193 +# >=dev-lang/orc-0.4.23 rely on environment variables to find a place to
194 +# allocate files to mmap.
195 +gstreamer_environment_reset() {
196 + xdg_environment_reset
197 +}
198 +
199 +# @FUNCTION: gstreamer_get_plugin_dir
200 +# @USAGE: gstreamer_get_plugin_dir [<build_dir>]
201 +# @INTERNAL
202 +# @DESCRIPTION:
203 +# Finds plugin build directory and output it.
204 +# Defaults to ${GST_PLUGINS_BUILD_DIR} if argument is not provided
205 +gstreamer_get_plugin_dir() {
206 + local build_dir=${1:-${GST_PLUGINS_BUILD_DIR}}
207 +
208 + if [[ ! -d ${S}/ext/${build_dir} ]]; then
209 + if [[ ! -d ${S}/sys/${build_dir} ]]; then
210 + ewarn "No such plugin directory"
211 + die
212 + fi
213 + einfo "Got system plugin in ${build_dir}..." >&2
214 + echo sys/${build_dir}
215 + else
216 + einfo "Got external plugin in ${build_dir}..." >&2
217 + echo ext/${build_dir}
218 + fi
219 +}
220 +
221 +# @FUNCTION: gstreamer_multilib_src_configure
222 +# @DESCRIPTION:
223 +# Handles logic common to configuring gstreamer plugins
224 +gstreamer_multilib_src_configure() {
225 + local plugin gst_conf=( ) EMESON_SOURCE=${EMESON_SOURCE:-${S}}
226 +
227 + gstreamer_environment_reset
228 +
229 + # app-editor/vis regex for meson_options.txt: :x/option\('([^']*)'.*/ c/\1/
230 + for plugin in ${GST_PLUGINS_DISABLED} ; do
231 + gst_conf+=( -D${plugin}=disabled )
232 + done
233 +
234 + for plugin in ${GST_PLUGINS_ENABLED} ; do
235 + gst_conf+=( -D${plugin}=enabled )
236 + done
237 +
238 + if grep -q "option('orc'" "${EMESON_SOURCE}"/meson_options.txt ; then
239 + if in_iuse orc ; then
240 + gst_conf+=( -Dorc=$(usex orc enabled disabled) )
241 + else
242 + gst_conf+=( -Dorc=disabled )
243 + eqawarn "QA: IUSE=orc is missing while plugin supports it"
244 + fi
245 + fi
246 +
247 + if grep -q "option(\'maintainer-mode\'" "${EMESON_SOURCE}"/meson_options.txt ; then
248 + gst_conf+=( -Dmaintainer-mode=disabled )
249 + fi
250 +
251 + if grep -q "option(\'schemas-compile\'" "${EMESON_SOURCE}"/meson_options.txt ; then
252 + gst_conf+=( -Dschemas-compile=disabled )
253 + fi
254 +
255 + if [[ ${PN} == ${GST_ORG_MODULE} ]]; then
256 + gst_conf+=(
257 + $(meson_feature nls)
258 + $(meson_feature test tests)
259 + )
260 + fi
261 +
262 + einfo "Configuring to build ${GST_PLUGINS_ENABLED} plugin(s) ..."
263 + gst_conf+=(
264 + -Dexamples=disabled
265 + -Dpackage-name="Gentoo GStreamer ebuild"
266 + -Dpackage-origin="https://www.gentoo.org"
267 + -Dgst_debug=false
268 + "${@}"
269 + )
270 + meson_src_configure "${gst_conf[@]}"
271 +}
272 +
273 +
274 +# @FUNCTION: _gstreamer_get_target_filename
275 +# @INTERNAL
276 +# @DESCRIPTION:
277 +# Looks for first argument being present as a substring in install targets
278 +# Got ported from python to perl for greater language-stability
279 +_gstreamer_get_target_filename() {
280 + cat >"${WORKDIR}/_gstreamer_get_target_filename.pl" <<"EOF"
281 +#!/usr/bin/env perl
282 +use strict;
283 +use utf8;
284 +use JSON::PP;
285 +
286 +open(my $targets_file, '<:encoding(UTF-8)', 'meson-info/intro-targets.json') || die $!;
287 +my $data = decode_json <$targets_file>;
288 +close($targets_file) || die $!;
289 +
290 +if(!$ARGV[0]) {
291 + die "Requires a target as argument";
292 +}
293 +
294 +foreach my $target (@{$data}) {
295 + if($target->{'installed'}
296 + and (index($target->{'filename'}[0], $ARGV[0]) != -1)
297 + ) {
298 + printf "%s:%s\n", $target->{'filename'}[0], $target->{'install_filename'}[0];
299 + }
300 +}
301 +EOF
302 +
303 + chmod +x "${WORKDIR}/_gstreamer_get_target_filename.pl" || die
304 +
305 + perl "${WORKDIR}/_gstreamer_get_target_filename.pl" $@ \
306 + || die "Failed to extract target filenames from meson-info"
307 +}
308 +
309 +# @FUNCTION: gstreamer_multilib_src_compile
310 +# @DESCRIPTION:
311 +# Compiles requested gstreamer plugin.
312 +gstreamer_multilib_src_compile() {
313 + local plugin_dir plugin
314 +
315 + for plugin_dir in ${GST_PLUGINS_BUILD_DIR} ; do
316 + plugin=$(_gstreamer_get_target_filename $(gstreamer_get_plugin_dir ${plugin_dir}))
317 + plugin_path="${plugin%%:*}"
318 + eninja "${plugin_path/"${BUILD_DIR}/"}"
319 + done
320 +}
321 +
322 +# @FUNCTION: gstreamer_multilib_src_test
323 +# @DESCRIPTION:
324 +# Tests the gstreamer plugin (non-split)
325 +gstreamer_multilib_src_test() {
326 + GST_GL_WINDOW=x11 virtx eninja test;
327 +}
328 +
329 +# @FUNCTION: gstreamer_multilib_src_install
330 +# @DESCRIPTION:
331 +# Installs requested gstreamer plugin.
332 +gstreamer_multilib_src_install() {
333 + local plugin_dir plugin
334 +
335 + for plugin_dir in ${GST_PLUGINS_BUILD_DIR} ; do
336 + for plugin in $(_gstreamer_get_target_filename $(gstreamer_get_plugin_dir ${plugin_dir})); do
337 + local install_filename="${plugin##*:}"
338 + insinto "${install_filename%/*}"
339 + doins "${plugin%%:*}"
340 + done
341 + done
342 +}
343 +
344 +# @FUNCTION: gstreamer_multilib_src_install_all
345 +# @DESCRIPTION:
346 +# Installs documentation for requested gstreamer plugin
347 +gstreamer_multilib_src_install_all() {
348 + local plugin_dir
349 +
350 + for plugin_dir in ${GST_PLUGINS_BUILD_DIR} ; do
351 + local dir=$(gstreamer_get_plugin_dir ${plugin_dir})
352 + [[ -e ${dir}/README ]] && dodoc "${dir}"/README
353 + done
354 +}
355 --
356 2.26.2

Replies