File sorthash.patch of Package build

commit a06e44938202c533d0840c99de7a4310755261e3
Author: Bernhard M. Wiedemann <bwiedemann@suse.de>
Date:   Fri Sep 7 15:02:36 2018 +0200

    Sort hash keys
    
    to have more reproducible behaviour
    especially with building installation-images
    that uses rpmlist files produced here

diff --git a/Build.pm b/Build.pm
index 14ff8fd..7385352 100644
--- a/Build.pm
+++ b/Build.pm
@@ -141,7 +141,7 @@ sub init_helper_hashes {
     push @{$conflicts{$s}}, @s;
     push @{$conflicts{$_}}, $s for @s;
   }
-  for (keys %conflicts) {
+  for (sort keys %conflicts) {
     $conflicts{$_} = [ unify(@{$conflicts{$_}}) ]
   }
   $config->{'conflicth'} = \%conflicts;
@@ -373,7 +373,7 @@ sub read_config {
   for my $l (qw{preinstall vminstall required support keep runscripts repotype patterntype}) {
     $config->{$l} = [ unify(@{$config->{$l}}) ];
   }
-  for my $l (keys %{$config->{'substitute'}}) {
+  for my $l (sort keys %{$config->{'substitute'}}) {
     $config->{'substitute_vers'}->{$l} = [ map {/^(.*?)(=)?$/g} unify(@{$config->{'substitute'}->{$l}}) ];
     $config->{'substitute'}->{$l} = [ unify(@{$config->{'substitute'}->{$l}}) ];
     s/=$// for @{$config->{'substitute'}->{$l}};
@@ -731,7 +731,7 @@ sub readdeps {
   my $dofileprovides = %{$config->{'fileprovides'} || {}};
   for my $depfile (@depfiles) {
     if (ref($depfile) eq 'HASH') {
-      for my $rr (keys %$depfile) {
+      for my $rr (sort keys %$depfile) {
 	$provides{$rr} = $depfile->{$rr}->{'provides'};
 	$requires{$rr} = $depfile->{$rr}->{'requires'};
 	$pkgconflicts{$rr} = $depfile->{$rr}->{'conflicts'};
@@ -886,12 +886,12 @@ sub makewhatprovidesh {
   my %whatprovides;
   my $provides = $config->{'providesh'};
 
-  for my $p (keys %$provides) {
+  for my $p (sort keys %$provides) {
     my @pp = @{$provides->{$p}};
     s/[ <=>].*// for @pp;
     push @{$whatprovides{$_}}, $p for unify(@pp);
   }
-  for my $p (keys %{$config->{'fileprovides'}}) {
+  for my $p (sort keys %{$config->{'fileprovides'}}) {
     my @pp = grep {@{$provides->{$_} || []}} @{$config->{'fileprovides'}->{$p}};
     @{$whatprovides{$p}} = unify(@{$whatprovides{$p} || []}, @pp) if @pp;
   }
@@ -1314,7 +1314,7 @@ sub expand {
       my $n = normalizerich($config, undef, $r, 1, \@error);
       my %naconflicts;
       check_conddeps_inst(undef, $n, \@error, \%p, \%naconflicts, \@todo, \%todo_cond);
-      push @{$aconflicts{$_}}, $naconflicts{$_} for keys %naconflicts;
+      push @{$aconflicts{$_}}, $naconflicts{$_} for sort keys %naconflicts;
       next;
     }
     my @q = @{$whatprovides->{$r} || addproviders($config, $r)};
@@ -1350,7 +1350,7 @@ sub expand {
       my $n = normalizerich($config, undef, $r, 0, \@error);
       my %naconflicts;
       check_conddeps_inst(undef, $n, \@error, \%p, \%naconflicts, \@todo, \%todo_cond);
-      push @{$aconflicts{$_}}, $naconflicts{$_} for keys %naconflicts;
+      push @{$aconflicts{$_}}, $naconflicts{$_} for sort keys %naconflicts;
     } else {
       push @todo, $r, undef;
     }
@@ -1380,7 +1380,7 @@ sub expand {
           for my $c (@{delete $todo_cond{$p}}) {
 	    my %naconflicts;
 	    check_conddeps_inst($c->[1], [ $c->[0] ], \@error, \%p, \%naconflicts, \@todo);
-	    push @{$aconflicts{$_}}, $naconflicts{$_} for keys %naconflicts;
+	    push @{$aconflicts{$_}}, $naconflicts{$_} for sort keys %naconflicts;
 	  }
 	}
         delete $aconflicts{$p};		# no longer needed
@@ -1418,11 +1418,11 @@ sub expand {
 	}
 	if (%naconflicts) {
 	  push @error, map {"$p conflicts with $_"} grep {$_ ne $p && $p{$_}} sort keys %naconflicts;
-	  push @{$aconflicts{$_}}, $naconflicts{$_} for keys %naconflicts;
+	  push @{$aconflicts{$_}}, $naconflicts{$_} for sort keys %naconflicts;
 	}
 	if (%naobsoletes) {
 	  push @error, map {"$p obsoletes $_"} grep {$_ ne $p && $p{$_}} sort keys %naobsoletes;
-	  push @{$aconflicts{$_}}, $naobsoletes{$_} for keys %naobsoletes;
+	  push @{$aconflicts{$_}}, $naobsoletes{$_} for sort keys %naobsoletes;
 	}
 	push @rec_todo, $p if $userecommendsforchoices;
       }
@@ -1682,7 +1682,7 @@ sub add_all_providers {
       $a{$_} = 1 for @{$whatprovides->{$rn} || []};
     }
   }
-  push @p, keys %a;
+  push @p, sort keys %a;
   return unify(@p);
 }
 
diff --git a/expanddeps b/expanddeps
index ec0fe45..460339d 100755
--- a/expanddeps
+++ b/expanddeps
@@ -245,7 +245,7 @@ $cf->{'obspackage'} = $obspackage if defined $obspackage;
 my $dofileprovides = %{$cf->{'fileprovides'}};
 $dofileprovides = 1 if ($binarytype || 'rpm') ne 'rpm';
 
-for my $pack (keys %packs) {
+for my $pack (sort keys %packs) {
   my $r = {};
   my (@s, $s, @pr, @re, @co, @ob, @rc, @su);
   @s = split(' ', $prov{$packs{$pack}} || '');
diff --git a/mkbaselibs b/mkbaselibs
index 6620622..1045370 100755
--- a/mkbaselibs
+++ b/mkbaselibs
@@ -637,7 +637,7 @@ sub handle_rpms {
     }
 
     my %cpiodirs;
-    for (keys %files) {
+    for (sort keys %files) {
       next if $cfiles{$_} || $moves{$_};
       my $fn = $_;
       next unless $fn =~ s/\/[^\/]+$//;
@@ -645,7 +645,7 @@ sub handle_rpms {
     }
 
     my %alldirs;
-    for (keys %files) {
+    for (sort keys %files) {
       next if $cfiles{$_};
       my $fn = $_;
       if ($moves{$fn}) {
@@ -663,7 +663,7 @@ sub handle_rpms {
     for $ad (keys %alldirs) {
       $alldirs{$ad} = 1 while $ad =~ s/\/[^\/]+$//;
     }
-    for (keys %files) {
+    for (sort keys %files) {
       next if $cfiles{$_};
       my $fn = $_;
       if ($moves{$fn}) {
@@ -860,7 +860,7 @@ sub handle_rpms {
     for my $file (sort keys %alldirs) {
       print SPEC "%dir %attr(0755,root,root) $file\n";
     }
-    for my $file (keys %files) {
+    for my $file (sort keys %files) {
       my $fi = $files{$file};
       my $fm = $res{'FILEMODES'}->[$fi];
       my $fv = $res{'FILEVERIFYFLAGS'}->[$fi];
@@ -915,7 +915,7 @@ sub handle_rpms {
 	}
       }
     }
-    for (keys %symlinks) {
+    for (sort keys %symlinks) {
       printf SPEC "%%attr(-,root,root) $_\n";
     }
 
diff --git a/spectool b/spectool
index bdb897c..1f40511 100755
--- a/spectool
+++ b/spectool
@@ -304,7 +304,7 @@ for my $spec (@specs) {
   for my $tag (@opt_showtag) {
     if($tag =~ /^\/(.+)\/$/) {
       my $expr = $1;
-      for my $t (keys %$parsed) {
+      for my $t (sort keys %$parsed) {
         if ($t =~ $expr) {
           push @opt_showtag, $t;
         }
@@ -333,7 +333,7 @@ for my $spec (@specs) {
 	  timeout => 42);
       }
 
-      for my $t (keys %$parsed) {
+      for my $t (sort keys %$parsed) {
         next unless ($t =~ /^(?:source|patch)\d*/);
         my $url = $parsed->{$t};
         next unless $url =~ /^(?:https?|ftp):\/\//;
@@ -367,7 +367,7 @@ for my $spec (@specs) {
     }
     if ($opt_update) {
       my $changed;
-      for my $t (keys %$parsed) {
+      for my $t (sort keys %$parsed) {
         next unless ($t =~ /^(?:source|patch)\d*/);
         my $file = $parsed->{$t};
         $file =~ s/.*\///;
@@ -381,7 +381,7 @@ for my $spec (@specs) {
       }
       if($changed) {
         if(open(F, '>', $srcfile)) {
-          for my $file (keys %$files) {
+          for my $file (sort keys %$files) {
             $files->{$file} =~ s/^md5:// if $srcfile eq 'sources';
             print F $files->{$file}, ' ', $file, "\n";
           }
@@ -389,7 +389,7 @@ for my $spec (@specs) {
         }
       }
     } else {
-      for my $t (keys %$parsed) {
+      for my $t (sort keys %$parsed) {
         next unless ($t =~ /^(?:source|patch)\d*/);
         my $file = $parsed->{$t};
         $file =~ s/.*\///;
@@ -416,7 +416,7 @@ for my $spec (@specs) {
         }
         print $parsed->{$t}, "\n";
       }
-      for my $file (keys %$files) {
+      for my $file (sort keys %$files) {
         print "? $file\n";
       }
     }
diff --git a/substitutedeps b/substitutedeps
index 1763427..8b9e8c6 100755
--- a/substitutedeps
+++ b/substitutedeps
@@ -308,7 +308,7 @@ for my $line (@$xspec) {
   my %f2 = @f2;
   if ($isbuildrequires) {
     delete $f2{$_} for @neg;
-    delete $f2{$_} for grep {/^-/} keys %f2;
+    delete $f2{$_} for sort grep {/^-/} keys %f2;
   }
   while (@deps) {
     my ($pack, $vers) = splice(@deps, 0, 2);