Magellan Linux

Diff of /trunk/mage/usr/lib/mage/depwalker.sh

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2281 by niro, Wed Nov 20 12:21:28 2013 UTC revision 2840 by niro, Fri Oct 24 08:23:22 2014 UTC
# Line 1  Line 1 
1  #!/bin/bash  #!/bin/bash
2  # $Id$  # $Id$
3  # dependeny walker  # dependency walker
4    
5  # default die function  # default die function
6  die()  die()
# Line 9  die() Line 9  die()
9   exit 1   exit 1
10  }  }
11    
12    decho()
13    {
14     if [[ ${DEBUG} = 1 ]]
15     then
16     echo "DEBUG: $@" >&2
17     fi
18    }
19    
20  # include all needed files  # include all needed files
21  [ -f /etc/mage.rc.global ] &&  \  [ -f /etc/mage.rc.global ] &&  \
22   source /etc/mage.rc.global || \   source /etc/mage.rc.global || \
# Line 21  die() Line 29  die()
29   source ${MLIBDIR}/mage4.functions.sh || \   source ${MLIBDIR}/mage4.functions.sh || \
30   die "mage functions missing"   die "mage functions missing"
31    
32    [ -f ${MLIBDIR}/smage2.functions.sh ] && \
33     source ${MLIBDIR}/smage2.functions.sh || \
34     die "smage functions missing"
35    
36  usage()  usage()
37  {  {
38   echo   echo
# Line 32  usage() Line 44  usage()
44   echo "  -v     --pver          version number of the package"   echo "  -v     --pver          version number of the package"
45   echo "  -b     --pbuild        build number of the package"   echo "  -b     --pbuild        build number of the package"
46   echo "  -m     --method        which calc method should be used:"   echo "  -m     --method        which calc method should be used:"
47   echo "                         install, srcinstall, depend, srcdepend"   echo "                         install, srcinstall, pretend, srcpretend"
48   echo "                         upgrade, srcupgrade,"   echo "                         upgrade, srcupgrade,"
49   echo "                         install-build-prerequisites,"   echo "                         install-build-prerequisites,"
50   echo "                         pretend-build-prerequisites"   echo "                         pretend-build-prerequisites"
51     echo "                         install-deep-build-prerequisites,"
52     echo "                         pretend-deep-build-prerequisites"
53   echo "  -d     --debug         enable debug mode"   echo "  -d     --debug         enable debug mode"
54     echo "  -s     --smage         use a smage to calculate dependencies"
55   echo   echo
56   echo "method, category, name, version and build must be given !"   echo "method, category, name, version and build must be given !"
57   echo   echo
58   exit 1   exit 1
59  }  }
60    
61  # always default debug=0  # set some sane defaults
62  DEBUG=0  DEBUG=0
63    SMAGE_DEPEND=0
64    SDEPEND_ONETIME=0
65    
66  # very basic getops  # very basic getops
67  for i in $*  for i in $*
# Line 56  do Line 73  do
73   --pbuild|-b) shift; PBUILD="$1" ;;   --pbuild|-b) shift; PBUILD="$1" ;;
74   --method|-m) shift; METHOD="$1" ;;   --method|-m) shift; METHOD="$1" ;;
75   --debug|-d) shift; DEBUG=1 ;;   --debug|-d) shift; DEBUG=1 ;;
76     --smage|-s) shift; SMAGEFILE="$1"; SMAGE_DEPEND=1; SILENT=1; FVERBOSE=off ;;
77   --help|-h) usage ;;   --help|-h) usage ;;
78   esac   esac
79   shift   shift
80  done  done
81    
82  # sanity checks; abort if not given  # sanity checks; abort if not given
83  [ -z "${PCAT}" ] && usage  if [[ -z ${SMAGEFILE} ]]
84  [ -z "${PNAME}" ] && usage  then
85  [ -z "${PVER}" ] && usage   [ -z "${PCAT}" ] && usage
86  [ -z "${PBUILD}" ] && usage   [ -z "${PNAME}" ] && usage
87     [ -z "${PVER}" ] && usage
88     [ -z "${PBUILD}" ] && usage
89    fi
90  [ -z "${METHOD}" ] && usage  [ -z "${METHOD}" ] && usage
91    
92  # check needed global vars  # check needed global vars
# Line 73  done Line 94  done
94  [ -z "${INSTALLDB}" ] && die "\$INSTALLDB not set."  [ -z "${INSTALLDB}" ] && die "\$INSTALLDB not set."
95  [ -z "${BUILDDIR}" ] && die "\$BUILDDIR not set."  [ -z "${BUILDDIR}" ] && die "\$BUILDDIR not set."
96    
97    # load mage-features to support them with smagesource()
98    load_mage_features
99    
100  # other needed vars  # other needed vars
101  ALLDEPS=""  ALLDEPS=""
102    if [[ -n ${SMAGEFILE} ]]
103    then
104     if [[ -e ${SMAGEFILE} ]]
105     then
106     smagesource "${SMAGEFILE}"
107     else
108     die "Smage file '${SMAGEFILE}' does not exist!"
109     fi
110    fi
111  MAGEFILE="${MAGEDIR}/${PCAT}/${PNAME}/${PNAME}-${PVER}-${PBUILD}.mage"  MAGEFILE="${MAGEDIR}/${PCAT}/${PNAME}/${PNAME}-${PVER}-${PBUILD}.mage"
112    
113  # much faster than fgrep  # much faster than fgrep
# Line 127  depwalking() Line 160  depwalking()
160    
161   DFILE="$1"   DFILE="$1"
162    
163   if [[ ${DEBUG} = 1 ]]   # debug info
164   then   decho "depwalking magefile '${DFILE}'"
165   echo "DEBUG: depwalking magefile '${DFILE}'" >&2   decho
  echo >&2  
  fi  
