chantra / rpms / rpm

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