Gentoo Archives: gentoo-dev

From: Anna Vyalkova <cyber+gentoo@×××××.in>
To: gentoo-dev@l.g.o
Cc: vim@g.o, Thomas Bracht Laumann Jespersen <t@×××××××.xyz>
Subject: [gentoo-dev] [PATCH v5 1/9] vim-doc.eclass: support EAPI 8
Date: Mon, 11 Apr 2022 12:33:52
Message-Id: 20220411123306.24750-2-cyber+gentoo@sysrq.in
In Reply to: [gentoo-dev] [PATCH v5 0/9] Vim eclasses by Anna Vyalkova
1 From: Thomas Bracht Laumann Jespersen <t@×××××××.xyz>
2
3 * Added "|| die" statements
4 * Create links only if they don't exist yet
5 * `readlink` -> `readlink -f`
6 * Quoted variables
7
8 Signed-off-by: Thomas Bracht Laumann Jespersen <t@×××××××.xyz>
9 Signed-off-by: Anna Vyalkova <cyber+gentoo@×××××.in>
10 ---
11 eclass/vim-doc.eclass | 66 +++++++++++++++++++++++++------------------
12 1 file changed, 39 insertions(+), 27 deletions(-)
13
14 diff --git a/eclass/vim-doc.eclass b/eclass/vim-doc.eclass
15 index ba9d00f4f5..f0c5c6edc6 100644
16 --- a/eclass/vim-doc.eclass
17 +++ b/eclass/vim-doc.eclass
18 @@ -1,86 +1,98 @@
19 -# Copyright 1999-2021 Gentoo Authors
20 +# Copyright 1999-2022 Gentoo Authors
21 # Distributed under the terms of the GNU General Public License v2
22
23 # @ECLASS: vim-doc.eclass
24 # @MAINTAINER:
25 # vim@g.o
26 -# @SUPPORTED_EAPIS: 6 7
27 +# @SUPPORTED_EAPIS: 6 7 8
28 # @BLURB: Eclass for vim{,-plugin}.eclass to update documentation tags.
29 # @DESCRIPTION:
30 # This eclass is used by vim.eclass and vim-plugin.eclass to update
31 # the documentation tags. This is necessary since vim doesn't look in
32 # /usr/share/vim/vimfiles/doc for documentation; it only uses the
33 # versioned directory, for example /usr/share/vim/vim62/doc
34 #
35 # We depend on vim being installed, which is satisfied by either the
36 # DEPEND in vim-plugin or by whatever version of vim is being
37 # installed by the eclass.
38
39 -case ${EAPI:-0} in
40 - [67]) ;;
41 +case ${EAPI} in
42 + 6|7|8) ;;
43 *) die "${ECLASS}: EAPI ${EAPI:-0} not supported" ;;
44 esac
45
46 -if [[ -z ${_VIM_DOC_ECLASS} ]] ; then
47 -_VIM_DOC_ECLASS=1
48 +if [[ ! ${_VIM_DOC_ECLASS} ]] ; then
49
50 update_vim_helptags() {
51 - local vimfiles vim d s
52 + local vimfiles helpfile files vim d
53
54 # This is where vim plugins are installed
55 vimfiles="${EROOT}"/usr/share/vim/vimfiles
56
57 - if [[ $PN != vim-core ]]; then
58 + if [[ ${PN} != vim-core ]]; then
59 # Find a suitable vim binary for updating tags :helptags
60 vim=$(type -P vim 2>/dev/null)
61 - [[ -z "$vim" ]] && vim=$(type -P gvim 2>/dev/null)
62 - [[ -z "$vim" ]] && vim=$(type -P kvim 2>/dev/null)
63 - if [[ -z "$vim" ]]; then
64 + [[ -z "${vim}" ]] && vim=$(type -P gvim 2>/dev/null)
65 + [[ -z "${vim}" ]] && vim=$(type -P kvim 2>/dev/null)
66 + if [[ -z "${vim}" ]]; then
67 ewarn "No suitable vim binary to rebuild documentation tags"
68 fi
69 fi
70
71 # Make vim not try to connect to X. See :help gui-x11-start
72 # in vim for how this evil trickery works.
73 if [[ -n "${vim}" ]] ; then
74 - ln -s "${vim}" "${T}/tagvim"
75 + ln -s "${vim}" "${T}/tagvim" || die
76 vim="${T}/tagvim"
77 fi
78
79 # Install the documentation symlinks into the versioned vim
80 # directory and run :helptags
81 for d in "${EROOT%/}"/usr/share/vim/vim[0-9]*; do
82 - [[ -d "$d/doc" ]] || continue # catch a failed glob
83 + [[ -d "${d}/doc" ]] || continue # catch a failed glob
84
85 - # Remove links, and possibly remove stale dirs
86 - find $d/doc -name \*.txt -type l | while read s; do
87 - [[ $(readlink "$s") = $vimfiles/* ]] && rm -f "$s"
88 + # Remove links
89 + readarray -d '' files < <(find "${d}"/doc -name "*.txt" -type l -print0 || die "cannot traverse ${d}/doc" )
90 + for helpfile in "${files[@]}"; do
91 + if [[ $(readlink -f "${helpfile}") == "${vimfiles}"/* ]]; then
92 + rm "${helpfile}" || die
93 + fi
94 done
95 - if [[ -f "$d/doc/tags" && $(find "$d" | wc -l | tr -d ' ') = 3 ]]; then
96 +
97 + # Remove stale dirs, if possible
98 + readarray -d '' files < <(find "${d}" -print0 || die "cannot traverse ${d}")
99 + if [[ -f "${d}/doc/tags" && ${#files[@]} -eq 3 ]]; then
100 # /usr/share/vim/vim61
101 # /usr/share/vim/vim61/doc
102 # /usr/share/vim/vim61/doc/tags
103 - einfo "Removing $d"
104 - rm -r "$d"
105 + einfo "Removing ${d}"
106 + rm -r "${d}" || die
107 continue
108 fi
109
110 # Re-create / install new links
111 - if [[ -d $vimfiles/doc ]]; then
112 - ln -s $vimfiles/doc/*.txt $d/doc 2>/dev/null
113 + if [[ -d "${vimfiles}"/doc ]]; then
114 + for helpfile in "${vimfiles}"/doc/*.txt; do
115 + if [[ ! -e "${d}/doc/$(basename "${helpfile}")" ]]; then
116 + ln -s "${helpfile}" "${d}/doc" || die
117 + fi
118 + done
119 fi
120
121 # Update tags; need a vim binary for this
122 - if [[ -n "$vim" ]]; then
123 - einfo "Updating documentation tags in $d"
124 - DISPLAY= $vim -u NONE -U NONE -T xterm -X -n -f \
125 + if [[ -n "${vim}" ]]; then
126 + einfo "Updating documentation tags in ${d}"
127 + DISPLAY= "${vim}" -u NONE -U NONE -T xterm -X -n -f \
128 '+set nobackup nomore' \
129 - "+helptags $d/doc" \
130 - '+qa!' </dev/null &>/dev/null
131 + "+helptags ${d}/doc" \
132 + '+qa!' </dev/null &>/dev/null || die
133 fi
134 done
135
136 - [[ -n "${vim}" && -f "${vim}" ]] && rm "${vim}"
137 + if [[ -n "${vim}" && -f "${vim}" ]]; then
138 + rm "${vim}" || die
139 + fi
140 }
141
142 +_VIM_DOC_ECLASS=1
143 fi
144 --
145 2.35.1