]> git.pld-linux.org Git - packages/rpm-build-macros.git/blame - rpm-php-requires.php
Add rename notice
[packages/rpm-build-macros.git] / rpm-php-requires.php
CommitLineData
5fe5c49b
JR
1#!/usr/bin/php
2<?php
3/*
4 * minify.spec does not see these: pear(HTTP/ConditionalGet.php) pear(HTTP/Encoder.php)
5 * perl version does
6 */
7/**
8 *
9 * Check system dependences between php-pear modules.
10 *
11 * Paweł Gołaszewski <blues@pld-linux.org> (Perl version)
12 * Michał Moskal <malekith@pld-linux.org> (Perl version)
13 * Elan Ruusamäe <glen@pld-linux.org>
14 *
15 * URL: <http://cvs.pld-linux.org/cgi-bin/cvsweb.cgi/packages/rpm/rpm-php-requires.php>
16 *
17 * Requires: php-pear-PHP_CompatInfo
18 * Requires: php-pcre
19 */
20
21/**
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.
26 */
27function peardeps($files) {
28 // files inside php_pear_dir have this prefix
29 $prefix = RPM_BUILD_ROOT. PHP_PEAR_DIR . DIRECTORY_SEPARATOR;
30 $length = strlen($prefix);
31
32 $req = array();
33 foreach ($files as $f) {
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
46 foreach (file($f) as $line) {
47 // skip comments -- not perfect, matches "*" at start of line (very rare altho)
48 if (preg_match('/^\s*(#|\/\/|\*|\/\*)/', $line)) {
49 continue;
50 }
51
52 if (preg_match("/(\W|^)(require|include)(_once)?
53 \s* \(? \s*
54 (\"([^\"]*)\"|'([^']*)')
55 \s* \)? \s* ;/x", $line, $m)) {
56
57 if ($m[5]) {
58 $x = $m[5];
59 } else if ($m[6]) {
60 $x = $m[6];
61 } else {
62 continue 2;
63 }
64
65 if (substr($x, 0, 2) == './' || substr($x, -1) == '$') { # XXX must be: CONTAINS DOLLAR
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
80 if (preg_match("/(\W|^)(require|include)(_once)?
81 \s* \(? \s* dirname \s* \( \s* __FILE__ \s* \) \s* \. \s*
82 (\"([^\"]*)\"|'([^']*)')
83 \s* \)? \s* ;/x", $line, $m)) {
84
85 if ($m[5]) {
86 $x = $m[5];
87 } else if ($m[6]) {
88 $x = $m[6];
89 } else {
90 continue 2;
91 }
92
93 if (substr($x, -1) == '$') { # XXX must be: CONTAINS DOLLAR
94 continue 2;
95 }
96 if (substr($x, -4) != '.php') {
97 continue 2;
98 }
99
100 $x = "$file_dir/$x";
101 // remove double slashes
102 // TODO: resolve simpletest/test/../socket.php -> simpletest/socket.php
103 $x = str_replace("//", "/", $x);
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)) {
113 continue;
114 }
115 echo "pear($f)\n";
116 }
117}
118
119/**
120 * Produce dependencies for extensions using PEAR PHP_CompatInfo package.
121 */
122function extdeps($files) {
123 require_once 'PHP/CompatInfo.php';
124
125 $info = new PHP_CompatInfo('null');
126 $res = $info->parseData($files);
127
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')) {
133 # force php-<name> only deps when php5
134 # XXX what about php-pecl-<name> virtual provides?
135 $fmt = 'php-%s';
136 $epoch = 4;
137 } else {
138 $fmt = 'php(%s)';
139 $epoch = 3;
140 }
141 echo "php-common >= ", $epoch, ":", $version, "\n";
142
143 // process extensions
144 foreach ($res['extensions'] as $ext) {
145 // bz2 ext is in php-bzip2 package
146 if ($ext == 'bz2') {
147 $ext = 'bzip2';
148 }
149 // libxml ext is in php-xml package
150 if ($ext == 'libxml') {
151 $ext = 'xml';
152 }
153
154 // these need to be lowercased
155 if (in_array($ext, array('SPL', 'PDO', 'SQLite', 'Reflection', 'SimpleXML'))) {
156 $ext = strtolower($ext);
157 }
158
159 printf("$fmt\n", $ext);
160 }
161}
162
163define('RPM_BUILD_ROOT', getenv('RPM_BUILD_ROOT'));
164define('PHP_PEAR_DIR', '/usr/share/pear');
165define('PHP_MIN_VERSION', getenv('PHP_MIN_VERSION'));
166
167if ($argc > 1) {
168 $files = array_splice($argv, 1);
169} else {
170 $files = explode(PHP_EOL, trim(file_get_contents('php://stdin')));
171}
172
173peardeps($files);
174extdeps($files);
This page took 0.105173 seconds and 4 git commands to generate.