1 |
Before this change, optfeature() would print a list of optional dependencies, |
2 |
or nothing if deps are installed. Ebuilds commonly print their own elog |
3 |
ahead of optfeature, which then may not be followed up by any list at all. |
4 |
|
5 |
This change adds a default header text, which may be changed by the ebuild, |
6 |
that is only printed if optfeature is about to list at least one dependency. |
7 |
|
8 |
v2: Introduce optfeature_header() function |
9 |
Set a custom header for follow-up optfeature calls, or reset to default |
10 |
header by calling it without argument. This can not only be used to customize |
11 |
the header but also to distinguish optfeature "groups", e.g. to list a number |
12 |
of different possible database backends, and then a number of optional |
13 |
regular runtime features. |
14 |
|
15 |
Signed-off-by: Andreas Sturmlechner <asturm@g.o> |
16 |
|
17 |
--- a/eclass/optfeature.eclass |
18 |
+++ b/eclass/optfeature.eclass |
19 |
@@ -1,4 +1,4 @@ |
20 |
-# Copyright 1999-2020 Gentoo Authors |
21 |
+# Copyright 1999-2021 Gentoo Authors |
22 |
# Distributed under the terms of the GNU General Public License v2 |
23 |
|
24 |
# @ECLASS: optfeature.eclass |
25 |
@@ -14,6 +14,56 @@ esac |
26 |
if [[ -z ${_OPTFEATURE_ECLASS} ]]; then |
27 |
_OPTFEATURE_ECLASS=1 |
28 |
|
29 |
+# @ECLASS-VARIABLE: _OPTFEATURE_DEFAULT_HEADER |
30 |
+# @INTERNAL |
31 |
+# @DESCRIPTION: |
32 |
+# Default header printed ahead of optfeature output. Can be overridden |
33 |
+# by calling optfeature_header function. Will not be displayed if all optional |
34 |
+# dependencies are present. |
35 |
+_OPTFEATURE_DEFAULT_HEADER="Install additional packages for optional runtime features:" |
36 |
+ |
37 |
+readonly _OPTFEATURE_DEFAULT_HEADER |
38 |
+ |
39 |
+# @ECLASS-VARIABLE: _OPTFEATURE_HEADER |
40 |
+# @INTERNAL |
41 |
+# @DESCRIPTION: |
42 |
+# Default empty. Custom header printed ahead of optfeature output. |
43 |
+# Set by calling optfeature_header function with the desired output, or reset |
44 |
+# by optfeature_header without argument. Will not be displayed if all optional |
45 |
+# dependencies are present. |
46 |
+_OPTFEATURE_HEADER= |
47 |
+ |
48 |
+# @ECLASS-VARIABLE: _OPTFEATURE_DOHEADER |
49 |
+# @INTERNAL |
50 |
+# @DESCRIPTION: |
51 |
+# If true, print header ahead of the first optfeature output. |
52 |
+_OPTFEATURE_DOHEADER=true |
53 |
+ |
54 |
+# @FUNCTION: optfeature_header |
55 |
+# @USAGE: [custom header for follow-up optfeature calls] |
56 |
+# @DESCRIPTION: |
57 |
+# Set a custom header for follow-up optfeature calls, or reset to default |
58 |
+# header by calling it without argument. This can not only be used to customize |
59 |
+# the header but also to distinguish optfeature "groups", e.g. to list a number |
60 |
+# of different possible database backends, and then a number of optional |
61 |
+# regular runtime features. |
62 |
+# |
63 |
+# The following snippet will leave the default header untouched for the first |
64 |
+# two optfeature calls. Then a custom header is set that is going to be |
65 |
+# displayed in case dev-db/a or dev-db/b are not installed. |
66 |
+# @CODE |
67 |
+# optfeature "foo support" app-misc/foo |
68 |
+# optfeature "bar support" app-misc/bar |
69 |
+# optfeature_header "Install optional database backends:" |
70 |
+# optfeature "a DB backend" dev-db/a |
71 |
+# optfeature "b DB backend" dev-db/b |
72 |
+# @CODE |
73 |
+optfeature_header() { |
74 |
+ debug-print-function ${FUNCNAME} "$@" |
75 |
+ _OPTFEATURE_HEADER="${1}" |
76 |
+ _OPTFEATURE_DOHEADER=true |
77 |
+} |
78 |
+ |
79 |
# @FUNCTION: optfeature |
80 |
# @USAGE: <short description> <package atom to match> [other atoms] |
81 |
# @DESCRIPTION: |
82 |
@@ -51,6 +101,10 @@ optfeature() { |
83 |
fi |
84 |
done |
85 |
if [[ ${flag} -eq 0 ]]; then |
86 |
+ if [[ ${_OPTFEATURE_DOHEADER} == true ]]; then |
87 |
+ elog ${_OPTFEATURE_HEADER:-${_OPTFEATURE_DEFAULT_HEADER}} |
88 |
+ _OPTFEATURE_DOHEADER=false |
89 |
+ fi |
90 |
for i; do |
91 |
read -r -d '' -a arr <<<"${i}" |
92 |
msg=" " |