aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJauhien Piatlicki <jauhien@gentoo.org>2015-04-24 00:09:39 +0200
committerJauhien Piatlicki <jauhien@gentoo.org>2015-04-24 00:09:39 +0200
commit997d76d9ee5b16fbde4fa1e033d44c55ab636e2a (patch)
tree844a449b1a9e02d4fcc18d056f5130c5928bc3ca /src/modules/rust.eselect
parentMerge pull request #2 from geovex/master (diff)
downloadeselect-rust-997d76d9ee5b16fbde4fa1e033d44c55ab636e2a.tar.gz
eselect-rust-997d76d9ee5b16fbde4fa1e033d44c55ab636e2a.tar.bz2
eselect-rust-997d76d9ee5b16fbde4fa1e033d44c55ab636e2a.zip
make symlink management configurable on per package basis
Diffstat (limited to 'src/modules/rust.eselect')
-rw-r--r--src/modules/rust.eselect87
1 files changed, 62 insertions, 25 deletions
diff --git a/src/modules/rust.eselect b/src/modules/rust.eselect
index 26b2fae..f72e044 100644
--- a/src/modules/rust.eselect
+++ b/src/modules/rust.eselect
@@ -1,17 +1,13 @@
# -*-eselect-*- vim: ft=eselect
-# Copyright 2014 Gentoo Foundation
+# Copyright 2015 Gentoo Foundation
# Distributed under the terms of the GNU GPL version 2 or later
DESCRIPTION="Manage the Rust compiler versions"
MAINTAINER="jauhien@gentoo.org"
-VERSION="0.2"
+VERSION="0.3"
inherit package-manager path-manipulation
-SITELISP=/usr/share/emacs/site-lisp
-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
@@ -33,6 +29,42 @@ get_postfix() {
echo "${target}" | cut -d- -f2-
}
+#get current target
+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")") ]] \
+ && echo $i && return 0
+ done
+ echo "NOT_SET"
+}
+
+#get lists of symlinks
+get_symlinks() {
+ local target=$1
+ if [ "${target}" == "NOT_SET" ]; then
+ echo /usr/bin/rustdoc
+ return
+ fi
+ if is_number "${target}"; then
+ local targets=( $(find_targets) )
+ target=${targets[target]}
+ fi
+
+ local symlinks=()
+ local i
+ for i in `cat "${EROOT}/etc/env.d/rust/provider-${target}"`; do
+ symlinks+=($i)
+ done
+
+ if [ ${#symlinks[@]} -eq 0 ]; then
+ echo /usr/bin/rustdoc
+ else
+ echo "${symlinks[@]}"
+ fi
+}
+
# remove symlink if exists
remove_symlink() {
local symlink=$1
@@ -46,7 +78,6 @@ remove_symlink() {
fi
}
-
# set symlink if source exists
set_symlink() {
local source=$1
@@ -62,10 +93,12 @@ set_symlink() {
# unset the rust version
unset_version() {
- remove_symlink "${EROOT}"/usr/bin/rustc
- remove_symlink "${EROOT}"/usr/bin/rustdoc
- remove_symlink "${EROOT}"/usr/bin/rust-lldb
- remove_symlink "${EROOT}"/usr/bin/rust-gdb
+ local target=$(get_current_target)
+ local symlinks=( $(get_symlinks ${target}) )
+ for i in "${symlinks[@]}"; do
+ remove_symlink "${EROOT}${i}"
+ done
+ remove_symlink "${EROOT}/usr/bin/rustc"
}
# set the rust version
@@ -82,17 +115,21 @@ set_version() {
target=${targets[target-1]}
fi
- target=$(get_postfix ${target})
+ target_postfix=$(get_postfix ${target})
- [[ -z ${target} || ! -x "${EROOT}/usr/bin/rustc-${target}" ]] \
+ [[ -z ${target_postfix} || ! -x "${EROOT}/usr/bin/rustc-${target_postfix}" ]] \
&& die -q "Target \"$1\" doesn't appear to be valid!"
unset_version
- 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"
- set_symlink "${EROOT}/usr/bin/rust-lldb-${target}" "${EROOT}/usr/bin/rust-lldb" || write_warning_msg "rust-lldb symlink setting failed (it can be ok for the older or newer rust)"
- set_symlink "${EROOT}/usr/bin/rust-gdb-${target}" "${EROOT}/usr/bin/rust-gdb" || write_warning_msg "rust-gdb symlink setting failed (it can be ok for the older rust)"
+ set_symlink "${EROOT}/usr/bin/rustc-${target_postfix}" "${EROOT}/usr/bin/rustc" \
+ || die -q "rustc symlink setting failed"
+
+ local symlinks=( $(get_symlinks ${target}) )
+ for i in "${symlinks[@]}"; do
+ set_symlink "${EROOT}${i}-${target_postfix}" "${EROOT}${i}" \
+ || die -q "${i} symlink setting failed"
+ done
}
### list action ###
@@ -102,16 +139,16 @@ describe_list() {
}
do_list() {
- local i targets=( $(find_targets) )
+ local i
+ local targets=( $(find_targets) )
+ local target=$(get_current_target)
+
+ if is_number "${target}"; then
+ targets[target]=$(highlight_marker "${targets[target]}")
+ fi
write_list_start "Available Rust versions:"
- for (( i = 0; i < ${#targets[@]}; i++ )); do
- # highlight the target where the symlink is pointing to
- [[ rustc-$(get_postfix ${targets[i]}) = \
- $(basename "$(canonicalise "${EROOT}/usr/bin/rustc")") ]] \
- && targets[i]=$(highlight_marker "${targets[i]}")
- done
- write_numbered_list -m "(none found)" "${targets[@]}"
+ write_numbered_list -m "(none found)" "${targets[@]}"
}
### set action ###