--- trunk/mage/usr/lib/mage/depwalker.sh 2011/12/28 10:05:49 1564 +++ branches/mage-next/src/depwalker.in 2014/10/22 12:27:17 2839 @@ -1,45 +1,53 @@ #!/bin/bash # $Id$ -# dependeny walker +# dependency walker -# default die function -die() +# set default variables +: ${MAGERC="@@SYSCONFDIR@@/mage.rc"} +: ${MLIBDIR="@@MAGELIBDIR@@"} + +# first of all include common functions +source ${MLIBDIR}/common.functions.sh || exit 1 +source @@SYSCONFDIR@@/mage.rc.global || die "@@SYSCONFDIR@@/mage.rc.global missing" +source ${MAGERC} || die "Your ${MAGERC} is missing. Aborting." +source ${MLIBDIR}/mage4.functions.sh || die "mage functions missing" +source ${MLIBDIR}/smage2.functions.sh || die "smage functions missing" + +decho() { - echo ${COLRED}"$@"${COLDEFAULT} - exit 1 + if [[ ${DEBUG} = 1 ]] + then + echo "DEBUG: $@" >&2 + fi } -# include all needed files -[ -f /etc/mage.rc.global ] && \ - source /etc/mage.rc.global || \ - die "/etc/mage.rc.global missing" - -[ -f ${MAGERC} ] && source ${MAGERC} || \ - die "Your ${MAGERC} is missing. Aborting." - -[ -f ${MLIBDIR}/mage4.functions.sh ] && \ - source ${MLIBDIR}/mage4.functions.sh || \ - die "mage functions missing" - usage() { echo echo "Usage: $(basename $0) [command] [arg] ..." echo echo " -h --help shows this help" - echo " -c --pcat categorie of the package" + echo " -c --pcat category of the package" echo " -n --pname name of the package" echo " -v --pver version number of the package" echo " -b --pbuild build number of the package" echo " -m --method which calc method should be used:" - echo " install, srcinstall, depend, srcdepend" - echo " upgrade, srcupgrade" + echo " install, srcinstall, pretend, srcpretend" + echo " upgrade, srcupgrade," + echo " install-build-prerequisites," + echo " pretend-build-prerequisites" + echo " -d --debug enable debug mode" + echo " -s --smage use a smage to calculate dependencies" echo - echo "method, name, version and build must be given !" + echo "method, category, name, version and build must be given !" echo exit 1 } +# set some sane defaults +DEBUG=0 +SMAGE_DEPEND=0 + # very basic getops for i in $* do @@ -49,16 +57,21 @@ --pver|-v) shift; PVER="$1" ;; --pbuild|-b) shift; PBUILD="$1" ;; --method|-m) shift; METHOD="$1" ;; + --debug|-d) shift; DEBUG=1 ;; + --smage|-s) shift; SMAGEFILE="$1"; SMAGE_DEPEND=1; SILENT=1; FVERBOSE=off ;; --help|-h) usage ;; esac shift done # sanity checks; abort if not given -[ -z "${PCAT}" ] && usage -[ -z "${PNAME}" ] && usage -[ -z "${PVER}" ] && usage -[ -z "${PBUILD}" ] && usage +if [[ -z ${SMAGEFILE} ]] +then + [ -z "${PCAT}" ] && usage + [ -z "${PNAME}" ] && usage + [ -z "${PVER}" ] && usage + [ -z "${PBUILD}" ] && usage +fi [ -z "${METHOD}" ] && usage # check needed global vars @@ -66,8 +79,20 @@ [ -z "${INSTALLDB}" ] && die "\$INSTALLDB not set." [ -z "${BUILDDIR}" ] && die "\$BUILDDIR not set." +# load mage-features to support them with smagesource() +load_mage_features + # other needed vars ALLDEPS="" +if [[ -n ${SMAGEFILE} ]] +then + if [[ -e ${SMAGEFILE} ]] + then + smagesource "${SMAGEFILE}" + else + die "Smage file '${SMAGEFILE}' does not exist!" + fi +fi MAGEFILE="${MAGEDIR}/${PCAT}/${PNAME}/${PNAME}-${PVER}-${PBUILD}.mage" # much faster than fgrep @@ -120,6 +145,10 @@ DFILE="$1" + # debug info + decho "depwalking magefile '${DFILE}'" + decho + source ${DFILE} # forced nodeps @@ -132,10 +161,12 @@ MY_DEPEND="${DEPEND}" # for srcinstall & srcdepend only; SDEPEND also needed - if [[ ${METHOD} = srcinstall ]] || \ - [[ ${METHOD} = srcpretend ]] || \ - [[ ${METHOD} = srcupgrade ]] || \ - [[ ${METHOD} = srcuppretend ]] + if [[ ${METHOD} = srcinstall ]] || + [[ ${METHOD} = srcpretend ]] || + [[ ${METHOD} = srcupgrade ]] || + [[ ${METHOD} = srcuppretend ]] || + [[ ${METHOD} = install-build-prerequisites ]] || + [[ ${METHOD} = pretend-build-prerequisites ]] then # only if SDEPEND is not zero if [ -n "${SDEPEND}" ] @@ -156,11 +187,15 @@ if [ -z "${MY_DEPEND}" ] then + decho "MY_DEPEND is empty; deps of '${DFILE}' ignored" return 1 fi while read SYM DEPNAME do + # debug info + decho "DEPNAME='${DEPNAME}'" + # exclude empty depnames [[ -z ${DEPNAME} ]] && continue @@ -172,13 +207,18 @@ # mark depfile as processed to prevent double runs -without version # but do not add any virtuals to PROCESSEDDEPS or their resolved - # pkgnames will be ignored and they are missing on the dependecy-list + # pkgnames will be ignored and they are missing on the dependency-list if [[ ${DEPNAME/virtual\//} = ${DEPNAME} ]] then PROCESSEDDEPS="${PROCESSEDDEPS} ${DEPNAME%-*}" fi HIGHEST_DEPFILE=$(dep2highest_magefile "${DEPNAME}") + if [[ -z ${HIGHEST_DEPFILE} ]] + then + INVALID_DEPS+=" ${DEPNAME}:${DFILE}" + continue + fi PCAT="$(magename2pcat ${HIGHEST_DEPFILE})" PNAME="$(magename2pname ${HIGHEST_DEPFILE})" @@ -194,8 +234,10 @@ ### check if the dependency is already installed ### if [ ! -d ${MROOT}${INSTALLDB}/${PCAT}/${PNAME}-${PVER}-${PBUILD} ] then + # but first get all deps of highest_depfile to catch all dependencies of it depwalking ${HIGHEST_DEPFILE} ALLDEPS="${ALLDEPS} ${HIGHEST_DEPFILE}" + decho "added '${HIGHEST_DEPFILE}' to ALLDEPS" fi fi done << EOF @@ -207,7 +249,8 @@ [[ ${METHOD} = pretend ]] || \ [[ ${METHOD} = srcpretend ]] || \ [[ ${METHOD} = uppretend ]] || \ - [[ ${METHOD} = srcuppretend ]] && \ + [[ ${METHOD} = srcuppretend ]] || \ + [[ ${METHOD} = pretend-build-prerequisites ]] && \ echo -n "Calculating dependencies ... " @@ -225,11 +268,18 @@ # get the highest mage file from mage-db MAGEFILE="$(get_highest_magefile ${PCAT} ${PNAME})" + # debug info + decho "dep='${dep}'" + decho "PCAT='${PCAT}'" + decho "PNAME='${PNAME}'" + decho "MAGEFILE='${MAGEFILE}'" + # if no install candidate was found, record this # and process with the next one if [[ -z ${MAGEFILE} ]] then NO_UPGRADE_CANDIDATE="${NO_UPGRADE_CANDIDATE} ${PCAT}/${PNAME}" + decho "added to NO_UPGRADE_CANDIDATE" continue fi @@ -237,6 +287,10 @@ PVER="$(magename2pver ${MAGEFILE})" PBUILD="$(magename2pbuild ${MAGEFILE})" + # debug info + decho "PVER='${PVER}'" + decho "PBUILD='${PBUILD}'" + # do not walk files which are installed if [ ! -d ${INSTALLDB}/${PCAT}/${PNAME}-${PVER}-${PBUILD} ] then @@ -245,25 +299,48 @@ # now add the package itself to the dependencies # (if not exists already) - #if [ -z "$(echo ${ALLDEPS} | fgrep "${MAGEFILE}")" ] if checklist_alldeps "${MAGEFILE}" then + decho "added '${MAGEFILE}' to ALLDEPS" ALLDEPS="${ALLDEPS} ${MAGEFILE}" fi + else + # debug info + decho "ignored package" + decho fi done else # get all dependencies of the package - depwalking ${MAGEFILE} + if [[ -n ${SMAGEFILE} ]] + then + depwalking "${SMAGEFILE}" + else + depwalking "${MAGEFILE}" + fi +fi +if [[ ${METHOD} != install-build-prerequisites ]] && + [[ ${METHOD} != pretend-build-prerequisites ]] && + [[ ${METHOD} != upgrade ]] && + [[ ${METHOD} != uppretend ]] && + [[ ${METHOD} != srcupgrade ]] && + [[ ${METHOD} != srcuppretend ]] +then # now add the package itself to the dependencies - ALLDEPS="${ALLDEPS} ${MAGEFILE}" + # (if not exists already) + if checklist_alldeps "${MAGEFILE}" + then + decho "added '${MAGEFILE}' to ALLDEPS" + ALLDEPS="${ALLDEPS} ${MAGEFILE}" + fi fi [[ ${METHOD} = pretend ]] || \ [[ ${METHOD} = srcpretend ]] || \ [[ ${METHOD} = uppretend ]] || \ - [[ ${METHOD} = srcuppretend ]] && \ + [[ ${METHOD} = srcuppretend ]] || \ + [[ ${METHOD} = pretend-build-prerequisites ]] && \ echo "done" @@ -271,7 +348,8 @@ if [[ ${METHOD} = pretend ]] || \ [[ ${METHOD} = srcpretend ]] || \ [[ ${METHOD} = uppretend ]] || \ - [[ ${METHOD} = srcuppretend ]] + [[ ${METHOD} = srcuppretend ]] || \ + [[ ${METHOD} = pretend-build-prerequisites ]] then # this is a little bit faster declare -i x=0 @@ -288,7 +366,7 @@ PBUILD="$(magename2pbuild ${i})" if [ -z "${list}" ] then - list="\t${COLBLUE}[${k}] ${COLGREEN}${PCAT}/${PNAME}-${PVER}-${PBUILD}${COLDEFAULT}" + list="\t${COLBLUE}[${k}] ${COLGREEN}${PCAT}/${PNAME}-${PVER}-${PBUILD}${COLDEFAULT}" else list="${list} \t${COLBLUE}[${k}] ${COLGREEN}${PCAT}/${PNAME}-${PVER}-${PBUILD}${COLDEFAULT}" @@ -299,6 +377,18 @@ echo -e "${list}" echo + if [[ ! -z ${INVALID_DEPS} ]] + then + echo -e "${COLRED}Invalid dependencies found:${COLDEFAULT}" + for i in ${INVALID_DEPS} + do + _dep="${i%%:*}" + _mage="${i##*:}" + echo -e "${COLRED} '${_dep}' -> '${_mage}'${COLDEFAULT}" + done + echo + fi + if [[ ! -z ${NO_UPGRADE_CANDIDATE} ]] then echo -e "${COLRED}Currently no candidates found for:${COLDEFAULT}" @@ -318,5 +408,6 @@ [[ ${METHOD} = install ]] || \ [[ ${METHOD} = srcinstall ]] || \ [[ ${METHOD} = upgrade ]] || \ - [[ ${METHOD} = srcupgrade ]] && \ + [[ ${METHOD} = srcupgrade ]] || \ + [[ ${METHOD} = install-build-prerequisites ]] && \ echo "${ALLDEPS}"