Magellan Linux

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

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

revision 2220 by niro, Wed Oct 16 06:52:01 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
39   echo "Usage: $(basename $0) [command] [arg] ..."   echo "Usage: $(basename $0) [command] [arg] ..."
40   echo   echo
41   echo "  -h     --help          shows this help"   echo "  -h     --help          shows this help"
42   echo "  -c     --pcat          categorie of the package"   echo "  -c     --pcat          category of the package"
43   echo "  -n     --pname         name of the package"   echo "  -n     --pname         name of the package"
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, pretend-build-prerequisites"   echo "                         install-build-prerequisites,"
50     echo "                         pretend-build-prerequisites"
51     echo "                         install-deep-build-prerequisites,"
52     echo "                         pretend-deep-build-prerequisites"
53     echo "  -d     --debug         enable debug mode"
54     echo "  -s     --smage         use a smage to calculate dependencies"
55   echo   echo
56   echo "method, 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    # set some sane defaults
62    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 $*
68  do  do
# Line 50  do Line 72  do
72   --pver|-v) shift; PVER="$1" ;;   --pver|-v) shift; PVER="$1" ;;
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 ;;
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 67  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 121  depwalking() Line 160  depwalking()
160    
161   DFILE="$1"   DFILE="$1"
162    
163     # debug info
164     decho "depwalking magefile '${DFILE}'"
165     decho
166    
167   source ${DFILE}   source ${DFILE}
168    
169   # forced nodeps   # forced nodeps
# Line 133  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 152  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 170  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 179  depwalking() Line 225  depwalking()
225    
226   if [ -z "${MY_DEPEND}" ]   if [ -z "${MY_DEPEND}" ]
227   then   then
228     decho "MY_DEPEND is empty; deps of '${DFILE}' ignored"
229   return 1   return 1
230   fi   fi
231    
232   while read SYM DEPNAME   while read SYM DEPNAME
233   do   do
234     # debug info
235     decho "DEPNAME='${DEPNAME}'"
236    
237   # exclude empty depnames   # exclude empty depnames
238   [[ -z ${DEPNAME} ]] && continue   [[ -z ${DEPNAME} ]] && continue
239    
# Line 195  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 222  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     decho "added '${HIGHEST_DEPFILE}' to ALLDEPS"
279   fi   fi
280   fi   fi
281   done << EOF   done << EOF
# Line 254  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     # debug info
310     decho "dep='${dep}'"
311     decho "PCAT='${PCAT}'"
312     decho "PNAME='${PNAME}'"
313     decho "MAGEFILE='${MAGEFILE}'"
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     decho "added to NO_UPGRADE_CANDIDATE"
321   continue   continue
322   fi   fi
323    
# Line 266  then Line 325  then
325   PVER="$(magename2pver ${MAGEFILE})"   PVER="$(magename2pver ${MAGEFILE})"
326   PBUILD="$(magename2pbuild ${MAGEFILE})"   PBUILD="$(magename2pbuild ${MAGEFILE})"
327    
328     # debug info
329     decho "PVER='${PVER}'"
330     decho "PBUILD='${PBUILD}'"
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} ]
334   then   then
335   # get dependencies the package   # get dependencies the package
336   depwalking ${MAGEFILE}   depwalking ${MAGEFILE}
337    
338     # now add the package itself to the dependencies
339     # (if not exists already)
340     if checklist_alldeps "${MAGEFILE}"
341     then
342     decho "added '${MAGEFILE}' to ALLDEPS"
343     ALLDEPS="${ALLDEPS} ${MAGEFILE}"
344     fi
345     else
346     # debug info
347     decho "ignored package"
348     decho
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 ]] &&
366     [[ ${METHOD} != uppretend ]] &&
367     [[ ${METHOD} != srcupgrade ]] &&
368     [[ ${METHOD} != srcuppretend ]]
369  then  then
370   # now add the package itself to the dependencies   # now add the package itself to the dependencies
371   # (if not exists already)   # (if not exists already)
372   if checklist_alldeps "${MAGEFILE}"   if checklist_alldeps "${MAGEFILE}"
373   then   then
374     decho "added '${MAGEFILE}' to ALLDEPS"
375   ALLDEPS="${ALLDEPS} ${MAGEFILE}"   ALLDEPS="${ALLDEPS} ${MAGEFILE}"
376   fi   fi
377  fi  fi
# Line 294  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 303  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 363  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.2220  
changed lines
  Added in v.2840