]> git.pld-linux.org Git - packages/rpm.git/blame - rpm-php-requires.php
- include URL in sourcefile
[packages/rpm.git] / rpm-php-requires.php
CommitLineData
e7daca0a
ER
1#!/usr/bin/php
2<?php
4553acd5
ER
3/**
4 *
5 * Check system dependences between php-pear modules.
4553acd5 6 *
01049366
ER
7 * Paweł Gołaszewski <blues@pld-linux.org> (Perl version)
8 * Michał Moskal <malekith@pld-linux.org> (Perl version)
4553acd5 9 * Elan Ruusamäe <glen@pld-linux.org>
784009ae 10 *
d72048f0
ER
11 * URL: <http://cvs.pld-linux.org/cgi-bin/cvsweb.cgi/packages/rpm/rpm-php-requires.php>
12 *
784009ae
ER
13 * Requires: php-pear-PHP_CompatInfo
14 * Requires: php-pcre
4553acd5 15 */
ec981489 16
e7daca0a 17/**
01049366
ER
18 * Produce pear(Path/To/File.php) deps
19 * Ported to PHP from Perl version of rpm-php-requires.
20 *
21 * @TODO: use tokenizer to parse php files.
e7daca0a 22 */
ec981489 23function peardeps($files) {
bf998152 24 // files inside php_pear_dir have this prefix
4083bfec 25 $prefix = RPM_BUILD_ROOT. PHP_PEAR_DIR . DIRECTORY_SEPARATOR;
ec981489 26 $length = strlen($prefix);
01049366
ER
27
28 $req = array();
ec981489 29 foreach ($files as $f) {
01049366
ER
30 // skip non-php files
31 if (substr($f, -4) != '.php') {
32 continue;
33 }
34
35 // subdir inside php_pear_dir
36 if (substr($f, 0, $length) == $prefix) {
37 $file_dir = dirname(substr($f, $length));
38 } else {
39 $file_dir = null;
40 }
41
784009ae 42 foreach (file($f) as $line) {
9d5910eb 43 // skip comments -- not perfect, matches "*" at start of line (very rare altho)
01049366
ER
44 if (preg_match('/^\s*(#|\/\/|\*|\/\*)/', $line)) {
45 continue;
46 }
47
11435866 48 if (preg_match("/(\W|^)(require|include)(_once)?
01049366
ER
49 \s* \(? \s*
50 (\"([^\"]*)\"|'([^']*)')
51 \s* \)? \s* ;/x", $line, $m)) {
52
9d5910eb 53 if ($m[5]) {
01049366 54 $x = $m[5];
9d5910eb 55 } else if ($m[6]) {
01049366
ER
56 $x = $m[6];
57 } else {
58 continue 2;
59 }
60
9d5910eb 61 if (substr($x, 0, 2) == './' || substr($x, -1) == '$') { # XXX must be: CONTAINS DOLLAR
01049366
ER
62 continue 2;
63 }
64
65 if (substr($x, -4) != '.php') {
66 continue 2;
67 }
68 $req[$x] = 1;
69 continue 2;
70 }
71
72 if (is_null($file_dir)) {
73 continue;
74 }
75
11435866 76 if (preg_match("/(\W|^)(require|include)(_once)?
01049366
ER
77 \s* \(? \s* dirname \s* \( \s* __FILE__ \s* \) \s* \. \s*
78 (\"([^\"]*)\"|'([^']*)')
79 \s* \)? \s* ;/x", $line, $m)) {
80
9d5910eb 81 if ($m[5]) {
01049366 82 $x = $m[5];
9d5910eb 83 } else if ($m[6]) {
01049366
ER
84 $x = $m[6];
85 } else {
86 continue 2;
87 }
88
9d5910eb 89 if (substr($x, -1) == '$') { # XXX must be: CONTAINS DOLLAR
01049366
ER
90 continue 2;
91 }
92 if (substr($x, -4) != '.php') {
93 continue 2;
94 }
95
96 $x = "$file_dir/$x";
9d5910eb
ER
97 // remove double slashes
98 // TODO: resolve simpletest/test/../socket.php -> simpletest/socket.php
99 $x = str_replace("//", "/", $x);
01049366
ER
100 $req[$x] = 1;
101 continue;
102 }
103 }
104 }
105
106 foreach (array_keys($req) as $f) {
107 // skip self deps
108 if (array_key_exists($f, $files)) {
ec981489
ER
109 continue;
110 }
784009ae 111 echo "pear($f)\n";
ec981489
ER
112 }
113}
e7daca0a 114
ec981489
ER
115/**
116 * Produce dependencies for extensions using PEAR PHP_CompatInfo package.
117 */
118function extdeps($files) {
119 require_once 'PHP/CompatInfo.php';
e7daca0a 120
ec981489
ER
121 $info = new PHP_CompatInfo('null');
122 $res = $info->parseData($files);
e7daca0a 123
58f4fffb
ER
124 // minimum php version we accept
125 // "%define php_min_version 5.1.2" in spec to minimum version to be 5.1.2
126 $version = max(PHP_MIN_VERSION, $res['version']);
127
128 if (version_compare($version, '5.0.0', 'ge')) {
005de36a
ER
129 # force php-<name> only deps when php5
130 # XXX what about php-pecl-<name> virtual provides?
131 $fmt = 'php-%s';
ec981489 132 $epoch = 4;
ec981489 133 } else {
005de36a 134 $fmt = 'php(%s)';
ec981489 135 $epoch = 3;
ec981489 136 }
58f4fffb 137 echo "php-common >= ", $epoch, ":", $version, "\n";
e7daca0a 138
ec981489
ER
139 // process extensions
140 foreach ($res['extensions'] as $ext) {
7eb63ec6
ER
141 // bz2 ext is in php-bzip2 package
142 if ($ext == 'bz2') {
143 $ext = 'bzip2';
144 }
2ef898b9
ER
145 // libxml ext is in php-xml package
146 if ($ext == 'libxml') {
147 $ext = 'xml';
148 }
53a7793d
ER
149
150 // these need to be lowercased
151 if (in_array($ext, array('SPL', 'PDO', 'SQLite', 'Reflection', 'SimpleXML'))) {
152 $ext = strtolower($ext);
005de36a 153 }
53a7793d 154
005de36a 155 printf("$fmt\n", $ext);
e7daca0a 156 }
ec981489 157}
e7daca0a 158
ec981489
ER
159define('RPM_BUILD_ROOT', getenv('RPM_BUILD_ROOT'));
160define('PHP_PEAR_DIR', '/usr/share/pear');
58f4fffb 161define('PHP_MIN_VERSION', getenv('PHP_MIN_VERSION'));
ec981489
ER
162
163if ($argc > 1) {
164 $files = array_splice($argv, 1);
165} else {
01049366 166 $files = explode(PHP_EOL, trim(file_get_contents('php://stdin')));
e7daca0a 167}
ec981489
ER
168
169peardeps($files);
170extdeps($files);
This page took 0.053158 seconds and 4 git commands to generate.