Gentoo Archives: gentoo-commits

From: Marek Szuba <marecki@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] repo/gentoo:master commit in: eclass/
Date: Mon, 05 Oct 2020 12:14:55
Message-Id: 1601900052.6c869809927d3b3d35be224dd8dfe5c8aba490ee.marecki@gentoo
1 commit: 6c869809927d3b3d35be224dd8dfe5c8aba490ee
2 Author: Marek Szuba <marecki <AT> gentoo <DOT> org>
3 AuthorDate: Wed Sep 30 16:03:54 2020 +0000
4 Commit: Marek Szuba <marecki <AT> gentoo <DOT> org>
5 CommitDate: Mon Oct 5 12:14:12 2020 +0000
6 URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=6c869809
7
8 lua-single.eclass: new eclass for single-implementation Lua ebuilds
9
10 With many thanks to Michał Górny and other authors of
11 python-single-r1.eclass.
12
13 Signed-off-by: Marek Szuba <marecki <AT> gentoo.org>
14
15 eclass/lua-single.eclass | 510 +++++++++++++++++++++++++++++++++++++++++++++++
16 1 file changed, 510 insertions(+)
17
18 diff --git a/eclass/lua-single.eclass b/eclass/lua-single.eclass
19 new file mode 100644
20 index 00000000000..2233fdd33b6
21 --- /dev/null
22 +++ b/eclass/lua-single.eclass
23 @@ -0,0 +1,510 @@
24 +# Copyright 1999-2020 Gentoo Authors
25 +# Distributed under the terms of the GNU General Public License v2
26 +
27 +# @ECLASS: lua-single.eclass
28 +# @MAINTAINER:
29 +# William Hubbs <williamh@g.o>
30 +# Marek Szuba <marecki@g.o>
31 +# @AUTHOR:
32 +# Marek Szuba <marecki@g.o>
33 +# Based on python-single-r1.eclass by Michał Górny <mgorny@g.o> et al.
34 +# @SUPPORTED_EAPIS: 7
35 +# @BLURB: An eclass for Lua packages not installed for multiple implementations.
36 +# @DESCRIPTION:
37 +# An extension of lua.eclass suite for packages which don't support being
38 +# installed for multiple Lua implementations. This mostly includes software
39 +# embedding Lua.
40 +#
41 +# This eclass sets correct IUSE. It also provides LUA_DEPS
42 +# and LUA_REQUIRED_USE that need to be added to appropriate ebuild
43 +# metadata variables.
44 +#
45 +# The eclass exports LUA_SINGLE_USEDEP that is suitable for depending
46 +# on other packages using the eclass. Dependencies on packages using
47 +# lua.eclass should be created via lua_gen_cond_dep() function, using
48 +# LUA_USEDEP placeholder.
49 +#
50 +# Please note that packages support multiple Lua implementations
51 +# (using lua.eclass) cannot depend on packages not supporting
52 +# them (using this eclass).
53 +#
54 +# Note that since this eclass always inherits lua-utils as well, in ebuilds
55 +# using the former there is no need to explicitly inherit the latter in order
56 +# to use helper functions such as lua_get_CFLAGS.
57 +
58 +case ${EAPI:-0} in
59 + 0|1|2|3|4|5|6)
60 + die "Unsupported EAPI=${EAPI} (too old) for ${ECLASS}"
61 + ;;
62 + 7)
63 + ;;
64 + *)
65 + die "Unsupported EAPI=${EAPI} (unknown) for ${ECLASS}"
66 + ;;
67 +esac
68 +
69 +if [[ ! ${_LUA_SINGLE_R0} ]]; then
70 +
71 +if [[ ${_LUA_R0} ]]; then
72 + die 'lua-single.eclass cannot be used with lua.eclass.'
73 +fi
74 +
75 +inherit lua-utils
76 +
77 +fi
78 +
79 +EXPORT_FUNCTIONS pkg_setup
80 +
81 +# @ECLASS-VARIABLE: LUA_COMPAT
82 +# @REQUIRED
83 +# @PRE_INHERIT
84 +# @DESCRIPTION:
85 +# This variable contains a list of Lua implementations the package
86 +# supports. It must be set before the `inherit' call. It has to be
87 +# an array.
88 +#
89 +# Example:
90 +# @CODE
91 +# LUA_COMPAT=( lua5-1 lua5-2 lua5-3 )
92 +# @CODE
93 +#
94 +# Please note that you can also use bash brace expansion if you like:
95 +# @CODE
96 +# LUA_COMPAT=( lua5-{1..3} )
97 +# @CODE
98 +
99 +# @ECLASS-VARIABLE: LUA_COMPAT_OVERRIDE
100 +# @USER_VARIABLE
101 +# @DEFAULT_UNSET
102 +# @DESCRIPTION:
103 +# This variable can be used when working with ebuilds to override
104 +# the in-ebuild LUA_COMPAT. It is a string listing all
105 +# the implementations which package will be built for. It need be
106 +# specified in the calling environment, and not in ebuilds.
107 +#
108 +# It should be noted that in order to preserve metadata immutability,
109 +# LUA_COMPAT_OVERRIDE does not affect IUSE nor dependencies.
110 +# The state of LUA_TARGETS is ignored, and all the implementations
111 +# in LUA_COMPAT_OVERRIDE are built. Dependencies need to be satisfied
112 +# manually.
113 +#
114 +# Example:
115 +# @CODE
116 +# LUA_COMPAT_OVERRIDE='lua5-2' emerge -1v dev-lua/foo
117 +# @CODE
118 +
119 +# @ECLASS-VARIABLE: LUA_REQ_USE
120 +# @DEFAULT_UNSET
121 +# @PRE_INHERIT
122 +# @DESCRIPTION:
123 +# The list of USE flags required to be enabled on the chosen Lua
124 +# implementations, formed as a USE-dependency string. It should be valid
125 +# for all implementations in LUA_COMPAT, so it may be necessary to
126 +# use USE defaults.
127 +# This must be set before calling `inherit'.
128 +#
129 +# Example:
130 +# @CODE
131 +# LUA_REQ_USE="deprecated"
132 +# @CODE
133 +#
134 +# It will cause the Lua dependencies to look like:
135 +# @CODE
136 +# lua_targets_luaX-Y? ( dev-lang/lua:X.Y[deprecated] )
137 +# @CODE
138 +
139 +# @ECLASS-VARIABLE: LUA_DEPS
140 +# @OUTPUT_VARIABLE
141 +# @DESCRIPTION:
142 +# This is an eclass-generated Lua dependency string for all
143 +# implementations listed in LUA_COMPAT.
144 +#
145 +# Example use:
146 +# @CODE
147 +# RDEPEND="${LUA_DEPS}
148 +# dev-foo/mydep"
149 +# DEPEND="${RDEPEND}"
150 +# @CODE
151 +#
152 +# Example value:
153 +# @CODE
154 +# lua_targets_lua5-1? ( dev-lang/lua:5.1 )
155 +# lua_targets_lua5-2? ( dev-lang/lua:5.2 )
156 +# @CODE
157 +
158 +# @ECLASS-VARIABLE: LUA_REQUIRED_USE
159 +# @OUTPUT_VARIABLE
160 +# @DESCRIPTION:
161 +# This is an eclass-generated required-use expression which ensures at
162 +# least one Lua implementation has been enabled.
163 +#
164 +# This expression should be utilized in an ebuild by including it in
165 +# REQUIRED_USE, optionally behind a use flag.
166 +#
167 +# Example use:
168 +# @CODE
169 +# REQUIRED_USE="lua? ( ${LUA_REQUIRED_USE} )"
170 +# @CODE
171 +#
172 +# Example value:
173 +# @CODE
174 +# || ( lua_targets_lua5-1 lua_targets_lua5-2 )
175 +# @CODE
176 +
177 +# @ECLASS-VARIABLE: LUA_SINGLE_USEDEP
178 +# @OUTPUT_VARIABLE
179 +# @DESCRIPTION:
180 +# This is an eclass-generated USE-dependency string which can be used
181 +# to depend on another lua-single package being built for the same
182 +# Lua implementations.
183 +#
184 +# If you need to depend on a multi-impl (lua.eclass) package, use
185 +# lua_gen_cond_dep with LUA_USEDEP placeholder instead.
186 +#
187 +# Example use:
188 +# @CODE
189 +# RDEPEND="dev-lua/foo[${LUA_SINGLE_USEDEP}]"
190 +# @CODE
191 +#
192 +# Example value:
193 +# @CODE
194 +# lua_single_target_lua5-1(-)?
195 +# @CODE
196 +
197 +# @ECLASS-VARIABLE: LUA_USEDEP
198 +# @OUTPUT_VARIABLE
199 +# @DESCRIPTION:
200 +# This is an eclass-generated USE-dependency string which can be used to
201 +# depend on another Lua package being built for the same Lua
202 +# implementations.
203 +#
204 +# Example use:
205 +# @CODE
206 +# RDEPEND="dev-lua/foo[${LUA_USEDEP}]"
207 +# @CODE
208 +#
209 +# Example value:
210 +# @CODE
211 +# lua_targets_lua5-1(-)?,lua_targets_lua5-2(-)?
212 +# @CODE
213 +
214 +# @FUNCTION: _lua_single_set_globals
215 +# @INTERNAL
216 +# @DESCRIPTION:
217 +# Sets all the global output variables provided by this eclass.
218 +# This function must be called once, in global scope.
219 +_lua_single_set_globals() {
220 + _lua_set_impls
221 +
222 + local flags=( "${_LUA_SUPPORTED_IMPLS[@]/#/lua_single_target_}" )
223 +
224 + if [[ ${#_LUA_SUPPORTED_IMPLS[@]} -eq 1 ]]; then
225 + # if only one implementation is supported, use IUSE defaults
226 + # to avoid requesting the user to enable it
227 + IUSE="+${flags[0]}"
228 + else
229 + IUSE="${flags[*]}"
230 + fi
231 +
232 + local requse="^^ ( ${flags[*]} )"
233 + local single_flags="${flags[@]/%/(-)?}"
234 + local single_usedep=${single_flags// /,}
235 +
236 + local deps= i PYTHON_PKG_DEP
237 + for i in "${_LUA_SUPPORTED_IMPLS[@]}"; do
238 + _lua_export "${i}" LUA_PKG_DEP
239 + deps+="lua_single_target_${i}? ( ${LUA_PKG_DEP} ) "
240 + done
241 +
242 + if [[ ${LUA_DEPS+1} ]]; then
243 + if [[ ${LUA_DEPS} != "${deps}" ]]; then
244 + eerror "LUA_DEPS have changed between inherits (LUA_REQ_USE?)!"
245 + eerror "Before: ${LUA_DEPS}"
246 + eerror "Now : ${deps}"
247 + die "LUA_DEPS integrity check failed"
248 + fi
249 +
250 + # these two are formality -- they depend on LUA_COMPAT only
251 + if [[ ${LUA_REQUIRED_USE} != ${requse} ]]; then
252 + eerror "LUA_REQUIRED_USE have changed between inherits!"
253 + eerror "Before: ${LUA_REQUIRED_USE}"
254 + eerror "Now : ${requse}"
255 + die "LUA_REQUIRED_USE integrity check failed"
256 + fi
257 +
258 + if [[ ${LUA_SINGLE_USEDEP} != "${single_usedep}" ]]; then
259 + eerror "LUA_SINGLE_USEDEP have changed between inherits!"
260 + eerror "Before: ${LUA_SINGLE_USEDEP}"
261 + eerror "Now : ${single_usedep}"
262 + die "LUA_SINGLE_USEDEP integrity check failed"
263 + fi
264 + else
265 + LUA_DEPS=${deps}
266 + LUA_REQUIRED_USE=${requse}
267 + LUA_SINGLE_USEDEP=${single_usedep}
268 + LUA_USEDEP='%LUA_USEDEP-NEEDS-TO-BE-USED-IN-LUA_GEN_COND_DEP%'
269 + readonly LUA_DEPS LUA_REQUIRED_USE LUA_SINGLE_USEDEP LUA_USEDEP
270 + fi
271 +}
272 +
273 +_lua_single_set_globals
274 +unset -f _lua_single_set_globals
275 +
276 +if [[ ! ${_LUA_SINGLE_R0} ]]; then
277 +
278 +# @FUNCTION: _lua_gen_usedep
279 +# @USAGE: [<pattern>...]
280 +# @INTERNAL
281 +# @DESCRIPTION:
282 +# Output a USE dependency string for Lua implementations which
283 +# are both in LUA_COMPAT and match any of the patterns passed
284 +# as parameters to the function.
285 +#
286 +# The patterns can be fnmatch-style patterns (matched via bash == operator
287 +# against LUA_COMPAT values). Remember to escape or quote the fnmatch
288 +# patterns to prevent accidental shell filename expansion.
289 +#
290 +# This is an internal function used to implement lua_gen_cond_dep.
291 +_lua_gen_usedep() {
292 + debug-print-function ${FUNCNAME} "${@}"
293 +
294 + local impl matches=()
295 +
296 + _lua_verify_patterns "${@}"
297 + for impl in "${_LUA_SUPPORTED_IMPLS[@]}"; do
298 + if _lua_impl_matches "${impl}" "${@}"; then
299 + matches+=(
300 + "lua_single_target_${impl}(-)?"
301 + )
302 + fi
303 + done
304 +
305 + [[ ${matches[@]} ]] || die "No supported implementations match lua_gen_usedep patterns: ${@}"
306 +
307 + local out=${matches[@]}
308 + echo "${out// /,}"
309 +}
310 +
311 +# @FUNCTION: _lua_impl_matches
312 +# @USAGE: <impl> [<pattern>...]
313 +# @INTERNAL
314 +# @DESCRIPTION:
315 +# Check whether the specified <impl> matches at least one
316 +# of the patterns following it. Return 0 if it does, 1 otherwise.
317 +# Matches if no patterns are provided.
318 +#
319 +# <impl> can be in LUA_COMPAT or ELUA form. The patterns can be
320 +# fnmatch-style patterns, e.g. 'lua5*', '..
321 +_lua_impl_matches() {
322 + [[ ${#} -ge 1 ]] || die "${FUNCNAME}: takes at least 1 parameter"
323 + [[ ${#} -eq 1 ]] && return 0
324 +
325 + local impl=${1} pattern
326 + shift
327 +
328 + for pattern; do
329 + # unify value style to allow lax matching
330 + if [[ ${impl/./-} == ${pattern/./-} ]]; then
331 + return 0
332 + fi
333 + done
334 +
335 + return 1
336 +}
337 +
338 +# @FUNCTION: _lua_verify_patterns
339 +# @USAGE: <pattern>...
340 +# @INTERNAL
341 +# @DESCRIPTION:
342 +# Verify whether the patterns passed to the eclass function are correct
343 +# (i.e. can match any valid implementation). Dies on wrong pattern.
344 +_lua_verify_patterns() {
345 + debug-print-function ${FUNCNAME} "${@}"
346 +
347 + local impl pattern
348 + for pattern; do
349 + for impl in "${_LUA_ALL_IMPLS[@]}"; do
350 + [[ ${impl} == ${pattern/./-} ]] && continue 2
351 + done
352 +
353 + die "Invalid implementation pattern: ${pattern}"
354 + done
355 +}
356 +
357 +# @FUNCTION: lua_gen_cond_dep
358 +# @USAGE: <dependency> [<pattern>...]
359 +# @DESCRIPTION:
360 +# Output a list of <dependency>-ies made conditional to USE flags
361 +# of Lua implementations which are both in LUA_COMPAT and match
362 +# any of the patterns passed as the remaining parameters.
363 +#
364 +# The patterns can be fnmatch-style patterns (matched via bash == operator
365 +# against LUA_COMPAT values). Remember to escape or quote the fnmatch
366 +# patterns to prevent accidental shell filename expansion.
367 +#
368 +# In order to enforce USE constraints on the packages, verbatim
369 +# '${LUA_SINGLE_USEDEP}' and '${LUA_USEDEP}' (quoted!) may
370 +# be placed in the dependency specification. It will get expanded within
371 +# the function into a proper USE dependency string.
372 +#
373 +# Example:
374 +# @CODE
375 +# LUA_COMPAT=( lua5-{1..3} )
376 +# RDEPEND="$(lua_gen_cond_dep \
377 +# 'dev-lua/backported_core_module[${LUA_USEDEP}]' lua5-1 lua5-2 )"
378 +# @CODE
379 +#
380 +# It will cause the variable to look like:
381 +# @CODE
382 +# RDEPEND="lua_single_target_lua5-1? (
383 +# dev-lua/backported_core_module[lua_targets_lua5-1(-)?,...] )
384 +# lua_single_target_lua5-2? (
385 +# dev-lua/backported_core_module[lua_targets_lua5-2(-)?,...] )"
386 +# @CODE
387 +lua_gen_cond_dep() {
388 + debug-print-function ${FUNCNAME} "${@}"
389 +
390 + local impl matches=()
391 +
392 + local dep=${1}
393 + shift
394 +
395 + _lua_verify_patterns "${@}"
396 + for impl in "${_LUA_SUPPORTED_IMPLS[@]}"; do
397 + if _lua_impl_matches "${impl}" "${@}"; then
398 + # substitute ${LUA_SINGLE_USEDEP} if used
399 + # (since lua_gen_usedep() will not return
400 + # ${LUA_SINGLE_USEDEP}, the code is run at most once)
401 + if [[ ${dep} == *'${LUA_SINGLE_USEDEP}'* ]]; then
402 + local usedep=$(_lua_gen_usedep "${@}")
403 + dep=${dep//\$\{LUA_SINGLE_USEDEP\}/${usedep}}
404 + fi
405 + local multi_usedep="lua_targets_${impl}(-)"
406 +
407 + local subdep=${dep//\$\{LUA_MULTI_USEDEP\}/${multi_usedep}}
408 + matches+=( "lua_single_target_${impl}? (
409 + ${subdep//\$\{LUA_USEDEP\}/${multi_usedep}} )" )
410 + fi
411 + done
412 +
413 + echo "${matches[@]}"
414 +}
415 +
416 +# @FUNCTION: lua_gen_impl_dep
417 +# @USAGE: [<requested-use-flags> [<impl-pattern>...]]
418 +# @DESCRIPTION:
419 +# Output a dependency on Lua implementations with the specified USE
420 +# dependency string appended, or no USE dependency string if called
421 +# without the argument (or with empty argument). If any implementation
422 +# patterns are passed, the output dependencies will be generated only
423 +# for the implementations matching them.
424 +#
425 +# The patterns can be fnmatch-style patterns (matched via bash == operator
426 +# against LUA_COMPAT values). Remember to escape or quote the fnmatch
427 +# patterns to prevent accidental shell filename expansion.
428 +#
429 +# Use this function when you need to request different USE flags
430 +# on the Lua interpreter depending on package's USE flags. If you
431 +# only need a single set of interpreter USE flags, just set
432 +# LUA_REQ_USE and use ${LUA_DEPS} globally.
433 +#
434 +# Example:
435 +# @CODE
436 +# LUA_COMPAT=( lua5-{1..3} )
437 +# RDEPEND="foo? ( $(lua_gen_impl_dep 'deprecated(+)' lua5-3 ) )"
438 +# @CODE
439 +#
440 +# It will cause the variable to look like:
441 +# @CODE
442 +# RDEPEND="foo? (
443 +# lua_single_target_lua5-3? ( dev-lang/lua:5.3[deprecated(+)] )
444 +# )"
445 +# @CODE
446 +lua_gen_impl_dep() {
447 + debug-print-function ${FUNCNAME} "${@}"
448 +
449 + local impl
450 + local matches=()
451 +
452 + local LUA_REQ_USE=${1}
453 + shift
454 +
455 + _lua_verify_patterns "${@}"
456 + for impl in "${_LUA_SUPPORTED_IMPLS[@]}"; do
457 + if _lua_impl_matches "${impl}" "${@}"; then
458 + local LUA_PKG_DEP
459 + _lua_export "${impl}" LUA_PKG_DEP
460 + matches+=( "lua_single_target_${impl}? ( ${LUA_PKG_DEP} )" )
461 + fi
462 + done
463 +
464 + echo "${matches[@]}"
465 +}
466 +
467 +# @FUNCTION: lua_setup
468 +# @DESCRIPTION:
469 +# Determine what the selected Lua implementation is and set
470 +# the Lua build environment up for it.
471 +lua_setup() {
472 + debug-print-function ${FUNCNAME} "${@}"
473 +
474 + unset ELUA
475 +
476 + # support developer override
477 + if [[ ${LUA_COMPAT_OVERRIDE} ]]; then
478 + local impls=( ${LUA_COMPAT_OVERRIDE} )
479 + [[ ${#impls[@]} -eq 1 ]] || die "LUA_COMPAT_OVERRIDE must name exactly one implementation for lua-single"
480 +
481 + ewarn "WARNING: LUA_COMPAT_OVERRIDE in effect. The following Lua"
482 + ewarn "implementation will be used:"
483 + ewarn
484 + ewarn " ${LUA_COMPAT_OVERRIDE}"
485 + ewarn
486 + ewarn "Dependencies won't be satisfied, and LUA_SINGLE_TARGET flags will be ignored."
487 +
488 + _lua_export "${impls[0]}" ELUA LUA
489 + _lua_wrapper_setup
490 + einfo "Using ${ELUA} to build"
491 + return
492 + fi
493 +
494 + local impl
495 + for impl in "${_LUA_SUPPORTED_IMPLS[@]}"; do
496 + if use "lua_single_target_${impl}"; then
497 + if [[ ${ELUA} ]]; then
498 + eerror "Your LUA_SINGLE_TARGET setting lists more than a single Lua"
499 + eerror "implementation. Please set it to just one value. If you need"
500 + eerror "to override the value for a single package, please use package.env"
501 + eerror "or an equivalent solution (man 5 portage)."
502 + echo
503 + die "More than one implementation in LUA_SINGLE_TARGET."
504 + fi
505 +
506 + _lua_export "${impl}" ELUA LUA
507 + _lua_wrapper_setup
508 + einfo "Using ${ELUA} to build"
509 + fi
510 + done
511 +
512 + if [[ ! ${ELUA} ]]; then
513 + eerror "No Lua implementation selected for the build. Please set"
514 + eerror "the LUA_SINGLE_TARGET variable in your make.conf to one"
515 + eerror "of the following values:"
516 + eerror
517 + eerror "${_LUA_SUPPORTED_IMPLS[@]}"
518 + echo
519 + die "No supported Lua implementation in LUA_SINGLE_TARGET."
520 + fi
521 +}
522 +
523 +# @FUNCTION: lua-single_pkg_setup
524 +# @DESCRIPTION:
525 +# Runs lua_setup.
526 +lua-single_pkg_setup() {
527 + debug-print-function ${FUNCNAME} "${@}"
528 +
529 + [[ ${MERGE_TYPE} != binary ]] && lua_setup
530 +}
531 +
532 +_LUA_SINGLE_R0=1
533 +fi