Gentoo Archives: gentoo-dev

From: "Michał Górny" <mgorny@g.o>
To: gentoo-dev@l.g.o
Subject: Re: [gentoo-dev] [PATCH] bash-completion-r1.eclass: Add EAPI 8 support
Date: Fri, 16 Jul 2021 15:07:01
Message-Id: 2201185d90e18029567097165139f4628938830c.camel@gentoo.org
In Reply to: Re: [gentoo-dev] [PATCH] bash-completion-r1.eclass: Add EAPI 8 support by David Seifert
1 On Fri, 2021-07-16 at 16:21 +0200, David Seifert wrote:
2 > On Fri, 2021-07-16 at 15:08 +0200, Michał Górny wrote:
3 > > Signed-off-by: Michał Górny <mgorny@g.o>
4 > > ---
5 > >  eclass/bash-completion-r1.eclass | 13 +++++++++----
6 > >  1 file changed, 9 insertions(+), 4 deletions(-)
7 > >
8 > > diff --git a/eclass/bash-completion-r1.eclass b/eclass/bash-
9 > > completion-r1.eclass
10 > > index 80f2d5fcd32a..58c1debf334e 100644
11 > > --- a/eclass/bash-completion-r1.eclass
12 > > +++ b/eclass/bash-completion-r1.eclass
13 > > @@ -1,138 +1,143 @@
14 > >  # Copyright 1999-2021 Gentoo Authors
15 > >  # Distributed under the terms of the GNU General Public License v2
16 > >  
17 > >  # @ECLASS: bash-completion-r1.eclass
18 > >  # @MAINTAINER:
19 > >  # mgorny@g.o
20 > > -# @SUPPORTED_EAPIS: 0 1 2 3 4 5 6 7
21 > > +# @SUPPORTED_EAPIS: 0 1 2 3 4 5 6 7 8
22 > >  # @BLURB: A few quick functions to install bash-completion files
23 > >  # @EXAMPLE:
24 > >  #
25 > >  # @CODE
26 > > -# EAPI=5
27 > > +# EAPI=8
28 > >  #
29 > >  # src_configure() {
30 > >  #      econf \
31 > >  #              --with-bash-completion-dir="$(get_bashcompdir)"
32 > >  # }
33 > >  #
34 > >  # src_install() {
35 > >  #      default
36 > >  #
37 > >  #      newbashcomp contrib/${PN}.bash-completion ${PN}
38 > >  # }
39 > >  # @CODE
40 > >  
41 > > +if [[ ! ${_BASH_COMPLETION_R1} ]]; then
42 > > +
43 >
44 > _BASH_COMPLETION_R1_ECLASS is the common style.
45 >
46 > >  inherit toolchain-funcs
47 > >  
48 > >  case ${EAPI:-0} in
49 > > -       0|1|2|3|4|5|6|7) ;;
50 > > -       *) die "EAPI ${EAPI} unsupported (yet)."
51 > > +       [5-8]) ;;
52 > > +       *) die "EAPI ${EAPI} unsupported."
53 > >  esac
54 > >
55 >
56 > I think we've settled on the "5|6|7|8" style over the single-char glob
57 > range.
58
59 We need a skel.eclass.
60
61 >
62 > >  # @FUNCTION: _bash-completion-r1_get_bashdir
63 > >  # @INTERNAL
64 > >  # @DESCRIPTION:
65 > >  # First argument is name of the string in bash-completion.pc
66 > >  # Second argument is the fallback directory if the string is not
67 > > found
68 > >  # @EXAMPLE:
69 > >  # _bash-completion-r1_get_bashdir completionsdir /usr/share/bash-
70 > > completion
71 > >  _bash-completion-r1_get_bashdir() {
72 > >         debug-print-function ${FUNCNAME} "${@}"
73 > >  
74 > >         if $(tc-getPKG_CONFIG) --exists bash-completion &>/dev/null;
75 > > then
76 > >                 local path
77 > >                 path=$($(tc-getPKG_CONFIG) --variable="${1}" bash-
78 > > completion) || die
79 > >                 # we need to return unprefixed, so strip from what
80 > > pkg-config returns
81 > >                 # to us, bug #477692
82 > >                 echo "${path#${EPREFIX}}"
83 > >         else
84 > >                 echo "${2}"
85 > >         fi
86 > >  }
87 > >  
88 > >  # @FUNCTION: _bash-completion-r1_get_bashcompdir
89 > >  # @INTERNAL
90 > >  # @DESCRIPTION:
91 > >  # Get unprefixed bash-completion completions directory.
92 > >  _bash-completion-r1_get_bashcompdir() {
93 > >         debug-print-function ${FUNCNAME} "${@}"
94 > >  
95 > >         _bash-completion-r1_get_bashdir completionsdir
96 > > /usr/share/bash-completion/completions
97 > >  }
98 > >  
99 > >  # @FUNCTION: _bash-completion-r1_get_helpersdir
100 > >  # @INTERNAL
101 > >  # @DESCRIPTION:
102 > >  # Get unprefixed bash-completion helpers directory.
103 > >  _bash-completion-r1_get_bashhelpersdir() {
104 > >         debug-print-function ${FUNCNAME} "${@}"
105 > >  
106 > >         _bash-completion-r1_get_bashdir helpersdir /usr/share/bash-
107 > > completion/helpers
108 > >  }
109 > >  
110 > >  # @FUNCTION: get_bashcompdir
111 > >  # @DESCRIPTION:
112 > >  # Get the bash-completion completions directory.
113 > >  get_bashcompdir() {
114 > >         debug-print-function ${FUNCNAME} "${@}"
115 > >  
116 > >         echo "${EPREFIX}$(_bash-completion-r1_get_bashcompdir)"
117 > >  }
118 > >  
119 > >  # @FUNCTION: get_bashhelpersdir
120 > >  # @INTERNAL
121 > >  # @DESCRIPTION:
122 > >  # Get the bash-completion helpers directory.
123 > >  get_bashhelpersdir() {
124 > >         debug-print-function ${FUNCNAME} "${@}"
125 > >  
126 > >         echo "${EPREFIX}$(_bash-completion-r1_get_bashhelpersdir)"
127 > >  }
128 > >  
129 > >  # @FUNCTION: dobashcomp
130 > >  # @USAGE: <file> [...]
131 > >  # @DESCRIPTION:
132 > >  # Install bash-completion files passed as args. Has EAPI-dependent
133 > > failure
134 > >  # behavior (like doins).
135 > >  dobashcomp() {
136 > >         debug-print-function ${FUNCNAME} "${@}"
137 > >  
138 > >         (
139 > >                 insopts -m 0644
140 > >                 insinto "$(_bash-completion-r1_get_bashcompdir)"
141 > >                 doins "${@}"
142 > >         )
143 > >  }
144 > >  
145 > >  # @FUNCTION: newbashcomp
146 > >  # @USAGE: <file> <newname>
147 > >  # @DESCRIPTION:
148 > >  # Install bash-completion file under a new name. Has EAPI-dependent
149 > > failure
150 > >  # behavior (like newins).
151 > >  newbashcomp() {
152 > >         debug-print-function ${FUNCNAME} "${@}"
153 > >  
154 > >         (
155 > >                 insopts -m 0644
156 > >                 insinto "$(_bash-completion-r1_get_bashcompdir)"
157 > >                 newins "${@}"
158 > >         )
159 > >  }
160 > >  
161 > >  # @FUNCTION: bashcomp_alias
162 > >  # @USAGE: <basename> <alias>...
163 > >  # @DESCRIPTION:
164 > >  # Alias <basename> completion to one or more commands (<alias>es).
165 > >  bashcomp_alias() {
166 > >         debug-print-function ${FUNCNAME} "${@}"
167 > >  
168 > >         [[ ${#} -lt 2 ]] && die "Usage: ${FUNCNAME} <basename>
169 > > <alias>..."
170 > >         local base=${1} f
171 > >         shift
172 > >  
173 > >         for f; do
174 > >                 dosym "${base}" "$(_bash-completion-
175 > > r1_get_bashcompdir)/${f}" \
176 > >                         || return
177 > >         done
178 > >  }
179 > > +
180 > > +_BASH_COMPLETION_R1=1
181 > > +fi
182 >
183 >
184 >
185
186 --
187 Best regards,
188 Michał Górny