No USE flags are introduced because we only install files and symlinks. Although some complex plugins could benefit from USE-dependencies, extra complexity is not worth it.
Since we don't use Vim to generate documentation tags anymore, we can remove it from DEPEND. Closes: https://bugs.gentoo.org/586882 Closes: https://bugs.gentoo.org/612644 Signed-off-by: Anna (cybertailor) Vyalkova <[email protected]> --- eclass/vim-plugin.eclass | 163 ++++++++++++++++++++++++++++++++++----- 1 file changed, 144 insertions(+), 19 deletions(-) diff --git a/eclass/vim-plugin.eclass b/eclass/vim-plugin.eclass index fc25be9a764..31cb87eaf38 100644 --- a/eclass/vim-plugin.eclass +++ b/eclass/vim-plugin.eclass @@ -5,15 +5,17 @@ # @MAINTAINER: # [email protected] # @SUPPORTED_EAPIS: 7 8 9 -# @BLURB: install addons for Vim +# @BLURB: install addons for Vim/Neovim # @DESCRIPTION: -# This eclass simplifies installation of Vim plugins into a corresponding +# This eclass simplifies installation of Vim/Neovim plugins into a corresponding # version-independent directory and generating the help tags file for any # documentation. # # If EAPI 9 or later is used, plugins are installed into directories following # Vim's native package hierarchy (see ":help packages"), while older EAPIs are # using the legacy addon packaging. +# +# Neovim is supported since EAPI 9. if [[ -z ${_VIM_PLUGIN_ECLASS} ]]; then _VIM_PLUGIN_ECLASS=1 @@ -26,6 +28,22 @@ esac [[ ${EAPI} != 7 ]] && _DEFINE_VIM_PLUGIN_SRC_PREPARE=true +# @ECLASS_VARIABLE: VIM_COMPAT +# @PRE_INHERIT +# @DEFAULT_UNSET +# @DESCRIPTION: +# This variable contains a list of Vim implementations the package supports. It +# must be set before the `inherit' call. It has to be an array. +# +# This variable only makes effect since EAPI 9. +# +# Supported values: nvim, vim. +# +# Example: +# @CODE +# VIM_COMPAT=( nvim vim ) +# @CODE + # @ECLASS_VARIABLE: VIM_PLUGIN_NAME # @DESCRIPTION: # The addon's name. @@ -69,11 +87,72 @@ else : "${VIM_PLUGIN_VIM_VERSION:=7.3}" fi -DEPEND="|| ( >=app-editors/vim-${VIM_PLUGIN_VIM_VERSION} - >=app-editors/gvim-${VIM_PLUGIN_VIM_VERSION} )" -RDEPEND="${DEPEND}" -_using_vim_pack && +# @ECLASS_VARIABLE: VIM_PLUGIN_NEOVIM_VERSION +# @PRE_INHERIT +# @DESCRIPTION: +# Minimum Neovim version the plugin supports. +: "${VIM_PLUGIN_NEOVIM_VERSION:=0.2.2}" + +# @ECLASS_VARIABLE: VIM_DEPEND +# @OUTPUT_VARIABLE +# @DESCRIPTION: +# Associative array of dependencies on Vim implementations. +# +# This variable is only available since EAPI 9. +# +# Example use: test a plugin with every Vim implementation. +# @CODE +# BDEPEND=" +# test? ( +# ${VIM_DEPEND[@]} +# app-vim/foobar +# ) +# " +# @CODE + +# @FUNCTION: _vim_plugin_set_globals +# @INTERNAL +# @DESCRIPTION: +# Check VIM_COMPAT for well-formedness and validity, then set dependencies on +# Vim implementations. +_vim_plugin_set_globals() { + local impl + + if [[ ${VIM_COMPAT@a} != *a* ]]; then + die "VIM_COMPAT must be an array." + elif [[ ${#VIM_COMPAT[@]} -eq 0 ]]; then + die "VIM_COMPAT must not be empty." + fi + + declare -Ag VIM_DEPEND=() + for impl in "${VIM_COMPAT[@]}"; do + case "${impl}" in + nvim) + VIM_DEPEND[${impl}]=">=app-editors/neovim-${VIM_PLUGIN_NEOVIM_VERSION}" ;; + vim) + VIM_DEPEND[${impl}]=" + || ( + >=app-editors/vim-${VIM_PLUGIN_VIM_VERSION} + >=app-editors/gvim-${VIM_PLUGIN_VIM_VERSION} + ) + " ;; + *) + die "Invalid implementation in VIM_COMPAT: ${impl}" ;; + esac + done + + RDEPEND="|| ( ${VIM_DEPEND[@]} )" BDEPEND="app-vim/helpztags" +} + +if ! _using_vim_pack; then + DEPEND="|| ( >=app-editors/vim-${VIM_PLUGIN_VIM_VERSION} + >=app-editors/gvim-${VIM_PLUGIN_VIM_VERSION} )" + RDEPEND="${DEPEND}" +else + _vim_plugin_set_globals + unset -f _vim_plugin_set_globals +fi if [[ ${PV} != 9999* ]] ; then SRC_URI="mirror://gentoo/${P}.tar.bz2 @@ -117,24 +196,69 @@ fi # @ECLASS_VARIABLE: _VIM_PLUGIN_ALLOWED_DIRS # @INTERNAL # @DESCRIPTION: -# List of directories recognized by Vim. +# List of directories recognized by "vanilla" Vim/Neovim. # # See ":help runtimepath" for a reference. -_VIM_PLUGIN_ALLOWED_DIRS=( - after autoload colors compiler doc ftdetect ftplugin indent keymap - macros plugin spell syntax -) +case ${EAPI} in + 7) ;; + 8) + _VIM_PLUGIN_ALLOWED_DIRS=( + after autoload colors compiler doc ftdetect ftplugin indent keymap + macros plugin spell syntax + ) ;; + *) + # Directories added: + # - common: import, lang, print, tutor + # - nvim: lsp, lua, parser, queries, rplugin + _VIM_PLUGIN_ALLOWED_DIRS=( + # common + after autoload colors compiler doc ftdetect ftplugin import indent + keymap lang macros plugin print spell syntax tutor + + # nvim-specific + lsp lua parser queries rplugin + ) ;; +esac + +# @FUNCTION: _install_vim_plugin_symlinks +# @USAGE: <src> +# @INTERNAL +# @DESCRIPTION: +# Symlink installed plugin files so they can be found by Vim/Neovim. +_install_vim_plugin_symlinks() { + local -A vim_pack_dir=( + [nvim]="/usr/share/nvim/site/pack/dist-bundle" + [vim]="/usr/share/vim/vimfiles/pack/dist-bundle" + ) + + local impl dest + for impl in "${VIM_COMPAT[@]}"; do + dest="${vim_pack_dir[${impl}]}" + if [[ ${VIM_PLUGIN_AUTOLOAD} ]]; then + dest+="/start" + else + dest+="/opt" + fi + dest+="/${VIM_PLUGIN_NAME}" + + dosym -r "${1}" "${dest}" + done +} # @FUNCTION: vim-plugin_src_install # @USAGE: [<dir>...] # @DESCRIPTION: # Overrides the default src_install phase. # -# This function installs all plugin files that are recognized by -# default Vim installation (see ":help runtimepath" for an overview). +# This function installs all plugin files that are recognized by default +# Vim/Neovim installation (see ":help runtimepath" for an overview). # If any additional directories are passed to this function as # arguments, install them too. # +# If the new plugin packaging is used, a plugin is first installed into +# /usr/share/gentoo-vim-dist and then symlinks are created to avoid duplication +# between different Vim implementations. +# # Example use: # @CODE # src_install() { @@ -152,20 +276,21 @@ vim-plugin_src_install() { *) dirs_to_install=( "${_VIM_PLUGIN_ALLOWED_DIRS[@]}" "${@}" ) ;; esac - local vim_pack_dir="/usr/share/vim/vimfiles/pack/dist-bundle" - if ! _using_vim_pack; then - insinto /usr/share/vim/vimfiles - elif [[ ${VIM_PLUGIN_AUTOLOAD} ]]; then - insinto "${vim_pack_dir}/start/${VIM_PLUGIN_NAME}" + local dest + if _using_vim_pack; then + dest="/usr/share/gentoo-vim-dist/${PN}" else - insinto "${vim_pack_dir}/opt/${VIM_PLUGIN_NAME}" + dest="/usr/share/vim/vimfiles" fi + insinto "${dest}" local d for d in "${dirs_to_install[@]}"; do [[ -d "${d}" ]] || continue doins -r "${d}" done + + _using_vim_pack && _install_vim_plugin_symlinks "${dest}" } # @FUNCTION: vim-plugin_pkg_postinst -- 2.52.0