166    
167   source ${DFILE}   source ${DFILE}
168    
# Line 145  depwalking() Line 176  depwalking()
176   MY_DEPEND="${DEPEND}"   MY_DEPEND="${DEPEND}"
177    
178   # for srcinstall & srcdepend only; SDEPEND also needed   # for srcinstall & srcdepend only; SDEPEND also needed
179   if [[ ${METHOD} = srcinstall ]] || \   if [[ ${METHOD} = srcinstall ]] ||
180   [[ ${METHOD} = srcpretend ]] || \   [[ ${METHOD} = srcpretend ]] ||
181   [[ ${METHOD} = srcupgrade ]] || \   [[ ${METHOD} = srcupgrade ]] ||
182   [[ ${METHOD} = srcuppretend ]]   [[ ${METHOD} = srcuppretend ]] ||
183     [[ ${METHOD} = install-deep-build-prerequisites ]] ||
184     [[ ${METHOD} = pretend-deep-build-prerequisites ]]
185   then   then
186   # only if SDEPEND is not zero   # only if SDEPEND is not zero
187   if [ -n "${SDEPEND}" ]   if [ -n "${SDEPEND}" ]
# Line 164  depwalking() Line 197  depwalking()
197   fi   fi
198   fi   fi
199    
200   if [[ ${METHOD} = install-build-prerequisites ]] || \   # add sdepend for the smage/mage file only for the first time
201     # to catch sdepend only from the target
202     if [[ ${METHOD} = install-build-prerequisites ]] ||
203   [[ ${METHOD} = pretend-build-prerequisites ]]   [[ ${METHOD} = pretend-build-prerequisites ]]
204   then   then
205   # only one time   if [[ ${SDEPEND_ONETIME} = 0 ]]
  if [[ ${LOOP_COUNTER} -lt 1 ]]  
206   then   then
207   # only if SDEPEND is not zero   # only if SDEPEND is not zero
208   if [ -n "${SDEPEND}" ]   if [ -n "${SDEPEND}" ]
# Line 182  depwalking() Line 216  depwalking()
216   MY_DEPEND="${SDEPEND}"   MY_DEPEND="${SDEPEND}"
217   fi   fi
218   fi   fi
219     SDEPEND_ONETIME=1
220   fi   fi
  LOOP_COUNTER=${LOOP_COUNTER}+1  
221   fi   fi
222    
223   unset DEPEND   unset DEPEND
# Line 191  depwalking() Line 225  depwalking()
225    
226   if [ -z "${MY_DEPEND}" ]   if [ -z "${MY_DEPEND}" ]
227   then   then
228   if [[ ${DEBUG} = 1 ]]   decho "MY_DEPEND is empty; deps of '${DFILE}' ignored"
  then  
  echo "DEBUG: MY_DEPEND is empty; deps of '${DFILE}' ignored" >&2  
  fi  
229   return 1   return 1
230   fi   fi
231    
232   while read SYM DEPNAME   while read SYM DEPNAME
233   do   do
234   if [[ ${DEBUG} = 1 ]]   # debug info
235   then   decho "DEPNAME='${DEPNAME}'"
  echo "DEBUG: DEPNAME='${DEPNAME}'" >&2  
  fi  
