michal-grzedzicki / rpms / rpm

Forked from rpms/rpm 4 months ago
Clone

Blame SOURCES/rpm-4.11.x-remove-perl-provides-from-requires.patch

dac7c0
--- rpm-4.11.3/scripts/perl.req.old	2019-01-02 13:14:10.258068525 +0100
dac7c0
+++ rpm-4.11.3/scripts/perl.req	2019-02-28 11:00:57.200220227 +0100
dac7c0
@@ -42,18 +42,29 @@
dac7c0
 $HAVE_VERSION = 0;
dac7c0
 eval { require version; $HAVE_VERSION = 1; };
dac7c0
 
dac7c0
+use File::Basename;
dac7c0
+my $dir = dirname($0);
dac7c0
+$HAVE_PROV = 0;
dac7c0
+if ( -e "$dir/perl.prov" ) {
dac7c0
+  $HAVE_PROV = 1;
dac7c0
+  $prov_script = "$dir/perl.prov";
dac7c0
+}
dac7c0
 
dac7c0
 if ("@ARGV") {
dac7c0
-  foreach (@ARGV) {
dac7c0
-    process_file($_);
dac7c0
+  foreach my $file (@ARGV) {
dac7c0
+    process_file($file);
dac7c0
+    process_file_provides($file);
dac7c0
+    compute_global_requires();
dac7c0
   }
dac7c0
 } else {
dac7c0
 
dac7c0
   # notice we are passed a list of filenames NOT as common in unix the
dac7c0
   # contents of the file.
dac7c0
 
dac7c0
-  foreach (<>) {
dac7c0
-    process_file($_);
dac7c0
+  foreach my $file (<>) {
dac7c0
+    process_file($file);
dac7c0
+    process_file_provides($file);
dac7c0
+    compute_global_requires();
dac7c0
   }
dac7c0
 }
dac7c0
 
dac7c0
@@ -61,8 +72,9 @@
dac7c0
 foreach $perlver (sort keys %perlreq) {
dac7c0
   print "perl >= $perlver\n";
dac7c0
 }
dac7c0
-foreach $module (sort keys %require) {
dac7c0
-  if (length($require{$module}) == 0) {
dac7c0
+
dac7c0
+foreach my $module (sort keys %global_require) {
dac7c0
+  if (length($global_require{$module}) == 0) {
dac7c0
     print "perl($module)\n";
dac7c0
   } else {
dac7c0
 
dac7c0
@@ -70,13 +82,35 @@
dac7c0
     # operators. Also I will need to change the processing of the
dac7c0
     # $RPM_* variable when I upgrade.
dac7c0
 
dac7c0
-    print "perl($module) >= $require{$module}\n";
dac7c0
+    print "perl($module) >= $global_require{$module}\n";
dac7c0
   }
dac7c0
 }
dac7c0
 
dac7c0
 exit 0;
dac7c0
 
dac7c0
-
dac7c0
+sub compute_global_requires {
dac7c0
+ 
dac7c0
+# restrict require to all non provided by the file
dac7c0
+  foreach my $moduler (sort keys %require) {
dac7c0
+    if (exists $provide{$moduler} && length($require{$moduler}) == 0) {
dac7c0
+      $require = delete $require{$moduler};
dac7c0
+    } 
dac7c0
+  }
dac7c0
+# store requires to global_requires
dac7c0
+  foreach my $module (sort keys %require) {
dac7c0
+    my $oldver = $global_require{$module};
dac7c0
+    my $newver = $require{$module};
dac7c0
+    if ($oldver) {
dac7c0
+      $global_require{$module} = $newver
dac7c0
+        if ($HAVE_VERSION && $newver && version->new($oldver) < $newver);
dac7c0
+    } else {
dac7c0
+      $global_require{$module} = $newver;
dac7c0
+    }
dac7c0
+  }
dac7c0
+# remove all local requires and provides
dac7c0
+  undef %require;
dac7c0
+  undef %provide;
dac7c0
+}
dac7c0
 
dac7c0
 sub add_require {
dac7c0
   my ($module, $newver) = @_;
dac7c0
@@ -328,3 +362,17 @@
dac7c0
 
dac7c0
   return;
dac7c0
 }
dac7c0
+
dac7c0
+sub process_file_provides {
dac7c0
+
dac7c0
+  my ($file) = @_;
dac7c0
+  chomp $file;
dac7c0
+
dac7c0
+  return if (! $HAVE_PROV);
dac7c0
+
dac7c0
+  my @result = readpipe( "$prov_script $file" );
dac7c0
+  foreach my $prov (@result) {
dac7c0
+    $provide{$1} = undef if $prov =~ /perl\(([_:a-zA-Z0-9]+)\)/;
dac7c0
+  }
dac7c0
+
dac7c0
+}