X-Git-Url: http://git.pld-linux.org/?p=packages%2Frpm.git;a=blobdiff_plain;f=rpm-php-requires.php;h=b39802993bc09d5d25656eb32939a69a054b101e;hp=810155b38ed47c8bf14ce1cce29f22b268b68541;hb=2f409bb76d70b5ef73c6090e62da15a3250b4c9a;hpb=4083bfec30da95fe9ce16f3d4c831f85985e3d93 diff --git a/rpm-php-requires.php b/rpm-php-requires.php index 810155b..b398029 100644 --- a/rpm-php-requires.php +++ b/rpm-php-requires.php @@ -1,26 +1,117 @@ #!/usr/bin/php # -# Michał Moskal # -# Elan Ruusamäe # -##################################################################### +/* + * minify.spec does not see these: pear(HTTP/ConditionalGet.php) pear(HTTP/Encoder.php) + * perl version does + */ +/** + * + * Check system dependences between php-pear modules. + * + * Paweł Gołaszewski (Perl version) + * Michał Moskal (Perl version) + * Elan Ruusamäe + * + * URL: + * + * Requires: php-pear-PHP_CompatInfo + * Requires: php-pcre + */ /** - * Produce old style pear(Path/To/File.php) deps + * Produce pear(Path/To/File.php) deps + * Ported to PHP from Perl version of rpm-php-requires. + * + * @TODO: use tokenizer to parse php files. */ function peardeps($files) { - // all files must begin with $RPM_BUILD_ROOT%{php_pear_dir} + // files inside php_pear_dir have this prefix $prefix = RPM_BUILD_ROOT. PHP_PEAR_DIR . DIRECTORY_SEPARATOR; $length = strlen($prefix); + + $req = array(); foreach ($files as $f) { - if (substr($f, 0, $length) != $prefix) { + // skip non-php files + if (substr($f, -4) != '.php') { + continue; + } + + // subdir inside php_pear_dir + if (substr($f, 0, $length) == $prefix) { + $file_dir = dirname(substr($f, $length)); + } else { + $file_dir = null; + } + + foreach (file($f) as $line) { + // skip comments -- not perfect, matches "*" at start of line (very rare altho) + if (preg_match('/^\s*(#|\/\/|\*|\/\*)/', $line)) { + continue; + } + + if (preg_match("/(\W|^)(require|include)(_once)? + \s* \(? \s* + (\"([^\"]*)\"|'([^']*)') + \s* \)? \s* ;/x", $line, $m)) { + + if ($m[5]) { + $x = $m[5]; + } else if ($m[6]) { + $x = $m[6]; + } else { + continue 2; + } + + if (substr($x, 0, 2) == './' || substr($x, -1) == '$') { # XXX must be: CONTAINS DOLLAR + continue 2; + } + + if (substr($x, -4) != '.php') { + continue 2; + } + $req[$x] = 1; + continue 2; + } + + if (is_null($file_dir)) { + continue; + } + + if (preg_match("/(\W|^)(require|include)(_once)? + \s* \(? \s* dirname \s* \( \s* __FILE__ \s* \) \s* \. \s* + (\"([^\"]*)\"|'([^']*)') + \s* \)? \s* ;/x", $line, $m)) { + + if ($m[5]) { + $x = $m[5]; + } else if ($m[6]) { + $x = $m[6]; + } else { + continue 2; + } + + if (substr($x, -1) == '$') { # XXX must be: CONTAINS DOLLAR + continue 2; + } + if (substr($x, -4) != '.php') { + continue 2; + } + + $x = "$file_dir/$x"; + // remove double slashes + // TODO: resolve simpletest/test/../socket.php -> simpletest/socket.php + $x = str_replace("//", "/", $x); + $req[$x] = 1; + continue; + } + } + } + + foreach (array_keys($req) as $f) { + // skip self deps + if (array_key_exists($f, $files)) { continue; } - $f = substr($f, $length); echo "pear($f)\n"; } } @@ -34,43 +125,49 @@ function extdeps($files) { $info = new PHP_CompatInfo('null'); $res = $info->parseData($files); - if (version_compare($res['version'], '5.0.0', 'ge')) { + // minimum php version we accept + // "%define php_min_version 5.1.2" in spec to minimum version to be 5.1.2 + $version = max(PHP_MIN_VERSION, $res['version']); + + if (version_compare($version, '5.0.0', 'ge')) { + # force php- only deps when php5 + # XXX what about php-pecl- virtual provides? + $fmt = 'php-%s'; $epoch = 4; - // produce dependencies only for php5 - $compat = false; - // session has always been compiled in - // date, spl are internal for php - $staticmods = array('session', 'date', 'spl'); } else { + $fmt = 'php(%s)'; $epoch = 3; - // produce dependencies where php4/php5 both are ok - $compat = true; - // session has always been compiled in - $staticmods = array('session'); } - echo "php-common >= ", $epoch, ":", $res['version'], "\n"; + echo "php-common >= ", $epoch, ":", $version, "\n"; // process extensions foreach ($res['extensions'] as $ext) { - if (in_array($ext, $staticmods)) { - continue; + // bz2 ext is in php-bzip2 package + if ($ext == 'bz2') { + $ext = 'bzip2'; + } + // libxml ext is in php-xml package + if ($ext == 'libxml') { + $ext = 'xml'; } - if ($compat) { - echo "php(", $ext, ")\n"; - } else { - echo "php-", $ext, "\n"; + // these need to be lowercased + if (in_array($ext, array('SPL', 'PDO', 'SQLite', 'Reflection', 'SimpleXML'))) { + $ext = strtolower($ext); } + + printf("$fmt\n", $ext); } } define('RPM_BUILD_ROOT', getenv('RPM_BUILD_ROOT')); define('PHP_PEAR_DIR', '/usr/share/pear'); +define('PHP_MIN_VERSION', getenv('PHP_MIN_VERSION')); if ($argc > 1) { $files = array_splice($argv, 1); } else { - $files = split(PHP_EOL, trim(file_get_contents('php://stdin'))); + $files = explode(PHP_EOL, trim(file_get_contents('php://stdin'))); } peardeps($files);