236    
237   # exclude empty depnames   # exclude empty depnames
238   [[ -z ${DEPNAME} ]] && continue   [[ -z ${DEPNAME} ]] && continue
# Line 216  depwalking() Line 245  depwalking()
245    
246   # mark depfile as processed to prevent double runs -without version   # mark depfile as processed to prevent double runs -without version
247   # but do not add any virtuals to PROCESSEDDEPS or their resolved   # but do not add any virtuals to PROCESSEDDEPS or their resolved
248   # pkgnames will be ignored and they are missing on the dependecy-list   # pkgnames will be ignored and they are missing on the dependency-list
249   if [[ ${DEPNAME/virtual\//} = ${DEPNAME} ]]   if [[ ${DEPNAME/virtual\//} = ${DEPNAME} ]]
250   then   then
251   PROCESSEDDEPS="${PROCESSEDDEPS} ${DEPNAME%-*}"   PROCESSEDDEPS="${PROCESSEDDEPS} ${DEPNAME%-*}"
# Line 243  depwalking() Line 272  depwalking()
272   ### check if the dependency is already installed ###   ### check if the dependency is already installed ###
273   if [ ! -d ${MROOT}${INSTALLDB}/${PCAT}/${PNAME}-${PVER}-${PBUILD} ]   if [ ! -d ${MROOT}${INSTALLDB}/${PCAT}/${PNAME}-${PVER}-${PBUILD} ]
274   then   then
275     # but first get all deps of highest_depfile to catch all dependencies of it
276   depwalking ${HIGHEST_DEPFILE}   depwalking ${HIGHEST_DEPFILE}
277   ALLDEPS="${ALLDEPS} ${HIGHEST_DEPFILE}"   ALLDEPS="${ALLDEPS} ${HIGHEST_DEPFILE}"
278   if [[ ${DEBUG} = 1 ]]   decho "added '${HIGHEST_DEPFILE}' to ALLDEPS"
  then  
  echo "DEBUG: added '${HIGHEST_DEPFILE}' to ALLDEPS" >&2  
  fi  
279   fi   fi
280   fi   fi
281   done << EOF   done << EOF
# Line 279  then Line 306  then
306   # get the highest mage file from mage-db   # get the highest mage file from mage-db
307   MAGEFILE="$(get_highest_magefile ${PCAT} ${PNAME})"   MAGEFILE="$(get_highest_magefile ${PCAT} ${PNAME})"
308    
309   if [[ ${DEBUG} = 1 ]]   # debug info
310   then   decho "dep='${dep}'"
311   echo "DEBUG: dep='${dep}'" >&2   decho "PCAT='${PCAT}'"
312   echo "DEBUG: PCAT='${PCAT}'" >&2   decho "PNAME='${PNAME}'"
313   echo "DEBUG: PNAME='${PNAME}'" >&2   decho "MAGEFILE='${MAGEFILE}'"
  echo "DEBUG: MAGEFILE='${MAGEFILE}'" >&2  
  fi  
314    
315   # if no install candidate was found, record this   # if no install candidate was found, record this
316   # and process with the next one   # and process with the next one
317   if [[ -z ${MAGEFILE} ]]   if [[ -z ${MAGEFILE} ]]
318   then   then
319   NO_UPGRADE_CANDIDATE="${NO_UPGRADE_CANDIDATE} ${PCAT}/${PNAME}"   NO_UPGRADE_CANDIDATE="${NO_UPGRADE_CANDIDATE} ${PCAT}/${PNAME}"
320   if [[ ${DEBUG} = 1 ]]   decho "added to NO_UPGRADE_CANDIDATE"
  then  
  echo "DEBUG: added to NO_UPGRADE_CANDIDATE" >&2  
  fi  
321   continue   continue
322   fi   fi
323    
# Line 303  then Line 325  then
325   PVER="$(magename2pver ${MAGEFILE})"   PVER="$(magename2pver ${MAGEFILE})"
326   PBUILD="$(magename2pbuild ${MAGEFILE})"   PBUILD="$(magename2pbuild ${MAGEFILE})"
327    
328   if [[ ${DEBUG} = 1 ]]   # debug info
329   then   decho "PVER='${PVER}'"
330   echo "DEBUG: PVER='${PVER}'" >&2   decho "PBUILD='${PBUILD}'"
  echo "DEBUG: PBUILD='${PBUILD}'" >&2  
  fi  
331    
332   # do not walk files which are installed   # do not walk files which are installed
333   if [ ! -d ${INSTALLDB}/${PCAT}/${PNAME}-${PVER}-${PBUILD} ]   if [ ! -d ${INSTALLDB}/${PCAT}/${PNAME}-${PVER}-${PBUILD} ]
# Line 319  then Line 339  then
339   # (if not exists already)   # (if not exists already)
340   if checklist_alldeps "${MAGEFILE}"   if checklist_alldeps "${MAGEFILE}"
341   then   then
342   if [[ ${DEBUG} = 1 ]]   decho "added '${MAGEFILE}' to ALLDEPS"
  then  
  echo "DEBUG: added '${MAGEFILE}' to ALLDEPS" >&2  
  fi  
343   ALLDEPS="${ALLDEPS} ${MAGEFILE}"   ALLDEPS="${ALLDEPS} ${MAGEFILE}"
344   fi   fi
345   else   else
346   if [[ ${DEBUG} = 1 ]]   # debug info
347   then   decho "ignored package"
348   echo "DEBUG: ignored package" >&2   decho
  echo >&2  
  fi  
349   fi   fi
350   done   done
351  else  else
  LOOP_COUNTER=0  
352   # get all dependencies of the package   # get all dependencies of the package
353   depwalking ${MAGEFILE}   if [[ -n ${SMAGEFILE} ]]
354     then
355     depwalking "${SMAGEFILE}"
356     else
357     depwalking "${MAGEFILE}"
358     fi
359  fi  fi
360    
361  if [[ ${METHOD} != install-build-prerequisites ]] &&  if [[ ${METHOD} != install-build-prerequisites ]] &&
362   [[ ${METHOD} != pretend-build-prerequisites ]] &&   [[ ${METHOD} != pretend-build-prerequisites ]] &&
363     [[ ${METHOD} != install-deep-build-prerequisites ]] &&
364     [[ ${METHOD} != pretend-deep-build-prerequisites ]] &&
365   [[ ${METHOD} != upgrade ]] &&   [[ ${METHOD} != upgrade ]] &&
366   [[ ${METHOD} != uppretend ]] &&   [[ ${METHOD} != uppretend ]] &&
367   [[ ${METHOD} != srcupgrade ]] &&   [[ ${METHOD} != srcupgrade ]] &&
# Line 350  then Line 371  then
371   # (if not exists already)   # (if not exists already)
372   if checklist_alldeps "${MAGEFILE}"   if checklist_alldeps "${MAGEFILE}"
373   then   then
374   if [[ ${DEBUG} = 1 ]]   decho "added '${MAGEFILE}' to ALLDEPS"
  then  
  echo "DEBUG: added '${MAGEFILE}' to ALLDEPS" >&2  
  fi  
375   ALLDEPS="${ALLDEPS} ${MAGEFILE}"   ALLDEPS="${ALLDEPS} ${MAGEFILE}"
376   fi   fi
377  fi  fi
# Line 362  fi Line 380  fi
380   [[ ${METHOD} = srcpretend ]] || \   [[ ${METHOD} = srcpretend ]] || \
381   [[ ${METHOD} = uppretend ]] || \   [[ ${METHOD} = uppretend ]] || \
382   [[ ${METHOD} = srcuppretend ]] || \   [[ ${METHOD} = srcuppretend ]] || \
383   [[ ${METHOD} = pretend-build-prerequisites ]] && \   [[ ${METHOD} = pretend-build-prerequisites ]] || \
384     [[ ${METHOD} = pretend-deep-build-prerequisites ]] && \
385   echo "done"   echo "done"
386    
387    
# Line 371  if [[ ${METHOD} = pretend ]] || \ Line 390  if [[ ${METHOD} = pretend ]] || \
390   [[ ${METHOD} = srcpretend ]] || \   [[ ${METHOD} = srcpretend ]] || \
391   [[ ${METHOD} = uppretend ]] || \   [[ ${METHOD} = uppretend ]] || \
392   [[ ${METHOD} = srcuppretend ]] || \   [[ ${METHOD} = srcuppretend ]] || \
393   [[ ${METHOD} = pretend-build-prerequisites ]]   [[ ${METHOD} = pretend-build-prerequisites ]] || \
394     [[ ${METHOD} = pretend-deep-build-prerequisites ]]
395  then  then
396   # this is a little bit faster   # this is a little bit faster
397   declare -i x=0   declare -i x=0
# Line 431  fi Line 451  fi
451   [[ ${METHOD} = srcinstall ]] || \   [[ ${METHOD} = srcinstall ]] || \
452   [[ ${METHOD} = upgrade ]] || \   [[ ${METHOD} = upgrade ]] || \
453   [[ ${METHOD} = srcupgrade ]] || \   [[ ${METHOD} = srcupgrade ]] || \
454   [[ ${METHOD} = install-build-prerequisites ]] && \   [[ ${METHOD} = install-build-prerequisites ]] || \
455     [[ ${METHOD} = install-deep-build-prerequisites ]] && \
456   echo "${ALLDEPS}"   echo "${ALLDEPS}"

Legend:
Removed from v.2281  
changed lines
  Added in v.2840