Gentoo Archives: gentoo-dev

From: Alec Warner <antarus@g.o>
To: Gentoo Dev <gentoo-dev@l.g.o>
Cc: "Haelwenn (lanodan) Monnier" <contact@×××××××××.me>
Subject: Re: [gentoo-dev] [PATCH] gstreamer-meson.eclass: New eclass required for gstreamer-1.18.0+
Date: Wed, 17 Mar 2021 16:14:14
Message-Id: CAAr7Pr9t=wxqVRTBkL7e29vKBdBti9+a4S9XeUX5-x7Mszf5KQ@mail.gmail.com
In Reply to: [gentoo-dev] [PATCH] gstreamer-meson.eclass: New eclass required for gstreamer-1.18.0+ by "Haelwenn (lanodan) Monnier"
1 On Tue, Mar 16, 2021 at 6:49 PM Haelwenn (lanodan) Monnier
2 <contact@×××××××××.me> wrote:
3 >
4 > Gstreamer switched to meson in 1.16.0 and removed autotools support in 1.18.0,
5 > this eclass is an update of gstreamer.eclass.
6 >
7 > One significant change between autotools and meson is that in the latter we
8 > don't have easily extractable semantics in the buildsystem to get a list
9 > of plugins with extraneous dependencies that we currently split in other
10 > packages.
11 > Hence the rather ugly but currently required GST_PLUGINS_DISABLED block.
12 >
13 > Fixes: https://bugs.gentoo.org/690468
14 >
15 > Signed-off-by: Haelwenn (lanodan) Monnier <contact@×××××××××.me>
16 > ---
17 > eclass/gstreamer-meson.eclass | 293 ++++++++++++++++++++++++++++++++++
18 > 1 file changed, 293 insertions(+)
19 > create mode 100644 eclass/gstreamer-meson.eclass
20 >
21 > diff --git a/eclass/gstreamer-meson.eclass b/eclass/gstreamer-meson.eclass
22 > new file mode 100644
23 > index 00000000000..263deeb08aa
24 > --- /dev/null
25 > +++ b/eclass/gstreamer-meson.eclass
26 > @@ -0,0 +1,293 @@
27 > +# Copyright 1999-2021 Gentoo Authors
28 > +# Distributed under the terms of the GNU General Public License v2
29 > +
30 > +# @ECLASS: gstreamer-meson.eclass
31 > +# @MAINTAINER:
32 > +# gstreamer@g.o
33 > +# @AUTHOR:
34 > +# Michał Górny <mgorny@g.o>
35 > +# Gilles Dartiguelongue <eva@g.o>
36 > +# Saleem Abdulrasool <compnerd@g.o>
37 > +# foser <foser@g.o>
38 > +# zaheerm <zaheerm@g.o>
39 > +# Steven Newbury
40 > +# Haelwenn (lanodan) Monnier <contact@×××××××××.me>
41 > +# @SUPPORTED_EAPIS: 5 6
42 > +# @BLURB: Helps building core & split gstreamer plugins.
43 > +# @DESCRIPTION:
44 > +# Eclass to make external gst-plugins emergable on a per-plugin basis
45 > +# and to solve the problem with gst-plugins generating far too much
46 > +# unneeded dependencies.
47 > +#
48 > +# GStreamer consuming applications should depend on the specific plugins
49 > +# they need as defined in their source code. Usually you can find that
50 > +# out by grepping the source tree for 'factory_make'. If it uses playbin
51 > +# plugin, consider adding media-plugins/gst-plugins-meta dependency, but
52 > +# also list any packages that provide explicitly requested plugins.
53 > +
54 > +inherit eutils multilib meson multilib-minimal toolchain-funcs versionator xdg-utils
55 > +
56 > +case "${EAPI:-0}" in
57 > + 5|6)
58 > + ;;
59 > + 0|1|2|3|4)
60 > + die "EAPI=\"${EAPI:-0}\" is not supported anymore"
61 > + ;;
62 > + *)
63 > + die "EAPI=\"${EAPI}\" is not supported yet"
64 > + ;;
65 > +esac
66 > +
67 > +# @ECLASS-VARIABLE: GST_PLUGINS_ENABLED
68 > +# @DESCRIPTION:
69 > +# Defines the plugins to be built.
70 > +# May be set by an ebuild and contain more than one indentifier, space
71 > +# seperated (only src_configure can handle mutiple plugins at this time).
72 > +: ${GST_PLUGINS_ENABLED:=${PN/gst-plugins-/}}
73 > +
74 > +# @ECLASS-VARIABLE: GST_PLUGINS_DISABLED
75 > +# @DESCRIPTION:
76 > +# Defines the plugins to not be built, GST_PLUGINS_ENABLED overrides it.
77 > +# May be set by an ebuild and contain more than one indentifier, space
78 > +# seperated (only src_configure can handle mutiple plugins at this time).
79 > +case "${GST_ORG_MODULE}" in
80 > + # copied GST_PLUGINS_DISABLED from media-libs/${GST_ORG_MODULE} then added GST_PLUGINS_ENABLED
81 > + gst-plugins-bad)
82 > + # removed from list: shm ipcpipeline gl
83 > + 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"
84 > + 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"
85 > + ;;
86 > + gst-plugins-base)
87 > + GST_PLUGINS_DISABLED="cdparanoia libvisual opus tremor"
88 > + 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"
89 > + ;;
90 > + gst-plugins-good)
91 > + 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"
92 > + 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"
93 > + ;;
94 > + gst-plugins-ugly)
95 > + GST_PLUGINS_DISABLED="a52dec amrnb amrwbdec cdio dvdread mpeg2dec sidplay x264"
96 > + GST_PLUGINS_DISABLED="${GST_PLUGINS_DISABLED} asfdemux dvdlpcmdec dvdsub realmedia xingmux"
97 > + ;;
98 > +esac
99 > +
100 > +# @ECLASS-VARIABLE: GST_PLUGINS_BUILD_DIR
101 > +# @DESCRIPTION:
102 > +# Actual build directory of the plugin.
103 > +# Most often the same as the configure switch name.
104 > +: ${GST_PLUGINS_BUILD_DIR:=${PN/gst-plugins-/}}
105 > +
106 > +# @ECLASS-VARIABLE: GST_TARBALL_SUFFIX
107 > +# @DESCRIPTION:
108 > +# Most projects hosted on gstreamer.freedesktop.org mirrors provide
109 > +# tarballs as tar.bz2 or tar.xz. This eclass defaults to xz. This is
110 > +# because the gstreamer mirrors are moving to only have xz tarballs for
111 > +# new releases.
112 > +: ${GST_TARBALL_SUFFIX:="xz"}
113 > +
114 > +# Even though xz-utils are in @system, they must still be added to DEPEND; see
115 > +# https://archives.gentoo.org/gentoo-dev/msg_a0d4833eb314d1be5d5802a3b710e0a4.xml
116 > +if [[ ${GST_TARBALL_SUFFIX} == "xz" ]]; then
117 > + DEPEND="${DEPEND} app-arch/xz-utils"
118 > +fi
119 > +
120 > +# @ECLASS-VARIABLE: GST_ORG_MODULE
121 > +# @DESCRIPTION:
122 > +# Name of the module as hosted on gstreamer.freedesktop.org mirrors.
123 > +# Leave unset if package name matches module name.
124 > +: ${GST_ORG_MODULE:=$PN}
125 > +
126 > +# @ECLASS-VARIABLE: GST_ORG_PVP
127 > +# @INTERNAL
128 > +# @DESCRIPTION:
129 > +# Major and minor numbers of the version number.
130 > +: ${GST_ORG_PVP:=$(get_version_component_range 1-2)}
131 > +
132 > +
133 > +DESCRIPTION="${BUILD_GST_PLUGINS} plugin for gstreamer"
134 > +HOMEPAGE="https://gstreamer.freedesktop.org/"
135 > +SRC_URI="https://gstreamer.freedesktop.org/src/${GST_ORG_MODULE}/${GST_ORG_MODULE}-${PV}.tar.${GST_TARBALL_SUFFIX}"
136 > +
137 > +LICENSE="GPL-2"
138 > +case ${GST_ORG_PVP} in
139 > + 1.*) SLOT="1.0"; GST_MIN_PV="1.2.4-r1" ;;
140 > + *) die "Unkown gstreamer release."
141 > +esac
142 > +
143 > +S="${WORKDIR}/${GST_ORG_MODULE}-${PV}"
144 > +
145 > +RDEPEND="
146 > + >=dev-libs/glib-2.38.2-r1:2[${MULTILIB_USEDEP}]
147 > + >=media-libs/gstreamer-${GST_MIN_PV}:${SLOT}[${MULTILIB_USEDEP}]
148 > +"
149 > +DEPEND="
150 > + >=sys-apps/sed-4
151 > + >=virtual/pkgconfig-0-r1[${MULTILIB_USEDEP}]
152 > +"
153 > +
154 > +# Export common multilib phases.
155 > +multilib_src_configure() { gstreamer_multilib_src_configure; }
156 > +
157 > +if [[ ${PN} != ${GST_ORG_MODULE} ]]; then
158 > + # Do not run test phase for invididual plugin ebuilds.
159 > + RESTRICT="test"
160 > + RDEPEND="${RDEPEND}
161 > + >=media-libs/${GST_ORG_MODULE}-${PV}:${SLOT}[${MULTILIB_USEDEP}]"
162 > +
163 > + # Export multilib phases used for split builds.
164 > + multilib_src_compile() { gstreamer_multilib_src_compile; }
165 > + multilib_src_install() { gstreamer_multilib_src_install; }
166 > + multilib_src_install_all() { gstreamer_multilib_src_install_all; }
167 > +else
168 > + IUSE="nls"
169 > + DEPEND="${DEPEND} nls? ( >=sys-devel/gettext-0.17 )"
170 > +
171 > + multilib_src_compile() { eninja; }
172 > + multilib_src_install() { DESTDIR="${D}" eninja install; }
173 > +fi
174 > +
175 > +DEPEND="${DEPEND} ${RDEPEND}"
176 > +
177 > +# @FUNCTION: gstreamer_environment_reset
178 > +# @INTERNAL
179 > +# @DESCRIPTION:
180 > +# Clean up environment for clean builds.
181 > +# >=dev-lang/orc-0.4.23 rely on environment variables to find a place to
182 > +# allocate files to mmap.
183 > +gstreamer_environment_reset() {
184 > + xdg_environment_reset
185 > +}
186 > +
187 > +# @FUNCTION: gstreamer_get_plugin_dir
188 > +# @USAGE: gstreamer_get_plugin_dir [<build_dir>]
189 > +# @INTERNAL
190 > +# @DESCRIPTION:
191 > +# Finds plugin build directory and output it.
192 > +# Defaults to ${GST_PLUGINS_BUILD_DIR} if argument is not provided
193 > +gstreamer_get_plugin_dir() {
194 > + local build_dir=${1:-${GST_PLUGINS_BUILD_DIR}}
195 > +
196 > + if [[ ! -d ${S}/ext/${build_dir} ]]; then
197 > + if [[ ! -d ${S}/sys/${build_dir} ]]; then
198 > + ewarn "No such plugin directory"
199 > + die
200 > + fi
201 > + einfo "Building system plugin in ${build_dir}..." >&2
202 > + echo sys/${build_dir}
203 > + else
204 > + einfo "Building external plugin in ${build_dir}..." >&2
205 > + echo ext/${build_dir}
206 > + fi
207 > +}
208 > +
209 > +# @FUNCTION: gstreamer_multilib_src_configure
210 > +# @DESCRIPTION:
211 > +# Handles logic common to configuring gstreamer plugins
212 > +gstreamer_multilib_src_configure() {
213 > + local plugin emesonargs=() EMESON_SOURCE=${EMESON_SOURCE:-${S}}
214 > +
215 > + gstreamer_environment_reset
216 > +
217 > + # app-editor/vis regex for meson_options.txt: :x/option\('([^']*)'.*/ c/\1/
218 > + for plugin in ${GST_PLUGINS_DISABLED} ; do
219 > + emesonargs+=( -D${plugin}=disabled )
220 > + done
221 > +
222 > + for plugin in ${GST_PLUGINS_ENABLED} ; do
223 > + emesonargs+=( -D${plugin}=enabled )
224 > + done
225 > +
226 > + if grep -q "option(\'orc\'" "${EMESON_SOURCE}"/meson_options.txt ; then
227 > + if in_iuse orc ; then
228 > + emesonargs+=( -Dorc=$(usex orc enabled disabled) )
229 > + else
230 > + emesonargs+=( -Dorc=disabled )
231 > + fi
232 > + fi
233 > +
234 > + if grep -q "option(\'maintainer-mode\'" "${EMESON_SOURCE}"/meson_options.txt ; then
235 > + gst_conf+=( -Dmaintainer-mode=disabled )
236 > + fi
237 > +
238 > + if grep -q "option(\'schemas-compile\'" "${EMESON_SOURCE}"/meson_options.txt ; then
239 > + gst_conf+=( -Dschemas-compile=disabled )
240 > + fi
241 > +
242 > + if [[ ${PN} == ${GST_ORG_MODULE} ]]; then
243 > + emesonargs+=( $(meson_feature nls) )
244 > + fi
245 > +
246 > + einfo "Configuring to build ${GST_PLUGINS_ENABLED} plugin(s) ..."
247 > + emesonargs+=(
248 > + -Dexamples=disabled
249 > + -Dpackage-name="Gentoo GStreamer ebuild"
250 > + -Dpackage-origin="https://www.gentoo.org"
251 > + "${@}"
252 > + )
253 > + meson_src_configure
254 > +}
255 > +
256 > +read -d '' __MESON_EXTRACT_TARGET_FILENAME <<"EOF"
257 > +import json
258 > +import sys
259 > +
260 > +with open("meson-info/intro-targets.json", "r") as targets_file:
261 > + data = json.load(targets_file)
262 > +
263 > +for i in range(len(data)):
264
265 Not grokking this loop.
266
267 for target in data.values():
268 if target['installed']:
269 ...
270
271 Is likely sufficient.
272
273 Also this short script has no error handling, so any malformed json
274 will crash it, as well any json objects missing these fields; I assume
275 that's OK because...those all go to stderr, right; and print() goes to
276 stdout by default, so it won't hurt _gstreamer_get_target_filename ?
277
278 > + target = data[i]
279 > + if target['installed']:
280 > + if sys.argv[1] in target['filename'][0]:
281 > + print(target['filename'][0] + ':' + target['install_filename'][0])
282 > +EOF
283 > +
284 > +# @FUNCTION: _gstreamer_get_target_filename
285 > +# @INTERNAL
286 > +# @DESCRIPTION:
287 > +# Extracts build and target filenames from meson-data for given submatch
288 > +_gstreamer_get_target_filename() {
289 > + python -c "${__MESON_EXTRACT_TARGET_FILENAME}" "$@"
290 > +}
291 > +
292 > +# @FUNCTION: gstreamer_multilib_src_compile
293 > +# @DESCRIPTION:
294 > +# Compiles requested gstreamer plugin.
295 > +gstreamer_multilib_src_compile() {
296 > + local plugin_dir plugin
297 > +
298 > + for plugin_dir in ${GST_PLUGINS_BUILD_DIR} ; do
299 > + plugin=$(_gstreamer_get_target_filename $(gstreamer_get_plugin_dir ${plugin_dir}))
300 > + plugin_path="${plugin%%:*}"
301 > + eninja "${plugin_path/"${BUILD_DIR}/"}"
302 > + done
303 > +}
304 > +
305 > +# @FUNCTION: gstreamer_multilib_src_install
306 > +# @DESCRIPTION:
307 > +# Installs requested gstreamer plugin.
308 > +gstreamer_multilib_src_install() {
309 > + local plugin_dir plugin
310 > +
311 > + for plugin_dir in ${GST_PLUGINS_BUILD_DIR} ; do
312 > + for plugin in $(_gstreamer_get_target_filename $(gstreamer_get_plugin_dir ${plugin_dir})); do
313 > + local install_filename="${plugin##*:}"
314 > + insinto "${install_filename%/*}"
315 > + doins "${plugin%%:*}"
316 > + done
317 > + done
318 > +}
319 > +
320 > +# @FUNCTION: gstreamer_multilib_src_install_all
321 > +# @DESCRIPTION:
322 > +# Installs documentation for requested gstreamer plugin, and removes .la
323 > +# files.
324 > +gstreamer_multilib_src_install_all() {
325 > + local plugin_dir
326 > +
327 > + for plugin_dir in ${GST_PLUGINS_BUILD_DIR} ; do
328 > + local dir=$(gstreamer_get_plugin_dir ${plugin_dir})
329 > + [[ -e ${dir}/README ]] && dodoc "${dir}"/README
330 > + done
331 > +
332 > + prune_libtool_files --modules
333 > +}
334 > --
335 > 2.26.2
336 >
337 >