Gentoo Archives: gentoo-dev

From: Anna Vyalkova <cyber+gentoo@×××××.in>
To: gentoo-dev@l.g.o
Cc: vim@g.o
Subject: [gentoo-dev] [PATCH v5 4/9] vim-plugin.eclass: EAPI 8: add src_prepare
Date: Mon, 11 Apr 2022 12:34:47
Message-Id: 20220411123306.24750-5-cyber+gentoo@sysrq.in
In Reply to: [gentoo-dev] [PATCH v5 0/9] Vim eclasses by Anna Vyalkova
1 Signed-off-by: Anna Vyalkova <cyber+gentoo@×××××.in>
2 ---
3 eclass/vim-plugin.eclass | 39 ++++++++++++++++++++++++++++++++++++---
4 1 file changed, 36 insertions(+), 3 deletions(-)
5
6 diff --git a/eclass/vim-plugin.eclass b/eclass/vim-plugin.eclass
7 index 0c323e0d09..a7b5f258b0 100644
8 --- a/eclass/vim-plugin.eclass
9 +++ b/eclass/vim-plugin.eclass
10 @@ -1,192 +1,225 @@
11 # Copyright 1999-2022 Gentoo Authors
12 # Distributed under the terms of the GNU General Public License v2
13
14 # @ECLASS: vim-plugin.eclass
15 # @MAINTAINER:
16 # vim@g.o
17 # @SUPPORTED_EAPIS: 6 7 8
18 # @BLURB: used for installing vim plugins
19 # @DESCRIPTION:
20 # This eclass simplifies installation of app-vim plugins into
21 # /usr/share/vim/vimfiles. This is a version-independent directory
22 # which is read automatically by vim. The only exception is
23 # documentation, for which we make a special case via vim-doc.eclass.
24
25 case ${EAPI} in
26 - 6|7|8) ;;
27 + 6|7) ;;
28 + 8) _DEFINE_VIM_PLUGIN_SRC_PREPARE=true ;;
29 *) die "${ECLASS}: EAPI ${EAPI:-0} not supported" ;;
30 esac
31
32 if [[ ! ${_VIM_PLUGIN_ECLASS} ]]; then
33
34 inherit vim-doc
35
36 +fi
37 +
38 +EXPORT_FUNCTIONS src_install pkg_postinst pkg_postrm
39 +
40 +# src_prepare is only exported in EAPI >= 8
41 +case ${EAPI:-0} in
42 + 6|7) ;;
43 + 8) EXPORT_FUNCTIONS src_prepare ;;
44 +esac
45 +
46 +if [[ ! ${_VIM_PLUGIN_ECLASS} ]]; then
47 VIM_PLUGIN_VIM_VERSION="${VIM_PLUGIN_VIM_VERSION:-7.3}"
48
49 DEPEND="|| ( >=app-editors/vim-${VIM_PLUGIN_VIM_VERSION}
50 >=app-editors/gvim-${VIM_PLUGIN_VIM_VERSION} )"
51 RDEPEND="${DEPEND}"
52 if [[ ${PV} != 9999* ]] ; then
53 SRC_URI="mirror://gentoo/${P}.tar.bz2
54 https://dev.gentoo.org/~radhermit/vim/${P}.tar.bz2"
55 fi
56 SLOT="0"
57
58 +if ${_DEFINE_VIM_PLUGIN_SRC_PREPARE}; then
59 +# @FUNCTION: vim-plugin_src_prepare
60 +# @USAGE:
61 +# @DESCRIPTION:
62 +# Moves "after/syntax" plugins to directories to avoid file collisions with
63 +# other packages.
64 +# Note that this function is only defined and exported in EAPIs >= 8.
65 +vim-plugin_src_prepare() {
66 + default_src_prepare
67 +
68 + # return if there's nothing to do
69 + [[ -d after/syntax ]] || return
70 +
71 + pushd after/syntax >/dev/null || die
72 + for file in *.vim; do
73 + [[ -f "${file}" ]] || continue
74 + mkdir "${file%.vim}" || die
75 + mv "${file}" "${file%.vim}/${PN}.vim" || die
76 + done
77 + popd >/dev/null || die
78 +}
79 +fi
80 +
81 # @ECLASS_VARIABLE: _VIM_PLUGIN_ALLOWED_DIRS
82 # @INTERNAL
83 # @DESCRIPTION:
84 # Vanilla Vim dirs.
85 # See /usr/share/vim/vim* for reference.
86 _VIM_PLUGIN_ALLOWED_DIRS=(
87 after autoload colors compiler doc ftdetect ftplugin indent keymap
88 macros plugin spell syntax
89 )
90
91 # @FUNCTION: vim-plugin_src_install
92 # @USAGE: [<dir>...]
93 # @DESCRIPTION:
94 # Overrides the default src_install phase. In order, this function:
95 # * installs help and documentation files.
96 # * installs all files recognized by default Vim installation and directories
97 # passed to this function as arguments in "${ED}"/usr/share/vim/vimfiles.
98 #
99 # Example use:
100 # @CODE
101 # src_install() {
102 # vim-plugin_src_install syntax_checkers
103 # }
104 # @CODE
105 vim-plugin_src_install() {
106 # Install non-vim-help-docs
107 einstalldocs
108
109 # Install remainder of plugin
110 insinto /usr/share/vim/vimfiles/
111 local d
112 case ${EAPI:-0} in
113 6|7)
114 for d in *; do
115 [[ -d "${d}" ]] || continue
116 doins -r "${d}"
117 done ;;
118 *)
119 for d in "${_VIM_PLUGIN_ALLOWED_DIRS[@]}" "${@}"; do
120 [[ -d "${d}" ]] || continue
121 doins -r "${d}"
122 done ;;
123 esac
124 }
125
126 # @FUNCTION: vim-plugin_pkg_postinst
127 # @USAGE:
128 # @DESCRIPTION:
129 # Overrides the pkg_postinst phase for this eclass.
130 # The following functions are called:
131 # * update_vim_helptags
132 # * update_vim_afterscripts
133 # * display_vim_plugin_help
134 vim-plugin_pkg_postinst() {
135 update_vim_helptags # from vim-doc
136 update_vim_afterscripts # see below
137 display_vim_plugin_help # see below
138 }
139
140 # @FUNCTION: vim-plugin_pkg_postrm
141 # @DESCRIPTION:
142 # Overrides the pkg_postrm phase for this eclass.
143 # This function calls the update_vim_helptags and update_vim_afterscripts
144 # functions and eventually removes a bunch of empty directories.
145 vim-plugin_pkg_postrm() {
146 update_vim_helptags # from vim-doc
147 update_vim_afterscripts # see below
148
149 # Remove empty dirs; this allows
150 # /usr/share/vim to be removed if vim-core is unmerged
151 find "${EPREFIX}/usr/share/vim/vimfiles" -depth -type d -exec rmdir {} \; 2>/dev/null || \
152 die "rmdir failed"
153 }
154
155 # @FUNCTION: update_vim_afterscripts
156 # @USAGE:
157 # @DESCRIPTION:
158 # Creates scripts in /usr/share/vim/vimfiles/after/*
159 # comprised of the snippets in /usr/share/vim/vimfiles/after/*/*.d
160 update_vim_afterscripts() {
161 local d f afterdir="${EROOT}"/usr/share/vim/vimfiles/after
162
163 # Nothing to do if the dir isn't there
164 [[ -d "${afterdir}" ]] || return 0
165
166 einfo "Updating scripts in ${afterdir}"
167 find "${afterdir}" -type d -name \*.vim.d | while read d; do
168 echo '" Generated by update_vim_afterscripts' > "${d%.d}" || die
169 find "${d}" -name \*.vim -type f -maxdepth 1 -print0 | sort -z | \
170 xargs -0 cat >> "${d%.d}" || die "update_vim_afterscripts failed"
171 done
172
173 einfo "Removing dead scripts in ${afterdir}"
174 find "${afterdir}" -type f -name \*.vim | \
175 while read f; do
176 [[ "$(head -n 1 ${f})" == '" Generated by update_vim_afterscripts' ]] \
177 || continue
178 # This is a generated file, but might be abandoned. Check
179 # if there's no corresponding .d directory, or if the
180 # file's effectively empty
181 if [[ ! -d "${f}.d" || -z "$(grep -v '^"' "${f}")" ]]; then
182 rm "${f}" || die
183 fi
184 done
185 }
186
187 # @FUNCTION: display_vim_plugin_help
188 # @USAGE:
189 # @DESCRIPTION:
190 # Displays a message with the plugin's help file if one is available. Uses the
191 # VIM_PLUGIN_HELPFILES env var. If multiple help files are available, they
192 # should be separated by spaces. If no help files are available, but the env
193 # var VIM_PLUGIN_HELPTEXT is set, that is displayed instead. Finally, if we
194 # have nothing else, this functions displays a link to VIM_PLUGIN_HELPURI. An
195 # extra message regarding enabling filetype plugins is displayed if
196 # VIM_PLUGIN_MESSAGES includes the word "filetype".
197 display_vim_plugin_help() {
198 local h
199
200 if [[ -z ${REPLACING_VERSIONS} ]]; then
201 if [[ -n ${VIM_PLUGIN_HELPFILES} ]]; then
202 elog " "
203 elog "This plugin provides documentation via vim's help system. To"
204 elog "view it, use:"
205 for h in ${VIM_PLUGIN_HELPFILES}; do
206 elog " :help ${h}"
207 done
208 elog " "
209
210 elif [[ -n ${VIM_PLUGIN_HELPTEXT} ]]; then
211 elog " "
212 while read h ; do
213 elog "$h"
214 done <<<"${VIM_PLUGIN_HELPTEXT}"
215 elog " "
216
217 elif [[ -n ${VIM_PLUGIN_HELPURI} ]]; then
218 elog " "
219 elog "Documentation for this plugin is available online at:"
220 elog " ${VIM_PLUGIN_HELPURI}"
221 elog " "
222 fi
223
224 if has filetype ${VIM_PLUGIN_MESSAGES}; then
225 elog "This plugin makes use of filetype settings. To enable these,"
226 elog "add lines like:"
227 elog " filetype plugin on"
228 elog " filetype indent on"
229 elog "to your ~/.vimrc file."
230 elog " "
231 fi
232 fi
233 }
234
235 _VIM_PLUGIN_ECLASS=1
236 fi
237 -
238 -EXPORT_FUNCTIONS src_install pkg_postinst pkg_postrm
239 --
240 2.35.1

Replies

Subject Author
Re: [gentoo-dev] [PATCH v5 4/9] vim-plugin.eclass: EAPI 8: add src_prepare Thomas Bracht Laumann Jespersen <t@×××××××.xyz>
[gentoo-dev] [PATCH v5.5] vim-plugin.eclass: EAPI 8: add src_prepare Anna Vyalkova <cyber+gentoo@×××××.in>