]> git.pld-linux.org Git - packages/php-pear-PEAR_Command_Packaging.git/blob - php-pear-PEAR_Command_Packaging.patch
- drop obsolete and outdated manual inclusion of rpm macros
[packages/php-pear-PEAR_Command_Packaging.git] / php-pear-PEAR_Command_Packaging.patch
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
3 @@ -54,6 +54,11 @@
4                      'arg' => 'FILE',
5                      'doc' => 'Use FILE as RPM spec file template'
6                      ),
7 +                'output' => array(
8 +                    'shortopt' => 'o',
9 +                    'arg' => 'FILE',
10 +                    'doc' => 'Use FILE as output filename'
11 +                    ),
12                  'rpm-release' => array(
13                      'shortopt' => 'r',
14                      'arg' => 'RELEASE',
15 @@ -121,10 +126,10 @@
16       * $commands array above and in Packaging.xml so that it is consistent.
17       */
18      var $_rpm_pkgname_format = array(
19 -        'pkg'  => '%C::%s',
20 +        'pkg'  => 'php-%c-%s',
21          'chan' => 'php-channel-%c',
22      );
23 -    
24 +
25      /**
26       * The default format of various dependencies that might be generated in the
27       * spec file. The currently-handled dependency types are:
28 @@ -140,9 +145,11 @@
29       * %P   = use the same as whatever rpm_pkgname_format is set to be
30       */
31      var $_rpm_depname_format = array(
32 -        'pkg'  => '%P',
33 +        'pkg'  => 'php-%c-%s',
34          'ext'  => 'php-%l',
35 -        'php'  => 'php',
36 +        'pear-pkg' => 'php-pear-%s',
37 +        'pecl-ext'  => 'php-pecl-%l',
38 +        'php'  => 'php-common',
39          'chan' => 'php-channel(%n)',
40      );
41      
42 @@ -159,7 +166,7 @@
43       * chan - used when generating a spec file for a channel
44       */
45      var $_rpm_specname_format = array(
46 -        'pkg'  => '%P-%v.spec',
47 +        'pkg'  => '%P.spec',
48          'chan' => 'php-channel-%c.spec'
49      );
50      
51 @@ -182,22 +189,30 @@
52       * need to be listed here
53       */
54      var $_file_prefixes = array(
55 -        'php' => '%{_libdir}/php/pear',
56 +        'php' => '%{php_pear_dir}',
57          'doc' => '',
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'
67      );
68 +
69 +    /**
70 +     * Role packages to use for non-standard file roles. Used when generating
71 +     * specs for packages only.
72 +     */
73 +    var $_role_packages = array(
74 +        'horde' => 'php-horde-Horde_Role',
75 +    );
76      
77      /**
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.
81       */
82 -    var $_spec_line_format = '%s %s';
83 +    var $_spec_line_format = "%s\t%s";
84      
85      // ------------------------------------------------------------------------
86      // --- END DISTRIBUTION CONFIG
87 @@ -247,6 +262,7 @@
88          'test_dir' => '',
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
92      );
93      
94      // The name of the template spec file to use
95 @@ -330,15 +346,24 @@
96          
97          // Initialise the RPM package/dep naming format options
98          $this->_initialiseNamingOptions($options);        
99 -        
100 +
101          // Set the RPM release version
102          if (isset($options['rpm-release'])) {
103              $this->_output['release'] = $options['rpm-release'];
104          }
105 +
106 +        // Pass output file in options
107 +        if (isset($options['output'])) {
108 +            $this->_output['output-file'] = $options['output'];
109 +        }
110 +
111 +        // PLD Linux specific. need source md5
112 +        $this->_output['tarball'] = $source_file;
113 +        $this->_output['tarball_md5'] = md5(file_get_contents($source_file));
114          
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');
117 -        
118 +
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 @@
123      /**
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
128       * @return string
129       */
130 -    function _formatRpmHeader($header, $value)
131 +    function _formatRpmHeader($header, $values)
132 +    {
133 +        // PLD Linux: we want values sorted and each on their line
134 +        $values = (array )$values;
135 +        sort($values);
136 +        $ret = '';
137 +        foreach ($values as $value) {
138 +            $ret .= sprintf($this->_spec_line_format, $header . ':', $value) . "\n";
139 +        }
140 +        return $ret;
141 +    }
142 +
143 +
144 +    /*
145 +     * Get an version for RPM package.
146 +     *
147 +     * @param  string $version         Package version (e.g. '1.2.3RC1')
148 +     * @return string Normalized version
149 +     */
150 +    function _formatRpmVersion($version)
151      {
152 -        return sprintf($this->_spec_line_format, $header . ':', $value);
153 +
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']}";
158 +        }
159 +
160 +        return $version;
161      }
162 +
163      
164      /**
165       * Replace a macro in the output spec file
166 @@ -410,16 +462,20 @@
167          } else {
168              $package_name = null;
169          }
170 -        
171 +
172          // Work out the name of the output spec file
173 -        $spec_file = $this->_getRPMNameFromFormat(
174 -            $this->_rpm_specname_format[$type],
175 -            $package_name,
176 -            $this->_output['possible_channel'],
177 -            $this->_output['channel_alias'],
178 -            $this->_output['version']
179 -        );
180 -        
181 +        if (isset($this->_output['output-file'])) {
182 +            $spec_file = $this->_output['output-file'];
183 +        } else {
184 +            $spec_file = $this->_getRPMNameFromFormat(
185 +                $this->_rpm_specname_format[$type],
186 +                $package_name,
187 +                $this->_output['possible_channel'],
188 +                $this->_output['channel_alias'],
189 +                $this->_output['version']
190 +            );
191 +        }
192 +
193          // Write the actual file
194          $wp = fopen($spec_file, 'wb');
195          if (!$wp) {
196 @@ -457,7 +513,7 @@
197          
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";
202          }
203              
204          // Channels don't really have version numbers; this will need to be
205 @@ -564,7 +620,7 @@
206          
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());
214 @@ -591,7 +647,7 @@
215  
216          // Generate the Requires and Conflicts for the RPM
217          if ($pf->getDeps()) {
218 -            $this->_generatePackageDeps($pf);
219 +            $this->_generatePackageDeps($pf, $package_info['filelist']);
220          }
221      
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]);
226              } else {
227 +                $attr = '';
228                  if ($role == 'cfg') {
229 -                    $this->_output[$macro_name] = '%config(noreplace) ' . implode("\n%config(noreplace) ", $files);
230 -                } else {
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) ';
235                  }
236 +                $this->_output[$macro_name] = $attr . implode("\n$attr", $files);
237              }
238          }
239          $this->_output['files'] = trim($this->_output['files']);
240 +
241 +               // figure registry file location
242 +               if (in_array($this->_output['possible_channel'], $this->_standard_channels)) {
243 +                       $registry_dir = '%s/.registry/*.reg';
244 +               } else {
245 +                       $registry_dir = '%s/.registry/.channel.*/*.reg';
246 +               }
247 +               $this->_output['registry_files_statement'] = str_replace('%s', $this->_file_prefixes['php'], $registry_dir);
248          
249          // Handle doc files
250          if (isset($file_list['doc'])) {
251 @@ -683,14 +749,13 @@
252      }
253      
254  
255 -    function _generatePackageDeps($pf)
256 +    function _generatePackageDeps($pf, $filelist)
257      {
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') {
263 -                    continue;
264 -                }
265 +            $deps = $pf->getDeps();
266 +            foreach ($deps as $dep) {
267 +                $optional = isset($dep['optional']) && $dep['optional'] == 'yes';
268                  
269                  if (!isset($dep['type']) || $dep['type'] == 'pkg') {
270                      $type = 'pkgdep';
271 @@ -698,8 +763,14 @@
272                      $type = $dep['type'];
273                  }
274                  
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);
283 +                }
284                  
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;
292 +                    if ($optional) {
293 +                        $suggests[$package] = $package;
294 +                    } else {
295 +                        $requires[$package] = $package;
296 +                    }
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']);
306 +                    if ($optional) {
307 +                        $suggests[$package] = $package . ' ' . $trans[$dep['rel']] . ' ' . $version;
308 +                    } else {
309 +                        $requires[$package] = $package . ' ' . $trans[$dep['rel']] . ' ' . $version;
310 +                    }
311                  }
312              }
313 -            if (count($requires)) {
314 -                $this->_output['extra_headers'] .= $this->_formatRpmHeader('Requires', implode(', ', $requires)) . "\n";
315 -            }
316 -            if (count($conflicts)) {
317 -                $this->_output['extra_headers'] .= $this->_formatRpmHeader('Conflicts', implode(', ', $conflicts)) . "\n";
318 -            }
319          } else {
320              $this->_output['package2xml'] = '2'; // tell the spec to use package2.xml
321              $deps = $pf->getDeps(true);
322 @@ -842,10 +917,10 @@
323                          }
324                      } else {
325                          if (isset($dep['min'])) {
326 -                            $requires[$package] = $package . ' >= ' . $dep['min'];
327 +                            $requires[$package] = $package . ' >= ' . $this->_formatRpmVersion($dep['min']);
328                          }
329                          if (isset($dep['max'])) {
330 -                            $requires[$package] = $package . ' <= ' . $dep['max'];
331 +                            $requires[$package] = $package . ' <= ' . $this->_formatRpmVersion($dep['max']);
332                          }
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;
347                  }
348 -                if (count($requires)) {
349 -                    $this->_output['extra_headers'] .= $this->_formatRpmHeader('Requires', implode(', ', $requires)) . "\n";
350 +            }
351 +
352 +            if (isset($deps['required']['extension'])) {
353 +                if (!isset($deps['required']['extension'][0])) {
354 +                    $deps['required']['extension'] = array($deps['required']['extension']);
355 +                }
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');
361 +
362 +                    if (empty($package)) {
363 +                        continue;
364 +                    }
365 +
366 +                    $requires[$package] = $package;
367 +                }
368 +            }
369 +
370 +            if (isset($deps['required']['subpackage'])) {
371 +                if (!isset($deps['required']['subpackage'][0])) {
372 +                    $deps['required']['subpackage'] = array($deps['required']['subpackage']);
373 +                }
374 +                foreach ($deps['required']['subpackage'] as $dep) {
375 +                    if (!isset($dep['channel'])) $dep['channel'] = null;
376 +
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');
380 +
381 +                    if (empty($package)) {
382 +                        continue;
383 +                    }
384 +
385 +                    $requires[$package] = $package;
386 +                    // XXX: should be more complese like above with ranges, etc
387 +                }
388 +            }
389 +
390 +            if (isset($deps['optional']['package'])) {
391 +                if (!isset($deps['optional']['package'][0])) {
392 +                    $deps['optional']['package'] = array($deps['optional']['package']);
393 +                }
394 +                foreach ($deps['optional']['package'] as $dep) {
395 +                    if (!isset($dep['channel'])) $dep['channel'] = null;
396 +
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');
400 +
401 +                    if (empty($package)) {
402 +                        continue;
403 +                    }
404 +
405 +                    // suggests are not versioned (makes no sense in poldek)
406 +                    $suggests[$package] = $package;
407 +
408 +                    // PLD Linux: Fill extra info for _noautoreq deps
409 +                    $this->_output['_noautoreq'] .= " pear(". str_replace('_', '/', $dep['name']) . ".*)";
410                  }
411 -                if (count($conflicts)) {
412 -                    $this->_output['extra_headers'] .= $this->_formatRpmHeader('Conflicts', implode(', ', $conflicts)) . "\n";
413 +            }
414 +
415 +            if (isset($deps['optional']['extension'])) {
416 +                if (!isset($deps['optional']['extension'][0])) {
417 +                    $deps['optional']['extension'] = array($deps['optional']['extension']);
418 +                }
419 +                foreach ($deps['optional']['extension'] as $dep) {
420 +                    if (!isset($dep['channel'])) $dep['channel'] = null;
421 +
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');
425 +
426 +                    if (empty($package)) {
427 +                        continue;
428 +                    }
429 +
430 +                    // suggests are not versioned (makes no sense in poldek)
431 +                    $suggests[$package] = $package;
432                  }
433              }
434          }
435 +
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'])) {
440 +                continue;
441 +            }
442 +            $role = $attr['role'];
443 +            
444 +            if (!isset($this->_file_prefixes[$role])) {
445 +                if (isset($this->_role_packages[$role])) {
446 +                    $pkg = $this->_role_packages[$role];
447 +                    $buildrequires[$pkg] = $pkg;
448 +                }
449 +                // TODO: else use some rpm virtual provides for role?
450 +            }
451 +        }
452 +
453 +        // append extra headers which we collected
454 +        if (count($buildrequires)) {
455 +            $this->_output['extra_headers'] .= $this->_formatRpmHeader('BuildRequires', $buildrequires) . "\n";
456 +        }
457 +        if (count($requires)) {
458 +            $this->_output['extra_headers'] .= $this->_formatRpmHeader('Requires', $requires) . "\n";
459 +        }
460 +        if (count($conflicts)) {
461 +            $this->_output['extra_headers'] .= $this->_formatRpmHeader('Conflicts', $conflicts) . "\n";
462 +        }
463 +        if (count($suggests)) {
464 +            $this->_output['extra_headers'] .= $this->_formatRpmHeader('Suggests', $suggests) . "\n";
465 +        }
466      }
467  
468 @@ -927,9 +1110,21 @@
469              case 'pkg':
470                  return $this->_getRPMNameFromFormat($this->_rpm_pkgname_format['pkg'], $package_name, $chan_name, $chan_alias);
471              case 'pkgdep':
472 -                $type = 'pkg';
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';
478 +                } else {
479 +                    $type = 'pkg';
480 +                }
481                  // let it drop through...
482              default:
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';
487 +                }
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);
490                  }
This page took 0.125532 seconds and 3 git commands to generate.