]> git.pld-linux.org Git - projects/distfiles.git/blobdiff - specparser.pl
Allow urls like 'https://pypi.python.org/packages/source/d/dugong/dugong-%{version...
[projects/distfiles.git] / specparser.pl
index 1709c8e4464ce3b389ffa4ca64c5c61714712303..510fbc5e001d422f0e5d0657cd87b33da4260c6a 100755 (executable)
@@ -20,7 +20,7 @@ my $spec;
 my $base_spec;
 my @spec;
 my @sources;
-my $sources;
+my $sources_file;
 my %patchset;
 
 sub print_source($$$);
@@ -124,11 +124,15 @@ 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) {
+               } elsif (my ($patchset) = /^%patchset_source\s+(.+)$/) {
+                       use Getopt::Long qw(GetOptionsFromString);
+                       my ($f, $s);
+                       my ($ret, $args) = GetOptionsFromString($patchset, 's=s' => \$s, 'f=s' => \$f);
                        %patchset = (
-                               pattern => $patchset_pattern,
-                               start => $patchset_start,
-                               end => $patchset_end
+                               pattern => $f,
+                               filelist => $s,
+                               start => $args->[0],
+                               end => $args->[1],
                        );
                }
        }
@@ -137,18 +141,42 @@ sub preparse_spec($) # {{{
        shift @spec;
 } # }}}
 
-sub process_patchset($) {
-       my $macros = shift;
-       return unless %patchset or $sources;
+# read in 'sources' file
+sub read_sources_file {
+       my $filename = $_[0] || $sources_file;
+       return () unless $filename and -e $filename;
 
-       # parse sources file
        my %files;
-       open(my $fh, '<', $sources) or die $!;
+
+       open(my $fh, '<', $filename) or die $!;
        while (<$fh>) {
                chomp;
                next unless my ($hash, $filename) = /^([a-f0-9]{32})\s+\*?(.+)$/;
                $files{$filename} = $hash;
        }
+       return \%files;
+}
+
+sub process_patchset($) {
+       my $macros = shift;
+       my $checksums;
+
+       return unless %patchset;
+
+       # print all files from sources file
+       if ($patchset{filelist}) {
+               my $prefix = expand($patchset{pattern}, $macros);
+               my $filelist = expand($patchset{filelist}, $macros);
+               $checksums = read_sources_file($filelist);
+               while (my($file, $hash) = each %$checksums) {
+                       my $url = $prefix . $file;
+                       print_source "patchset $file", $hash, $url;
+               }
+               return;
+       }
+
+       # parse sources file sequences
+       $checksums = read_sources_file() or return;
 
        # print out patchset entries which source md5 is present in source file
        my $start = expand($patchset{start}, $macros);
@@ -157,7 +185,7 @@ sub process_patchset($) {
        for (my $i = $start; $i <= $end; $i++) {
                my $url = sprintf($pattern, $i);
                my ($basename) = $url =~ m{/([^/]+$)};
-               my $hash = $files{$basename} or next;
+               my $hash = $checksums->{$basename} or next;
                print_source "patchset $i", $hash, $url;
        }
 }
@@ -253,7 +281,7 @@ sub print_source($$$) # {{{
 {
        my ($no, $md5, $s) = @_;
 
-       if ($s =~ /^([a-z0-9A-Z;:\=\?&\@\+\~\.,\-\/_]|\%[0-9])+(#\/[a-zA-Z0-9\._-]+)?$/) {
+       if ($s =~ /^([a-z0-9A-Z;:\=\?&\@\+\~\.,\-\/\#_]|\%[0-9])+(#\/[a-zA-Z0-9\._-]+)?$/) {
                if ($s =~ /^(ftp|http|https):\/\//) {
                        if ($s =~ /\/$/) {
                                error("source $no ($s) is directory");
@@ -311,11 +339,21 @@ sub add_md5_to_print($) # {{{
                }
        }
        close(F);
+
+       # find extra sources from detached checksum file
+       my $checksums = read_sources_file();
+       my @mapped = map { $_->[0] } @sources;
+       delete @sourcemap{@mapped};
+       while (my($source, $url) = each %sourcemap) {
+               my ($basename) = $url =~ m{/([^/]+$)};
+               next unless defined $basename;
+               my $hash = $checksums->{$basename} or next;
+               push @sources, [$source, $hash, $url];
+       }
 } # }}}
 
 next_spec(shift);
-$sources = shift if @ARGV;
-undef $sources if $sources and not -e $sources;
+$sources_file = shift if @ARGV;
 preparse_spec($spec);
 add_md5_to_print($spec);
 cont( \@spec, { "nil" => "" } );
This page took 0.133319 seconds and 4 git commands to generate.