summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlastair Tse <liquidx@gentoo.org>2003-11-01 18:33:58 +0000
committerAlastair Tse <liquidx@gentoo.org>2003-11-01 18:33:58 +0000
commit359567097438f2945f820d7b2cbdde94e964e611 (patch)
tree0c0d9289f118235004fc5d4f1b5aff3bf66c5f9a /eclass/alternatives.eclass
parentoops someone forgot me ! (diff)
downloadhistorical-359567097438f2945f820d7b2cbdde94e964e611.tar.gz
historical-359567097438f2945f820d7b2cbdde94e964e611.tar.bz2
historical-359567097438f2945f820d7b2cbdde94e964e611.zip
reintroducing relative linking in alternatives, this time the reverse sorting is fixed via some bash hackery. also some minor fixes in python.eclass
Diffstat (limited to 'eclass/alternatives.eclass')
-rw-r--r--eclass/alternatives.eclass63
1 files changed, 39 insertions, 24 deletions
diff --git a/eclass/alternatives.eclass b/eclass/alternatives.eclass
index 8e611f06a282..b2a30e6779b7 100644
--- a/eclass/alternatives.eclass
+++ b/eclass/alternatives.eclass
@@ -1,6 +1,6 @@
# Copyright 1999-2003 Gentoo Technologies, Inc.
# Distributed under the terms of the GNU General Public License v2
-# $Header: /var/cvsroot/gentoo-x86/eclass/alternatives.eclass,v 1.5 2003/11/01 17:39:11 liquidx Exp $
+# $Header: /var/cvsroot/gentoo-x86/eclass/alternatives.eclass,v 1.6 2003/11/01 18:33:58 liquidx Exp $
# Author : Alastair Tse <liquidx@gentoo.org> (03 Oct 2003)
# Short Desc: Creates symlink to the latest version of multiple slotted
@@ -47,25 +47,31 @@ INHERITED="$INHERITED $ECLASS"
# automatic deduction based on a symlink and a regex mask
alternatives_auto_makesym() {
- local SOURCE REGEX ALT
- local unsorted
- SOURCE=$1
+ local SYMLINK REGEX ALT myregex
+ SYMLINK=$1
REGEX=$2
-
- ALT="`ls -1 --color=never ${ROOT}${REGEX} | sed -e "s:^${ROOT}::" | sort -r | xargs`"
- if [ -n "${ALT}" ]; then
- alternatives_makesym ${SOURCE} ${ALT}
+ if [ "${REGEX:0:1}" != "/" ]
+ then
+ #not an absolute path:
+ #inherit the root directory of our main link path for our regex search
+ myregex="${SYMLINK%/*}/${REGEX}"
else
- eerror "regex ${REGEX} doesn't match any files."
- fi
+ myregex=${REGEX}
+ fi
+
+ # sort a space delimited string by converting it to a multiline list
+ # and then run sort -r over it.
+ ALT="$(for i in $(echo ${myregex}); do echo $i; done | sort -r)"
+ alternatives_makesym ${SYMLINK} ${ALT}
}
alternatives_makesym() {
local ALTERNATIVES=""
- local SOURCE=""
-
+ local SYMLINK=""
+ local alt pref
# usage: alternatives_makesym <resulting symlink> [alternative targets..]
- SOURCE=$1
+ SYMLINK=$1
+ pref=${ROOT:0:${#ROOT}-1}
shift
ALTERNATIVES=$@
@@ -73,23 +79,32 @@ alternatives_makesym() {
# and if one exists, link it and finish.
for alt in ${ALTERNATIVES}; do
- if [ -f "${ROOT}${alt}" ]; then
- if [ -L "${ROOT}${SOURCE}" ]; then
- rm -f ${ROOT}${SOURCE}
+ if [ -f "${pref}${alt}" ]; then
+ einfo "Linking ${alt} to ${pref}${SYMLINK}"
+ [ -L "${pref}${SYMLINK}" ] && rm -f ${pref}${SYMLINK}
+ #are files in same directory?
+ if [ "${alt%/*}" = "${SYMLINK%/*}" ]
+ then
+ #yes; strip leading dirname from alt to create relative symlink
+ ln -s ${alt##*/} ${pref}${SYMLINK}
+ else
+ #no; keep absolute path
+ ln -s ${pref}${alt} ${pref}${SYMLINK}
fi
- einfo "Linking ${alt} to ${SOURCE}"
- # we do this instead of ${ROOT}${SOURCE} because if
- # ROOT=/, then a symlink to //usr/bin/python confuses distutils
- cd ${ROOT}; ln -s ${alt} ${SOURCE}
break
fi
done
# report any errors
- if [ ! -L ${ROOT}${SOURCE} ]; then
- ewarn "Unable to establish ${SOURCE} symlink"
- elif [ ! -f "`readlink ${ROOT}${SOURCE}`" -a ! -f "${ROOT}`readlink ${ROOT}${SOURE}`" ]; then
- ewarn "${SOURCE} is a dead symlink."
+ if [ ! -L ${pref}${SYMLINK} ]; then
+ ewarn "Unable to establish ${pref}${SYMLINK} symlink"
+ else
+ # we need to check for either the target being in relative path form
+ # or absolute path form
+ if [ ! -f "`dirname ${pref}${SYMLINK}`/`readlink ${pref}${SYMLINK}`" -a \
+ ! -f "`readlink ${pref}${SYMLINK}`" ]; then
+ ewarn "${pref}${SYMLINK} is a dead symlink."
+ fi
fi
}