Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2841 - (show 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 #!/bin/bash
2 # $Id$
3 # dependency walker
4
5 # set default variables
6 : ${MAGERC="@@SYSCONFDIR@@/mage.rc"}
7 : ${MLIBDIR="@@MAGELIBDIR@@"}
8
9 # first of all include common functions
10 source ${MLIBDIR}/common.functions.sh || exit 1
11 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
16 decho()
17 {
18 if [[ ${DEBUG} = 1 ]]
19 then
20 echo "DEBUG: $@" >&2
21 fi
22 }
23
24 usage()
25 {
26 echo
27 echo "Usage: $(basename $0) [command] [arg] ..."
28 echo
29 echo " -h --help shows this help"
30 echo " -c --pcat category of the package"
31 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 echo " install, srcinstall, pretend, srcpretend"
36 echo " upgrade, srcupgrade,"
37 echo " install-build-prerequisites,"
38 echo " pretend-build-prerequisites"
39 echo " install-deep-build-prerequisites,"
40 echo " pretend-deep-build-prerequisites"
41 echo " -d --debug enable debug mode"
42 echo " -s --smage use a smage to calculate dependencies"
43 echo
44 echo "method, category, name, version and build must be given !"
45 echo
46 exit 1
47 }
48
49 # set some sane defaults
50 DEBUG=0
51 SMAGE_DEPEND=0
52 SDEPEND_ONETIME=0
53
54 # 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 --debug|-d) shift; DEBUG=1 ;;
64 --smage|-s) shift; SMAGEFILE="$1"; SMAGE_DEPEND=1; SILENT=1; FVERBOSE=off ;;
65 --help|-h) usage ;;
66 esac
67 shift
68 done
69
70 # sanity checks; abort if not given
71 if [[ -z ${SMAGEFILE} ]]
72 then
73 [ -z "${PCAT}" ] && usage
74 [ -z "${PNAME}" ] && usage
75 [ -z "${PVER}" ] && usage
76 [ -z "${PBUILD}" ] && usage
77 fi
78 [ -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 # load mage-features to support them with smagesource()
86 load_mage_features
87
88 # other needed vars
89 ALLDEPS=""
90 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 MAGEFILE="${MAGEDIR}/${PCAT}/${PNAME}/${PNAME}-${PVER}-${PBUILD}.mage"
100
101 # 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 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 #####################
129 ## depwalking /path/to/mage/file/.mage
130 depwalking()
131 {
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 local PVER
147 local PBUILD
148
149 DFILE="$1"
150
151 # debug info
152 decho "depwalking magefile '${DFILE}'"
153 decho
154
155 source ${DFILE}
156
157 # forced nodeps
158 if [[ ${NODEPS} = true ]]
159 then
160 DEPEND=""
161 SDEPEND=""
162 fi
163
164 MY_DEPEND="${DEPEND}"
165
166 # for srcinstall & srcdepend only; SDEPEND also needed
167 if [[ ${METHOD} = srcinstall ]] ||
168 [[ ${METHOD} = srcpretend ]] ||
169 [[ ${METHOD} = srcupgrade ]] ||
170 [[ ${METHOD} = srcuppretend ]] ||
171 [[ ${METHOD} = install-deep-build-prerequisites ]] ||
172 [[ ${METHOD} = pretend-deep-build-prerequisites ]]
173 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 # 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 unset DEPEND
212 unset SDEPEND
213
214 if [ -z "${MY_DEPEND}" ]
215 then
216 decho "MY_DEPEND is empty; deps of '${DFILE}' ignored"
217 return 1
218 fi
219
220 while read SYM DEPNAME
221 do
222 # debug info
223 decho "DEPNAME='${DEPNAME}'"
224
225 # exclude empty depnames
226 [[ -z ${DEPNAME} ]] && continue
227
228 # 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 # but do not add any virtuals to PROCESSEDDEPS or their resolved
236 # pkgnames will be ignored and they are missing on the dependency-list
237 if [[ ${DEPNAME/virtual\//} = ${DEPNAME} ]]
238 then
239 PROCESSEDDEPS="${PROCESSEDDEPS} ${DEPNAME%-*}"
240 fi
241
242 HIGHEST_DEPFILE=$(dep2highest_magefile "${DEPNAME}")
243 if [[ -z ${HIGHEST_DEPFILE} ]]
244 then
245 INVALID_DEPS+=" ${DEPNAME}:${DFILE}"
246 continue
247 fi
248
249 PCAT="$(magename2pcat ${HIGHEST_DEPFILE})"
250 PNAME="$(magename2pname ${HIGHEST_DEPFILE})"
251 PVER="$(magename2pver ${HIGHEST_DEPFILE})"
252 PBUILD="$(magename2pbuild ${HIGHEST_DEPFILE})"
253
254 ## dep already in ALLDEPS? then going on
255
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 then
260 ### check if the dependency is already installed ###
261 if [ ! -d ${MROOT}${INSTALLDB}/${PCAT}/${PNAME}-${PVER}-${PBUILD} ]
262 then
263 # but first get all deps of highest_depfile to catch all dependencies of it
264 depwalking ${HIGHEST_DEPFILE}
265 ALLDEPS="${ALLDEPS} ${HIGHEST_DEPFILE}"
266 decho "added '${HIGHEST_DEPFILE}' to ALLDEPS"
267 fi
268 fi
269 done << EOF
270 ${MY_DEPEND}
271 EOF
272 return 0
273 }
274
275 [[ ${METHOD} = pretend ]] || \
276 [[ ${METHOD} = srcpretend ]] || \
277 [[ ${METHOD} = uppretend ]] || \
278 [[ ${METHOD} = srcuppretend ]] || \
279 [[ ${METHOD} = pretend-build-prerequisites ]] && \
280 echo -n "Calculating dependencies ... "
281
282
283 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
294 # get the highest mage file from mage-db
295 MAGEFILE="$(get_highest_magefile ${PCAT} ${PNAME})"
296
297 # debug info
298 decho "dep='${dep}'"
299 decho "PCAT='${PCAT}'"
300 decho "PNAME='${PNAME}'"
301 decho "MAGEFILE='${MAGEFILE}'"
302
303 # 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 decho "added to NO_UPGRADE_CANDIDATE"
309 continue
310 fi
311
312 # now get the pver&pbuild from the new file
313 PVER="$(magename2pver ${MAGEFILE})"
314 PBUILD="$(magename2pbuild ${MAGEFILE})"
315
316 # debug info
317 decho "PVER='${PVER}'"
318 decho "PBUILD='${PBUILD}'"
319
320 # do not walk files which are installed
321 if [ ! -d ${INSTALLDB}/${PCAT}/${PNAME}-${PVER}-${PBUILD} ]
322 then
323 # get dependencies the package
324 depwalking ${MAGEFILE}
325
326 # now add the package itself to the dependencies
327 # (if not exists already)
328 if checklist_alldeps "${MAGEFILE}"
329 then
330 decho "added '${MAGEFILE}' to ALLDEPS"
331 ALLDEPS="${ALLDEPS} ${MAGEFILE}"
332 fi
333 else
334 # debug info
335 decho "ignored package"
336 decho
337 fi
338 done
339 else
340 # get all dependencies of the package
341 if [[ -n ${SMAGEFILE} ]]
342 then
343 depwalking "${SMAGEFILE}"
344 else
345 depwalking "${MAGEFILE}"
346 fi
347 fi
348
349 if [[ ${METHOD} != install-build-prerequisites ]] &&
350 [[ ${METHOD} != pretend-build-prerequisites ]] &&
351 [[ ${METHOD} != install-deep-build-prerequisites ]] &&
352 [[ ${METHOD} != pretend-deep-build-prerequisites ]] &&
353 [[ ${METHOD} != upgrade ]] &&
354 [[ ${METHOD} != uppretend ]] &&
355 [[ ${METHOD} != srcupgrade ]] &&
356 [[ ${METHOD} != srcuppretend ]]
357 then
358 # now add the package itself to the dependencies
359 # (if not exists already)
360 if checklist_alldeps "${MAGEFILE}"
361 then
362 decho "added '${MAGEFILE}' to ALLDEPS"
363 ALLDEPS="${ALLDEPS} ${MAGEFILE}"
364 fi
365 fi
366
367 [[ ${METHOD} = pretend ]] || \
368 [[ ${METHOD} = srcpretend ]] || \
369 [[ ${METHOD} = uppretend ]] || \
370 [[ ${METHOD} = srcuppretend ]] || \
371 [[ ${METHOD} = pretend-build-prerequisites ]] || \
372 [[ ${METHOD} = pretend-deep-build-prerequisites ]] && \
373 echo "done"
374
375
376 ## show output of pretend
377 if [[ ${METHOD} = pretend ]] || \
378 [[ ${METHOD} = srcpretend ]] || \
379 [[ ${METHOD} = uppretend ]] || \
380 [[ ${METHOD} = srcuppretend ]] || \
381 [[ ${METHOD} = pretend-build-prerequisites ]] || \
382 [[ ${METHOD} = pretend-deep-build-prerequisites ]]
383 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 list="\t${COLBLUE}[${k}] ${COLGREEN}${PCAT}/${PNAME}-${PVER}-${PBUILD}${COLDEFAULT}"
400 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
410 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 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 echo -e "${COLRED}anymore and there will be no further support for them.${COLDEFAULT}"
433 echo
434 fi
435 fi
436
437 ## return output from src/install deps
438 [[ ${METHOD} = install ]] || \
439 [[ ${METHOD} = srcinstall ]] || \
440 [[ ${METHOD} = upgrade ]] || \
441 [[ ${METHOD} = srcupgrade ]] || \
442 [[ ${METHOD} = install-build-prerequisites ]] || \
443 [[ ${METHOD} = install-deep-build-prerequisites ]] && \
444 echo "${ALLDEPS}"