Advertisement
Guest User

Untitled

a guest
May 7th, 2011
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.35 KB | None | 0 0
  1. gen_wok_db()
  2. {
  3. report step "Generating wok database"
  4. report open-bloc
  5. report step "Removing old files"
  6. for file in $wan_db $dep_db $PACKAGES_REPOSITORY/cookorder.txt; do
  7. [ -f $file ] && rm $file
  8. done
  9. report step "Generating wok-wanted.txt"
  10. gen_wan_db
  11. report step "Generating wok-depends.txt"
  12. for PACKAGE in $(cut -f1 -d '|' $PACKAGES_REPOSITORY/packages.desc \
  13. $INCOMING_REPOSITORY/packages.desc | sort -u); do
  14. RECEIPT=$WOK/$PACKAGE/receipt
  15. if [ -s $RECEIPT ]; then
  16. source_receipt
  17. echo -e $PACKAGE"\t "$DEPENDS" \t "$BUILD_DEPENDS' ' >> $dep_db
  18. fi
  19. done
  20. sort_db
  21. report close-bloc
  22. }
  23.  
  24. gen_wan_db()
  25. {
  26. rm -f $wan_db
  27. for RECEIPT in $(fgrep -l WANTED $WOK/*/receipt); do
  28. WANTED=
  29. source $RECEIPT
  30. [ "$WANTED" ] || continue
  31. echo -e $PACKAGE"\t"$WANTED >> $wan_db
  32. done
  33. }
  34.  
  35. update_wan_db()
  36. {
  37. local PACKAGE=$PACKAGE
  38. wanted_list=$(fgrep WANTED=\"$PACKAGE\" $WOK/*/receipt | cut -f1 -d ':')
  39. grep $'\t'$PACKAGE $wan_db | cut -f 1 | while read wan; do
  40. echo "$wanted_list" | fgrep -q /$wan/receipt && continue
  41. sed "/^$wan\t/d" -i $wan_db
  42. done
  43. for RECEIPT in $wanted_list; do
  44. unset WANTED PACKAGE
  45. source $RECEIPT
  46. [ "$WANTED" ] || continue
  47. sed "/^$PACKAGE\t/d" -i $wan_db
  48. echo -e $PACKAGE"\t"$WANTED >> $wan_db
  49. done
  50. unset wanted_list
  51. }
  52.  
  53. update_dep_db()
  54. {
  55. sed "/^$PACKAGE\t/d" -i $dep_db
  56. echo -e $PACKAGE"\t "$DEPENDS" \t "$BUILD_DEPENDS' ' >> $dep_db
  57. }
  58.  
  59. sort_db()
  60. {
  61. report step "Generating cookorder.txt"
  62. cat $dep_db | sed 's/ \t / /' | while read PACKAGE BUILD_DEPENDS; do
  63. grep -q ^$PACKAGE$'\t' $wan_db && continue
  64.  
  65. # Replace each BUILD_DEPENDS with a WANTED package by it's
  66. # WANTED package.
  67. replace_by_wanted()
  68. {
  69. for p in $BUILD_DEPENDS; do
  70. if grep -q ^$p$'\t' $wan_db; then
  71. echo -n $(grep ^$p$'\t' $wan_db | cut -f 2)' '
  72. else
  73. echo -n $p' '
  74. fi
  75. done | tr ' ' '\n' | sort -u | sed "/^$PACKAGE$/d" | tr '\n' ' '
  76. }
  77. echo -e $PACKAGE"\t $(replace_by_wanted) "
  78. done > $tmp/db
  79. while [ -s "$tmp/db" ]; do
  80. status=start
  81. for pkg in $(cut -f 1 $tmp/db); do
  82. if ! fgrep -q ' '$pkg' ' $tmp/db; then
  83. echo $pkg >> $tmp/cookorder
  84. sed -e "/^$pkg\t/d" -e "s/ $pkg / /g" -i $tmp/db
  85. status=proceed
  86. fi
  87. done
  88. if [ "$status" = start ]; then
  89. cp -f $tmp/db /tmp/remain-depends.txt
  90. echo "Can't go further because of dependency loop(s). The remaining packages will be commented in the cookorder and will be unbuilt in case of major updates until the problem is solved." >&2
  91. for blocked in $(cut -f 1 $tmp/db); do
  92. echo "$blocked" >> $PACKAGES_REPOSITORY/blocked
  93. done
  94. break
  95. fi
  96. done
  97. [ -s $tmp/cookorder ] || touch $tmp/cookorder
  98.  
  99. # The toolchain packages are moved in first position.
  100. grep $(for pkg in `scan "$SLITAZ_TOOLCHAIN $SLITAZ_TOOLCHAIN_EXTRA" \
  101. --look_for=all --with_args`; do echo " -e ^$pkg$"; done) \
  102. $tmp/cookorder | tac > $PACKAGES_REPOSITORY/cookorder.txt
  103. for pkg in $(cat $PACKAGES_REPOSITORY/cookorder.txt); do
  104. sed "/^$pkg$/d" -i $tmp/cookorder
  105. done
  106.  
  107. tac $tmp/cookorder >> $PACKAGES_REPOSITORY/cookorder.txt
  108. report end-step
  109. }
  110.  
  111. ########################################################################
  112. # SCAN CORE
  113. ########################
  114. # Includes various scan core-functions. It's not intended to be used
  115. # directly : prefer scan wrappers in next section.
  116.  
  117. look_for_dep()
  118. {
  119. if [ "$undigest" ] && [ ! -f "$WOK/$PACKAGE/receipt" ]; then
  120. grep -m1 ^$PACKAGE$'\t' $SLITAZ_DIR/$SLITAZ_VERSION/packages-incoming/wok-depends.txt \
  121. | cut -f 2
  122. else
  123. grep -m1 ^$PACKAGE$'\t' $INCOMING_REPOSITORY/wok-depends.txt | \
  124. cut -f 2
  125. fi
  126. }
  127.  
  128. look_for_bdep()
  129. {
  130. look_for_all
  131. }
  132.  
  133. look_for_all()
  134. {
  135. if [ "$undigest" ] && [ ! -f "$WOK/$PACKAGE/receipt" ]; then
  136. grep -m1 ^$PACKAGE$'\t' $SLITAZ_DIR/$SLITAZ_VERSION/packages-incoming/wok-depends.txt \
  137. | cut -f 2,3 | sed 's/ / /'
  138. else
  139. grep -m1 ^$PACKAGE$'\t' $INCOMING_REPOSITORY/wok-depends.txt | \
  140. cut -f 2,3 | sed 's/ / /'
  141. fi
  142. }
  143.  
  144. look_for_rdep()
  145. {
  146. fgrep ' '$PACKAGE' ' $INCOMING_REPOSITORY/wok-depends.txt | cut -f 1
  147. if [ "$undigest" ]; then
  148. for rdep in $(fgrep ' '$PACKAGE' ' $SLITAZ_DIR/$SLITAZ_VERSION/packages-incoming/wok-depends.txt | cut -f 1); do
  149. if [ ! -f "WOK$/$rdep/receipt" ]; then
  150. echo "$rdep"
  151. fi
  152. done
  153. fi
  154. }
  155.  
  156. look_for_rbdep()
  157. {
  158. fgrep ' '$PACKAGE' ' $INCOMING_REPOSITORY/wok-depends.txt | \
  159. cut -f 1,3 | fgrep ' '$PACKAGE' ' | cut -f 1
  160. if [ "$undigest" ]; then
  161. for rdep in $(fgrep ' '$PACKAGE' ' $SLITAZ_DIR/$SLITAZ_VERSION/packages-incoming/wok-depends.txt \
  162. | cut -f 1,3 | fgrep ' '$PACKAGE' ' | cut -f 1); do
  163. if [ ! -f "WOK$/$rdep/receipt" ]; then
  164. echo "$rdep"
  165. fi
  166. done
  167. fi
  168. }
  169.  
  170. # Return WANTED if it exists.
  171. look_for_wanted()
  172. {
  173. if [ "$undigest" ] && [ ! -f "$WOK/$PACKAGE/receipt" ]; then
  174. grep -m1 ^$PACKAGE$'\t' $SLITAZ_DIR/$SLITAZ_VERSION/packages-incoming/wok-wanted.txt | cut -f 2
  175. else
  176. grep -m1 ^$PACKAGE$'\t' $INCOMING_REPOSITORY/wok-wanted.txt | cut -f 2
  177. fi
  178. }
  179.  
  180. # Return packages which wants PACKAGE.
  181. look_for_rwanted()
  182. {
  183. grep $'\t'$PACKAGE$ $INCOMING_REPOSITORY/wok-wanted.txt | cut -f 1
  184. if [ "$undigest" ]; then
  185. for rwanted in $(grep $'\t'$PACKAGE$ $SLITAZ_DIR/$SLITAZ_VERSION/packages-incoming/wok-wanted.txt | cut -f 1); do
  186. if [ ! -f "$WOK/$rwanted/receipt" ]; then
  187. echo "$rwanted"
  188. fi
  189. done
  190. fi
  191. }
  192.  
  193. look_for_dev()
  194. {
  195. WANTED=$(look_for_wanted)
  196. if [ "$WANTED" ]; then
  197. if [ "$undigest" ] && [ ! -f "$WOK/$WANTED/receipt" ]; then
  198. [ -f "$SLITAZ_DIR/$SLITAZ_VERSION/wok/$WANTED-dev/receipt" ] && echo $WANTED-dev
  199. else
  200. [ -f "$WOK/$WANTED-dev/receipt" ] && echo $WANTED-dev
  201. fi
  202. fi
  203. if [ "$undigest" ] && [ ! -f "$WOK/$PACKAGE/receipt" ]; then
  204. [ -f "$SLITAZ_DIR/$SLITAZ_VERSION/wok/$PACKAGE-dev/receipt" ] && echo $PACKAGE-dev
  205. else
  206. [ -f "$WOK/$PACKAGE-dev/receipt" ] && echo $PACKAGE-dev
  207. fi
  208. }
  209.  
  210. with_dev()
  211. {
  212. for PACKAGE in $(cat); do
  213. echo $PACKAGE
  214. look_for_dev
  215. done
  216. }
  217.  
  218. with_wanted()
  219. {
  220. for PACKAGE in $(cat); do
  221. echo $PACKAGE
  222. look_for_wanted
  223. done
  224. }
  225.  
  226. use_wanted()
  227. {
  228. for input in $(cat); do
  229. { grep ^$input$'\t' $wan_db || echo $input
  230. } | sed 's/.*\t//'
  231. done
  232. }
  233.  
  234. ########################################################################
  235. # SCAN
  236. ########################
  237. # Use wok-wanted.txt and wok-depeds.txt to scan depends.
  238. # Option in command line (must be first arg) :
  239. # --look_for=bdep/rbdep - Look for depends or reverse depends.
  240. # --with_dev - Add development packages (*-dev) in the result.
  241. # --with_wanted - Add package+reverse wanted in the result.
  242. # --with_args - Include packages in argument in the result.
  243.  
  244. scan()
  245. {
  246. # Get packages in argument.
  247. local PACKAGE=$PACKAGE WANTED=$WANTED pkg_list=
  248. for arg in $@; do
  249. [ "$arg" = "${arg#--}" ] || continue
  250. pkg_list="$pkg_list $arg"
  251. done
  252.  
  253. # Get options.
  254. [ "$pkg_list" ] || return
  255. local cooklist= look_for= with_dev= with_wanted= with_args= log_command="$0 $@" \
  256. get_options_list="look_for with_dev with_wanted with_args cooklist use_wanted"
  257. get_options
  258.  
  259. # Get db md5 to be able to check for changes latter.
  260. db_md5=$(md5sum $dep_db $wan_db)
  261.  
  262. # Cooklist is a special case where we need to modify a little
  263. # scan behavior
  264. if [ "$cooklist" ]; then
  265. gen_wan_db
  266. look_for=all && with_args=yes && with_dev= && with_wanted=
  267. filter=use_wanted
  268. if [ "$COMMAND" = gen-cooklist ]; then
  269. for PACKAGE in $pkg_list; do
  270. grep -q ^$PACKAGE$'\t' $dep_db && continue
  271. [ -d "$WOK/$p" ] || continue
  272. check_for_missing
  273. done
  274. append_to_dep()
  275. {
  276. if ! grep -q ^$PACKAGE$'\t' $dep_db; then
  277. check_for_missing && echo $PACKAGE >> $tmp/dep
  278. else
  279. echo $PACKAGE >> $tmp/dep
  280. fi
  281. }
  282. else
  283. append_to_dep()
  284. {
  285. check_for_commit && echo $PACKAGE >> $tmp/dep
  286. }
  287. fi
  288. else
  289. append_to_dep()
  290. {
  291. echo $PACKAGE >> $tmp/dep
  292. }
  293. # If requested packages are not in dep_db, partial generation of this db is needed.
  294. for PACKAGE in $pkg_list; do
  295. grep -q ^$PACKAGE$'\t' $dep_db && continue
  296. [ -d "$WOK/$p" ] || continue
  297. plan_check_for_missing=yes
  298. check_for_missing
  299. done
  300. if [ "$plan_check_for_missing" ]; then
  301. append_to_dep()
  302. {
  303. if ! grep -q ^$PACKAGE$'\t' $dep_db; then
  304. check_for_missing && echo $PACKAGE >> $tmp/dep
  305. else
  306. echo $PACKAGE >> $tmp/dep
  307. fi
  308. }
  309. unset plan_check_for_missing
  310. fi
  311. fi
  312.  
  313. [ "$with_dev" ] && filter=with_dev
  314. [ "$with_wanted" ] && filter=with_wanted
  315. if [ "$filter" ]; then
  316. pkg_list=$(echo $pkg_list | $filter | sort -u)
  317. scan_pkg()
  318. {
  319. look_for_$look_for | $filter
  320. }
  321. else
  322. scan_pkg()
  323. {
  324. look_for_$look_for
  325. }
  326. fi
  327. touch $tmp/dep
  328. for PACKAGE in $pkg_list; do
  329. [ "$with_args" ] && append_to_dep
  330. scan_pkg
  331. done | tr ' ' '\n' | sort -u > $tmp/list
  332. [ "$look_for" = bdep ] && look_for=dep
  333. while [ -s $tmp/list ]; do
  334. PACKAGE=$(sed 1!d $tmp/list)
  335. sed 1d -i $tmp/list
  336. append_to_dep
  337. for pkg in $(scan_pkg); do
  338. if ! grep -q ^$pkg$ $tmp/list $tmp/dep; then
  339. echo $pkg >> $tmp/list
  340. fi
  341. done
  342. done
  343. if [ "$cooklist" ]; then
  344. mv $tmp/dep $tmp/cooklist
  345. else
  346. cat $tmp/dep | sort -u
  347. fi
  348. rm -f $tmp/dep $tmp/list
  349. sort -o $dep_db $dep_db
  350. sort -o $wan_db $wan_db
  351. if [ "$db_md5" != "$(md5sum $dep_db $wan_db)" ]; then
  352. grep -q "^#" $PACKAGES_REPOSITORY/cookorder.txt ||
  353. sed 1i"#PlanSort" -i $PACKAGES_REPOSITORY/cookorder.txt
  354. fi
  355. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement