mirror of the now-defunct rocklinux.org
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

231 lines
5.2 KiB

  1. #!/bin/bash
  2. #
  3. # --- ROCK-COPYRIGHT-NOTE-BEGIN ---
  4. #
  5. # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
  6. # Please add additional copyright information _after_ the line containing
  7. # the ROCK-COPYRIGHT-NOTE-END tag. Otherwise it might get removed by
  8. # the ./scripts/Create-CopyPatch script. Do not edit this copyright text!
  9. #
  10. # ROCK Linux: rock-src/scripts/Create-DepDB
  11. # ROCK Linux is Copyright (C) 1998 - 2006 Clifford Wolf
  12. #
  13. # This program is free software; you can redistribute it and/or modify
  14. # it under the terms of the GNU General Public License as published by
  15. # the Free Software Foundation; either version 2 of the License, or
  16. # (at your option) any later version. A copy of the GNU General Public
  17. # License can be found at Documentation/COPYING.
  18. #
  19. # Many people helped and are helping developing ROCK Linux. Please
  20. # have a look at http://www.rocklinux.org/ and the Documentation/TEAM
  21. # file for details.
  22. #
  23. # --- ROCK-COPYRIGHT-NOTE-END ---
  24. cachedir="package"
  25. descdir="package"
  26. debug=''
  27. while [ "$1" ] ; do
  28. case "$1" in
  29. -cachedir)
  30. cachedir=$2 ; shift ; shift ;;
  31. -descdir)
  32. descdir=$2 ; shift ; shift ;;
  33. -debug)
  34. debug=$2 ; shift ; shift ;;
  35. *)
  36. echo
  37. echo "Usage: $0 [ -cachedir cachedir ] [ -descdir descdir ] \\"
  38. echo " ${0//?/ } [ -debug pkg ] > filename"
  39. echo
  40. echo " This scripts creates the scripts/dep_db.txt file from"
  41. echo " the *.cache and *.desc files."
  42. echo
  43. exit 1 ;;
  44. esac
  45. done
  46. echo "Reading *.cache and *.desc files ..." >&2
  47. perl1="" perl2=""
  48. while read package command group packages
  49. do
  50. package=${package%.desc:*}
  51. package=${package##*/}
  52. for p in $package $packages; do
  53. perl1="$perl1 \$deps{'$group'} = 1 if defined \$deps{'$p'};"
  54. perl2="$perl2 \$deps{'$p'} = 1 if defined \$deps{'$group'};"
  55. done
  56. done < <( egrep '^\[(E|DEP|DEPENDENCY)\][ ]+group[ ]' $descdir/*/*/*.desc )
  57. perl -e '
  58. my %deldeps = ();
  59. my %adddeps = ();
  60. # open(F, "scripts/dep_fixes.txt") or die $!;
  61. # while (<F>) {
  62. # chomp;
  63. # if (/^([^#\s]\S*)\s+del\s+(.*)$/) {
  64. # my ($p, $l) = ($1, $2);
  65. # $deldeps{$p}{$_} = 1 foreach (split /\s+/, $l);
  66. # next;
  67. # }
  68. # if (/^([^#\s]\S*)\s+add\s+(.*)$/) {
  69. # my ($p, $l) = ($1, $2);
  70. # $adddeps{$p}{$_} = 1 foreach (split /\s+/, $l);
  71. # next;
  72. # }
  73. # }
  74. # close F;
  75. foreach my $c (<'$cachedir'/*/*/*.cache>) {
  76. my ($pri, $time) = (1, 1);
  77. my $pkg = $c; $pkg=~s,^.*/([^/]*)\.cache$,$1,;
  78. my $found_dep_entries = 0;
  79. my %deps = ();
  80. my $d = $c;
  81. $d =~ s,([^/]*)/[^/]*\.cache$,$1/$1.desc,;
  82. $d =~ s,^'$cachedir','$descdir',;
  83. if ( ! -f $d ) {
  84. print STDERR "WARNING: Can'\''t find $d -> skipping $c.\n";
  85. next;
  86. }
  87. $deps{$_} = 1 foreach (keys %{$adddeps{$pkg}});
  88. open(F, "$c") or die "$!: $c";
  89. while (<F>) {
  90. if (/^\[BUILDTIME\]/) {
  91. @_ = split /\s+/;
  92. $time = $_[1];
  93. next;
  94. }
  95. if (/^\[DEP\]/) {
  96. @_ = split /:\S+\s+|\s+/; shift @_;
  97. foreach (@_) { $deps{$_} = 1 unless defined $deldeps{$pkg}{$_}; }
  98. $found_dep_entries = 1;
  99. next;
  100. }
  101. }
  102. close F;
  103. # no dep_db entry if this package failed in ref build
  104. next unless $found_dep_entries;
  105. open(F, "$d") or die "$!: $d";
  106. while (<F>) {
  107. if (/^\[(P|PRI|PRIORITY)\]/) {
  108. @_ = split /\s+/;
  109. $_[2] =~ s/^.*([0-8]).*$/$1/;
  110. $pri = $_[2].".".$_[3];
  111. next;
  112. }
  113. }
  114. close F;
  115. '"$perl1 $perl2"'
  116. print "$pkg $time $pri ", join(" ", sort keys %deps), " $pkg\n";
  117. }
  118. ' | gawk '
  119. function getpri(package) {
  120. datafile="'$tmp1'";
  121. delete todo;
  122. delete done;
  123. todo[ package ] = 1;
  124. returncode=0;
  125. endloop=0;
  126. level=0;
  127. if (debug != "") {
  128. print "";
  129. print "Creating priority for " package " ...";
  130. }
  131. while ( ! endloop ) {
  132. endloop=1; level++;
  133. for (pkg in todo) {
  134. endloop=0;
  135. delete todo[pkg];
  136. done[pkg] = 1;
  137. firstdebug=1;
  138. for (nextpkg in database) {
  139. if ( index(database[nextpkg], " " pkg " ") ) {
  140. if ( ! (nextpkg in done) &&
  141. ! (nextpkg in todo) &&
  142. ! (nextpkg in ignore) ) {
  143. if ("x" orderdb[nextpkg] < "x" orderdb[pkg]) {
  144. if (debug != "") {
  145. if (firstdebug)
  146. print "\n\t(" level ") Found " \
  147. "dependencies for " pkg ":";
  148. print "\t\t" pkg ": " \
  149. "required by " nextpkg \
  150. " (ignore reverse dep)";
  151. firstdebug=0;
  152. }
  153. } else {
  154. if (debug != "") {
  155. if (firstdebug)
  156. print "\n\t(" level ") Found " \
  157. "dependencies for " pkg ":";
  158. print "\t\t" pkg ": " \
  159. "required by " nextpkg;
  160. firstdebug=0;
  161. }
  162. todo[nextpkg] = 1;
  163. returncode++;
  164. }
  165. }
  166. }
  167. }
  168. }
  169. }
  170. return returncode;
  171. }
  172. BEGIN {
  173. counter=0;
  174. debug="'$debug'";
  175. }
  176. {
  177. orderdb[$1]=$3; $3=0;
  178. database[$1]=$0;
  179. if (NF > 150) {
  180. printf "\rPackage %s has more then 150 (%d) dependencies. " \
  181. "I do not believe this.\n", $1, NF - 3 > "/dev/stderr";
  182. ignore[$1] = 1;
  183. }
  184. counter++;
  185. }
  186. END {
  187. if (debug != "") {
  188. pri=getpri(debug);
  189. print "\nResulting Priority: " pri;
  190. } else {
  191. for (package in database) {
  192. printf "\rCreating dependency database (" \
  193. counter ") ... \b" > "/dev/stderr";
  194. $0 = database[package];
  195. $3 = getpri(package);
  196. $1 = $1 ":"; print;
  197. counter--;
  198. }
  199. print "\rCreating dependency database ... " \
  200. "done." > "/dev/stderr";
  201. }
  202. }
  203. ' | if [ "$debug" ] ; then cat ; else sort ; fi