]>
Commit | Line | Data |
---|---|---|
1 | #!/usr/bin/php | |
2 | <?php | |
3 | /** | |
4 | * | |
5 | * Check system dependences between php-pear modules. | |
6 | * | |
7 | * Paweł Gołaszewski <blues@pld-linux.org> (Perl version) | |
8 | * Michał Moskal <malekith@pld-linux.org> (Perl version) | |
9 | * Elan Ruusamäe <glen@pld-linux.org> | |
10 | */ | |
11 | ||
12 | /** | |
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. | |
17 | */ | |
18 | function peardeps($files) { | |
19 | // files inside php_pear_dir have this prefix | |
20 | $prefix = RPM_BUILD_ROOT. PHP_PEAR_DIR . DIRECTORY_SEPARATOR; | |
21 | $length = strlen($prefix); | |
22 | ||
23 | $req = array(); | |
24 | foreach ($files as $f) { | |
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)) { | |
101 | continue; | |
102 | } | |
103 | print "pear($f)\n"; | |
104 | } | |
105 | } | |
106 | ||
107 | /** | |
108 | * Produce dependencies for extensions using PEAR PHP_CompatInfo package. | |
109 | */ | |
110 | function extdeps($files) { | |
111 | require_once 'PHP/CompatInfo.php'; | |
112 | ||
113 | $info = new PHP_CompatInfo('null'); | |
114 | $res = $info->parseData($files); | |
115 | ||
116 | if (version_compare($res['version'], '5.0.0', 'ge')) { | |
117 | $epoch = 4; | |
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'); | |
122 | } else { | |
123 | $epoch = 3; | |
124 | // session has always been compiled in | |
125 | $staticmods = array('standard', 'ereg', 'session'); | |
126 | } | |
127 | echo "php-common >= ", $epoch, ":", $res['version'], "\n"; | |
128 | ||
129 | // process extensions | |
130 | foreach ($res['extensions'] as $ext) { | |
131 | if (in_array($ext, $staticmods)) { | |
132 | continue; | |
133 | } | |
134 | ||
135 | echo "php(", $ext, ")\n"; | |
136 | } | |
137 | } | |
138 | ||
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 { | |
145 | $files = explode(PHP_EOL, trim(file_get_contents('php://stdin'))); | |
146 | } | |
147 | ||
148 | peardeps($files); | |
149 | extdeps($files); |