]> git.pld-linux.org Git - projects/distfiles.git/blobdiff - specparser.pl
add support for PACKAGE/sources file containing additional checksum of files
[projects/distfiles.git] / specparser.pl
index d449145ccf155a94741bd016fd4c3e12826d2366..e2274e941c524257ea41b7c33e140c993637ffff 100755 (executable)
@@ -21,6 +21,8 @@ my $spec;
 my $base_spec;
 my @spec;
 my @sources;
+my $sources;
+my %patchset;
 
 sub next_spec($)
 {
@@ -121,6 +123,12 @@ sub preparse_spec($) # {{{
             push @spec, $_;
         } elsif (/^NoSource\s*:\s*(\d+)\s*$/i) {
             $no_source{ "source" . $1 } = 1;
+        } elsif (my ($patchset_pattern, $patchset_start, $patchset_end) = /^%patchset_source.+-f\s+(\S+)\s+(\S+)\s+(\S+)/i) {
+            %patchset = (
+                pattern => $patchset_pattern,
+                start => $patchset_start,
+                end => $patchset_end
+            );
         }
     }
     close(F);
@@ -128,6 +136,30 @@ sub preparse_spec($) # {{{
     shift @spec;
 } # }}}
 
+sub process_patchset($) {
+    my $macros = shift;
+    return unless %patchset or $sources;
+
+    # parse sources file
+    my %files;
+    open(my $fh, '<', $sources) or die $!;
+    while (<$fh>) {
+        chomp;
+        next unless my ($hash, $filename) = /^([a-f0-9]{32})\s+\*?(.+)$/;
+        $files{$filename} = $hash;
+    }
+
+    # print out patchset entries which source md5 is present in source file
+    my $start = expand($patchset{start}, $macros);
+    my $end = expand($patchset{end}, $macros);
+    for (my $i = $start; $i < $end; $i++) {
+        my $url = sprintf($patchset{pattern}, $i);
+        my ($basename) = $url =~ m{/([^/]+$)};
+        my $hash = $files{$basename} or next;
+        printf "%s %s\n", $hash, $url;
+    }
+}
+
 
 my $total = 0;
 
@@ -184,6 +216,9 @@ sub cont($$) # {{{
         }
     }
 
+    # so we have macros now, can parse patchset source
+    process_patchset($macros);
+
     # the end, yuppie !
     foreach my $s (@sources) {
         my $src = expand( $s->[2], $macros );
@@ -277,6 +312,8 @@ sub add_md5_to_print($) # {{{
 } # }}}
 
 next_spec(shift);
+$sources = shift if @ARGV;
+undef $sources if $sources and not -e $sources;
 preparse_spec($spec);
 add_md5_to_print($spec);
 cont( \@spec, { "nil" => "" } );
This page took 0.026615 seconds and 4 git commands to generate.