5 * Check system dependences between php-pear modules.
7 * Paweł Gołaszewski <blues@pld-linux.org> (Perl version)
8 * Michał Moskal <malekith@pld-linux.org> (Perl version)
9 * Elan Ruusamäe <glen@pld-linux.org>
11 * Requires: php-pear-PHP_CompatInfo
16 * Produce pear(Path/To/File.php) deps
17 * Ported to PHP from Perl version of rpm-php-requires.
19 * @TODO: use tokenizer to parse php files.
21 function peardeps($files) {
22 // files inside php_pear_dir have this prefix
23 $prefix = RPM_BUILD_ROOT. PHP_PEAR_DIR . DIRECTORY_SEPARATOR;
24 $length = strlen($prefix);
27 foreach ($files as $f) {
29 if (substr($f, -4) != '.php') {
33 // subdir inside php_pear_dir
34 if (substr($f, 0, $length) == $prefix) {
35 $file_dir = dirname(substr($f, $length));
40 foreach (file($f) as $line) {
41 // skip comments -- not perfect, matches "*" at start of line (very rare altho)
42 if (preg_match('/^\s*(#|\/\/|\*|\/\*)/', $line)) {
46 if (preg_match("/(\W|^)(require|include)(_once)?
48 (\"([^\"]*)\"|'([^']*)')
49 \s* \)? \s* ;/x", $line, $m)) {
59 if (substr($x, 0, 2) == './' || substr($x, -1) == '$') { # XXX must be: CONTAINS DOLLAR
63 if (substr($x, -4) != '.php') {
70 if (is_null($file_dir)) {
74 if (preg_match("/(\W|^)(require|include)(_once)?
75 \s* \(? \s* dirname \s* \( \s* __FILE__ \s* \) \s* \. \s*
76 (\"([^\"]*)\"|'([^']*)')
77 \s* \)? \s* ;/x", $line, $m)) {
87 if (substr($x, -1) == '$') { # XXX must be: CONTAINS DOLLAR
90 if (substr($x, -4) != '.php') {
95 // remove double slashes
96 // TODO: resolve simpletest/test/../socket.php -> simpletest/socket.php
97 $x = str_replace("//", "/", $x);
104 foreach (array_keys($req) as $f) {
106 if (array_key_exists($f, $files)) {
114 * Produce dependencies for extensions using PEAR PHP_CompatInfo package.
116 function extdeps($files) {
117 require_once 'PHP/CompatInfo.php';
119 $info = new PHP_CompatInfo('null');
120 $res = $info->parseData($files);
122 // minimum php version we accept
123 // "%define php_min_version 5.1.2" in spec to minimum version to be 5.1.2
124 $version = max(PHP_MIN_VERSION, $res['version']);
126 if (version_compare($version, '5.0.0', 'ge')) {
127 # force php-<name> only deps when php5
128 # XXX what about php-pecl-<name> virtual provides?
135 echo "php-common >= ", $epoch, ":", $version, "\n";
137 // process extensions
138 foreach ($res['extensions'] as $ext) {
139 // bz2 ext is in php-bzip2 package
143 // libxml ext is in php-xml package
144 if ($ext == 'libxml') {
148 // these need to be lowercased
149 if (in_array($ext, array('SPL', 'PDO', 'SQLite', 'Reflection', 'SimpleXML'))) {
150 $ext = strtolower($ext);
153 printf("$fmt\n", $ext);
157 define('RPM_BUILD_ROOT', getenv('RPM_BUILD_ROOT'));
158 define('PHP_PEAR_DIR', '/usr/share/pear');
159 define('PHP_MIN_VERSION', getenv('PHP_MIN_VERSION'));
162 $files = array_splice($argv, 1);
164 $files = explode(PHP_EOL, trim(file_get_contents('php://stdin')));