Try to keep the names closer to alphabetical order.
[fedora-mingw.git] / smock / smock.pl
index b33d07c..0833b68 100755 (executable)
@@ -2,6 +2,21 @@
 #
 # SMOCK - Simpler Mock
 # by Dan Berrange and Richard W.M. Jones.
+# Copyright (C) 2008 Red Hat Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
 use strict;
 
@@ -152,10 +167,24 @@ sub is_member_of
     0;
 }
 
-my @names = keys %srpms;
+sub dependency_in
+{
+    my $dep = shift;           # eg. dbus-devel
+
+    while ($dep) {
+       return $dep if is_member_of ($dep, @_);
+       my $newdep = $dep;
+       $newdep =~ s/-\w+$//;   # eg. dbus-devel -> dbus
+       last if $newdep eq $dep;
+       $dep = $newdep;
+    }
+    0;
+}
+
+my @names = sort keys %srpms;
 foreach my $name (@names) {
     my @buildrequires = @{$srpms{$name}->{buildrequires}};
-    @buildrequires = grep { is_member_of ($_, @names) } @buildrequires;
+    @buildrequires = grep { $_ = dependency_in ($_, @names) } @buildrequires;
     $srpms{$name}{buildrequires} = \@buildrequires;
 }
 
@@ -214,15 +243,17 @@ if (! -d "$localrepo/scratch") {
 
 system "rm -f $localrepo/scratch/*";
 
-foreach my $name (@buildorder) {
-    my $version = $srpms{$name}->{version};
-    my $release = $srpms{$name}->{release};
-    my $srpm_filename = $srpms{$name}->{filename};
+# NB: Need to do the arch/distro in the outer loop to work
+# around the caching bug in mock/yum.
+foreach my $arch (@arches) {
+    foreach my $distro (@distros) {
+       foreach my $name (@buildorder) {
+           my $version = $srpms{$name}->{version};
+           my $release = $srpms{$name}->{release};
+           my $srpm_filename = $srpms{$name}->{filename};
 
-    $release =~ s/\.fc?\d+$//; # "1.fc9" -> "1"
+           $release =~ s/\.fc?\d+$//; # "1.fc9" -> "1"
 
-    foreach my $arch (@arches) {
-       foreach my $distro (@distros) {
            # Does the built (binary) package exist already?
            my $pattern = "$localrepo/$distro/$arch/RPMS/$name-$version-$release.*.rpm";
            #print "pattern = $pattern\n";