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.

226 lines
5.1 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 - 2005 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 "Usage: $0 [ -cachedir cachedir ] [ -descdir descdir ] \\"
  37. echo " ${0//?/ } [ -debug pkg ] > filename"
  38. exit 1 ;;
  39. esac
  40. done
  41. echo "Reading *.cache and *.desc files ..." >&2
  42. perl1="" perl2=""
  43. while read package command group packages
  44. do
  45. package=${package%.desc:*}
  46. package=${package##*/}
  47. for p in $package $packages; do
  48. perl1="$perl1 \$deps{'$group'} = 1 if defined \$deps{'$p'};"
  49. perl2="$perl2 \$deps{'$p'} = 1 if defined \$deps{'$group'};"
  50. done
  51. done < <( egrep '^\[(E|DEP|DEPENDENCY)\][ ]+group[ ]' $descdir/*/*/*.desc )
  52. perl -e '
  53. my %deldeps = ();
  54. my %adddeps = ();
  55. # open(F, "scripts/dep_fixes.txt") or die $!;
  56. # while (<F>) {
  57. # chomp;
  58. # if (/^([^#\s]\S*)\s+del\s+(.*)$/) {
  59. # my ($p, $l) = ($1, $2);
  60. # $deldeps{$p}{$_} = 1 foreach (split /\s+/, $l);
  61. # next;
  62. # }
  63. # if (/^([^#\s]\S*)\s+add\s+(.*)$/) {
  64. # my ($p, $l) = ($1, $2);
  65. # $adddeps{$p}{$_} = 1 foreach (split /\s+/, $l);
  66. # next;
  67. # }
  68. # }
  69. # close F;
  70. foreach my $c (<'$cachedir'/*/*/*.cache>) {
  71. my ($pri, $time) = (1, 1);
  72. my $pkg = $c; $pkg=~s,^.*/([^/]*)\.cache$,$1,;
  73. my $found_dep_entries = 0;
  74. my %deps = ();
  75. my $d = $c;
  76. $d =~ s,([^/]*)/[^/]*\.cache$,$1/$1.desc,;
  77. $d =~ s,^'$cachedir','$descdir',;
  78. if ( ! -f $d ) {
  79. print STDERR "WARNING: Can'\''t find $d -> skipping $c.\n";
  80. next;
  81. }
  82. $deps{$_} = 1 foreach (keys %{$adddeps{$pkg}});
  83. open(F, "$c") or die "$!: $c";
  84. while (<F>) {
  85. if (/^\[BUILDTIME\]/) {
  86. @_ = split /\s+/;
  87. $time = $_[1];
  88. next;
  89. }
  90. if (/^\[DEP\]/) {
  91. @_ = split /:\S+\s+|\s+/; shift @_;
  92. foreach (@_) { $deps{$_} = 1 unless defined $deldeps{$pkg}{$_}; }
  93. $found_dep_entries = 1;
  94. next;
  95. }
  96. }
  97. close F;
  98. # no dep_db entry if this package failed in ref build
  99. next unless $found_dep_entries;
  100. open(F, "$d") or die "$!: $d";
  101. while (<F>) {
  102. if (/^\[(P|PRI|PRIORITY)\]/) {
  103. @_ = split /\s+/;
  104. $_[2] =~ s/^.*([0-8]).*$/$1/;
  105. $pri = $_[2].".".$_[3];
  106. next;
  107. }
  108. }
  109. close F;
  110. '"$perl1 $perl2"'
  111. print "$pkg $time $pri ", join(" ", sort keys %deps), " $pkg\n";
  112. }
  113. ' | gawk '
  114. function getpri(package) {
  115. datafile="'$tmp1'";
  116. delete todo;
  117. delete done;
  118. todo[ package ] = 1;
  119. returncode=0;
  120. endloop=0;
  121. level=0;
  122. if (debug != "") {
  123. print "";
  124. print "Creating priority for " package " ...";
  125. }
  126. while ( ! endloop ) {
  127. endloop=1; level++;
  128. for (pkg in todo) {
  129. endloop=0;
  130. delete todo[pkg];
  131. done[pkg] = 1;
  132. firstdebug=1;
  133. for (nextpkg in database) {
  134. if ( index(database[nextpkg], " " pkg " ") ) {
  135. if ( ! (nextpkg in done) &&
  136. ! (nextpkg in todo) &&
  137. ! (nextpkg in ignore) ) {
  138. if ("x" orderdb[nextpkg] < "x" orderdb[pkg]) {
  139. if (debug != "") {
  140. if (firstdebug)
  141. print "\n\t(" level ") Found " \
  142. "dependencies for " pkg ":";
  143. print "\t\t" pkg ": " \
  144. "required by " nextpkg \
  145. " (ignore reverse dep)";
  146. firstdebug=0;
  147. }
  148. } else {
  149. if (debug != "") {
  150. if (firstdebug)
  151. print "\n\t(" level ") Found " \
  152. "dependencies for " pkg ":";
  153. print "\t\t" pkg ": " \
  154. "required by " nextpkg;
  155. firstdebug=0;
  156. }
  157. todo[nextpkg] = 1;
  158. returncode++;
  159. }
  160. }
  161. }
  162. }
  163. }
  164. }
  165. return returncode;
  166. }
  167. BEGIN {
  168. counter=0;
  169. debug="'$debug'";
  170. }
  171. {
  172. orderdb[$1]=$3; $3=0;
  173. database[$1]=$0;
  174. if (NF > 150) {
  175. printf "\rPackage %s has %d dependencies. I don'\''t " \
  176. "believe this.\n", $1, NF - 3 > "/dev/stderr";
  177. ignore[$1] = 1;
  178. }
  179. counter++;
  180. }
  181. END {
  182. if (debug != "") {
  183. pri=getpri(debug);
  184. print "\nResulting Priority: " pri;
  185. } else {
  186. for (package in database) {
  187. printf "\rCreating dependency database (" \
  188. counter ") ... \b" > "/dev/stderr";
  189. $0 = database[package];
  190. $3 = getpri(package);
  191. $1 = $1 ":"; print;
  192. counter--;
  193. }
  194. print "\rCreating dependency database ... " \
  195. "done." > "/dev/stderr";
  196. }
  197. }
  198. ' | if [ "$debug" ] ; then cat ; else sort ; fi