Gentoo Archives: gentoo-dev

From: David Seifert <soap@g.o>
To: gentoo-dev@l.g.o
Cc: David Seifert <soap@g.o>
Subject: [gentoo-dev] [PATCH 1/2] optfeature.eclass: New eclass with definition from eutils
Date: Sun, 06 Sep 2020 15:48:08
Message-Id: 20200906154731.162917-1-soap@gentoo.org
1 Signed-off-by: David Seifert <soap@g.o>
2 ---
3 eclass/optfeature.eclass | 63 ++++++++++++++++++++++++++++++++++++++++
4 1 file changed, 63 insertions(+)
5 create mode 100644 eclass/optfeature.eclass
6
7 diff --git a/eclass/optfeature.eclass b/eclass/optfeature.eclass
8 new file mode 100644
9 index 00000000000..b0082606cd6
10 --- /dev/null
11 +++ b/eclass/optfeature.eclass
12 @@ -0,0 +1,63 @@
13 +# Copyright 1999-2020 Gentoo Authors
14 +# Distributed under the terms of the GNU General Public License v2
15 +
16 +# @ECLASS: optfeature.eclass
17 +# @MAINTAINER:
18 +# base-system@g.o
19 +# @BLURB: Advertise optional functionality that might be useful to users
20 +
21 +case "${EAPI:-0}" in
22 + [0-7]) ;;
23 + *) die "Unsupported EAPI=${EAPI} (unknown) for ${ECLASS}" ;;
24 +esac
25 +
26 +if [[ -z ${_OPTFEATURE_ECLASS} ]]; then
27 +_OPTFEATURE_ECLASS=1
28 +
29 +# @FUNCTION: optfeature
30 +# @USAGE: <short description> <package atom to match> [other atoms]
31 +# @DESCRIPTION:
32 +# Print out a message suggesting an optional package (or packages)
33 +# not currently installed which provides the described functionality.
34 +#
35 +# The following snippet would suggest app-misc/foo for optional foo support,
36 +# app-misc/bar or app-misc/baz[bar] for optional bar support
37 +# and either both app-misc/a and app-misc/b or app-misc/c for alphabet support.
38 +# @CODE
39 +# optfeature "foo support" app-misc/foo
40 +# optfeature "bar support" app-misc/bar app-misc/baz[bar]
41 +# optfeature "alphabet support" "app-misc/a app-misc/b" app-misc/c
42 +# @CODE
43 +optfeature() {
44 + debug-print-function ${FUNCNAME} "$@"
45 +
46 + local i j msg
47 + local desc=$1
48 + local flag=0
49 + shift
50 + for i; do
51 + for j in ${i}; do
52 + if has_version "${j}"; then
53 + flag=1
54 + else
55 + flag=0
56 + break
57 + fi
58 + done
59 + if [[ ${flag} -eq 1 ]]; then
60 + break
61 + fi
62 + done
63 + if [[ ${flag} -eq 0 ]]; then
64 + for i; do
65 + msg=" "
66 + for j in ${i}; do
67 + msg+=" ${j} and"
68 + done
69 + msg="${msg:0: -4} for ${desc}"
70 + elog "${msg}"
71 + done
72 + fi
73 +}
74 +
75 +fi
76 --
77 2.28.0

Replies