1 |
On Sat, 2022-12-03 at 09:19 +0100, Ulrich Mueller wrote: |
2 |
> > > > > > On Sat, 03 Dec 2022, Michał Górny wrote: |
3 |
> |
4 |
> > --- /dev/null |
5 |
> > +++ b/eclass/app-alternatives.eclass |
6 |
> > @@ -0,0 +1,84 @@ |
7 |
> > +# Copyright 2022 Gentoo Authors |
8 |
> > +# Distributed under the terms of the GNU General Public License v2 |
9 |
> > + |
10 |
> > +# @ECLASS: app-alternatives.eclass |
11 |
> > +# @MAINTAINER: |
12 |
> > +# Michał Górny <mgorny@g.o> |
13 |
> > +# @AUTHOR: |
14 |
> > +# Michał Górny <mgorny@g.o> |
15 |
> > +# @SUPPORTED_EAPIS: 8 |
16 |
> > +# @BLURB: Common logic for app-alternatives/* |
17 |
> > +# @DESCRIPTION: |
18 |
> > +# This eclass provides common logic shared by app-alternatives/* |
19 |
> > +# ebuilds. A global ALTERNATIVES variable needs to be declared |
20 |
> > +# that lists available options and their respective dependencies. |
21 |
> > +# HOMEPAGE, S, LICENSE, SLOT, IUSE, REQUIRED_USE and RDEPEND are |
22 |
> > set. |
23 |
> > +# A get_alternative() function is provided that prints the |
24 |
> > determines |
25 |
> |
26 |
> Grammar? |
27 |
|
28 |
Nope, ^w error. |
29 |
|
30 |
> |
31 |
> > +# the selected alternative and prints its respective flag name. |
32 |
> > + |
33 |
> > +case ${EAPI} in |
34 |
> > + 8) ;; |
35 |
> > + *) die "${ECLASS}: EAPI ${EAPI} unsupported." |
36 |
> |
37 |
> ${EAPI:-0} here? |
38 |
|
39 |
Sure. |
40 |
|
41 |
> |
42 |
> > +esac |
43 |
> > + |
44 |
> > +if [[ ! ${_APP_ALTERNATIVES_ECLASS} ]]; then |
45 |
> > +_APP_ALTERNATIVES_ECLASS=1 |
46 |
> > + |
47 |
> > +# @ECLASS_VARIABLE: ALTERNATIVES |
48 |
> > +# @PRE_INHERIT |
49 |
> > +# @REQUIRED |
50 |
> > +# @DESCRIPTION: |
51 |
> > +# Array of "flag:dependency" pairs specifying the available |
52 |
> > +# alternatives. The default provider must be listed first. |
53 |
> > + |
54 |
> > +# @FUNCTION: _app-alternatives_set_globals |
55 |
> > +# @INTERNAL |
56 |
> > +# @DESCRIPTION: |
57 |
> > +# Set ebuild metadata variables. |
58 |
> > +_app-alternatives_set_globals() { |
59 |
> > + debug-print-function ${FUNCNAME} "${@}" |
60 |
> > + |
61 |
> > + if [[ $(declare -p ALTERNATIVES) != "declare -a"* ]]; then |
62 |
> |
63 |
> The more modern (and presumably, more reliable) check would be: |
64 |
> |
65 |
> if [[ ${ALTERNATIVES@a} != *a* ]]; then |
66 |
> |
67 |
> Since the eclass supports EAPI 8 only, bash-5.0 is guaranteed, so the |
68 |
> feature will be available. |
69 |
|
70 |
Ok. |
71 |
|
72 |
> |
73 |
> > + die 'ALTERNATIVES must be an array.' |
74 |
> > + elif [[ ${#ALTERNATIVES[@]} -eq 0 ]]; then |
75 |
> > + die 'ALTERNATIVES must not be empty.' |
76 |
> > + fi |
77 |
> > + |
78 |
> > + HOMEPAGE=" |
79 |
> > https://wiki.gentoo.org/wiki/Project:Base/Alternatives" |
80 |
> > + S=${WORKDIR} |
81 |
> > + |
82 |
> > + LICENSE="CC0-1.0" |
83 |
> > + SLOT="0" |
84 |
> > + |
85 |
> > + # yep, that's a cheap hack adding '+' to the first flag |
86 |
> > + IUSE="+${ALTERNATIVES[*]%%:*}" |
87 |
> > + REQUIRED_USE="^^ ( ${ALTERNATIVES[*]%%:*} )" |
88 |
> > + RDEPEND="" |
89 |
> > + |
90 |
> > + local flag dep |
91 |
> > + for flag in "${ALTERNATIVES[@]}"; do |
92 |
> > + [[ ${flag} != *:* ]] && die "Invalid ALTERNATIVES |
93 |
> > item: ${flag}" |
94 |
> > + dep=${flag#*:} |
95 |
> > + flag=${flag%%:*} |
96 |
> > + RDEPEND+=" |
97 |
> > + ${flag}? ( ${dep} ) |
98 |
> > + " |
99 |
> |
100 |
> Why two newlines? A single space should be enough. |
101 |
|
102 |
What's the difference? It will be normalized by the PM anyway. |
103 |
|
104 |
> |
105 |
> > + done |
106 |
> > +} |
107 |
> > +_app-alternatives_set_globals |
108 |
> > + |
109 |
> > +# @FUNCTION: get_alternative |
110 |
> > +# @DESCRIPTION: |
111 |
> > +# Get the flag name for the selected alterantive (i.e. the USE flag |
112 |
> > set). |
113 |
> |
114 |
> Typo. |
115 |
|
116 |
Sam already spotted this one. |
117 |
|
118 |
-- |
119 |
Best regards, |
120 |
Michał Górny |