OpenPKG CVS Repository
  http://www.openpkg.org/cvsweb/cvsweb.cgi
  ____________________________________________________________________________

  Server: cvs.openpkg.org                  Name:   Thomas Lotterer
  Root:   /e/openpkg/cvs                   Email:  [EMAIL PROTECTED]
  Module: openpkg-re                       Date:   08-Jul-2002 16:57:50
  Branch: HEAD                             Handle: 2002070815575000

  Modified files:
    openpkg-re              buildrdf.pl

  Log:
    pull spec file out of source rpm to get prereqs

  Summary:
    Revision    Changes     Path
    1.14        +61 -4      openpkg-re/buildrdf.pl
  ____________________________________________________________________________

  Index: openpkg-re/buildrdf.pl
  ============================================================
  $ cvs diff -u -r1.13 -r1.14 buildrdf.pl
  --- openpkg-re/buildrdf.pl    17 Dec 2001 14:12:06 -0000      1.13
  +++ openpkg-re/buildrdf.pl    8 Jul 2002 14:57:50 -0000       1.14
  @@ -18,8 +18,8 @@
   # - program skips inaccessible folders and prints a warning
   # - modifying filesystem during operation causes unpredictable results
   # 
  -# $Id: buildrdf.pl,v 1.13 2001/12/17 14:12:06 rse Exp $
  -# $Revision: 1.13 $
  +# $Id: buildrdf.pl,v 1.14 2002/07/08 14:57:50 thl Exp $
  +# $Revision: 1.14 $
   # 
   # (C)20011022 Cable & Wireless Deutschland GmbH
   # Application Services, Development Team
  @@ -203,8 +203,7 @@
           $q .= "[M-$t %{$t}\n]";
       }
   
  -    #combined
  -    $q .= "[M-BuildPreReq %{REQUIRENAME} 
%|REQUIREFLAGS?{%{REQUIREFLAGS:depflags}%{REQUIREVERSION}}:{}|\n]" if $s;
  +    #multivalued combinations
       $q .= "[M-Conflicts %{CONFLICTNAME} 
%|CONFLICTFLAGS?{%{CONFLICTFLAGS:depflags}%{CONFLICTVERSION}}:{}|\n]" if !$s;
       $q .= "[M-PreReq %{REQUIRENAME} 
%|REQUIREFLAGS?{%{REQUIREFLAGS:depflags}%{REQUIREVERSION}}:{}|\n]" if !$s;
       $q .= "[M-Provides %{PROVIDENAME} 
%|PROVIDEFLAGS?{%{PROVIDEFLAGS:depflags}%{PROVIDEVERSION}}:{}|\n]" if !$s;
  @@ -212,6 +211,9 @@
       #make the query
       $v = `$rpm -qp --qf "$q" $prefix$folder$file`;
   
  +    #   pull out entrails from a source package
  +    $v .= entrails("$prefix$folder$file") if $s;
  +    
       #do not list rpmlib dependencies
       $v =~ s|.-(Build)?PreReq rpmlib\(.*?\).*?\n||gs;
   
  @@ -246,3 +248,58 @@
       $rdf .= $o;
   }
   
  +sub entrails {
  +    #   PreReq cannot be determined from source RPMs, so extract and
  +    #   parse the spec file. For consistency reasons, BuildPreReq is
  +    #   also extracted this way also it could have been queried from the
  +    #   source RPM.
  +    my $rpmsource = $_[0];
  +
  +    $_ = $rpmsource;
  +    m|.*/(.*)-[^-]+-[^-]+|;
  +    my $name = $1;
  +
  +    #FIXME do we really need a FILE instead of stdio? If so, make it better!
  +    my $rc = `cd /tmp && ${rpm}2cpio <$rpmsource 2>/dev/null | cpio -i '$name.spec' 
2>/dev/null`;
  +    open(SPEC, "</tmp/$name.spec") || die; 
  +    my $spec = '';
  +    $spec .= $_ while (<SPEC>);
  +    close(SPEC);
  +    unlink "/tmp/$name.spec";
  +
  +    my $define = {};
  +    $spec =~ s|^%define\s+(\S+)\s+(\S+)|$define->{$1} = $2, ''|mge;
  +    $spec =~ s|^\s*([a-zA-Z][a-zA-Z0-9-_]*):\s*([^\n]*)\s*$|$define->{lc($1)} = $2, 
''|mge;
  +
  +    my $pkg_brequire = &expandvar($define, "buildprereq");
  +    my $pkg_rrequire = &expandvar($define, "prereq");
  +    sub expandvar {
  +        my ($define, $varname) = @_;
  +        my $varval = $define->{$varname};
  +        $varval =~ s|%\{([a-zA-Z_][a-zA-Z0-9-_]*)\}|&expandvar($define, $1)|sge;
  +        return $varval;
  +    }
  +
  +    my $buildprereq = &parserequires($pkg_brequire);
  +    my $prereq      = &parserequires($pkg_rrequire);
  +    sub parserequires {
  +        my ($reqspecs) = @_;
  +        my $reqlist = [];
  +        $reqspecs =~ 
s/\s*([^,\s]+(?:\s+(?:<=|>=|=|<|>)\s+[^,\s]+)?)\s*,?/&parserequire($reqlist, $1), 
''/sge;
  +
  +        sub parserequire {
  +            my ($reqlist, $reqspec) = @_;
  +            if ($reqspec =~ m/^\S+$/) {
  +                $reqspec = "$reqspec = *";
  +            }
  +            push(@{$reqlist}, $reqspec);
  +        }
  +        return $reqlist;
  +    }
  +
  +    my $rv = '';
  +    my $item;
  +    foreach $item (@{$prereq})      { $rv .= "M-PreReq $item\n" };
  +    foreach $item (@{$buildprereq}) { $rv .= "M-BuildPreReq $item\n" };
  +    return $rv;
  +}
______________________________________________________________________
The OpenPKG Project                                    www.openpkg.org
CVS Repository Commit List                     [EMAIL PROTECTED]

Reply via email to