Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2840 - (show annotations) (download) (as text)
Fri Oct 24 08:23:22 2014 UTC (9 years, 6 months ago) by niro
File MIME type: application/x-sh
File size: 10912 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 #!/bin/bash
2 # $Id$
3 # dependency walker
4
5 # default die function
6 die()
7 {
8 echo ${COLRED}"$@"${COLDEFAULT}
9 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
21 [ -f /etc/mage.rc.global ] && \
22 source /etc/mage.rc.global || \
23 die "/etc/mage.rc.global missing"
24
25 [ -f ${MAGERC} ] && source ${MAGERC} || \
26 die "Your ${MAGERC} is missing. Aborting."
27
28 [ -f ${MLIBDIR}/mage4.functions.sh ] && \
29 source ${MLIBDIR}/mage4.functions.sh || \
30 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()
37 {
38 echo
39 echo "Usage: $(basename $0) [command] [arg] ..."
40 echo
41 echo " -h --help shows this help"
42 echo " -c --pcat category of the package"
43 echo " -n --pname name of the package"
44 echo " -v --pver version number of the package"
45 echo " -b --pbuild build number of the package"
46 echo " -m --method which calc method should be used:"
47 echo " install, srcinstall, pretend, srcpretend"
48 echo " upgrade, srcupgrade,"
49 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
56 echo "method, category, name, version and build must be given !"
57 echo
58 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
67 for i in $*
68 do
69 case $1 in
70 --pcat|-c) shift; PCAT="$1" ;;
71 --pname|-n) shift; PNAME="$1" ;;
72 --pver|-v) shift; PVER="$1" ;;
73 --pbuild|-b) shift; PBUILD="$1" ;;
74 --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 ;;
78 esac
79 shift
80 done
81
82 # sanity checks; abort if not given
83 if [[ -z ${SMAGEFILE} ]]
84 then
85 [ -z "${PCAT}" ] && usage
86 [ -z "${PNAME}" ] && usage
87 [ -z "${PVER}" ] && usage
88 [ -z "${PBUILD}" ] && usage
89 fi
90 [ -z "${METHOD}" ] && usage
91
92 # check needed global vars
93 [ -z "${MAGEDIR}" ] && die "\$MAGEDIR not set."
94 [ -z "${INSTALLDB}" ] && die "\$INSTALLDB not set."
95 [ -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
101 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"
112
113 # much faster than fgrep
114 checklist_alldeps()
115 {
116 local i
117 local item="$1"
118
119 for i in ${ALLDEPS}
120 do
121 [[ ${i} = ${item} ]] && return 1
122 done
123
124 return 0
125 }
126
127 checklist_processeddeps()
128 {
129 local i
130 local item="$1"
131
132 for i in ${PROCESSEDDEPS}
133 do
134 [[ ${i} = ${item} ]] && return 1
135 done
136
137 return 0
138 }
139
140 #####################
141 ## depwalking /path/to/mage/file/.mage
142 depwalking()
143 {
144 unset DEPEND
145 unset SDEPEND
146 unset MY_DEPEND
147
148 local DFILE
149 local SYM
150 local DEPNAME
151 local HIGHEST_DEPFILE
152 local MY_DEPEND
153 local REAL_PGKNAME
154 local VIRTUAL_NAME
155 local INSTALL_VIRTUAL
156 local PNAME
157 local PCAT
158 local PVER
159 local PBUILD
160
161 DFILE="$1"
162
163 # debug info
164 decho "depwalking magefile '${DFILE}'"
165 decho
166
167 source ${DFILE}
168
169 # forced nodeps
170 if [[ ${NODEPS} = true ]]
171 then
172 DEPEND=""
173 SDEPEND=""
174 fi
175
176 MY_DEPEND="${DEPEND}"
177
178 # for srcinstall & srcdepend only; SDEPEND also needed
179 if [[ ${METHOD} = srcinstall ]] ||
180 [[ ${METHOD} = srcpretend ]] ||
181 [[ ${METHOD} = srcupgrade ]] ||
182 [[ ${METHOD} = srcuppretend ]] ||
183 [[ ${METHOD} = install-deep-build-prerequisites ]] ||
184 [[ ${METHOD} = pretend-deep-build-prerequisites ]]
185 then
186 # only if SDEPEND is not zero
187 if [ -n "${SDEPEND}" ]
188 then
189 # crlf is substantly needed !!
190 if [ -n "${MY_DEPEND}" ]
191 then
192 MY_DEPEND="${MY_DEPEND}
193 ${SDEPEND}"
194 else
195 MY_DEPEND="${SDEPEND}"
196 fi
197 fi
198 fi
199
200 # 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 ]]
204 then
205 if [[ ${SDEPEND_ONETIME} = 0 ]]
206 then
207 # only if SDEPEND is not zero
208 if [ -n "${SDEPEND}" ]
209 then
210 # crlf is substantly needed !!
211 if [ -n "${MY_DEPEND}" ]
212 then
213 MY_DEPEND="${MY_DEPEND}
214 ${SDEPEND}"
215 else
216 MY_DEPEND="${SDEPEND}"
217 fi
218 fi
219 SDEPEND_ONETIME=1
220 fi
221 fi
222
223 unset DEPEND
224 unset SDEPEND
225
226 if [ -z "${MY_DEPEND}" ]
227 then
228 decho "MY_DEPEND is empty; deps of '${DFILE}' ignored"
229 return 1
230 fi
231
232 while read SYM DEPNAME
233 do
234 # debug info
235 decho "DEPNAME='${DEPNAME}'"
236
237 # exclude empty depnames
238 [[ -z ${DEPNAME} ]] && continue
239
240 # exclude all already processed deps -without version
241 if ! checklist_processeddeps "${DEPNAME%-*}"
242 then
243 continue
244 fi
245
246 # mark depfile as processed to prevent double runs -without version
247 # but do not add any virtuals to PROCESSEDDEPS or their resolved
248 # pkgnames will be ignored and they are missing on the dependency-list
249 if [[ ${DEPNAME/virtual\//} = ${DEPNAME} ]]
250 then
251 PROCESSEDDEPS="${PROCESSEDDEPS} ${DEPNAME%-*}"
252 fi
253
254 HIGHEST_DEPFILE=$(dep2highest_magefile "${DEPNAME}")
255 if [[ -z ${HIGHEST_DEPFILE} ]]
256 then
257 INVALID_DEPS+=" ${DEPNAME}:${DFILE}"
258 continue
259 fi
260
261 PCAT="$(magename2pcat ${HIGHEST_DEPFILE})"
262 PNAME="$(magename2pname ${HIGHEST_DEPFILE})"
263 PVER="$(magename2pver ${HIGHEST_DEPFILE})"
264 PBUILD="$(magename2pbuild ${HIGHEST_DEPFILE})"
265
266 ## dep already in ALLDEPS? then going on
267
268 # usage of fgrep is extremly slow and consumes a lot of cpu power
269 #if [ -z "$(echo ${ALLDEPS} | fgrep "${HIGHEST_DEPFILE}")" ]
270 if checklist_alldeps "${HIGHEST_DEPFILE}"
271 then
272 ### check if the dependency is already installed ###
273 if [ ! -d ${MROOT}${INSTALLDB}/${PCAT}/${PNAME}-${PVER}-${PBUILD} ]
274 then
275 # but first get all deps of highest_depfile to catch all dependencies of it
276 depwalking ${HIGHEST_DEPFILE}
277 ALLDEPS="${ALLDEPS} ${HIGHEST_DEPFILE}"
278 decho "added '${HIGHEST_DEPFILE}' to ALLDEPS"
279 fi
280 fi
281 done << EOF
282 ${MY_DEPEND}
283 EOF
284 return 0
285 }
286
287 [[ ${METHOD} = pretend ]] || \
288 [[ ${METHOD} = srcpretend ]] || \
289 [[ ${METHOD} = uppretend ]] || \
290 [[ ${METHOD} = srcuppretend ]] || \
291 [[ ${METHOD} = pretend-build-prerequisites ]] && \
292 echo -n "Calculating dependencies ... "
293
294
295 if [[ ${METHOD} = upgrade ]] || \
296 [[ ${METHOD} = srcupgrade ]] || \
297 [[ ${METHOD} = uppretend ]] || \
298 [[ ${METHOD} = srcuppretend ]]
299 then
300 INSTDEPS="$(${MLIBDIR}/magequery.sh -i)"
301 for dep in ${INSTDEPS}
302 do
303 PCAT="$(magename2pcat ${dep} installdb)"
304 PNAME="$(magename2pname ${dep})"
305
306 # get the highest mage file from mage-db
307 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
316 # and process with the next one
317 if [[ -z ${MAGEFILE} ]]
318 then
319 NO_UPGRADE_CANDIDATE="${NO_UPGRADE_CANDIDATE} ${PCAT}/${PNAME}"
320 decho "added to NO_UPGRADE_CANDIDATE"
321 continue
322 fi
323
324 # now get the pver&pbuild from the new file
325 PVER="$(magename2pver ${MAGEFILE})"
326 PBUILD="$(magename2pbuild ${MAGEFILE})"
327
328 # debug info
329 decho "PVER='${PVER}'"
330 decho "PBUILD='${PBUILD}'"
331
332 # do not walk files which are installed
333 if [ ! -d ${INSTALLDB}/${PCAT}/${PNAME}-${PVER}-${PBUILD} ]
334 then
335 # get dependencies the package
336 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
350 done
351 else
352 # get all dependencies of the package
353 if [[ -n ${SMAGEFILE} ]]
354 then
355 depwalking "${SMAGEFILE}"
356 else
357 depwalking "${MAGEFILE}"
358 fi
359 fi
360
361 if [[ ${METHOD} != install-build-prerequisites ]] &&
362 [[ ${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
370 # now add the package itself to the dependencies
371 # (if not exists already)
372 if checklist_alldeps "${MAGEFILE}"
373 then
374 decho "added '${MAGEFILE}' to ALLDEPS"
375 ALLDEPS="${ALLDEPS} ${MAGEFILE}"
376 fi
377 fi
378
379 [[ ${METHOD} = pretend ]] || \
380 [[ ${METHOD} = srcpretend ]] || \
381 [[ ${METHOD} = uppretend ]] || \
382 [[ ${METHOD} = srcuppretend ]] || \
383 [[ ${METHOD} = pretend-build-prerequisites ]] || \
384 [[ ${METHOD} = pretend-deep-build-prerequisites ]] && \
385 echo "done"
386
387
388 ## show output of pretend
389 if [[ ${METHOD} = pretend ]] || \
390 [[ ${METHOD} = srcpretend ]] || \
391 [[ ${METHOD} = uppretend ]] || \
392 [[ ${METHOD} = srcuppretend ]] || \
393 [[ ${METHOD} = pretend-build-prerequisites ]] || \
394 [[ ${METHOD} = pretend-deep-build-prerequisites ]]
395 then
396 # this is a little bit faster
397 declare -i x=0
398 echo -n "Building dependencies list ... "
399 for i in ${ALLDEPS}
400 do
401 (( x++ ))
402 k="$x"
403 [ ${x} -le 9 ] && k="0${k}"
404 #[ ${x} -le 99 ] && k="0${k}"
405 PCAT="$(magename2pcat ${i})"
406 PNAME="$(magename2pname ${i})"
407 PVER="$(magename2pver ${i})"
408 PBUILD="$(magename2pbuild ${i})"
409 if [ -z "${list}" ]
410 then
411 list="\t${COLBLUE}[${k}] ${COLGREEN}${PCAT}/${PNAME}-${PVER}-${PBUILD}${COLDEFAULT}"
412 else
413 list="${list}
414 \t${COLBLUE}[${k}] ${COLGREEN}${PCAT}/${PNAME}-${PVER}-${PBUILD}${COLDEFAULT}"
415 fi
416 unset PCAT PNAME PVER PBUILD
417 done
418 echo "done"
419 echo -e "${list}"
420 echo
421
422 if [[ ! -z ${INVALID_DEPS} ]]
423 then
424 echo -e "${COLRED}Invalid dependencies found:${COLDEFAULT}"
425 for i in ${INVALID_DEPS}
426 do
427 _dep="${i%%:*}"
428 _mage="${i##*:}"
429 echo -e "${COLRED} '${_dep}' -> '${_mage}'${COLDEFAULT}"
430 done
431 echo
432 fi
433
434 if [[ ! -z ${NO_UPGRADE_CANDIDATE} ]]
435 then
436 echo -e "${COLRED}Currently no candidates found for:${COLDEFAULT}"
437 for i in ${NO_UPGRADE_CANDIDATE}
438 do
439 echo -e "${COLRED} ${i}${COLDEFAULT}"
440 done
441 echo
442 echo -e "${COLRED}Please consider to uninstall all of them first,${COLDEFAULT}"
443 echo -e "${COLRED}because these packages does not exist in this distribution${COLDEFAULT}"
444 echo -e "${COLRED}anymore and there will be no further support for them.${COLDEFAULT}"
445 echo
446 fi
447 fi
448
449 ## return output from src/install deps
450 [[ ${METHOD} = install ]] || \
451 [[ ${METHOD} = srcinstall ]] || \
452 [[ ${METHOD} = upgrade ]] || \
453 [[ ${METHOD} = srcupgrade ]] || \
454 [[ ${METHOD} = install-build-prerequisites ]] || \
455 [[ ${METHOD} = install-deep-build-prerequisites ]] && \
456 echo "${ALLDEPS}"

Properties

Name Value
svn:executable *