Magellan Linux

Annotation of /branches/mage-next/src/depwalker.in

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2841 - (hide annotations) (download)
Fri Oct 24 08:24:16 2014 UTC (9 years, 6 months ago) by niro
File size: 10854 byte(s)
-support deep and simple build-prerequisites, which reduces the overhead as they only respect the sdepend of the target mage/smagefile and not from all deps
1 niro 226 #!/bin/bash
2 niro 1559 # $Id$
3 niro 2829 # dependency walker
4 niro 226
5 niro 2627 # set default variables
6     : ${MAGERC="@@SYSCONFDIR@@/mage.rc"}
7     : ${MLIBDIR="@@MAGELIBDIR@@"}
8    
9 niro 2626 # first of all include common functions
10     source ${MLIBDIR}/common.functions.sh || exit 1
11 niro 2625 source @@SYSCONFDIR@@/mage.rc.global || die "@@SYSCONFDIR@@/mage.rc.global missing"
12     source ${MAGERC} || die "Your ${MAGERC} is missing. Aborting."
13     source ${MLIBDIR}/mage4.functions.sh || die "mage functions missing"
14     source ${MLIBDIR}/smage2.functions.sh || die "smage functions missing"
15 niro 226
16 niro 2628 decho()
17     {
18     if [[ ${DEBUG} = 1 ]]
19     then
20     echo "DEBUG: $@" >&2
21     fi
22     }
23    
24 niro 226 usage()
25     {
26     echo
27     echo "Usage: $(basename $0) [command] [arg] ..."
28     echo
29     echo " -h --help shows this help"
30 niro 2275 echo " -c --pcat category of the package"
31 niro 226 echo " -n --pname name of the package"
32     echo " -v --pver version number of the package"
33     echo " -b --pbuild build number of the package"
34     echo " -m --method which calc method should be used:"
35 niro 2359 echo " install, srcinstall, pretend, srcpretend"
36 niro 2210 echo " upgrade, srcupgrade,"
37 niro 2274 echo " install-build-prerequisites,"
38     echo " pretend-build-prerequisites"
39 niro 2841 echo " install-deep-build-prerequisites,"
40     echo " pretend-deep-build-prerequisites"
41 niro 2269 echo " -d --debug enable debug mode"
42 niro 2360 echo " -s --smage use a smage to calculate dependencies"
43 niro 226 echo
44 niro 2276 echo "method, category, name, version and build must be given !"
45 niro 226 echo
46     exit 1
47     }
48    
49 niro 2832 # set some sane defaults
50 niro 2221 DEBUG=0
51 niro 2832 SMAGE_DEPEND=0
52 niro 2841 SDEPEND_ONETIME=0
53 niro 2221
54 niro 226 # very basic getops
55     for i in $*
56     do
57     case $1 in
58     --pcat|-c) shift; PCAT="$1" ;;
59     --pname|-n) shift; PNAME="$1" ;;
60     --pver|-v) shift; PVER="$1" ;;
61     --pbuild|-b) shift; PBUILD="$1" ;;
62     --method|-m) shift; METHOD="$1" ;;
63 niro 2221 --debug|-d) shift; DEBUG=1 ;;
64 niro 2832 --smage|-s) shift; SMAGEFILE="$1"; SMAGE_DEPEND=1; SILENT=1; FVERBOSE=off ;;
65 niro 226 --help|-h) usage ;;
66     esac
67     shift
68     done
69    
70     # sanity checks; abort if not given
71 niro 2360 if [[ -z ${SMAGEFILE} ]]
72     then
73     [ -z "${PCAT}" ] && usage
74     [ -z "${PNAME}" ] && usage
75     [ -z "${PVER}" ] && usage
76     [ -z "${PBUILD}" ] && usage
77     fi
78 niro 226 [ -z "${METHOD}" ] && usage
79    
80     # check needed global vars
81     [ -z "${MAGEDIR}" ] && die "\$MAGEDIR not set."
82     [ -z "${INSTALLDB}" ] && die "\$INSTALLDB not set."
83     [ -z "${BUILDDIR}" ] && die "\$BUILDDIR not set."
84    
85 niro 2839 # load mage-features to support them with smagesource()
86     load_mage_features
87    
88 niro 226 # other needed vars
89     ALLDEPS=""
90 niro 2360 if [[ -n ${SMAGEFILE} ]]
91     then
92     if [[ -e ${SMAGEFILE} ]]
93     then
94     smagesource "${SMAGEFILE}"
95     else
96     die "Smage file '${SMAGEFILE}' does not exist!"
97     fi
98     fi
99 niro 226 MAGEFILE="${MAGEDIR}/${PCAT}/${PNAME}/${PNAME}-${PVER}-${PBUILD}.mage"
100    
101 niro 598 # much faster than fgrep
102     checklist_alldeps()
103     {
104     local i
105     local item="$1"
106    
107     for i in ${ALLDEPS}
108     do
109     [[ ${i} = ${item} ]] && return 1
110     done
111    
112     return 0
113     }
114    
115 niro 654 checklist_processeddeps()
116     {
117     local i
118     local item="$1"
119    
120     for i in ${PROCESSEDDEPS}
121     do
122     [[ ${i} = ${item} ]] && return 1
123     done
124    
125     return 0
126     }
127    
128 niro 226 #####################
129 niro 1563 ## depwalking /path/to/mage/file/.mage
130     depwalking()
131 niro 226 {
132     unset DEPEND
133     unset SDEPEND
134     unset MY_DEPEND
135    
136     local DFILE
137     local SYM
138     local DEPNAME
139     local HIGHEST_DEPFILE
140     local MY_DEPEND
141     local REAL_PGKNAME
142     local VIRTUAL_NAME
143     local INSTALL_VIRTUAL
144     local PNAME
145     local PCAT
146 niro 250 local PVER
147     local PBUILD
148 niro 226
149     DFILE="$1"
150    
151 niro 2285 # debug info
152     decho "depwalking magefile '${DFILE}'"
153     decho
154 niro 2281
155 niro 226 source ${DFILE}
156 niro 778
157     # forced nodeps
158     if [[ ${NODEPS} = true ]]
159     then
160     DEPEND=""
161     SDEPEND=""
162     fi
163    
164 niro 226 MY_DEPEND="${DEPEND}"
165    
166     # for srcinstall & srcdepend only; SDEPEND also needed
167 niro 2286 if [[ ${METHOD} = srcinstall ]] ||
168     [[ ${METHOD} = srcpretend ]] ||
169     [[ ${METHOD} = srcupgrade ]] ||
170     [[ ${METHOD} = srcuppretend ]] ||
171 niro 2841 [[ ${METHOD} = install-deep-build-prerequisites ]] ||
172     [[ ${METHOD} = pretend-deep-build-prerequisites ]]
173 niro 226 then
174     # only if SDEPEND is not zero
175     if [ -n "${SDEPEND}" ]
176     then
177     # crlf is substantly needed !!
178     if [ -n "${MY_DEPEND}" ]
179     then
180     MY_DEPEND="${MY_DEPEND}
181     ${SDEPEND}"
182     else
183     MY_DEPEND="${SDEPEND}"
184     fi
185     fi
186     fi
187    
188 niro 2841 # add sdepend for the smage/mage file only for the first time
189     # to catch sdepend only from the target
190     if [[ ${METHOD} = install-build-prerequisites ]] ||
191     [[ ${METHOD} = pretend-build-prerequisites ]]
192     then
193     if [[ ${SDEPEND_ONETIME} = 0 ]]
194     then
195     # only if SDEPEND is not zero
196     if [ -n "${SDEPEND}" ]
197     then
198     # crlf is substantly needed !!
199     if [ -n "${MY_DEPEND}" ]
200     then
201     MY_DEPEND="${MY_DEPEND}
202     ${SDEPEND}"
203     else
204     MY_DEPEND="${SDEPEND}"
205     fi
206     fi
207     SDEPEND_ONETIME=1
208     fi
209     fi
210    
211 niro 226 unset DEPEND
212     unset SDEPEND
213    
214     if [ -z "${MY_DEPEND}" ]
215     then
216 niro 2285 decho "MY_DEPEND is empty; deps of '${DFILE}' ignored"
217 niro 226 return 1
218     fi
219    
220     while read SYM DEPNAME
221     do
222 niro 2285 # debug info
223     decho "DEPNAME='${DEPNAME}'"
224 niro 2221
225 niro 656 # exclude empty depnames
226     [[ -z ${DEPNAME} ]] && continue
227    
228 niro 654 # exclude all already processed deps -without version
229     if ! checklist_processeddeps "${DEPNAME%-*}"
230     then
231     continue
232     fi
233    
234     # mark depfile as processed to prevent double runs -without version
235 niro 677 # but do not add any virtuals to PROCESSEDDEPS or their resolved
236 niro 2737 # pkgnames will be ignored and they are missing on the dependency-list
237 niro 677 if [[ ${DEPNAME/virtual\//} = ${DEPNAME} ]]
238     then
239     PROCESSEDDEPS="${PROCESSEDDEPS} ${DEPNAME%-*}"
240     fi
241 niro 654
242 niro 226 HIGHEST_DEPFILE=$(dep2highest_magefile "${DEPNAME}")
243 niro 2141 if [[ -z ${HIGHEST_DEPFILE} ]]
244     then
245     INVALID_DEPS+=" ${DEPNAME}:${DFILE}"
246     continue
247     fi
248 niro 226
249     PCAT="$(magename2pcat ${HIGHEST_DEPFILE})"
250     PNAME="$(magename2pname ${HIGHEST_DEPFILE})"
251     PVER="$(magename2pver ${HIGHEST_DEPFILE})"
252     PBUILD="$(magename2pbuild ${HIGHEST_DEPFILE})"
253    
254 niro 1562 ## dep already in ALLDEPS? then going on
255 niro 598
256     # usage of fgrep is extremly slow and consumes a lot of cpu power
257     #if [ -z "$(echo ${ALLDEPS} | fgrep "${HIGHEST_DEPFILE}")" ]
258     if checklist_alldeps "${HIGHEST_DEPFILE}"
259 niro 226 then
260 niro 1564 ### check if the dependency is already installed ###
261 niro 226 if [ ! -d ${MROOT}${INSTALLDB}/${PCAT}/${PNAME}-${PVER}-${PBUILD} ]
262     then
263 niro 2828 # but first get all deps of highest_depfile to catch all dependencies of it
264     depwalking ${HIGHEST_DEPFILE}
265 niro 226 ALLDEPS="${ALLDEPS} ${HIGHEST_DEPFILE}"
266 niro 2285 decho "added '${HIGHEST_DEPFILE}' to ALLDEPS"
267 niro 226 fi
268     fi
269     done << EOF
270     ${MY_DEPEND}
271     EOF
272     return 0
273     }
274    
275 niro 231 [[ ${METHOD} = pretend ]] || \
276     [[ ${METHOD} = srcpretend ]] || \
277     [[ ${METHOD} = uppretend ]] || \
278 niro 2210 [[ ${METHOD} = srcuppretend ]] || \
279     [[ ${METHOD} = pretend-build-prerequisites ]] && \
280 niro 226 echo -n "Calculating dependencies ... "
281    
282    
283 niro 231 if [[ ${METHOD} = upgrade ]] || \
284     [[ ${METHOD} = srcupgrade ]] || \
285     [[ ${METHOD} = uppretend ]] || \
286     [[ ${METHOD} = srcuppretend ]]
287     then
288     INSTDEPS="$(${MLIBDIR}/magequery.sh -i)"
289     for dep in ${INSTDEPS}
290     do
291     PCAT="$(magename2pcat ${dep} installdb)"
292     PNAME="$(magename2pname ${dep})"
293 niro 226
294 niro 250 # get the highest mage file from mage-db
295     MAGEFILE="$(get_highest_magefile ${PCAT} ${PNAME})"
296 niro 226
297 niro 2285 # debug info
298     decho "dep='${dep}'"
299     decho "PCAT='${PCAT}'"
300     decho "PNAME='${PNAME}'"
301     decho "MAGEFILE='${MAGEFILE}'"
302 niro 2281
303 niro 701 # if no install candidate was found, record this
304     # and process with the next one
305     if [[ -z ${MAGEFILE} ]]
306     then
307     NO_UPGRADE_CANDIDATE="${NO_UPGRADE_CANDIDATE} ${PCAT}/${PNAME}"
308 niro 2285 decho "added to NO_UPGRADE_CANDIDATE"
309 niro 701 continue
310     fi
311    
312 niro 250 # now get the pver&pbuild from the new file
313     PVER="$(magename2pver ${MAGEFILE})"
314     PBUILD="$(magename2pbuild ${MAGEFILE})"
315    
316 niro 2285 # debug info
317     decho "PVER='${PVER}'"
318     decho "PBUILD='${PBUILD}'"
319 niro 2281
320 niro 1562 # do not walk files which are installed
321 niro 250 if [ ! -d ${INSTALLDB}/${PCAT}/${PNAME}-${PVER}-${PBUILD} ]
322     then
323     # get dependencies the package
324 niro 1563 depwalking ${MAGEFILE}
325 niro 2280
326     # now add the package itself to the dependencies
327     # (if not exists already)
328     if checklist_alldeps "${MAGEFILE}"
329     then
330 niro 2285 decho "added '${MAGEFILE}' to ALLDEPS"
331 niro 2280 ALLDEPS="${ALLDEPS} ${MAGEFILE}"
332     fi
333 niro 2281 else
334 niro 2376 # debug info
335     decho "ignored package"
336     decho
337 niro 250 fi
338 niro 231 done
339     else
340 niro 1562 # get all dependencies of the package
341 niro 2360 if [[ -n ${SMAGEFILE} ]]
342     then
343     depwalking "${SMAGEFILE}"
344     else
345     depwalking "${MAGEFILE}"
346     fi
347 niro 2195 fi
348 niro 226
349 niro 2210 if [[ ${METHOD} != install-build-prerequisites ]] &&
350 niro 2280 [[ ${METHOD} != pretend-build-prerequisites ]] &&
351 niro 2841 [[ ${METHOD} != install-deep-build-prerequisites ]] &&
352     [[ ${METHOD} != pretend-deep-build-prerequisites ]] &&
353 niro 2280 [[ ${METHOD} != upgrade ]] &&
354     [[ ${METHOD} != uppretend ]] &&
355     [[ ${METHOD} != srcupgrade ]] &&
356     [[ ${METHOD} != srcuppretend ]]
357 niro 2195 then
358 niro 2210 # now add the package itself to the dependencies
359     # (if not exists already)
360     if checklist_alldeps "${MAGEFILE}"
361     then
362 niro 2285 decho "added '${MAGEFILE}' to ALLDEPS"
363 niro 2210 ALLDEPS="${ALLDEPS} ${MAGEFILE}"
364     fi
365 niro 231 fi
366    
367     [[ ${METHOD} = pretend ]] || \
368     [[ ${METHOD} = srcpretend ]] || \
369     [[ ${METHOD} = uppretend ]] || \
370 niro 2210 [[ ${METHOD} = srcuppretend ]] || \
371 niro 2841 [[ ${METHOD} = pretend-build-prerequisites ]] || \
372     [[ ${METHOD} = pretend-deep-build-prerequisites ]] && \
373 niro 231 echo "done"
374    
375    
376 niro 226 ## show output of pretend
377 niro 231 if [[ ${METHOD} = pretend ]] || \
378     [[ ${METHOD} = srcpretend ]] || \
379     [[ ${METHOD} = uppretend ]] || \
380 niro 2210 [[ ${METHOD} = srcuppretend ]] || \
381 niro 2841 [[ ${METHOD} = pretend-build-prerequisites ]] || \
382     [[ ${METHOD} = pretend-deep-build-prerequisites ]]
383 niro 226 then
384     # this is a little bit faster
385     declare -i x=0
386     echo -n "Building dependencies list ... "
387     for i in ${ALLDEPS}
388     do
389     (( x++ ))
390     k="$x"
391     [ ${x} -le 9 ] && k="0${k}"
392     #[ ${x} -le 99 ] && k="0${k}"
393     PCAT="$(magename2pcat ${i})"
394     PNAME="$(magename2pname ${i})"
395     PVER="$(magename2pver ${i})"
396     PBUILD="$(magename2pbuild ${i})"
397     if [ -z "${list}" ]
398     then
399 niro 2220 list="\t${COLBLUE}[${k}] ${COLGREEN}${PCAT}/${PNAME}-${PVER}-${PBUILD}${COLDEFAULT}"
400 niro 226 else
401     list="${list}
402     \t${COLBLUE}[${k}] ${COLGREEN}${PCAT}/${PNAME}-${PVER}-${PBUILD}${COLDEFAULT}"
403     fi
404     unset PCAT PNAME PVER PBUILD
405     done
406     echo "done"
407     echo -e "${list}"
408     echo
409 niro 701
410 niro 2141 if [[ ! -z ${INVALID_DEPS} ]]
411     then
412     echo -e "${COLRED}Invalid dependencies found:${COLDEFAULT}"
413     for i in ${INVALID_DEPS}
414     do
415     _dep="${i%%:*}"
416     _mage="${i##*:}"
417     echo -e "${COLRED} '${_dep}' -> '${_mage}'${COLDEFAULT}"
418     done
419     echo
420     fi
421    
422 niro 701 if [[ ! -z ${NO_UPGRADE_CANDIDATE} ]]
423     then
424     echo -e "${COLRED}Currently no candidates found for:${COLDEFAULT}"
425     for i in ${NO_UPGRADE_CANDIDATE}
426     do
427     echo -e "${COLRED} ${i}${COLDEFAULT}"
428     done
429     echo
430     echo -e "${COLRED}Please consider to uninstall all of them first,${COLDEFAULT}"
431     echo -e "${COLRED}because these packages does not exist in this distribution${COLDEFAULT}"
432 niro 887 echo -e "${COLRED}anymore and there will be no further support for them.${COLDEFAULT}"
433 niro 701 echo
434     fi
435 niro 226 fi
436    
437     ## return output from src/install deps
438 niro 231 [[ ${METHOD} = install ]] || \
439     [[ ${METHOD} = srcinstall ]] || \
440     [[ ${METHOD} = upgrade ]] || \
441 niro 2210 [[ ${METHOD} = srcupgrade ]] || \
442 niro 2841 [[ ${METHOD} = install-build-prerequisites ]] || \
443     [[ ${METHOD} = install-deep-build-prerequisites ]] && \
444 niro 231 echo "${ALLDEPS}"