1 --- PEAR_Command_Packaging-0.2.0/usr/share/pear/PEAR/Command/Packaging.php 2011-04-10 18:34:41.270846822 +0300
2 +++ PEAR_Command_Packaging-0.2.0/usr/share/pear/PEAR/Command/Packaging.php 2011-05-03 09:26:29.397841813 +0300
5 'doc' => 'Use FILE as RPM spec file template'
10 + 'doc' => 'Use FILE as output filename'
12 'rpm-release' => array(
16 * $commands array above and in Packaging.xml so that it is consistent.
18 var $_rpm_pkgname_format = array(
20 + 'pkg' => 'php-%c-%s',
21 'chan' => 'php-channel-%c',
26 * The default format of various dependencies that might be generated in the
27 * spec file. The currently-handled dependency types are:
29 * %P = use the same as whatever rpm_pkgname_format is set to be
31 var $_rpm_depname_format = array(
33 + 'pkg' => 'php-%c-%s',
36 + 'pear-pkg' => 'php-pear-%s',
37 + 'pecl-ext' => 'php-pecl-%l',
38 + 'php' => 'php-common',
39 'chan' => 'php-channel(%n)',
43 * chan - used when generating a spec file for a channel
45 var $_rpm_specname_format = array(
46 - 'pkg' => '%P-%v.spec',
48 'chan' => 'php-channel-%c.spec'
52 * need to be listed here
54 var $_file_prefixes = array(
55 - 'php' => '%{_libdir}/php/pear',
56 + 'php' => '%{php_pear_dir}',
58 - 'ext' => '%{_libdir}/php',
59 - 'test' => '%{_libdir}/php/tests/%s',
60 - 'data' => '%{_libdir}/php/data/%s',
61 + 'ext' => '%{%php_extensiondir}',
62 + 'test' => '%{php_pear_dir}/tests/%s',
63 + 'data' => '%{php_pear_dir}/data/%s',
64 'script' => '%{_bindir}',
65 'cfg' => '%{_sysconfdir}/pear',
66 'www' => '%{_datadir}/pear/www'
70 + * Role packages to use for non-standard file roles. Used when generating
71 + * specs for packages only.
73 + var $_role_packages = array(
74 + 'horde' => 'php-horde-Horde_Role',
78 * The format to use when adding new RPM header lines to the spec file, in
79 * printf format. The first '%s' is the RPM header name followed by a colon,
80 * the second is the header value.
82 - var $_spec_line_format = '%s %s';
83 + var $_spec_line_format = "%s\t%s";
85 // ------------------------------------------------------------------------
86 // --- END DISTRIBUTION CONFIG
89 'test_files_statement' => '',// empty string, or list of test files
90 'www_files_statement' => '', // empty string, or newline-separated list of files with "www" role
91 + '_noautoreq' => '', // no autoreqdep. PLD Linux specific
94 // The name of the template spec file to use
97 // Initialise the RPM package/dep naming format options
98 $this->_initialiseNamingOptions($options);
101 // Set the RPM release version
102 if (isset($options['rpm-release'])) {
103 $this->_output['release'] = $options['rpm-release'];
106 + // Pass output file in options
107 + if (isset($options['output'])) {
108 + $this->_output['output-file'] = $options['output'];
111 + // PLD Linux specific. need source md5
112 + $this->_output['tarball'] = $source_file;
113 + $this->_output['tarball_md5'] = md5(file_get_contents($source_file));
115 // Set the PEAR RPM name for the PEAR core package
116 $this->_output['pear_rpm_name'] = $this->_getRPMName('PEAR', 'pear.php.net', null, 'pkgdep');
119 // If source file ends in ".xml" we assume we are creating an RPM spec
120 // for a channel rather than an actual package
121 if (substr(strtolower($source_file), -4) == '.xml') {
122 @@ -378,13 +403,40 @@
124 * Format an RPM header line to be added to the spec file
125 * @param string $header The name of the RPM header to be added
126 - * @param string $value The contents of the RPM header
127 + * @param mixed $value The contents of the RPM header
130 - function _formatRpmHeader($header, $value)
131 + function _formatRpmHeader($header, $values)
133 + // PLD Linux: we want values sorted and each on their line
134 + $values = (array )$values;
137 + foreach ($values as $value) {
138 + $ret .= sprintf($this->_spec_line_format, $header . ':', $value) . "\n";
145 + * Get an version for RPM package.
147 + * @param string $version Package version (e.g. '1.2.3RC1')
148 + * @return string Normalized version
150 + function _formatRpmVersion($version)
152 - return sprintf($this->_spec_line_format, $header . ':', $value);
154 + // In PLD Linux alpha, beta, rc versions are noted in Release: not Version: tag.
155 + preg_match('/^(?P<version>[0-9.]+)(?P<extraversion>.*)$/', $version, $m);
156 + if ($m['extraversion']) {
157 + $version = "{$m['version']}-0.{$m['extraversion']}";
165 * Replace a macro in the output spec file
166 @@ -410,16 +462,20 @@
168 $package_name = null;
172 // Work out the name of the output spec file
173 - $spec_file = $this->_getRPMNameFromFormat(
174 - $this->_rpm_specname_format[$type],
176 - $this->_output['possible_channel'],
177 - $this->_output['channel_alias'],
178 - $this->_output['version']
181 + if (isset($this->_output['output-file'])) {
182 + $spec_file = $this->_output['output-file'];
184 + $spec_file = $this->_getRPMNameFromFormat(
185 + $this->_rpm_specname_format[$type],
187 + $this->_output['possible_channel'],
188 + $this->_output['channel_alias'],
189 + $this->_output['version']
193 // Write the actual file
194 $wp = fopen($spec_file, 'wb');
198 $rpmdep = $this->_getRPMName(null, $cf->getName(), $cf->getAlias(), 'chandep');
199 if (!empty($rpmdep) && $rpmdep != $this->_output['rpm_package']) {
200 - $this->_output['extra_headers'] = $this->_formatRpmHeader('Provides', "$rpmdep") . "\n";
201 + $this->_output['extra_headers'] = $this->_formatRpmHeader('Provides', $rpmdep) . "\n";
204 // Channels don't really have version numbers; this will need to be
207 // Set up some of the basic macros
208 $this->_output['rpm_package'] = $this->_getRPMName($pf->getPackage(), $pf->getChannel(), null, 'pkg');
209 - $this->_output['description'] = wordwrap($package_info['description']);
210 + $this->_output['description'] = wordwrap($package_info['description'], 70);
211 $this->_output['summary'] = trim($package_info['summary']);
212 $this->_output['possible_channel'] = $pf->getChannel();
213 $this->_output['channel_alias'] = $this->_getChannelAlias($pf->getPackage(), $pf->getChannel());
216 // Generate the Requires and Conflicts for the RPM
217 if ($pf->getDeps()) {
218 - $this->_generatePackageDeps($pf);
219 + $this->_generatePackageDeps($pf, $package_info['filelist']);
222 // Hook to support virtual Provides, where the dependency name differs
223 @@ -646,14 +702,24 @@
224 if (substr($this->_file_prefixes[$role], -2) == '%s') {
225 $this->_output[$macro_name] = str_replace('%s', $pf->getPackage(), $this->_file_prefixes[$role]);
228 if ($role == 'cfg') {
229 - $this->_output[$macro_name] = '%config(noreplace) ' . implode("\n%config(noreplace) ", $files);
231 - $this->_output[$macro_name] = implode("\n", $files);
232 + $attr = '%config(noreplace) %verify(not md5 mtime size) ';
233 + } elseif ($role == 'script') {
234 + $attr = '%attr(755,root,root) ';
236 + $this->_output[$macro_name] = $attr . implode("\n$attr", $files);
239 $this->_output['files'] = trim($this->_output['files']);
241 + // figure registry file location
242 + if (in_array($this->_output['possible_channel'], $this->_standard_channels)) {
243 + $registry_dir = '%s/.registry/*.reg';
245 + $registry_dir = '%s/.registry/.channel.*/*.reg';
247 + $this->_output['registry_files_statement'] = str_replace('%s', $this->_file_prefixes['php'], $registry_dir);
250 if (isset($file_list['doc'])) {
251 @@ -683,14 +749,13 @@
255 - function _generatePackageDeps($pf)
256 + function _generatePackageDeps($pf, $filelist)
258 - $requires = $conflicts = array();
259 + $buildrequires = $requires = $conflicts = $suggests = array();
260 if ($pf->getPackagexmlVersion() == '1.0') {
261 - foreach ($pf->getDeps() as $dep) {
262 - if (isset($dep['optional']) && $dep['optional'] == 'yes') {
265 + $deps = $pf->getDeps();
266 + foreach ($deps as $dep) {
267 + $optional = isset($dep['optional']) && $dep['optional'] == 'yes';
269 if (!isset($dep['type']) || $dep['type'] == 'pkg') {
272 $type = $dep['type'];
275 - if (!isset($dep['channel'])) $dep['channel'] = null;
276 if (!isset($dep['name'])) $dep['name'] = ''; //e.g. "php" dep
277 + if (!isset($dep['channel'])) {
278 + // we need to figure out channel as pecl packages are might
279 + // be named differently than pear packages.
280 + $chan_alias = $this->_getChannelAlias($dep['name']);
281 + $reg = &$this->config->getRegistry();
282 + $dep['channel'] = $reg->channelName($chan_alias);
285 // $package contains the *dependency name* here, which may or may
286 // not be the same as the package name
287 @@ -725,21 +796,25 @@
288 if ($dep['rel'] == 'has') {
289 // We use $package as the index to the $requires array to de-duplicate deps.
290 // Note that in the case of duplicate deps, versioned deps will "win" - see several lines down.
291 - $requires[$package] = $package;
293 + $suggests[$package] = $package;
295 + $requires[$package] = $package;
297 } elseif ($dep['rel'] == 'not') {
298 $conflicts[] = $package;
299 } elseif ($dep['rel'] == 'ne') {
300 - $conflicts[] = $package . ' = ' . $dep['version'];
301 + $version = $this->_formatRpmVersion($dep['version']);
302 + $conflicts[] = $package . ' = ' . $version;
303 } elseif (isset($trans[$dep['rel']])) {
304 - $requires[$package] = $package . ' ' . $trans[$dep['rel']] . ' ' . $dep['version'];
305 + $version = $this->_formatRpmVersion($dep['version']);
307 + $suggests[$package] = $package . ' ' . $trans[$dep['rel']] . ' ' . $version;
309 + $requires[$package] = $package . ' ' . $trans[$dep['rel']] . ' ' . $version;
313 - if (count($requires)) {
314 - $this->_output['extra_headers'] .= $this->_formatRpmHeader('Requires', implode(', ', $requires)) . "\n";
316 - if (count($conflicts)) {
317 - $this->_output['extra_headers'] .= $this->_formatRpmHeader('Conflicts', implode(', ', $conflicts)) . "\n";
320 $this->_output['package2xml'] = '2'; // tell the spec to use package2.xml
321 $deps = $pf->getDeps(true);
322 @@ -842,10 +917,10 @@
325 if (isset($dep['min'])) {
326 - $requires[$package] = $package . ' >= ' . $dep['min'];
327 + $requires[$package] = $package . ' >= ' . $this->_formatRpmVersion($dep['min']);
329 if (isset($dep['max'])) {
330 - $requires[$package] = $package . ' <= ' . $dep['max'];
331 + $requires[$package] = $package . ' <= ' . $this->_formatRpmVersion($dep['max']);
333 if (isset($dep['exclude'])) {
334 $ex = $dep['exclude'];
335 @@ -865,17 +940,125 @@
336 $tar->popErrorHandling();
337 if ($a === null || PEAR::isError($a)) {
338 - $this->_output['package2xml'] = '';
339 // this doesn't have a package.xml version 1.0
340 - $requires[$this->_output['pear_rpm_name']] = $this->_output['pear_rpm_name'] . ' >= ' .
341 - $deps['required']['pearinstaller']['min'];
342 + $this->_output['package2xml'] = '';
343 + $version = $this->_formatRpmVersion($deps['required']['pearinstaller']['min']);
344 + // PLD linux hack: include epoch for PEAR package
345 + $version = "1:{$version}";
346 + $buildrequires[$this->_output['pear_rpm_name']] = $this->_output['pear_rpm_name'] . ' >= ' . $version;
348 - if (count($requires)) {
349 - $this->_output['extra_headers'] .= $this->_formatRpmHeader('Requires', implode(', ', $requires)) . "\n";
352 + if (isset($deps['required']['extension'])) {
353 + if (!isset($deps['required']['extension'][0])) {
354 + $deps['required']['extension'] = array($deps['required']['extension']);
356 + foreach ((array )$deps['required']['extension'] as $dep) {
357 + if (!isset($dep['channel'])) $dep['channel'] = null;
358 + // $package contains the *dependency name* here, which may or may
359 + // not be the same as the package name
360 + $package = $this->_getRPMName($dep['name'], $dep['channel'], null, 'ext');
362 + if (empty($package)) {
366 + $requires[$package] = $package;
370 + if (isset($deps['required']['subpackage'])) {
371 + if (!isset($deps['required']['subpackage'][0])) {
372 + $deps['required']['subpackage'] = array($deps['required']['subpackage']);
374 + foreach ($deps['required']['subpackage'] as $dep) {
375 + if (!isset($dep['channel'])) $dep['channel'] = null;
377 + // $package contains the *dependency name* here, which may or may
378 + // not be the same as the package name
379 + $package = $this->_getRPMName($dep['name'], $dep['channel'], null, 'pkgdep');
381 + if (empty($package)) {
385 + $requires[$package] = $package;
386 + // XXX: should be more complese like above with ranges, etc
390 + if (isset($deps['optional']['package'])) {
391 + if (!isset($deps['optional']['package'][0])) {
392 + $deps['optional']['package'] = array($deps['optional']['package']);
394 + foreach ($deps['optional']['package'] as $dep) {
395 + if (!isset($dep['channel'])) $dep['channel'] = null;
397 + // $package contains the *dependency name* here, which may or may
398 + // not be the same as the package name
399 + $package = $this->_getRPMName($dep['name'], $dep['channel'], null, 'pkgdep');
401 + if (empty($package)) {
405 + // suggests are not versioned (makes no sense in poldek)
406 + $suggests[$package] = $package;
408 + // PLD Linux: Fill extra info for _noautoreq deps
409 + $this->_output['_noautoreq'] .= " pear(". str_replace('_', '/', $dep['name']) . ".*)";
411 - if (count($conflicts)) {
412 - $this->_output['extra_headers'] .= $this->_formatRpmHeader('Conflicts', implode(', ', $conflicts)) . "\n";
415 + if (isset($deps['optional']['extension'])) {
416 + if (!isset($deps['optional']['extension'][0])) {
417 + $deps['optional']['extension'] = array($deps['optional']['extension']);
419 + foreach ($deps['optional']['extension'] as $dep) {
420 + if (!isset($dep['channel'])) $dep['channel'] = null;
422 + // $package contains the *dependency name* here, which may or may
423 + // not be the same as the package name
424 + $package = $this->_getRPMName($dep['name'], $dep['channel'], null, 'ext');
426 + if (empty($package)) {
430 + // suggests are not versioned (makes no sense in poldek)
431 + $suggests[$package] = $package;
436 + // go over filelist, to see if we need custom Role package presence
437 + foreach ($filelist as $filename => $attr) {
438 + // Ignore files with no role set or that didn't get installed
439 + if (!isset($attr['role']) || !isset($attr['installed_as'])) {
442 + $role = $attr['role'];
444 + if (!isset($this->_file_prefixes[$role])) {
445 + if (isset($this->_role_packages[$role])) {
446 + $pkg = $this->_role_packages[$role];
447 + $buildrequires[$pkg] = $pkg;
449 + // TODO: else use some rpm virtual provides for role?
453 + // append extra headers which we collected
454 + if (count($buildrequires)) {
455 + $this->_output['extra_headers'] .= $this->_formatRpmHeader('BuildRequires', $buildrequires) . "\n";
457 + if (count($requires)) {
458 + $this->_output['extra_headers'] .= $this->_formatRpmHeader('Requires', $requires) . "\n";
460 + if (count($conflicts)) {
461 + $this->_output['extra_headers'] .= $this->_formatRpmHeader('Conflicts', $conflicts) . "\n";
463 + if (count($suggests)) {
464 + $this->_output['extra_headers'] .= $this->_formatRpmHeader('Suggests', $suggests) . "\n";
468 @@ -927,9 +1110,21 @@
470 return $this->_getRPMNameFromFormat($this->_rpm_pkgname_format['pkg'], $package_name, $chan_name, $chan_alias);
473 + // PLD Linux: pecl extensions have different naming format
474 + if ($chan_alias == 'PECL') {
475 + $type = 'pecl-ext';
476 + } elseif ($chan_alias == 'PEAR') {
477 + $type = 'pear-pkg';
481 // let it drop through...
483 + // PLD Linux: sanitize gtk2 ext name.
484 + // http://bugs.php.net/bug.php?id=52663
485 + if ($type == 'ext' && $package_name == 'php-gtk') {
486 + $package_name = 'gtk2';
488 if (isset($this->_rpm_depname_format[$type]) && !empty($this->_rpm_depname_format[$type])) {
489 return $this->_getRPMNameFromFormat($this->_rpm_depname_format[$type], $package_name, $chan_name, $chan_alias);