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