support for rpmmd and yast repos
authorLudwig Nussel <ludwig.nussel@suse.de>
Fri, 22 Feb 2008 13:43:28 +0000 (13:43 +0000)
committerLudwig Nussel <ludwig.nussel@suse.de>
Fri, 22 Feb 2008 13:43:28 +0000 (13:43 +0000)
also speedup determining packages to keep by passing the rpmids

createrepomddeps [new file with mode: 0755]
createrpmdeps
createyastdeps [new file with mode: 0755]
expanddeps
init_buildsystem

diff --git a/createrepomddeps b/createrepomddeps
new file mode 100755 (executable)
index 0000000..3068036
--- /dev/null
@@ -0,0 +1,413 @@
+#!/usr/bin/perl -w
+
+BEGIN {
+  unshift @INC, ($::ENV{'BUILD_DIR'} || '/usr/lib/build');
+}
+
+use strict;
+use XML::Parser;
+use Data::Dumper;
+use Getopt::Long;
+use Build::Rpm;
+Getopt::Long::Configure("no_ignore_case");
+
+my @parent = [];
+my @primaryfiles = ();
+my @packages = ();
+
+my $baseurl; # current url
+
+my $opt_dump;
+my $opt_old;
+my $opt_nosrc;
+my $opt_bc;
+
+my $old_seen = ();
+
+my $repomdparser = {
+       repomd => {
+               data => {
+                       _start => \&repomd_handle_data_start,
+                       location => {
+                               _start => \&repomd_handle_location,
+                       },
+               },
+       },
+};
+
+my $primaryparser = {
+       metadata => {
+               'package' => {
+                       _start => \&primary_handle_package_start,
+                       _end => \&primary_handle_package_end,
+                       name => { _text => \&primary_collect_text, _end => \&primary_store_text },
+                       arch => { _text => \&primary_collect_text, _end => \&primary_store_text },
+                       version => { _start => \&primary_handle_version },
+                       'time' => { _start => \&primary_handle_time },
+                       format => {
+                               'rpm:provides' => { 'rpm:entry' => { _start => \&primary_handle_package_provides }, },
+                               'rpm:requires' => { 'rpm:entry' => { _start => \&primary_handle_package_requires }, },
+                               'rpm:conflicts' => { 'rpm:entry' => { _start => \&primary_handle_package_conflicts }, },
+                               'rpm:obsoletes' => { 'rpm:entry' => { _start => \&primary_handle_package_obsoletes }, },
+                               'rpm:buildhost' => { _text => \&primary_collect_text, _end => \&primary_store_text },
+                               'rpm:sourcerpm' => { _text => \&primary_collect_text, _end => \&primary_store_text },
+                               file => {
+                                       _start => \&primary_handle_file_start,
+                                       _text => \&primary_collect_text,
+                                       _end => \&primary_handle_file_end
+                               },
+                       },
+                       location => { _start => \&primary_handle_package_location },
+               },
+       },
+};
+
+# [ [tag, \%], ... ]
+my @cursor = ();
+
+sub repomd_handle_data_start
+{
+       my $p = shift;
+       my $el = shift;
+
+       my $attr = map_attrs(@_);
+       if($attr->{'type'} ne 'primary') {
+               pop @cursor;
+       }
+}
+
+sub repomd_handle_location
+{
+       my $p = shift;
+       my $el = shift;
+
+       my $attr = map_attrs(@_);
+       if(exists $attr->{'href'}) {
+               push @primaryfiles, { location => $attr->{'href'} };
+       }
+}
+
+sub generic_handle_start
+{
+       my $p = shift;
+       my $el = shift;
+
+       if(exists $cursor[-1]->[1]->{$el})
+       {
+               my $h = $cursor[-1]->[1]->{$el};
+               push @cursor, [$el, $h];
+               if(exists $h->{'_start'}) {
+                       &{$h->{'_start'}}($p, $el, @_);
+               }
+       }
+}
+
+sub generic_handle_char
+{
+       my $p = shift;
+       my $text = shift;
+
+       my $h = $cursor[-1]->[1];
+
+       if(exists $h->{'_text'}) {
+               &{$h->{'_text'}}($p, $text);
+       }
+}
+
+sub generic_handle_end
+{
+       my $p = shift;
+       my $el = shift;
+
+       if(!defined $cursor[-1]->[0] || $cursor[-1]->[0] eq $el)
+       {
+               my $h = $cursor[-1]->[1];
+
+               if(exists $h->{'_end'}) {
+                       &{$h->{'_end'}}($p, $el);
+               }
+
+               pop @cursor;
+       }
+}
+
+sub map_attrs
+{
+       my %h;
+       while(@_) {
+               my $k = shift;
+               $h{$k} = shift;
+       }
+
+       return \%h;
+}
+
+# expat does not guarantee that character data doesn't get split up
+# between multiple calls
+my $textbuf = '';
+sub primary_collect_text
+{
+       my $p = shift;
+       my $text = shift;
+
+       $textbuf .= $text;
+}
+
+sub primary_store_text
+{
+    my $p = shift;
+    my $el = shift;
+
+    $packages[-1]->{$cursor[-1]->[0]} = $textbuf;
+    $textbuf = '';
+}
+
+sub primary_handle_package_start
+{
+       my $p = shift;
+       my $el = shift;
+
+       my $attr = map_attrs(@_);
+
+       push @packages, { type => $attr->{'type'}, baseurl => $baseurl };
+}
+
+sub primary_handle_package_end
+{
+       my $p = shift;
+       my $el = shift;
+
+       if($opt_bc) {
+           printasbuildcachefile(@packages);
+           shift @packages;
+       } elsif ($opt_old) {
+           foreach my $pkg (@packages) {
+               my $arch = $pkg->{'arch'};
+               $arch = 'src' if $pkg->{'arch'} eq 'nosrc';
+               next if ($arch eq 'src' && $opt_nosrc);
+               if(exists($old_seen->{$pkg->{'name'}}->{$arch})) {
+                   my $pv = $old_seen->{$pkg->{'name'}}->{$arch}->{'ver'};
+                   my $rv = $pkg->{'ver'}.'-'.$pkg->{'rel'};
+                   my $vv = Build::Rpm::verscmp($pv, $rv, 0);
+                   if($vv < 0)
+                   {
+                       print $old_seen->{$pkg->{'name'}}->{$arch}->{'loc'}."\n";
+                       $old_seen->{$pkg->{'name'}}->{$arch}->{'ver'} = $pkg->{'ver'}.'-'.$pkg->{'rel'};
+                       $old_seen->{$pkg->{'name'}}->{$arch}->{'loc'} = $pkg->{'baseurl'} . $pkg->{'location'};
+                   } else {
+                       print $pkg->{'baseurl'} . $pkg->{'location'}."\n";
+                   }
+               } else {
+                   $old_seen->{$pkg->{'name'}}->{$arch}->{'ver'} = $pkg->{'ver'}.'-'.$pkg->{'rel'};
+                   $old_seen->{$pkg->{'name'}}->{$arch}->{'loc'} = $pkg->{'baseurl'} . $pkg->{'location'};
+               }
+           }
+           shift @packages;
+       }
+}
+
+sub primary_handle_version
+{
+       my $p = shift;
+       my $el = shift;
+
+       my $attr = map_attrs(@_);
+       $packages[-1]->{'ver'} = $attr->{'ver'};
+       $packages[-1]->{'rel'} = $attr->{'rel'};
+}
+
+sub primary_handle_time
+{
+       my $p = shift;
+       my $el = shift;
+
+       my $attr = map_attrs(@_);
+       $packages[-1]->{'filetime'} = $attr->{'file'};
+       $packages[-1]->{'buildtime'} = $attr->{'build'};
+}
+
+sub primary_handle_package_location
+{
+       my $p = shift;
+       my $el = shift;
+
+       my $attr = map_attrs(@_);
+       $packages[-1]->{'location'} = $attr->{'href'};
+}
+
+sub primary_handle_file_start
+{
+       my $p = shift;
+       my $el = shift;
+
+       my $attr = map_attrs(@_);
+       if(exists $attr->{'type'}) {
+               pop @cursor;
+       }
+}
+
+sub primary_handle_file_end
+{
+       my $p = shift;
+       my $text = shift;
+
+       primary_handle_package_deps('provides', 'name', $textbuf);
+       $textbuf = '';
+}
+
+my %flagmap = (
+       EQ => '=',
+       LE => '<=',
+       GE => '>=',
+       GT => '>',
+       LT => '<',
+       NE => '!=',
+);
+
+sub primary_handle_package_deps
+{
+       my $dep = shift;
+       my $attr = map_attrs(@_);
+
+       if(exists $attr->{'flags'}) {
+               if(!exists($flagmap{$attr->{'flags'}})) {
+                       print STDERR "bogus relation: ", $attr->{'flags'}, "\n";
+                       return;
+               }
+               $attr->{'flags'} = $flagmap{$attr->{'flags'}};
+       }
+       return if($attr->{'name'} =~ /^rpmlib\(/);
+       push @{$packages[-1]->{$dep}}, $attr;
+
+}
+
+sub primary_handle_package_conflicts
+{
+       shift;shift; primary_handle_package_deps('conflicts', @_);
+}
+
+sub primary_handle_package_obsoletes
+{
+       shift;shift; primary_handle_package_deps('obsoletes', @_);
+}
+
+sub primary_handle_package_requires
+{
+       shift;shift; primary_handle_package_deps('requires', @_);
+}
+sub primary_handle_package_provides
+{
+       shift;shift; primary_handle_package_deps('provides', @_);
+}
+
+sub deps2string
+{
+       return join(' ', map {
+                               my $s = $_->{'name'};
+                               if(exists $_->{'flags'}) {
+                                       $s .= ' '.$_->{'flags'}.' ';
+                                       $s .= $_->{'epoch'}.':' if(exists $_->{'epoch'} && $_->{'epoch'} != 0);
+                                       $s .= $_->{'ver'};
+                                       $s .= '-'.$_->{'rel'} if exists $_->{'rel'};
+                               }
+                               $s
+                       } @_);
+}
+
+sub printasbuildcachefile(@)
+{
+       foreach my $pkg (@_) {
+               next if $pkg->{'arch'} eq 'src' || $pkg->{'arch'} eq 'nosrc';
+               my $id = sprintf("%s.%s-%d/%d/%d: ",
+                       $pkg->{'name'},
+                       $pkg->{'arch'},
+                       $pkg->{'buildtime'},
+                       $pkg->{'filetime'},
+                       0);
+               print "F:".$id. $pkg->{'baseurl'} . $pkg->{'location'} . "\n";
+
+               my $deps = deps2string(@{$pkg->{'provides'}});
+               print "P:$id$deps\n";
+
+               $deps = deps2string(@{$pkg->{'requires'}});
+               print "R:$id$deps\n";
+
+               my $tag = sprintf("%s-%s-%s %s",
+                       $pkg->{'name'},
+                       $pkg->{'ver'},
+                       $pkg->{'rel'},
+#                      $pkg->{'rpm:buildhost'},
+                       $pkg->{'buildtime'});
+               print "I:$id$tag\n";
+       }
+}
+
+
+### main
+
+GetOptions (
+    "nosrc"   => \$opt_nosrc,
+    "dump"   => \$opt_dump,
+    "old"   => \$opt_old,
+    ) or exit(1);
+
+$opt_bc = 1 unless ($opt_dump || $opt_old);
+
+my $p = new XML::Parser(
+       Handlers => {
+               Start => \&generic_handle_start,
+               End => \&generic_handle_end,
+               Char => \&generic_handle_char
+       });
+
+#my $url = '/mounts/mirror/SuSE/ftp.suse.com/pub/suse/update/10.1/';
+foreach my $url (@ARGV) {
+       $url .= '/' unless $url =~ /\/$/;
+
+       $baseurl = $url;
+       @primaryfiles = ();
+       @cursor = ([undef, $repomdparser]);
+
+       $p->parsefile($url . 'repodata/repomd.xml');
+
+#      print Dumper(\@primaryfiles);
+
+       foreach my $f (@primaryfiles) {
+               @cursor = ([undef, $primaryparser]);
+
+               my $u = $url . $f->{'location'};
+               $u = 'gzip -cd ' . $u . '|' if ($u =~ /\.gz$/); # XXX
+
+               my $fh;
+               open($fh, $u) or next;
+               $p->parse($fh);
+               close($fh);
+       }
+}
+
+if ($opt_dump) {
+    print Data::Dumper->Dump([\@packages], ['packages']); # caution: excessive memory consumption!
+}
+
+#if($rpmdepdump) {
+#    my %amap = map { $_ => 1 } @archs;
+#    my $packages = do $rpmdepdump or die $!;
+#
+#    foreach my $pkg (@$packages) {
+#      next if exists $packs{$pkg->{'name'}};
+#      next unless exists $amap{$pkg->{'arch'}};
+#      next if $pkg->{'arch'} eq 'src' || $pkg->{'arch'} eq 'nosrc';
+#      next if $pkg->{'location'} =~ /\.(?:patch|delta)\.rpm$/;
+#
+#      my $pa = $pkg->{'name'}.'.'.$pkg->{'arch'};
+#      $packs{$pkg->{'name'}} = $pa;
+#      $fn{$pa} = $pkg->{'baseurl'}.$pkg->{'location'};
+#      my $r = {};
+#      # flags and version ignored
+#      my @pr = map { $_->{'name'} } @{$pkg->{'provides'}};
+#      my @re = map { $_->{'name'} } @{$pkg->{'requires'}};
+#      $r->{'provides'} = \@pr;
+#      $r->{'requires'} = \@re;
+#      $repo{$pkg->{'name'}} = $r;
+#    }
+#}
index 0ab5158..4a13686 100755 (executable)
@@ -11,6 +11,8 @@ use strict;
 
 my $rpmdepfile = $ARGV[0];
 
+my %tag;
+
 my %oldp;
 my %oldr;
 if (defined($rpmdepfile) && open(F, '<', $rpmdepfile)) {
@@ -26,24 +28,16 @@ if (defined($rpmdepfile) && open(F, '<', $rpmdepfile)) {
 }
 
 my $redo = 1;
-while ($redo) {
+foreach my $dir (@ARGV) {
   $redo = 0;
-  my $packages;
   my @known;
   my %known2fn;
   my %known2path;
   my %fnsize2id;
-  while (<STDIN>) {
+  my $cmd = "find $dir -follow -type f \\( -name \"*.rpm\" -o -name \"*.deb\" \\) -a ! -name \"*src.rpm\" -printf '\%T@/\%s/\%i \%p\\n'";
+  open(F, '-|', $cmd) or next;
+  while (<F>) {
     chomp;
-    if ($_ eq '') {
-      # next block;
-      $redo = 1;
-      last;
-    }
-    if (/\/packages$/) {
-      $packages = $_;
-      next;
-    }
     next unless /^(\d+\/\d+\/\d+) (.*)$/;
     my $id = $1;
     my $path = $2;
@@ -74,6 +68,8 @@ while ($redo) {
     $fnsize2id{"$fn-$size"} = $id;
   }
 
+  close F;
+
   my %newp;
   my %newr;
   for (@known) {
@@ -82,78 +78,11 @@ while ($redo) {
   }
 
   my @todo = grep {!($newp{$_} && $newr{$_})} @known;
-  if (@todo && $packages && open(F, '<', $packages)) {
-    my ($pack, $vers, $rel, $btime, $arch, $loc, $id, $size);
-    my ($req, $prv);
-    while (<F>) {
-      chomp;
-      next unless /^[=+]/;
-      my ($tag, $data);
-      if (/^\+(.*)$/) {
-       $tag = $1;
-       $data = '';
-       while (<F>) {
-         chomp;
-         last if $_ eq "-$tag";
-         $data .= "$_\n";
-       }
-       chop $data;
-      } else {
-       ($tag, $data) = split(' ', $_, 2);
-       $tag = substr($tag, 1);
-      }
-      if ($tag eq 'Pkg:') {
-       if ($pack && $loc && $size) {
-         my $id = $fnsize2id{"$loc-$size"};
-         if ($id && $known2path{"$pack.$arch-$id"}) {
-           $prv = "$pack = $vers-$rel" unless defined $prv;
-           $req = '' unless defined $req;
-           $newp{"$pack.$arch-$id"} = "P:$pack.$arch-$id: $prv";
-           $newr{"$pack.$arch-$id"} = "R:$pack.$arch-$id: $req";
-         }
-       }
-       ($pack, $vers, $rel, $arch) = split(' ', $data);
-       undef $req;
-       undef $prv;
-       undef $btime;
-       undef $size;
-       undef $loc;
-       undef $pack if $arch && ($arch eq 'src' || $arch eq 'nosrc');
-      } elsif ($tag eq 'Req:') {
-       next unless $pack;
-       $data =~ s/\n/ /gs;
-       $req = $data;
-      } elsif ($tag eq 'Prv:') {
-       next unless $pack;
-       # add self provides for old rpm versions
-       $data = "$pack = $vers-$rel\n$data" unless "\n$data" =~ /\n\Q$pack\E =/s;
-       $data =~ s/\n/ /gs;
-       $prv = $data;
-      } elsif ($tag eq 'Tim:') {
-       $btime = $data;
-      } elsif ($tag eq 'Loc:') {
-       my @data = split(' ', $data);
-       $loc = $data[1];
-      } elsif ($tag eq 'Siz:') {
-       my @data = split(' ', $data);
-       $size = $data[0];
-      }
-    }
-    close F;
-    if ($pack && $loc && $size) {
-      my $id = $fnsize2id{"$loc-$size"};
-      if ($id && $known2path{"$pack.$arch-$id"}) {
-       $newp{"$pack.$arch-$id"} = "P:$pack.$arch-$id: $prv";
-       $newr{"$pack.$arch-$id"} = "R:$pack.$arch-$id: $req";
-      }
-    }
-    @todo = grep {!($newp{$_} && $newr{$_})} @known;
-  }
   if (@todo) {
     for my $known (@todo) {
       my $path = $known2path{$known};
       if ($path =~ /\.rpm$/) {
-        my %res = Build::Rpm::rpmq($path, 1000, 1022, 1047, 1049, 1048, 1050, 1112, 1113);
+        my %res = Build::Rpm::rpmq($path, 1000, 1001, 1002, 1006, 1022, 1047, 1049, 1048, 1050, 1112, 1113);
         next unless %res;
         Build::Rpm::add_flagsvers(\%res, 1047, 1112, 1113);
         Build::Rpm::add_flagsvers(\%res, 1049, 1048, 1050);
@@ -168,6 +97,8 @@ while ($redo) {
         }
         $newp{$known} = "P:$known: ".join(' ', @{$res{1047} || []});
         $newr{$known} = "R:$known: ".join(' ', @{$res{1049} || []});
+       #$tag{$known} = $res{1000}->[0]."-".$res{1001}->[0]."-".$res{1002}->[0]." ".$res{1007}->[0]."-".$res{1006}->[0];
+       $tag{$known} = $res{1000}->[0]."-".$res{1001}->[0]."-".$res{1002}->[0]." ".$res{1006}->[0];
       } else {
         my %res = Build::Deb::debq($path);
         next unless %res;
@@ -200,5 +131,6 @@ while ($redo) {
     print "F:$_: $known2path{$_}\n";
     print "$newp{$_}\n";
     print "$newr{$_}\n";
+    print "I:$_: $tag{$_}\n" if exists $tag{$_};
   }
 }
diff --git a/createyastdeps b/createyastdeps
new file mode 100755 (executable)
index 0000000..fd59c85
--- /dev/null
@@ -0,0 +1,141 @@
+#!/usr/bin/perl -w
+
+BEGIN {
+  unshift @INC, ($::ENV{'BUILD_DIR'} || '/usr/lib/build');
+}
+
+use Build;
+use strict;
+
+sub print_pkg($)
+{
+  my $pkg = shift;
+
+  return if $pkg->{'arch'} eq 'src' || $pkg->{'arch'} eq 'nosrc';
+  my $id = sprintf("%s.%s-%d/%d/%d: ",
+         $pkg->{'name'},
+         $pkg->{'arch'},
+         $pkg->{'buildtime'},
+         0,
+         0);
+  print sprintf('F:%s%ssuse/%s/%s',$id,$pkg->{'baseurl'},
+    $pkg->{'arch'}, $pkg->{'location'}), "\n";
+
+  if(!$pkg->{'provides'}) # happens in 8.1 packages file
+  {
+    $pkg->{'provides'} = sprintf("%s = %s-%s", $pkg->{'name'}, $pkg->{'ver'}, $pkg->{'rel'});
+  }
+
+  print "P:$id".$pkg->{'provides'}."\n";
+  print "R:$id".$pkg->{'requires'}."\n";
+
+  my $tag = sprintf("%s-%s-%s %s",
+         $pkg->{'name'},
+         $pkg->{'ver'},
+         $pkg->{'rel'},
+#                      $pkg->{'rpm:buildhost'},
+         $pkg->{'buildtime'});
+  print "I:$id$tag\n";
+}
+
+while (@ARGV)
+{
+  my $url = shift;
+  $url .= '/' unless $url =~ /\/$/;
+
+# a really fucked up system
+#  if (-e $url."/yast/order") {
+#    if(open(F, '<', $url."/yast/order")) {
+#      my $found_products;
+#      while(<F>) {
+#      chomp;
+#      my ($a, $b) = split(/ /);
+#      $a =~ s/^\///;
+#      if(-e $url.$a)
+#      {
+#        push @ARGV, $url.$a;
+#        $found_products = 1;
+#        print STDERR "$url -> $url$a\n";
+#      }
+#      }
+#      close(F);
+#      next if $found_products;
+#    }
+#  }
+  # XXX: location is actually defined in content file
+  my $packages = $url.'suse/setup/descr/packages';
+
+  if(!open(F, '<', $packages)) {
+    if(!open(F, '-|', "gzip -dc $packages".'.gz')) {
+      die "$packages: $!";
+    }
+  }
+
+  {
+    my $pkg;
+    my ($req, $prv);
+    while (<F>) {
+      chomp;
+      next unless /^[=+]/;
+      my ($tag, $data);
+      if (/^\+(.*)$/) {
+       $tag = $1;
+       $data = '';
+       while (<F>) {
+         chomp;
+         last if $_ eq "-$tag";
+         $data .= "$_\n";
+       }
+       chop $data;
+      } else {
+       ($tag, $data) = split(' ', $_, 2);
+       $tag = substr($tag, 1);
+      }
+      if ($tag eq 'Pkg:') {
+       if($pkg) {
+         print_pkg($pkg);
+         undef $pkg;
+       }
+       my ($name, $vers, $rel, $arch) = split(' ', $data);
+       $pkg = {};
+       $pkg->{'name'} = $name;
+       $pkg->{'ver'} = $vers;
+       $pkg->{'rel'} = $rel;
+       $pkg->{'arch'} = $arch;
+       $pkg->{'baseurl'} = $url;
+      } elsif ($tag eq 'Req:') {
+       next unless $pkg;
+       $data =~ s/\n/ /gs;
+       $pkg->{'requires'} = $data;
+      } elsif ($tag eq 'Prv:') {
+       next unless $pkg;
+       # add self provides for old rpm versions
+       my $name = $pkg->{'name'};
+       $data = sprintf("%s = %s-%s",
+         $name,
+         $pkg->{'ver'},
+         $pkg->{'rel'}) ."\n".$data unless "\n$data" =~ /\n\Q$name\E =/s;
+       $data =~ s/\n/ /gs;
+       $pkg->{'provides'} = $data;
+      } elsif ($tag eq 'Tim:') {
+       $pkg->{'buildtime'} = $data;
+      } elsif ($tag eq 'Loc:') {
+       my @data = split(' ', $data);
+       # multi cd support hack
+       my $num = $data[0];
+       if($pkg->{'baseurl'} =~ /1\/$/ && $num ne 0) {
+         $pkg->{'baseurl'} =~ s/1\//$num\//;
+       }
+       $pkg->{'location'} = $data[1];
+      } elsif ($tag eq 'Siz:') {
+       my @data = split(' ', $data);
+       $pkg->{'size'} = $data[0];
+      }
+    }
+    close F;
+
+    print_pkg($pkg) if $pkg;
+  }
+}
+
+# vim: sw=2
index ef7f29e..bd60d9a 100755 (executable)
@@ -70,8 +70,12 @@ push @archs, 'noarch' unless grep {$_ eq 'noarch'} @archs;
 
 my (%fn, %prov, %req);
 
-open(F, '<', $rpmdeps) || die("$rpmdeps: $!\n");
+my %packs;
+my %repo;
+my %ids;
+
 my %packs_arch;
+open(F, '<', $rpmdeps) || die("$rpmdeps: $!\n");
 while(<F>) {
   chomp;
   if (/^F:(.*?)-\d+\/\d+\/\d+: (.*)$/) {
@@ -86,15 +90,47 @@ while(<F>) {
   } elsif (/^R:(.*?)-\d+\/\d+\/\d+: (.*)$/) {
     next if $req{$1};
     $req{$1} = $2;
+  } elsif (/^I:(.*?)-\d+\/\d+\/\d+: (.*)$/) {
+    next if $ids{$1};
+    $ids{$1} = $2;
   }
 }
 close F;
 
-my %packs;
 for my $arch (@archs) {
   $packs{$_} ||= "$_.$arch" for @{$packs_arch{$arch} || []};
 }
 
+for my $pack (keys %packs) {
+  my $r = {};
+  my (@s, $s, @pr, @re);
+  @s = split(' ', $prov{$packs{$pack}});
+  while (@s) {
+    $s = shift @s;
+    next if $s =~ /^\//;
+    if ($s =~ /^rpmlib\(/) {
+      splice(@s, 0, 2);
+      next;
+    }
+    push @pr, $s;
+    splice(@s, 0, 2) if @s && $s[0] =~ /^[<=>]/;
+  }
+  @s = split(' ', $req{$packs{$pack}});
+  while (@s) {
+    $s = shift @s;
+    next if $s =~ /^\//;
+    if ($s =~ /^rpmlib\(/) {
+      splice(@s, 0, 2);
+      next;
+    }
+    push @re, $s;
+    splice(@s, 0, 2) if @s && $s[0] =~ /^[<=>]/;
+  }
+  $r->{'provides'} = \@pr;
+  $r->{'requires'} = \@re;
+  $repo{$pack} = $r;
+}
+
 if (!defined($dist) || $dist eq '') {
   my $rpmarch = (grep {$fn{"rpm.$_"}} @archs)[0];
   if (!$rpmarch) {
@@ -179,36 +215,6 @@ if ($spec) {
   @packdeps = @{$d->{'deps'} || []};
 }
 
-my %repo;
-for my $pack (keys %packs) {
-  my $r = {};
-  my (@s, $s, @pr, @re);
-  @s = split(' ', $prov{$packs{$pack}});
-  while (@s) {
-    $s = shift @s;
-    next if $s =~ /^\//;
-    if ($s =~ /^rpmlib\(/) {
-      splice(@s, 0, 2);
-      next;
-    }
-    push @pr, $s;
-    splice(@s, 0, 2) if @s && $s[0] =~ /^[<=>]/;
-  }
-  @s = split(' ', $req{$packs{$pack}});
-  while (@s) {
-    $s = shift @s;
-    next if $s =~ /^\//;
-    if ($s =~ /^rpmlib\(/) {
-      splice(@s, 0, 2);
-      next;
-    }
-    push @re, $s;
-    splice(@s, 0, 2) if @s && $s[0] =~ /^[<=>]/;
-  }
-  $r->{'provides'} = \@pr;
-  $r->{'requires'} = \@re;
-  $repo{$pack} = $r;
-}
 Build::readdeps($cf, undef, \%repo);
 
 #######################################################################
@@ -223,6 +229,7 @@ if (!shift @bdeps) {
 
 for (@bdeps) {
   print "$_ $fn{$packs{$_}}\n";
+  print "rpmid: $_:$ids{$packs{$_}}\n" if exists $ids{$packs{$_}};
 }
 print "preinstall: @{$cf->{'preinstall'} || []}\n";
 print "runscripts: @{$cf->{'runscripts'} || []}\n";
index 17849bf..9b716b0 100755 (executable)
@@ -206,12 +206,23 @@ function validate_cache_file {
        test "$SRC" -nt $CACHE_FILE && rm -f $CACHE_FILE.id
     done
     if ! test -f $CACHE_FILE.id ; then
-       test -z "$LIST_STATE" && echo initializing $CACHE_FILE with find command...
+       test -z "$LIST_STATE" && echo initializing $CACHE_FILE ...
        for SRC in "${repos[@]}" ; do
-           test -z "$SRC" && SRC=.
-           find "$SRC" -type f -name packages -print -o -follow -type f \( -name "*.rpm" -o -name "*.deb" \) -a ! -name "*src.rpm" -printf '%T@/%s/%i %p\n'
-           echo
-       done | createrpmdeps $CACHE_FILE > $CACHE_FILE.new
+           test -z "$SRC" && SRC=`pwd`
+           if [ ! -e "$SRC" ]; then
+               echo "*** $SRC does not exist" >&2
+               cleanup_and_exit 1
+           elif [ -e "$SRC"/suse/setup/descr/packages -o -e "$SRC"/suse/setup/descr/packages.gz ]; then
+               set -- $BUILD_DIR/createyastdeps "$SRC"
+           elif [ -e "$SRC"/repodata/repomd.xml ]; then
+               set -- $BUILD_DIR/createrepomddeps "$SRC"
+           else
+               set -- $BUILD_DIR/createrpmdeps "$SRC"
+           fi
+           echo "$@" >&2
+           "$@" || cleanup_and_exit 1
+       done > $CACHE_FILE.new
+
        mv $CACHE_FILE.new $CACHE_FILE
        echo "${repos[*]}" > $CACHE_FILE.id
     fi
@@ -321,7 +332,7 @@ else
            continue
        fi
        if test "$PKG" = "rpmid:" ; then
-           echo "${SRC#*:}" > $BUILD_ROOT/.init_b_cache/rpm/${SRC%%:*}.id
+           echo "${SRC#*:}" > $BUILD_ROOT/.init_b_cache/rpms/${SRC%%:*}.id
            continue
        fi
        ln -s "$SRC" "$BUILD_ROOT/.init_b_cache/rpms/$PKG.${SRC##*.}"