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