From 5799b7ee8492860b6dfc5542d04a2d2a2e3f7d56 Mon Sep 17 00:00:00 2001 From: Thomas Deutschmann Date: Sun, 10 Mar 2019 04:33:35 +0100 Subject: Use variables for common used paths Signed-off-by: Thomas Deutschmann --- rust.eselect.in | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/rust.eselect.in b/rust.eselect.in index 96fba74..02f7b75 100644 --- a/rust.eselect.in +++ b/rust.eselect.in @@ -5,17 +5,20 @@ DESCRIPTION="Manage the Rust compiler versions" MAINTAINER="rust@gentoo.org" VERSION="@VERSION@" +ENV_D_PATH="${EROOT%/}/etc/env.d" +BIN_DIR="${EROOT%/}/usr/bin" + inherit package-manager path-manipulation # 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 +# in "${ENV_D_PATH}/rust" directory # this function prints list of $pkgname-$pkgver values find_targets() { local f local -a providers - for f in "${EROOT}"/etc/env.d/rust/provider-*; do + for f in "${ENV_D_PATH}"/rust/provider-*; do [[ -f ${f} ]] || continue providers=("${providers[@]}" "${f##*/provider-}") done @@ -33,7 +36,7 @@ get_current_target() { local i targets=( $(find_targets) ) for (( i = 0; i < ${#targets[@]}; i++ )); do [[ rustc-$(get_postfix ${targets[i]}) = \ - $(basename "$(canonicalise "${EROOT}/usr/bin/rustc")") ]] \ + $(basename "$(canonicalise "${BIN_DIR}/rustc")") ]] \ && echo $i && return 0 done echo "NOT_SET" @@ -60,7 +63,7 @@ get_symlinks_from_file() { #get last set symlinks get_last_set_symlinks() { - local symlinks=( $(get_symlinks_from_file "${EROOT}/etc/env.d/rust/last-set") ) + local symlinks=( $(get_symlinks_from_file "${ENV_D_PATH}/rust/last-set") ) echo "${symlinks[@]}" } @@ -76,7 +79,7 @@ get_symlinks() { target=${targets[target]} fi - local symlinks=( $(get_symlinks_from_file "${EROOT}/etc/env.d/rust/provider-${target}") ) + local symlinks=( $(get_symlinks_from_file "${ENV_D_PATH}/rust/provider-${target}") ) echo "${symlinks[@]}" } @@ -112,17 +115,17 @@ set_symlink() { unset_version() { local symlinks=( $(get_last_set_symlinks) ) for i in "${symlinks[@]}"; do - remove_symlink "${EROOT}${i}" + remove_symlink "${EROOT%/}${i}" done - remove_symlink "${EROOT}/usr/bin/rustc" - rm -f "${EROOT}/etc/env.d/rust/last-set" \ - || die -q "rm -f ${EROOT}/etc/env.d/rust/last-set failed" + remove_symlink "${BIN_DIR}/rustc" + rm -f "${ENV_D_PATH}/rust/last-set" \ + || die -q "rm -f ${ENV_D_PATH}/rust/last-set failed" } # set the rust version # each compiler provider should install # files named rustc-$postfix and rustdoc-$postfix -# in ${EROOT}/usr/bin directory +# in ${BIN_DIR} 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() { @@ -135,20 +138,20 @@ set_version() { target_postfix=$(get_postfix ${target}) - [[ -z ${target_postfix} || ! -x "${EROOT}/usr/bin/rustc-${target_postfix}" ]] \ + [[ -z ${target_postfix} || ! -x "${BIN_DIR}/rustc-${target_postfix}" ]] \ && die -q "Target \"$1\" doesn't appear to be valid!" unset_version - set_symlink "${EROOT}/usr/bin/rustc-${target_postfix}" "${EROOT}/usr/bin/rustc" + set_symlink "${BIN_DIR}/rustc-${target_postfix}" "${BIN_DIR}/rustc" local symlinks=( $(get_symlinks ${target}) ) for i in "${symlinks[@]}"; do - set_symlink "${EROOT}${i}-${target_postfix}" "${EROOT}${i}" + set_symlink "${EROOT%/}${i}-${target_postfix}" "${EROOT%/}${i}" done - cp "${EROOT}/etc/env.d/rust/provider-${target}" \ - "${EROOT}/etc/env.d/rust/last-set" || \ + cp "${ENV_D_PATH}/rust/provider-${target}" \ + "${ENV_D_PATH}/rust/last-set" || \ die -q "symlink list copying failed" } @@ -216,7 +219,7 @@ do_update() { shift done - if [[ "${if_unset}" == "1" && -f "${EROOT}"/usr/bin/rustc ]]; then + if [[ "${if_unset}" == "1" && -f "${BIN_DIR}/rustc" ]]; then return fi @@ -248,7 +251,7 @@ do_unset() { shift done - if [[ "${if_invalid}" == "1" && -e "${EROOT}"/usr/bin/rustc ]]; then + if [[ "${if_invalid}" == "1" && -e "${BIN_DIR}/rustc" ]]; then return fi -- cgit v1.2.3-65-gdbad