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