diff options
author | Jauhien Piatlicki <jauhien@gentoo.org> | 2014-10-10 23:04:54 +0200 |
---|---|---|
committer | Jauhien Piatlicki <jauhien@gentoo.org> | 2014-10-10 23:53:11 +0200 |
commit | 8318d70f6e710198a2497d25e4b0f1ce77ff0239 (patch) | |
tree | c9648333bfdb40d26231684d6fa3796bceeb1701 | |
parent | fix unset action (diff) | |
download | eselect-rust-8318d70f6e710198a2497d25e4b0f1ce77ff0239.tar.gz eselect-rust-8318d70f6e710198a2497d25e4b0f1ce77ff0239.tar.bz2 eselect-rust-8318d70f6e710198a2497d25e4b0f1ce77ff0239.zip |
split out emacs, vim and zsh stuff and prepare for handling of rust compilers provided by different packages0.2_pre20141011
-rw-r--r-- | src/modules/rust.eselect | 132 |
1 files changed, 26 insertions, 106 deletions
diff --git a/src/modules/rust.eselect b/src/modules/rust.eselect index c744d30..dc8c18c 100644 --- a/src/modules/rust.eselect +++ b/src/modules/rust.eselect @@ -4,7 +4,7 @@ DESCRIPTION="Manage the rust compiler versions" MAINTAINER="jauhien@gentoo.org" -VERSION="0.1" +VERSION="0.2" inherit package-manager path-manipulation @@ -13,18 +13,27 @@ SITEVIM=/usr/share/vim/vimfiles SITEZSH=/usr/share/zsh/site-functions # find a list of installed rust compilers +# each compiler provider should install +# a config file named provider-$pkgname-$pkgver +# in "${EROOT}"/etc/env.d/rust directory +# this function prints list of $pkgname-$pkgver values find_targets() { local f - local version - for f in "${EROOT}"/usr/bin/rustc-*; do - version="" - [[ -x ${f} ]] && version=`basename "${f}" | awk -F"-" '{ print $2 }'` - has_version "~dev-lang/rust-${version}" && echo ${version} + local -a providers + for f in "${EROOT}"/etc/env.d/rust/provider-*; do + [[ -f ${f} ]] || continue + providers=("${providers[@]}" "${f##*/provider-}") done + echo "${providers[@]}" } -# remove symlink if exists +#get rustc postfix +get_postfix() { + local target=$1 + echo "${target}" | cut -d- -f2- +} +# remove symlink if exists remove_symlink() { local symlink=$1 @@ -37,66 +46,8 @@ remove_symlink() { fi } -# Regenerate the site-gentoo.el file, based on packages' site -# initialisation files in the /usr/share/emacs/site-lisp/site-gentoo.d/ -# directory. -# A slightly changed function from elisp-common.eclass - -elisp-site-regen() { - local sitelisp=${EROOT}${SITELISP} - local sf i ret=0 null="" page=$'\f' - local -a sflist - local T=${EROOT}/tmp/eselect - - mkdir -p "${T}" || die -q "temporary directory creation failed for ${T}" - - [[ -d ${sitelisp} ]] \ - || die -q "elisp-site-regen: Directory ${sitelisp} does not exist" - - [[ -d ${T} ]] \ - || die -q "elisp-site-regen: Temporary directory ${T} does not exist" - - for sf in "${sitelisp}"/site-gentoo.d/[0-9][0-9]*.el; do - [[ -r ${sf} ]] && sflist+=("${sf}") - done - - cat <<-EOF >"${T}"/site-gentoo.el || ret=$? - ;;; site-gentoo.el --- site initialisation for Gentoo-installed packages - - ;;; Commentary: - ;; Automatically generated by eselect-rust - ;; DO NOT EDIT THIS FILE - - ;;; Code: - EOF - # Use sed instead of cat here, since files may miss a trailing newline. - sed '$q' "${sflist[@]}" </dev/null >>"${T}"/site-gentoo.el || ret=$? - cat <<-EOF >>"${T}"/site-gentoo.el || ret=$? - - ${page} - (provide 'site-gentoo) - - ;; Local ${null}Variables: - ;; no-byte-compile: t - ;; buffer-read-only: t - ;; End: - - ;;; site-gentoo.el ends here - EOF - - if [[ ${ret} -ne 0 ]]; then - die -q "elisp-site-regen: Writing site-gentoo.el failed." - else - mv "${T}"/site-gentoo.el "${sitelisp}"/site-gentoo.el || \ - die -q "elisp-site-regen: Replacing site-gentoo.el failed" - fi - - rm -rf "${T}" - true -} # set symlink if source exists - set_symlink() { local source=$1 local dest=$2 @@ -110,30 +61,17 @@ set_symlink() { } # unset the rust version - unset_version() { remove_symlink "${EROOT}"/usr/bin/rustc remove_symlink "${EROOT}"/usr/bin/rustdoc - remove_symlink "${EROOT}/${SITELISP}"/rust-mode - remove_symlink "${EROOT}/${SITELISP}"/site-gentoo.d/50rust-mode-gentoo.el - - if [[ -e "${EROOT}/${SITELISP}"/site-gentoo.el ]]; then - elisp-site-regen - fi - - for i in after/syntax autoload ftdetect ftplugin indent plugin syntax; do - remove_symlink "${EROOT}/${SITEVIM}/${i}/rust.vim" - done - for i in compiler syntax_checkers/rust; do - remove_symlink "${EROOT}/${SITEVIM}/${i}/rustc.vim" - done - remove_symlink "${EROOT}/${SITEVIM}/doc/rust.txt" - - remove_symlink "${EROOT}/${SITEZSH}/_rust" } # set the rust version - +# each compiler provider should install +# files named rustc-$postfix and rustdoc-$postfix +# in ${EROOT}/usr/bin directory +# $postfix is defined as the part of $pkgname-$pkgver after the first - +# for dev-lang/rust-bin-9999 ebuild it would be bin-9999 set_version() { local target=$1 @@ -142,33 +80,15 @@ set_version() { target=${targets[target-1]} fi + target=$(get_postfix ${target}) + [[ -z ${target} || ! -x "${EROOT}/usr/bin/rustc-${target}" ]] \ && die -q "Target \"$1\" doesn't appear to be valid!" unset_version - ln -s "${EROOT}/usr/bin/rustc-${target}" "${EROOT}/usr/bin/rustc" || die -q "rustc symlink setting failed" - ln -s "${EROOT}/usr/bin/rustdoc-${target}" "${EROOT}/usr/bin/rustdoc" || die -q "rustdoc symlink setting failed" - - local datadir="${EROOT}/usr/share/rust-${target}" - - set_symlink "${datadir}/emacs/site-lisp/rust-mode" "${EROOT}/${SITELISP}/rust-mode" && \ - set_symlink "${datadir}/emacs/site-lisp/site-gentoo.d/50rust-mode-gentoo.el" \ - "${EROOT}/${SITELISP}/site-gentoo.d/50rust-mode-gentoo.el" && \ - elisp-site-regen - - local rustvimdir="${datadir}/vim/vimfiles" - for i in after/syntax autoload ftdetect ftplugin indent plugin syntax; do - set_symlink "${rustvimdir}/${i}/rust.vim" "${EROOT}/${SITEVIM}/${i}/rust.vim" - done - for i in compiler syntax_checkers/rust; do - set_symlink "${rustvimdir}/${i}/rustc.vim" "${EROOT}/${SITEVIM}/${i}/rustc.vim" - done - set_symlink "${rustvimdir}/doc/rust.txt" "${EROOT}/${SITEVIM}/doc/rust.txt" - - set_symlink "${datadir}/zsh/site-functions/_rust" "${EROOT}/${SITEZSH}/_rust" - - true + set_symlink "${EROOT}/usr/bin/rustc-${target}" "${EROOT}/usr/bin/rustc" || die -q "rustc symlink setting failed" + set_symlink "${EROOT}/usr/bin/rustdoc-${target}" "${EROOT}/usr/bin/rustdoc" || die -q "rustdoc symlink setting failed" } ### list action ### @@ -183,7 +103,7 @@ do_list() { write_list_start "Available rust versions:" for (( i = 0; i < ${#targets[@]}; i++ )); do # highlight the target where the symlink is pointing to - [[ rustc-${targets[i]} = \ + [[ rustc-$(get_postfix ${targets[i]}) = \ $(basename "$(canonicalise "${EROOT}/usr/bin/rustc")") ]] \ && targets[i]=$(highlight_marker "${targets[i]}") done |