X-Git-Url: http://git.pld-linux.org/?p=packages%2Frpm.git;a=blobdiff_plain;f=rpm-php-requires;h=2a3fb601ac143e2bcc7fd30ca02f84dd91255cee;hp=330e49b2d17d300fa055f2c1da9d9d9a23996cf2;hb=d4c0c2eb292df3cda28484f058b063b8679ee078;hpb=801bbd4e0ea07c2d7a3dad085492c879455de02d diff --git a/rpm-php-requires b/rpm-php-requires index 330e49b..2a3fb60 100644 --- a/rpm-php-requires +++ b/rpm-php-requires @@ -1,78 +1,82 @@ -#!/usr/bin/perl -W +#!/usr/bin/perl ##################################################################### # # -# Check system dependencies between php-pear/php-pecl modules # +# Check system dependences between php-pear modules # # # -# Adam Go³êbiowski # -# # -# based on previous work by: # # Pawe³ Go³aszewski # -# Micha³ Moskal # -# # -# ----------------------------------------------------------------- # -# ChangeLog: # -# 20031201: complete rewrite to use PEAR's package.xml, now handles # -# all dependencies, including PHP modules (like php-gmp), # -# and PECL extensions (adamg) # +# Micha³ Moskal # +# ------------------------------------------------------------------# +# TODO: # +# - extension_loaded - dependencies. # +# - some clean-up... # ##################################################################### -@req_arr = (); -$fname = '/dev/null'; -foreach ( @ARGV ? $ARGV : <> ) -{ - $fname = $_ if (/package.xml/) -} +$pear = "/usr/share/pear"; + +@files = (); +%req = (); + +foreach (@ARGV ? $ARGV : <> ) { + chomp; + $f = $_; + push @files, $f; + # skip non-php files + next unless ($f =~ /\.php$/); + open(F, "< $f") or die; -open F, $fname; + if ($f =~ /$pear/) { + $file_dir = $f; + $file_dir =~ s|.*$pear/||; + $file_dir =~ s|/[^/]*$||; + } else { + $file_dir = undef; + } -while () { - if ( /\s+\) { + # skip comments + next if (/^\s*(#|\/\/|\*|\/\*)/); - # do we have version? - $version = ""; - $version = $1 if ( /version="([a-zA-z0-9\.\+]*)"/ ); + while (/(\W|^)(require|include)(_once)? + \s* \(? \s* ("([^"]*)"|'([^']*)') + \s* \)? \s* ;/xg) { + if ($5 ne "") { + $x = $5; + } elsif ($6 ne "") { + $x = $6; + } else { + next; + } - # optional - actually this one is optional ;) - # NOTE: - # even though this attribute marks dependency as optional, - # we will add it to Requires: - $optional = "no"; - $optional = $1 if ( /optional="([a-zA-Z]*)"/ ); - die ("ERROR: Ambigous value of optional attribute: $optional\n") if ( $optional !~ /(yes|no)/i ); + next if ($x =~ m|^\./| or $x =~ /\$/); + next unless ($x =~ /\.php$/); + $req{$x} = 1; + } - # now, check if we need to pull out package/extension/whatever name - $name = ""; - $name = "php" if ( $type =~ /php/ ); - $name = "$1" if ( $type !~ /php/ && /\>([a-zA-Z0-9\_\-]*)\=" if ( $rel eq "ge"); - $relation = ">" if ( $rel eq "gt"); - $relation = "=" if ( $rel eq "has"); - # die if we were unable to substitute relations - die "ERROR: Unexpected relation! ($rel)\n" if ( $relation eq ""); - - $req = ""; - $relver = ""; - $relver = "$relation $version" if ( $version !~ /^$/ ); - $req = "$name $relver" if ( $type =~ /(php|prog)/ ); - $req = "php-$name $relver" if ( $type =~ /ext/ ); - $req = "php-pear-$name" if ( $type =~ /pkg/ ); - - push @req_arr, $req + next unless (defined $file_dir); + + while (/(\W|^)(require|include)(_once)? + \s* \(? \s* dirname \s* \( \s* __FILE__ \s* \) \s* \. \s* + ("([^"]*)"|'([^']*)') + \s* \)? \s* ;/xg) { + if ($5 ne "") { + $x = $5; + } elsif ($6 ne "") { + $x = $6; + } else { + next; + } + + next if ($x =~ /\$/); + next unless ($x =~ /\.php$/); + + $x = "$file_dir/$x"; + $x =~ s|/+|/|g; + $req{$x} = 1; + } + } +} - } +f: for $f (keys %req) { + for $g (@files) { next f if ($g =~ /\Q$f\E$/); } + print "pear($f)\n"; } -for $r (@req_arr) { print "$r\n"; }