1 --- PEAR_Command_Packaging-0.2.0/usr/share/pear/PEAR/Command/Packaging.php 2010-10-20 09:36:32.428771477 +0300
2 +++ PEAR_Command_Packaging-0.2.0/usr/share/pear/PEAR/Command/Packaging.php 2011-04-10 18:34:41.270846822 +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'
68 * printf format. The first '%s' is the RPM header name followed by a colon,
69 * the second is the header value.
71 - var $_spec_line_format = '%s %s';
72 + var $_spec_line_format = "%s\t%s";
74 // ------------------------------------------------------------------------
75 // --- END DISTRIBUTION CONFIG
78 'test_files_statement' => '',// empty string, or list of test files
79 'www_files_statement' => '', // empty string, or newline-separated list of files with "www" role
80 + '_noautoreq' => '', // no autoreqdep. PLD Linux specific
83 // The name of the template spec file to use
86 // Initialise the RPM package/dep naming format options
87 $this->_initialiseNamingOptions($options);
90 // Set the RPM release version
91 if (isset($options['rpm-release'])) {
92 $this->_output['release'] = $options['rpm-release'];
95 + // Pass output file in options
96 + if (isset($options['output'])) {
97 + $this->_output['output-file'] = $options['output'];
100 + // PLD Linux specific. need source md5
101 + $this->_output['tarball'] = $source_file;
102 + $this->_output['tarball_md5'] = md5(file_get_contents($source_file));
104 // Set the PEAR RPM name for the PEAR core package
105 $this->_output['pear_rpm_name'] = $this->_getRPMName('PEAR', 'pear.php.net', null, 'pkgdep');
108 // If source file ends in ".xml" we assume we are creating an RPM spec
109 // for a channel rather than an actual package
110 if (substr(strtolower($source_file), -4) == '.xml') {
111 @@ -378,13 +395,40 @@
113 * Format an RPM header line to be added to the spec file
114 * @param string $header The name of the RPM header to be added
115 - * @param string $value The contents of the RPM header
116 + * @param mixed $value The contents of the RPM header
119 - function _formatRpmHeader($header, $value)
120 + function _formatRpmHeader($header, $values)
122 - return sprintf($this->_spec_line_format, $header . ':', $value);
123 + // PLD Linux: we want values sorted and each on their line
124 + $values = (array )$values;
127 + foreach ($values as $value) {
128 + $ret .= sprintf($this->_spec_line_format, $header . ':', $value) . "\n";
135 + * Get an version for RPM package.
137 + * @param string $version Package version (e.g. '1.2.3RC1')
138 + * @return string Normalized version
140 + function _formatRpmVersion($version)
143 + // In PLD Linux alpha, beta, rc versions are noted in Release: not Version: tag.
144 + preg_match('/^(?P<version>[0-9.]+)(?P<extraversion>.*)$/', $version, $m);
145 + if ($m['extraversion']) {
146 + $version = "{$m['version']}-0.{$m['extraversion']}";
154 * Replace a macro in the output spec file
155 @@ -410,16 +454,20 @@
157 $package_name = null;
161 // Work out the name of the output spec file
162 - $spec_file = $this->_getRPMNameFromFormat(
163 - $this->_rpm_specname_format[$type],
165 - $this->_output['possible_channel'],
166 - $this->_output['channel_alias'],
167 - $this->_output['version']
170 + if (isset($this->_output['output-file'])) {
171 + $spec_file = $this->_output['output-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']
182 // Write the actual file
183 $wp = fopen($spec_file, 'wb');
187 $rpmdep = $this->_getRPMName(null, $cf->getName(), $cf->getAlias(), 'chandep');
188 if (!empty($rpmdep) && $rpmdep != $this->_output['rpm_package']) {
189 - $this->_output['extra_headers'] = $this->_formatRpmHeader('Provides', "$rpmdep") . "\n";
190 + $this->_output['extra_headers'] = $this->_formatRpmHeader('Provides', $rpmdep) . "\n";
193 // Channels don't really have version numbers; this will need to be
196 // Set up some of the basic macros
197 $this->_output['rpm_package'] = $this->_getRPMName($pf->getPackage(), $pf->getChannel(), null, 'pkg');
198 - $this->_output['description'] = wordwrap($package_info['description']);
199 + $this->_output['description'] = wordwrap($package_info['description'], 70);
200 $this->_output['summary'] = trim($package_info['summary']);
201 $this->_output['possible_channel'] = $pf->getChannel();
202 $this->_output['channel_alias'] = $this->_getChannelAlias($pf->getPackage(), $pf->getChannel());
203 @@ -646,14 +694,24 @@
204 if (substr($this->_file_prefixes[$role], -2) == '%s') {
205 $this->_output[$macro_name] = str_replace('%s', $pf->getPackage(), $this->_file_prefixes[$role]);
208 if ($role == 'cfg') {
209 - $this->_output[$macro_name] = '%config(noreplace) ' . implode("\n%config(noreplace) ", $files);
211 - $this->_output[$macro_name] = implode("\n", $files);
212 + $attr = '%config(noreplace) %verify(not md5 mtime size) ';
213 + } elseif ($role == 'script') {
214 + $attr = '%attr(755,root,root) ';
216 + $this->_output[$macro_name] = $attr . implode("\n$attr", $files);
219 $this->_output['files'] = trim($this->_output['files']);
221 + // figure registry file location
222 + if (in_array($this->_output['possible_channel'], $this->_standard_channels)) {
223 + $registry_dir = '%s/.registry/*.reg';
225 + $registry_dir = '%s/.registry/.channel.*/*.reg';
227 + $this->_output['registry_files_statement'] = str_replace('%s', $this->_file_prefixes['php'], $registry_dir);
230 if (isset($file_list['doc'])) {
231 @@ -685,12 +743,11 @@
233 function _generatePackageDeps($pf)
235 - $requires = $conflicts = array();
236 + $buildrequires = $requires = $conflicts = $suggests = array();
237 if ($pf->getPackagexmlVersion() == '1.0') {
238 - foreach ($pf->getDeps() as $dep) {
239 - if (isset($dep['optional']) && $dep['optional'] == 'yes') {
242 + $deps = $pf->getDeps();
243 + foreach ($deps as $dep) {
244 + $optional = isset($dep['optional']) && $dep['optional'] == 'yes';
246 if (!isset($dep['type']) || $dep['type'] == 'pkg') {
249 $type = $dep['type'];
252 - if (!isset($dep['channel'])) $dep['channel'] = null;
253 if (!isset($dep['name'])) $dep['name'] = ''; //e.g. "php" dep
254 + if (!isset($dep['channel'])) {
255 + // we need to figure out channel as pecl packages are might
256 + // be named differently than pear packages.
257 + $chan_alias = $this->_getChannelAlias($dep['name']);
258 + $reg = &$this->config->getRegistry();
259 + $dep['channel'] = $reg->channelName($chan_alias);
262 // $package contains the *dependency name* here, which may or may
263 // not be the same as the package name
264 @@ -725,21 +788,25 @@
265 if ($dep['rel'] == 'has') {
266 // We use $package as the index to the $requires array to de-duplicate deps.
267 // Note that in the case of duplicate deps, versioned deps will "win" - see several lines down.
268 - $requires[$package] = $package;
270 + $suggests[$package] = $package;
272 + $requires[$package] = $package;
274 } elseif ($dep['rel'] == 'not') {
275 $conflicts[] = $package;
276 } elseif ($dep['rel'] == 'ne') {
277 - $conflicts[] = $package . ' = ' . $dep['version'];
278 + $version = $this->_formatRpmVersion($dep['version']);
279 + $conflicts[] = $package . ' = ' . $version;
280 } elseif (isset($trans[$dep['rel']])) {
281 - $requires[$package] = $package . ' ' . $trans[$dep['rel']] . ' ' . $dep['version'];
282 + $version = $this->_formatRpmVersion($dep['version']);
284 + $suggests[$package] = $package . ' ' . $trans[$dep['rel']] . ' ' . $version;
286 + $requires[$package] = $package . ' ' . $trans[$dep['rel']] . ' ' . $version;
290 - if (count($requires)) {
291 - $this->_output['extra_headers'] .= $this->_formatRpmHeader('Requires', implode(', ', $requires)) . "\n";
293 - if (count($conflicts)) {
294 - $this->_output['extra_headers'] .= $this->_formatRpmHeader('Conflicts', implode(', ', $conflicts)) . "\n";
297 $this->_output['package2xml'] = '2'; // tell the spec to use package2.xml
298 $deps = $pf->getDeps(true);
299 @@ -842,10 +909,10 @@
302 if (isset($dep['min'])) {
303 - $requires[$package] = $package . ' >= ' . $dep['min'];
304 + $requires[$package] = $package . ' >= ' . $this->_formatRpmVersion($dep['min']);
306 if (isset($dep['max'])) {
307 - $requires[$package] = $package . ' <= ' . $dep['max'];
308 + $requires[$package] = $package . ' <= ' . $this->_formatRpmVersion($dep['max']);
310 if (isset($dep['exclude'])) {
311 $ex = $dep['exclude'];
312 @@ -865,17 +932,108 @@
313 $tar->popErrorHandling();
314 if ($a === null || PEAR::isError($a)) {
315 - $this->_output['package2xml'] = '';
316 // this doesn't have a package.xml version 1.0
317 - $requires[$this->_output['pear_rpm_name']] = $this->_output['pear_rpm_name'] . ' >= ' .
318 - $deps['required']['pearinstaller']['min'];
319 + $this->_output['package2xml'] = '';
320 + $version = $this->_formatRpmVersion($deps['required']['pearinstaller']['min']);
321 + // PLD linux hack: include epoch for PEAR package
322 + $version = "1:{$version}";
323 + $buildrequires[$this->_output['pear_rpm_name']] = $this->_output['pear_rpm_name'] . ' >= ' . $version;
325 - if (count($requires)) {
326 - $this->_output['extra_headers'] .= $this->_formatRpmHeader('Requires', implode(', ', $requires)) . "\n";
329 + if (isset($deps['required']['extension'])) {
330 + if (!isset($deps['required']['extension'][0])) {
331 + $deps['required']['extension'] = array($deps['required']['extension']);
333 - if (count($conflicts)) {
334 - $this->_output['extra_headers'] .= $this->_formatRpmHeader('Conflicts', implode(', ', $conflicts)) . "\n";
335 + foreach ((array )$deps['required']['extension'] as $dep) {
336 + if (!isset($dep['channel'])) $dep['channel'] = null;
337 + // $package contains the *dependency name* here, which may or may
338 + // not be the same as the package name
339 + $package = $this->_getRPMName($dep['name'], $dep['channel'], null, 'ext');
341 + if (empty($package)) {
345 + $requires[$package] = $package;
349 + if (isset($deps['required']['subpackage'])) {
350 + if (!isset($deps['required']['subpackage'][0])) {
351 + $deps['required']['subpackage'] = array($deps['required']['subpackage']);
353 + foreach ($deps['required']['subpackage'] as $dep) {
354 + if (!isset($dep['channel'])) $dep['channel'] = null;
356 + // $package contains the *dependency name* here, which may or may
357 + // not be the same as the package name
358 + $package = $this->_getRPMName($dep['name'], $dep['channel'], null, 'pkgdep');
360 + if (empty($package)) {
364 + $requires[$package] = $package;
365 + // XXX: should be more complese like above with ranges, etc
369 + if (isset($deps['optional']['package'])) {
370 + if (!isset($deps['optional']['package'][0])) {
371 + $deps['optional']['package'] = array($deps['optional']['package']);
373 + foreach ($deps['optional']['package'] as $dep) {
374 + if (!isset($dep['channel'])) $dep['channel'] = null;
376 + // $package contains the *dependency name* here, which may or may
377 + // not be the same as the package name
378 + $package = $this->_getRPMName($dep['name'], $dep['channel'], null, 'pkgdep');
380 + if (empty($package)) {
384 + // suggests are not versioned (makes no sense in poldek)
385 + $suggests[$package] = $package;
387 + // PLD Linux: Fill extra info for _noautoreq deps
388 + $this->_output['_noautoreq'] .= " pear(". str_replace('_', '/', $dep['name']) . ".*)";
392 + if (isset($deps['optional']['extension'])) {
393 + if (!isset($deps['optional']['extension'][0])) {
394 + $deps['optional']['extension'] = array($deps['optional']['extension']);
396 + foreach ($deps['optional']['extension'] as $dep) {
397 + if (!isset($dep['channel'])) $dep['channel'] = null;
399 + // $package contains the *dependency name* here, which may or may
400 + // not be the same as the package name
401 + $package = $this->_getRPMName($dep['name'], $dep['channel'], null, 'ext');
403 + if (empty($package)) {
407 + // suggests are not versioned (makes no sense in poldek)
408 + $suggests[$package] = $package;
413 + // append extra headers which we collected
414 + if (count($buildrequires)) {
415 + $this->_output['extra_headers'] .= $this->_formatRpmHeader('BuildRequires', $buildrequires) . "\n";
417 + if (count($requires)) {
418 + $this->_output['extra_headers'] .= $this->_formatRpmHeader('Requires', $requires) . "\n";
420 + if (count($conflicts)) {
421 + $this->_output['extra_headers'] .= $this->_formatRpmHeader('Conflicts', $conflicts) . "\n";
423 + if (count($suggests)) {
424 + $this->_output['extra_headers'] .= $this->_formatRpmHeader('Suggests', $suggests) . "\n";
428 @@ -927,9 +1085,21 @@
430 return $this->_getRPMNameFromFormat($this->_rpm_pkgname_format['pkg'], $package_name, $chan_name, $chan_alias);
433 + // PLD Linux: pecl extensions have different naming format
434 + if ($chan_alias == 'PECL') {
435 + $type = 'pecl-ext';
436 + } elseif ($chan_alias == 'PEAR') {
437 + $type = 'pear-pkg';
441 // let it drop through...
443 + // PLD Linux: sanitize gtk2 ext name.
444 + // http://bugs.php.net/bug.php?id=52663
445 + if ($type == 'ext' && $package_name == 'php-gtk') {
446 + $package_name = 'gtk2';
448 if (isset($this->_rpm_depname_format[$type]) && !empty($this->_rpm_depname_format[$type])) {
449 return $this->_getRPMNameFromFormat($this->_rpm_depname_format[$type], $package_name, $chan_name, $chan_alias);