Gentoo Archives: gentoo-dev

From: "Marty E. Plummer" <hanetzer@×××××××××.com>
To: gentoo-dev@l.g.o
Cc: "Marty E. Plummer" <hanetzer@×××××××××.com>
Subject: [gentoo-dev] [PATCH] eutils.eclass: split unique functions into eutils-r1
Date: Sun, 08 Apr 2018 13:04:28
Message-Id: 20180408122929.20363-1-hanetzer@startmail.com
1 Split all functions unique to eutils into eutils-r1, and inherit it
2 from eutils. Issue a QA warning on EAPI=6 ebuilds using eutils directly
3 and suggest migrating to direct use of the needed eclass, with a list of
4 functions unique to eutils-r1.
5
6 With this we can start moving ebuilds which inherit eutils because they
7 need a function unique to the old eutils to eutils-r1, while being able
8 to single out ebuilds which used eutils to inherit other ebuilds lazily
9 or just cargo cult coding of always inheriting eutils.
10
11 Package-Manager: Portage-2.3.28, Repoman-2.3.9
12 ---
13 eclass/eutils-r1.eclass | 265 ++++++++++++++++++++++++++++++++++++++++
14 eclass/eutils.eclass | 253 ++------------------------------------
15 2 files changed, 278 insertions(+), 240 deletions(-)
16 create mode 100644 eclass/eutils-r1.eclass
17
18 diff --git a/eclass/eutils-r1.eclass b/eclass/eutils-r1.eclass
19 new file mode 100644
20 index 00000000000..93fd0be7928
21 --- /dev/null
22 +++ b/eclass/eutils-r1.eclass
23 @@ -0,0 +1,265 @@
24 +# Copyright 1999-2018 Gentoo Foundation
25 +# Distributed under the terms of the GNU General Public License v2
26 +
27 +# @ECLASS: eutils-r1.eclass
28 +# @MAINTAINER:
29 +# base-system@g.o
30 +# @BLURB: many extra (but common) functions that are used in ebuilds
31 +# @DESCRIPTION:
32 +# The eutils eclass contains a suite of functions that complement
33 +# the ones that ebuild.sh already contain. The idea is that the functions
34 +# are not required in all ebuilds but enough utilize them to have a common
35 +# home rather than having multiple ebuilds implementing the same thing.
36 +#
37 +# Due to the nature of this eclass, some functions may have maintainers
38 +# different from the overall eclass!
39 +
40 +if [[ -z ${_EUTILS_R1_ECLASS} ]]; then
41 +_EUTILS_R1_ECLASS=1
42 +
43 +case ${EAPI:-0} in
44 + 6) ;;
45 + *) [[ ${_EUTILS_ECLASS} == 1 ]] || die "${ECLASS}.eclass is banned n EAPI=${EAPI}" ;;
46 +esac
47 +
48 +# @FUNCTION: eqawarn
49 +# @USAGE: [message]
50 +# @DESCRIPTION:
51 +# Proxy to ewarn for package managers that don't provide eqawarn and use the PM
52 +# implementation if available. Reuses PORTAGE_ELOG_CLASSES as set by the dev
53 +# profile.
54 +if ! declare -F eqawarn >/dev/null ; then
55 + eqawarn() {
56 + has qa ${PORTAGE_ELOG_CLASSES} && ewarn "$@"
57 + :
58 + }
59 +fi
60 +
61 +# @FUNCTION: emktemp
62 +# @USAGE: [temp dir]
63 +# @DESCRIPTION:
64 +# Cheap replacement for when debianutils (and thus mktemp)
65 +# does not exist on the users system.
66 +emktemp() {
67 + local exe="touch"
68 + [[ $1 == -d ]] && exe="mkdir" && shift
69 + local topdir=$1
70 +
71 + if [[ -z ${topdir} ]] ; then
72 + [[ -z ${T} ]] \
73 + && topdir="/tmp" \
74 + || topdir=${T}
75 + fi
76 +
77 + if ! type -P mktemp > /dev/null ; then
78 + # system lacks `mktemp` so we have to fake it
79 + local tmp=/
80 + while [[ -e ${tmp} ]] ; do
81 + tmp=${topdir}/tmp.${RANDOM}.${RANDOM}.${RANDOM}
82 + done
83 + ${exe} "${tmp}" || ${exe} -p "${tmp}"
84 + echo "${tmp}"
85 + else
86 + # the args here will give slightly wierd names on BSD,
87 + # but should produce a usable file on all userlands
88 + if [[ ${exe} == "touch" ]] ; then
89 + TMPDIR="${topdir}" mktemp -t tmp.XXXXXXXXXX
90 + else
91 + TMPDIR="${topdir}" mktemp -dt tmp.XXXXXXXXXX
92 + fi
93 + fi
94 +}
95 +
96 +# @FUNCTION: edos2unix
97 +# @USAGE: <file> [more files ...]
98 +# @DESCRIPTION:
99 +# A handy replacement for dos2unix, recode, fixdos, etc... This allows you
100 +# to remove all of these text utilities from DEPEND variables because this
101 +# is a script based solution. Just give it a list of files to convert and
102 +# they will all be changed from the DOS CRLF format to the UNIX LF format.
103 +edos2unix() {
104 + [[ $# -eq 0 ]] && return 0
105 + sed -i 's/\r$//' -- "$@" || die
106 +}
107 +
108 +# @FUNCTION: strip-linguas
109 +# @USAGE: [<allow LINGUAS>|<-i|-u> <directories of .po files>]
110 +# @DESCRIPTION:
111 +# Make sure that LINGUAS only contains languages that
112 +# a package can support. The first form allows you to
113 +# specify a list of LINGUAS. The -i builds a list of po
114 +# files found in all the directories and uses the
115 +# intersection of the lists. The -u builds a list of po
116 +# files found in all the directories and uses the union
117 +# of the lists.
118 +strip-linguas() {
119 + local ls newls nols
120 + if [[ $1 == "-i" ]] || [[ $1 == "-u" ]] ; then
121 + local op=$1; shift
122 + ls=$(find "$1" -name '*.po' -exec basename {} .po ';'); shift
123 + local d f
124 + for d in "$@" ; do
125 + if [[ ${op} == "-u" ]] ; then
126 + newls=${ls}
127 + else
128 + newls=""
129 + fi
130 + for f in $(find "$d" -name '*.po' -exec basename {} .po ';') ; do
131 + if [[ ${op} == "-i" ]] ; then
132 + has ${f} ${ls} && newls="${newls} ${f}"
133 + else
134 + has ${f} ${ls} || newls="${newls} ${f}"
135 + fi
136 + done
137 + ls=${newls}
138 + done
139 + else
140 + ls="$@"
141 + fi
142 +
143 + nols=""
144 + newls=""
145 + for f in ${LINGUAS} ; do
146 + if has ${f} ${ls} ; then
147 + newls="${newls} ${f}"
148 + else
149 + nols="${nols} ${f}"
150 + fi
151 + done
152 + [[ -n ${nols} ]] \
153 + && einfo "Sorry, but ${PN} does not support the LINGUAS:" ${nols}
154 + export LINGUAS=${newls:1}
155 +}
156 +
157 +# @FUNCTION: make_wrapper
158 +# @USAGE: <wrapper> <target> [chdir] [libpaths] [installpath]
159 +# @DESCRIPTION:
160 +# Create a shell wrapper script named wrapper in installpath
161 +# (defaults to the bindir) to execute target (default of wrapper) by
162 +# first optionally setting LD_LIBRARY_PATH to the colon-delimited
163 +# libpaths followed by optionally changing directory to chdir.
164 +make_wrapper() {
165 + local wrapper=$1 bin=$2 chdir=$3 libdir=$4 path=$5
166 + local tmpwrapper=$(emktemp)
167 + has "${EAPI:-0}" 0 1 2 && local EPREFIX=""
168 +
169 + (
170 + echo '#!/bin/sh'
171 + [[ -n ${chdir} ]] && printf 'cd "%s"\n' "${EPREFIX}${chdir}"
172 + if [[ -n ${libdir} ]] ; then
173 + local var
174 + if [[ ${CHOST} == *-darwin* ]] ; then
175 + var=DYLD_LIBRARY_PATH
176 + else
177 + var=LD_LIBRARY_PATH
178 + fi
179 + cat <<-EOF
180 + if [ "\${${var}+set}" = "set" ] ; then
181 + export ${var}="\${${var}}:${EPREFIX}${libdir}"
182 + else
183 + export ${var}="${EPREFIX}${libdir}"
184 + fi
185 + EOF
186 + fi
187 + # We don't want to quote ${bin} so that people can pass complex
188 + # things as ${bin} ... "./someprog --args"
189 + printf 'exec %s "$@"\n' "${bin/#\//${EPREFIX}/}"
190 + ) > "${tmpwrapper}"
191 + chmod go+rx "${tmpwrapper}"
192 +
193 + if [[ -n ${path} ]] ; then
194 + (
195 + exeinto "${path}"
196 + newexe "${tmpwrapper}" "${wrapper}"
197 + ) || die
198 + else
199 + newbin "${tmpwrapper}" "${wrapper}" || die
200 + fi
201 +}
202 +
203 +# @FUNCTION: path_exists
204 +# @USAGE: [-a|-o] <paths>
205 +# @DESCRIPTION:
206 +# Check if the specified paths exist. Works for all types of paths
207 +# (files/dirs/etc...). The -a and -o flags control the requirements
208 +# of the paths. They correspond to "and" and "or" logic. So the -a
209 +# flag means all the paths must exist while the -o flag means at least
210 +# one of the paths must exist. The default behavior is "and". If no
211 +# paths are specified, then the return value is "false".
212 +path_exists() {
213 + local opt=$1
214 + [[ ${opt} == -[ao] ]] && shift || opt="-a"
215 +
216 + # no paths -> return false
217 + # same behavior as: [[ -e "" ]]
218 + [[ $# -eq 0 ]] && return 1
219 +
220 + local p r=0
221 + for p in "$@" ; do
222 + [[ -e ${p} ]]
223 + : $(( r += $? ))
224 + done
225 +
226 + case ${opt} in
227 + -a) return $(( r != 0 )) ;;
228 + -o) return $(( r == $# )) ;;
229 + esac
230 +}
231 +
232 +# @FUNCTION: use_if_iuse
233 +# @USAGE: <flag>
234 +# @DESCRIPTION:
235 +# Return true if the given flag is in USE and IUSE.
236 +#
237 +# Note that this function should not be used in the global scope.
238 +use_if_iuse() {
239 + in_iuse $1 || return 1
240 + use $1
241 +}
242 +
243 +# @FUNCTION: optfeature
244 +# @USAGE: <short description> <package atom to match> [other atoms]
245 +# @DESCRIPTION:
246 +# Print out a message suggesting an optional package (or packages)
247 +# not currently installed which provides the described functionality.
248 +#
249 +# The following snippet would suggest app-misc/foo for optional foo support,
250 +# app-misc/bar or app-misc/baz[bar] for optional bar support
251 +# and either both app-misc/a and app-misc/b or app-misc/c for alphabet support.
252 +# @CODE
253 +# optfeature "foo support" app-misc/foo
254 +# optfeature "bar support" app-misc/bar app-misc/baz[bar]
255 +# optfeature "alphabet support" "app-misc/a app-misc/b" app-misc/c
256 +# @CODE
257 +optfeature() {
258 + debug-print-function ${FUNCNAME} "$@"
259 + local i j msg
260 + local desc=$1
261 + local flag=0
262 + shift
263 + for i; do
264 + for j in ${i}; do
265 + if has_version "${j}"; then
266 + flag=1
267 + else
268 + flag=0
269 + break
270 + fi
271 + done
272 + if [[ ${flag} -eq 1 ]]; then
273 + break
274 + fi
275 + done
276 + if [[ ${flag} -eq 0 ]]; then
277 + for i; do
278 + msg=" "
279 + for j in ${i}; do
280 + msg+=" ${j} and"
281 + done
282 + msg="${msg:0: -4} for ${desc}"
283 + elog "${msg}"
284 + done
285 + fi
286 +}
287 +
288 +fi
289 diff --git a/eclass/eutils.eclass b/eclass/eutils.eclass
290 index 7840afbb77b..9b3c20db3b9 100644
291 --- a/eclass/eutils.eclass
292 +++ b/eclass/eutils.eclass
293 @@ -20,250 +20,23 @@ _EUTILS_ECLASS=1
294 # implicitly inherited (now split) eclasses
295 case ${EAPI:-0} in
296 0|1|2|3|4|5|6)
297 - inherit desktop epatch estack ltprune multilib preserve-libs \
298 + inherit desktop epatch estack eutils-r1 ltprune multilib preserve-libs \
299 toolchain-funcs vcs-clean
300 ;;
301 esac
302
303 -# @FUNCTION: eqawarn
304 -# @USAGE: [message]
305 -# @DESCRIPTION:
306 -# Proxy to ewarn for package managers that don't provide eqawarn and use the PM
307 -# implementation if available. Reuses PORTAGE_ELOG_CLASSES as set by the dev
308 -# profile.
309 -if ! declare -F eqawarn >/dev/null ; then
310 - eqawarn() {
311 - has qa ${PORTAGE_ELOG_CLASSES} && ewarn "$@"
312 - :
313 - }
314 -fi
315 -
316 -# @FUNCTION: emktemp
317 -# @USAGE: [temp dir]
318 -# @DESCRIPTION:
319 -# Cheap replacement for when debianutils (and thus mktemp)
320 -# does not exist on the users system.
321 -emktemp() {
322 - local exe="touch"
323 - [[ $1 == -d ]] && exe="mkdir" && shift
324 - local topdir=$1
325 -
326 - if [[ -z ${topdir} ]] ; then
327 - [[ -z ${T} ]] \
328 - && topdir="/tmp" \
329 - || topdir=${T}
330 - fi
331 -
332 - if ! type -P mktemp > /dev/null ; then
333 - # system lacks `mktemp` so we have to fake it
334 - local tmp=/
335 - while [[ -e ${tmp} ]] ; do
336 - tmp=${topdir}/tmp.${RANDOM}.${RANDOM}.${RANDOM}
337 - done
338 - ${exe} "${tmp}" || ${exe} -p "${tmp}"
339 - echo "${tmp}"
340 - else
341 - # the args here will give slightly wierd names on BSD,
342 - # but should produce a usable file on all userlands
343 - if [[ ${exe} == "touch" ]] ; then
344 - TMPDIR="${topdir}" mktemp -t tmp.XXXXXXXXXX
345 - else
346 - TMPDIR="${topdir}" mktemp -dt tmp.XXXXXXXXXX
347 - fi
348 - fi
349 -}
350 -
351 -# @FUNCTION: edos2unix
352 -# @USAGE: <file> [more files ...]
353 -# @DESCRIPTION:
354 -# A handy replacement for dos2unix, recode, fixdos, etc... This allows you
355 -# to remove all of these text utilities from DEPEND variables because this
356 -# is a script based solution. Just give it a list of files to convert and
357 -# they will all be changed from the DOS CRLF format to the UNIX LF format.
358 -edos2unix() {
359 - [[ $# -eq 0 ]] && return 0
360 - sed -i 's/\r$//' -- "$@" || die
361 -}
362 -
363 -# @FUNCTION: strip-linguas
364 -# @USAGE: [<allow LINGUAS>|<-i|-u> <directories of .po files>]
365 -# @DESCRIPTION:
366 -# Make sure that LINGUAS only contains languages that
367 -# a package can support. The first form allows you to
368 -# specify a list of LINGUAS. The -i builds a list of po
369 -# files found in all the directories and uses the
370 -# intersection of the lists. The -u builds a list of po
371 -# files found in all the directories and uses the union
372 -# of the lists.
373 -strip-linguas() {
374 - local ls newls nols
375 - if [[ $1 == "-i" ]] || [[ $1 == "-u" ]] ; then
376 - local op=$1; shift
377 - ls=$(find "$1" -name '*.po' -exec basename {} .po ';'); shift
378 - local d f
379 - for d in "$@" ; do
380 - if [[ ${op} == "-u" ]] ; then
381 - newls=${ls}
382 - else
383 - newls=""
384 - fi
385 - for f in $(find "$d" -name '*.po' -exec basename {} .po ';') ; do
386 - if [[ ${op} == "-i" ]] ; then
387 - has ${f} ${ls} && newls="${newls} ${f}"
388 - else
389 - has ${f} ${ls} || newls="${newls} ${f}"
390 - fi
391 - done
392 - ls=${newls}
393 - done
394 - else
395 - ls="$@"
396 - fi
397 -
398 - nols=""
399 - newls=""
400 - for f in ${LINGUAS} ; do
401 - if has ${f} ${ls} ; then
402 - newls="${newls} ${f}"
403 - else
404 - nols="${nols} ${f}"
405 - fi
406 - done
407 - [[ -n ${nols} ]] \
408 - && einfo "Sorry, but ${PN} does not support the LINGUAS:" ${nols}
409 - export LINGUAS=${newls:1}
410 -}
411 -
412 -# @FUNCTION: make_wrapper
413 -# @USAGE: <wrapper> <target> [chdir] [libpaths] [installpath]
414 -# @DESCRIPTION:
415 -# Create a shell wrapper script named wrapper in installpath
416 -# (defaults to the bindir) to execute target (default of wrapper) by
417 -# first optionally setting LD_LIBRARY_PATH to the colon-delimited
418 -# libpaths followed by optionally changing directory to chdir.
419 -make_wrapper() {
420 - local wrapper=$1 bin=$2 chdir=$3 libdir=$4 path=$5
421 - local tmpwrapper=$(emktemp)
422 - has "${EAPI:-0}" 0 1 2 && local EPREFIX=""
423 -
424 - (
425 - echo '#!/bin/sh'
426 - [[ -n ${chdir} ]] && printf 'cd "%s"\n' "${EPREFIX}${chdir}"
427 - if [[ -n ${libdir} ]] ; then
428 - local var
429 - if [[ ${CHOST} == *-darwin* ]] ; then
430 - var=DYLD_LIBRARY_PATH
431 - else
432 - var=LD_LIBRARY_PATH
433 - fi
434 - cat <<-EOF
435 - if [ "\${${var}+set}" = "set" ] ; then
436 - export ${var}="\${${var}}:${EPREFIX}${libdir}"
437 - else
438 - export ${var}="${EPREFIX}${libdir}"
439 - fi
440 - EOF
441 - fi
442 - # We don't want to quote ${bin} so that people can pass complex
443 - # things as ${bin} ... "./someprog --args"
444 - printf 'exec %s "$@"\n' "${bin/#\//${EPREFIX}/}"
445 - ) > "${tmpwrapper}"
446 - chmod go+rx "${tmpwrapper}"
447 -
448 - if [[ -n ${path} ]] ; then
449 - (
450 - exeinto "${path}"
451 - newexe "${tmpwrapper}" "${wrapper}"
452 - ) || die
453 - else
454 - newbin "${tmpwrapper}" "${wrapper}" || die
455 - fi
456 -}
457 -
458 -# @FUNCTION: path_exists
459 -# @USAGE: [-a|-o] <paths>
460 -# @DESCRIPTION:
461 -# Check if the specified paths exist. Works for all types of paths
462 -# (files/dirs/etc...). The -a and -o flags control the requirements
463 -# of the paths. They correspond to "and" and "or" logic. So the -a
464 -# flag means all the paths must exist while the -o flag means at least
465 -# one of the paths must exist. The default behavior is "and". If no
466 -# paths are specified, then the return value is "false".
467 -path_exists() {
468 - local opt=$1
469 - [[ ${opt} == -[ao] ]] && shift || opt="-a"
470 -
471 - # no paths -> return false
472 - # same behavior as: [[ -e "" ]]
473 - [[ $# -eq 0 ]] && return 1
474 -
475 - local p r=0
476 - for p in "$@" ; do
477 - [[ -e ${p} ]]
478 - : $(( r += $? ))
479 - done
480 -
481 - case ${opt} in
482 - -a) return $(( r != 0 )) ;;
483 - -o) return $(( r == $# )) ;;
484 - esac
485 -}
486 -
487 -# @FUNCTION: use_if_iuse
488 -# @USAGE: <flag>
489 -# @DESCRIPTION:
490 -# Return true if the given flag is in USE and IUSE.
491 -#
492 -# Note that this function should not be used in the global scope.
493 -use_if_iuse() {
494 - in_iuse $1 || return 1
495 - use $1
496 -}
497 -
498 -# @FUNCTION: optfeature
499 -# @USAGE: <short description> <package atom to match> [other atoms]
500 -# @DESCRIPTION:
501 -# Print out a message suggesting an optional package (or packages)
502 -# not currently installed which provides the described functionality.
503 -#
504 -# The following snippet would suggest app-misc/foo for optional foo support,
505 -# app-misc/bar or app-misc/baz[bar] for optional bar support
506 -# and either both app-misc/a and app-misc/b or app-misc/c for alphabet support.
507 -# @CODE
508 -# optfeature "foo support" app-misc/foo
509 -# optfeature "bar support" app-misc/bar app-misc/baz[bar]
510 -# optfeature "alphabet support" "app-misc/a app-misc/b" app-misc/c
511 -# @CODE
512 -optfeature() {
513 - debug-print-function ${FUNCNAME} "$@"
514 - local i j msg
515 - local desc=$1
516 - local flag=0
517 - shift
518 - for i; do
519 - for j in ${i}; do
520 - if has_version "${j}"; then
521 - flag=1
522 - else
523 - flag=0
524 - break
525 - fi
526 - done
527 - if [[ ${flag} -eq 1 ]]; then
528 - break
529 - fi
530 - done
531 - if [[ ${flag} -eq 0 ]]; then
532 - for i; do
533 - msg=" "
534 - for j in ${i}; do
535 - msg+=" ${j} and"
536 - done
537 - msg="${msg:0: -4} for ${desc}"
538 - elog "${msg}"
539 - done
540 - fi
541 -}
542 +# warn users to migrate away from eutils to direct use of inherited eclasses
543 +# in EAPI 6
544 +case ${EAPI:-0} in
545 +6)
546 + eqawarn "QA warning: eutils should not be used in EAPI=6. Instead, directly"
547 + eqawarn "inherit the eclasses you need."
548 + eqawarn "Should you require the functions emktemp, edos2unix, strip-linguas,"
549 + eqawarn "make_wrapper, path_exists, use_if_iuse, or optfeature please use"
550 + eqawarn "eutils-r1."
551 + ;;
552 +0|1|2|3|4|5) ;;
553 +esac
554
555 case ${EAPI:-0} in
556 0|1|2)
557 --
558 2.17.0

Replies