]>
Commit | Line | Data |
---|---|---|
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 ER |
9 | * Elan Ruusamäe <glen@pld-linux.org> |
10 | */ | |
ec981489 | 11 | |
e7daca0a | 12 | /** |
01049366 ER |
13 | * Produce pear(Path/To/File.php) deps |
14 | * Ported to PHP from Perl version of rpm-php-requires. | |
15 | * | |
16 | * @TODO: use tokenizer to parse php files. | |
e7daca0a | 17 | */ |
ec981489 | 18 | function peardeps($files) { |
bf998152 | 19 | // files inside php_pear_dir have this prefix |
4083bfec | 20 | $prefix = RPM_BUILD_ROOT. PHP_PEAR_DIR . DIRECTORY_SEPARATOR; |
ec981489 | 21 | $length = strlen($prefix); |
01049366 ER |
22 | |
23 | $req = array(); | |
ec981489 | 24 | foreach ($files as $f) { |
01049366 ER |
25 | // skip non-php files |
26 | if (substr($f, -4) != '.php') { | |
27 | continue; | |
28 | } | |
29 | ||
30 | // subdir inside php_pear_dir | |
31 | if (substr($f, 0, $length) == $prefix) { | |
32 | $file_dir = dirname(substr($f, $length)); | |
33 | } else { | |
34 | $file_dir = null; | |
35 | } | |
36 | ||
37 | foreach (explode(PHP_EOL, file_get_contents($f)) as $line) { | |
38 | // skip comments | |
39 | if (preg_match('/^\s*(#|\/\/|\*|\/\*)/', $line)) { | |
40 | continue; | |
41 | } | |
42 | ||
43 | while (preg_match("/(\W|^)(require|include)(_once)? | |
44 | \s* \(? \s* | |
45 | (\"([^\"]*)\"|'([^']*)') | |
46 | \s* \)? \s* ;/x", $line, $m)) { | |
47 | ||
48 | if ($m[5] != "") { | |
49 | $x = $m[5]; | |
50 | } else if ($m[6] != "") { | |
51 | $x = $m[6]; | |
52 | } else { | |
53 | continue 2; | |
54 | } | |
55 | ||
56 | if (substr($x, 0, 2) == './' || substr($x, -1) == '$') { | |
57 | continue 2; | |
58 | } | |
59 | ||
60 | if (substr($x, -4) != '.php') { | |
61 | continue 2; | |
62 | } | |
63 | $req[$x] = 1; | |
64 | continue 2; | |
65 | } | |
66 | ||
67 | if (is_null($file_dir)) { | |
68 | continue; | |
69 | } | |
70 | ||
71 | while (preg_match("/(\W|^)(require|include)(_once)? | |
72 | \s* \(? \s* dirname \s* \( \s* __FILE__ \s* \) \s* \. \s* | |
73 | (\"([^\"]*)\"|'([^']*)') | |
74 | \s* \)? \s* ;/x", $line, $m)) { | |
75 | ||
76 | if ($m[5] != "") { | |
77 | $x = $m[5]; | |
78 | } else if ($m[6] != "") { | |
79 | $x = $m[6]; | |
80 | } else { | |
81 | continue 2; | |
82 | } | |
83 | ||
84 | if (substr($x, -1) == '$') { | |
85 | continue 2; | |
86 | } | |
87 | if (substr($x, -4) != '.php') { | |
88 | continue 2; | |
89 | } | |
90 | ||
91 | $x = "$file_dir/$x"; | |
92 | $req[$x] = 1; | |
93 | continue; | |
94 | } | |
95 | } | |
96 | } | |
97 | ||
98 | foreach (array_keys($req) as $f) { | |
99 | // skip self deps | |
100 | if (array_key_exists($f, $files)) { | |
ec981489 ER |
101 | continue; |
102 | } | |
01049366 | 103 | print "pear($f)\n"; |
ec981489 ER |
104 | } |
105 | } | |
e7daca0a | 106 | |
ec981489 ER |
107 | /** |
108 | * Produce dependencies for extensions using PEAR PHP_CompatInfo package. | |
109 | */ | |
110 | function extdeps($files) { | |
111 | require_once 'PHP/CompatInfo.php'; | |
e7daca0a | 112 | |
ec981489 ER |
113 | $info = new PHP_CompatInfo('null'); |
114 | $res = $info->parseData($files); | |
e7daca0a | 115 | |
ec981489 ER |
116 | if (version_compare($res['version'], '5.0.0', 'ge')) { |
117 | $epoch = 4; | |
fc20423e ER |
118 | // session, pcre are statically compiled in |
119 | // date, SPL, SimpleXML are internal for php | |
120 | // sapi_apache? | |
121 | $staticmods = array('standard', 'ereg', 'session', 'pcre', 'date', 'spl', 'simplexml'); | |
ec981489 ER |
122 | } else { |
123 | $epoch = 3; | |
ec981489 | 124 | // session has always been compiled in |
fc20423e | 125 | $staticmods = array('standard', 'ereg', 'session'); |
ec981489 ER |
126 | } |
127 | echo "php-common >= ", $epoch, ":", $res['version'], "\n"; | |
e7daca0a | 128 | |
ec981489 ER |
129 | // process extensions |
130 | foreach ($res['extensions'] as $ext) { | |
131 | if (in_array($ext, $staticmods)) { | |
132 | continue; | |
133 | } | |
e7daca0a | 134 | |
b56286b3 | 135 | echo "php(", $ext, ")\n"; |
e7daca0a | 136 | } |
ec981489 | 137 | } |
e7daca0a | 138 | |
ec981489 ER |
139 | define('RPM_BUILD_ROOT', getenv('RPM_BUILD_ROOT')); |
140 | define('PHP_PEAR_DIR', '/usr/share/pear'); | |
141 | ||
142 | if ($argc > 1) { | |
143 | $files = array_splice($argv, 1); | |
144 | } else { | |
01049366 | 145 | $files = explode(PHP_EOL, trim(file_get_contents('php://stdin'))); |
e7daca0a | 146 | } |
ec981489 ER |
147 | |
148 | peardeps($files); | |
149 | extdeps($files); |