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

Replies

Subject Author
Re: [gentoo-dev] [PATCH v5 3/9] vim-plugin.eclass: EAPI 8: install allowed dirs only Thomas Bracht Laumann Jespersen <t@×××××××.xyz>