--- trunk/mage/usr/lib/mage/depwalker.sh 2013/10/16 07:40:02 2221 +++ branches/mage-next/src/depwalker.in 2014/03/05 08:15:28 2625 @@ -9,17 +9,19 @@ exit 1 } +decho() +{ + 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" +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" usage() { @@ -27,17 +29,19 @@ 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 " -d --debug enable debug mode" - echo " install, srcinstall, depend, srcdepend" + echo " install, srcinstall, pretend, srcpretend" echo " upgrade, srcupgrade," - echo " install-build-prerequisites, pretend-build-prerequisites" + 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 } @@ -55,16 +59,20 @@ --pbuild|-b) shift; PBUILD="$1" ;; --method|-m) shift; METHOD="$1" ;; --debug|-d) shift; DEBUG=1 ;; + --smage|-s) shift; SMAGEFILE="$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 @@ -74,6 +82,15 @@ # 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 @@ -126,6 +143,10 @@ DFILE="$1" + # debug info + decho "depwalking magefile '${DFILE}'" + decho + source ${DFILE} # forced nodeps @@ -138,10 +159,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}" ] @@ -157,42 +180,19 @@ fi fi - if [[ ${METHOD} = install-build-prerequisites ]] || \ - [[ ${METHOD} = pretend-build-prerequisites ]] - then - # only one time - if [[ ${LOOP_COUNTER} -lt 1 ]] - then - # only if SDEPEND is not zero - if [ -n "${SDEPEND}" ] - then - # crlf is substantly needed !! - if [ -n "${MY_DEPEND}" ] - then - MY_DEPEND="${MY_DEPEND} - ${SDEPEND}" - else - MY_DEPEND="${SDEPEND}" - fi - fi - fi - LOOP_COUNTER=${LOOP_COUNTER}+1 - fi - unset DEPEND unset SDEPEND if [ -z "${MY_DEPEND}" ] then + decho "MY_DEPEND is empty; deps of '${DFILE}' ignored" return 1 fi while read SYM DEPNAME do - if [[ ${DEBUG} = 1 ]] - then - echo "DEBUG: DEPNAME='${DEPNAME}'" >&2 - fi + # debug info + decho "DEPNAME='${DEPNAME}'" # exclude empty depnames [[ -z ${DEPNAME} ]] && continue @@ -234,6 +234,7 @@ then depwalking ${HIGHEST_DEPFILE} ALLDEPS="${ALLDEPS} ${HIGHEST_DEPFILE}" + decho "added '${HIGHEST_DEPFILE}' to ALLDEPS" fi fi done << EOF @@ -264,11 +265,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 @@ -276,26 +284,51 @@ 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 # get dependencies the package depwalking ${MAGEFILE} + + # now add the package itself to the dependencies + # (if not exists already) + if checklist_alldeps "${MAGEFILE}" + then + decho "added '${MAGEFILE}' to ALLDEPS" + ALLDEPS="${ALLDEPS} ${MAGEFILE}" + fi + else + # debug info + decho "ignored package" + decho fi done else - LOOP_COUNTER=0 # 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} != pretend-build-prerequisites ]] && + [[ ${METHOD} != upgrade ]] && + [[ ${METHOD} != uppretend ]] && + [[ ${METHOD} != srcupgrade ]] && + [[ ${METHOD} != srcuppretend ]] then # now add the package itself to the dependencies # (if not exists already) if checklist_alldeps "${MAGEFILE}" then + decho "added '${MAGEFILE}' to ALLDEPS" ALLDEPS="${ALLDEPS} ${MAGEFILE}" fi fi