PEAR
[ class tree: PEAR ] [ index: PEAR ] [ all elements ]

Source for file Package.php

Documentation is available at Package.php

  1. <?php
  2. //
  3. // +----------------------------------------------------------------------+
  4. // | PHP Version 5                                                        |
  5. // +----------------------------------------------------------------------+
  6. // | Copyright (c) 1997-2004 The PHP Group                                |
  7. // +----------------------------------------------------------------------+
  8. // | This source file is subject to version 3.0 of the PHP license,       |
  9. // | that is bundled with this package in the file LICENSE, and is        |
  10. // | available through the world-wide-web at the following url:           |
  11. // | http://www.php.net/license/3_0.txt.                                  |
  12. // | If you did not receive a copy of the PHP license and are unable to   |
  13. // | obtain it through the world-wide-web, please send a note to          |
  14. // | license@php.net so we can mail you a copy immediately.               |
  15. // +----------------------------------------------------------------------+
  16. // | Authors: Stig Bakken <ssb@php.net>                                   |
  17. // |          Martin Jansen <mj@php.net>                                  |
  18. // |          Greg Beaver <cellog@php.net>                                |
  19. // +----------------------------------------------------------------------+
  20. //
  21. // $Id: Package.php,v 1.61.2.7 2005/02/17 17:47:55 cellog Exp $
  22.  
  23. require_once 'PEAR/Common.php';
  24. require_once 'PEAR/Command/Common.php';
  25.  
  26. class PEAR_Command_Package extends PEAR_Command_Common
  27. {
  28.     // {{{ properties
  29.  
  30.     var $commands = array(
  31.         'package' => array(
  32.             'summary' => 'Build Package',
  33.             'function' => 'doPackage',
  34.             'shortcut' => 'p',
  35.             'options' => array(
  36.                 'nocompress' => array(
  37.                     'shortopt' => 'Z',
  38.                     'doc' => 'Do not gzip the package file'
  39.                     ),
  40.                 'showname' => array(
  41.                     'shortopt' => 'n',
  42.                     'doc' => 'Print the name of the packaged file.',
  43.                     ),
  44.                 ),
  45.             'doc' => '[descfile]
  46. Creates a PEAR package from its description file (usually called
  47. package.xml).
  48. '
  49.             ),
  50.         'package-validate' => array(
  51.             'summary' => 'Validate Package Consistency',
  52.             'function' => 'doPackageValidate',
  53.             'shortcut' => 'pv',
  54.             'options' => array(),
  55.             'doc' => '
  56. ',
  57.             ),
  58.         'cvsdiff' => array(
  59.             'summary' => 'Run a "cvs diff" for all files in a package',
  60.             'function' => 'doCvsDiff',
  61.             'shortcut' => 'cd',
  62.             'options' => array(
  63.                 'quiet' => array(
  64.                     'shortopt' => 'q',
  65.                     'doc' => 'Be quiet',
  66.                     ),
  67.                 'reallyquiet' => array(
  68.                     'shortopt' => 'Q',
  69.                     'doc' => 'Be really quiet',
  70.                     ),
  71.                 'date' => array(
  72.                     'shortopt' => 'D',
  73.                     'doc' => 'Diff against revision of DATE',
  74.                     'arg' => 'DATE',
  75.                     ),
  76.                 'release' => array(
  77.                     'shortopt' => 'R',
  78.                     'doc' => 'Diff against tag for package release REL',
  79.                     'arg' => 'REL',
  80.                     ),
  81.                 'revision' => array(
  82.                     'shortopt' => 'r',
  83.                     'doc' => 'Diff against revision REV',
  84.                     'arg' => 'REV',
  85.                     ),
  86.                 'context' => array(
  87.                     'shortopt' => 'c',
  88.                     'doc' => 'Generate context diff',
  89.                     ),
  90.                 'unified' => array(
  91.                     'shortopt' => 'u',
  92.                     'doc' => 'Generate unified diff',
  93.                     ),
  94.                 'ignore-case' => array(
  95.                     'shortopt' => 'i',
  96.                     'doc' => 'Ignore case, consider upper- and lower-case letters equivalent',
  97.                     ),
  98.                 'ignore-whitespace' => array(
  99.                     'shortopt' => 'b',
  100.                     'doc' => 'Ignore changes in amount of white space',
  101.                     ),
  102.                 'ignore-blank-lines' => array(
  103.                     'shortopt' => 'B',
  104.                     'doc' => 'Ignore changes that insert or delete blank lines',
  105.                     ),
  106.                 'brief' => array(
  107.                     'doc' => 'Report only whether the files differ, no details',
  108.                     ),
  109.                 'dry-run' => array(
  110.                     'shortopt' => 'n',
  111.                     'doc' => 'Don\'t do anything, just pretend',
  112.                     ),
  113.                 ),
  114.             'doc' => '<package.xml>
  115. Compares all the files in a package.  Without any options, this
  116. command will compare the current code with the last checked-in code.
  117. Using the -r or -R option you may compare the current code with that
  118. of a specific release.
  119. ',
  120.             ),
  121.         'cvstag' => array(
  122.             'summary' => 'Set CVS Release Tag',
  123.             'function' => 'doCvsTag',
  124.             'shortcut' => 'ct',
  125.             'options' => array(
  126.                 'quiet' => array(
  127.                     'shortopt' => 'q',
  128.                     'doc' => 'Be quiet',
  129.                     ),
  130.                 'reallyquiet' => array(
  131.                     'shortopt' => 'Q',
  132.                     'doc' => 'Be really quiet',
  133.                     ),
  134.                 'slide' => array(
  135.                     'shortopt' => 'F',
  136.                     'doc' => 'Move (slide) tag if it exists',
  137.                     ),
  138.                 'delete' => array(
  139.                     'shortopt' => 'd',
  140.                     'doc' => 'Remove tag',
  141.                     ),
  142.                 'dry-run' => array(
  143.                     'shortopt' => 'n',
  144.                     'doc' => 'Don\'t do anything, just pretend',
  145.                     ),
  146.                 ),
  147.             'doc' => '<package.xml>
  148. Sets a CVS tag on all files in a package.  Use this command after you have
  149. packaged a distribution tarball with the "package" command to tag what
  150. revisions of what files were in that release.  If need to fix something
  151. after running cvstag once, but before the tarball is released to the public,
  152. use the "slide" option to move the release tag.
  153. ',
  154.             ),
  155.         'run-tests' => array(
  156.             'summary' => 'Run Regression Tests',
  157.             'function' => 'doRunTests',
  158.             'shortcut' => 'rt',
  159.             'options' => array(
  160.                 'recur' => array(
  161.                     'shortopt' => 'r',
  162.                     'doc' => 'Run tests in child directories, recursively.  4 dirs deep maximum',
  163.                 ),
  164.                 'ini' => array(
  165.                     'shortopt' => 'i',
  166.                     'doc' => 'actual string of settings to pass to php in format " -d setting=blah"',
  167.                     'arg' => 'SETTINGS'
  168.                 ),
  169.                 'realtimelog' => array(
  170.                     'shortopt' => 'l',
  171.                     'doc' => 'Log test runs/results as they are run',
  172.                 ),
  173.             ),
  174.             'doc' => '[testfile|dir ...]
  175. Run regression tests with PHP\'s regression testing script (run-tests.php).',
  176.             ),
  177.         'package-dependencies' => array(
  178.             'summary' => 'Show package dependencies',
  179.             'function' => 'doPackageDependencies',
  180.             'shortcut' => 'pd',
  181.             'options' => array(),
  182.             'doc' => '
  183. List all depencies the package has.'
  184.             ),
  185.         'sign' => array(
  186.             'summary' => 'Sign a package distribution file',
  187.             'function' => 'doSign',
  188.             'shortcut' => 'si',
  189.             'options' => array(),
  190.             'doc' => '<package-file>
  191. Signs a package distribution (.tar or .tgz) file with GnuPG.',
  192.             ),
  193.         'makerpm' => array(
  194.             'summary' => 'Builds an RPM spec file from a PEAR package',
  195.             'function' => 'doMakeRPM',
  196.             'shortcut' => 'rpm',
  197.             'options' => array(
  198.                 'spec-template' => array(
  199.                     'shortopt' => 't',
  200.                     'arg' => 'FILE',
  201.                     'doc' => 'Use FILE as RPM spec file template'
  202.                     ),
  203.                 'rpm-pkgname' => array(
  204.                     'shortopt' => 'p',
  205.                     'arg' => 'FORMAT',
  206.                     'doc' => 'Use FORMAT as format string for RPM package name, %s is replaced
  207. by the PEAR package name, defaults to "PEAR::%s".',
  208.                     ),
  209.                 ),
  210.             'doc' => '<package-file>
  211.  
  212. Creates an RPM .spec file for wrapping a PEAR package inside an RPM
  213. package.  Intended to be used from the SPECS directory, with the PEAR
  214. package tarball in the SOURCES directory:
  215.  
  216. $ pear makerpm ../SOURCES/Net_Socket-1.0.tgz
  217. Wrote RPM spec file PEAR::Net_Geo-1.0.spec
  218. $ rpm -bb PEAR::Net_Socket-1.0.spec
  219. ...
  220. Wrote: /usr/src/redhat/RPMS/i386/PEAR::Net_Socket-1.0-1.i386.rpm
  221. ',
  222.             ),
  223.         );
  224.  
  225.     var $output;
  226.  
  227.     // }}}
  228.     // {{{ constructor
  229.  
  230.     /**
  231.      * PEAR_Command_Package constructor.
  232.      *
  233.      * @access public
  234.      */
  235.     function PEAR_Command_Package(&$ui&$config)
  236.     {
  237.         parent::PEAR_Command_Common($ui$config);
  238.     }
  239.  
  240.     // }}}
  241.  
  242.     // {{{ _displayValidationResults()
  243.  
  244.     function _displayValidationResults($err$warn$strict = false)
  245.     {
  246.         foreach ($err as $e{
  247.             $this->output .= "Error: $e\n";
  248.         }
  249.         foreach ($warn as $w{
  250.             $this->output .= "Warning: $w\n";
  251.         }
  252.         $this->output .= sprintf('Validation: %d error(s), %d warning(s)'."\n",
  253.                                        sizeof($err)sizeof($warn));
  254.         if ($strict && sizeof($err> 0{
  255.             $this->output .= "Fix these errors and try again.";
  256.             return false;
  257.         }
  258.         return true;
  259.     }
  260.  
  261.     // }}}
  262.     // {{{ doPackage()
  263.  
  264.     function doPackage($command$options$params)
  265.     {
  266.         $this->output '';
  267.         include_once 'PEAR/Packager.php';
  268.         if (sizeof($params< 1{
  269.             $params[0"package.xml";
  270.         }
  271.         $pkginfofile = isset($params[0]$params[0'package.xml';
  272.         $packager =new PEAR_Packager();
  273.         $err $warn = array();
  274.         $dir dirname($pkginfofile);
  275.         $compress = empty($options['nocompress']? true : false;
  276.         $result $packager->package($pkginfofile$compress);
  277.         if (PEAR::isError($result)) {
  278.             $this->ui->outputData($this->output$command);
  279.             return $this->raiseError($result);
  280.         }
  281.         // Don't want output, only the package file name just created
  282.         if (isset($options['showname'])) {
  283.             $this->output $result;
  284.         }
  285.         if (PEAR::isError($result)) {
  286.             $this->output .= "Package failed: ".$result->getMessage();
  287.         }
  288.         $this->ui->outputData($this->output$command);
  289.         return true;
  290.     }
  291.  
  292.     // }}}
  293.     // {{{ doPackageValidate()
  294.  
  295.     function doPackageValidate($command$options$params)
  296.     {
  297.         $this->output '';
  298.         if (sizeof($params< 1{
  299.             $params[0"package.xml";
  300.         }
  301.         $obj = new PEAR_Common;
  302.         $info = null;
  303.         if ($fp @fopen($params[0]"r")) {
  304.             $test fread($fp5);
  305.             fclose($fp);
  306.             if ($test == "<?xml"{
  307.                 $info $obj->infoFromDescriptionFile($params[0]);
  308.             }
  309.         }
  310.         if (empty($info)) {
  311.             $info $obj->infoFromTgzFile($params[0]);
  312.         }
  313.         if (PEAR::isError($info)) {
  314.             return $this->raiseError($info);
  315.         }
  316.         $obj->validatePackageInfo($info$err$warn);
  317.         $this->_displayValidationResults($err$warn);
  318.         $this->ui->outputData($this->output$command);
  319.         return true;
  320.     }
  321.  
  322.     // }}}
  323.     // {{{ doCvsTag()
  324.  
  325.     function doCvsTag($command$options$params)
  326.     {
  327.         $this->output '';
  328.         $_cmd $command;
  329.         if (sizeof($params< 1{
  330.             $help $this->getHelp($command);
  331.             return $this->raiseError("$command: missing parameter: $help[0]");
  332.         }
  333.         $obj = new PEAR_Common;
  334.         $info $obj->infoFromDescriptionFile($params[0]);
  335.         if (PEAR::isError($info)) {
  336.             return $this->raiseError($info);
  337.         }
  338.         $err $warn = array();
  339.         $obj->validatePackageInfo($info$err$warn);
  340.         if (!$this->_displayValidationResults($err$warntrue)) {
  341.             $this->ui->outputData($this->output$command);
  342.             break;
  343.         }
  344.         $version $info['version'];
  345.         $cvsversion preg_replace('/[^a-z0-9]/i''_'$version);
  346.         $cvstag = "RELEASE_$cvsversion";
  347.         $files array_keys($info['filelist']);
  348.         $command "cvs";
  349.         if (isset($options['quiet'])) {
  350.             $command .= ' -q';
  351.         }
  352.         if (isset($options['reallyquiet'])) {
  353.             $command .= ' -Q';
  354.         }
  355.         $command .= ' tag';
  356.         if (isset($options['slide'])) {
  357.             $command .= ' -F';
  358.         }
  359.         if (isset($options['delete'])) {
  360.             $command .= ' -d';
  361.         }
  362.         $command .= ' ' $cvstag ' ' escapeshellarg($params[0]);
  363.         foreach ($files as $file{
  364.             $command .= ' ' escapeshellarg($file);
  365.         }
  366.         if ($this->config->get('verbose'> 1{
  367.             $this->output .= "$command\n";
  368.         }
  369.         $this->output .= "$command\n";
  370.         if (empty($options['dry-run'])) {
  371.             $fp popen($command"r");
  372.             while ($line fgets($fp1024)) {
  373.                 $this->output .= rtrim($line)."\n";
  374.             }
  375.             pclose($fp);
  376.         }
  377.         $this->ui->outputData($this->output$_cmd);
  378.         return true;
  379.     }
  380.  
  381.     // }}}
  382.     // {{{ doCvsDiff()
  383.  
  384.     function doCvsDiff($command$options$params)
  385.     {
  386.         $this->output '';
  387.         if (sizeof($params< 1{
  388.             $help $this->getHelp($command);
  389.             return $this->raiseError("$command: missing parameter: $help[0]");
  390.         }
  391.         $obj = new PEAR_Common;
  392.         $info $obj->infoFromDescriptionFile($params[0]);
  393.         if (PEAR::isError($info)) {
  394.             return $this->raiseError($info);
  395.         }
  396.         $files array_keys($info['filelist']);
  397.         $cmd "cvs";
  398.         if (isset($options['quiet'])) {
  399.             $cmd .= ' -q';
  400.             unset($options['quiet']);
  401.         }
  402.         if (isset($options['reallyquiet'])) {
  403.             $cmd .= ' -Q';
  404.             unset($options['reallyquiet']);
  405.         }
  406.         if (isset($options['release'])) {
  407.             $cvsversion preg_replace('/[^a-z0-9]/i''_'$options['release']);
  408.             $cvstag = "RELEASE_$cvsversion";
  409.             $options['revision'$cvstag;
  410.             unset($options['release']);
  411.         }
  412.         $execute = true;
  413.         if (isset($options['dry-run'])) {
  414.             $execute = false;
  415.             unset($options['dry-run']);
  416.         }
  417.         $cmd .= ' diff';
  418.         // the rest of the options are passed right on to "cvs diff"
  419.         foreach ($options as $option => $optarg{
  420.             $arg @$this->commands[$command]['options'][$option]['arg'];
  421.             $short @$this->commands[$command]['options'][$option]['shortopt'];
  422.             $cmd .= $short ? " -$short" : " --$option";
  423.             if ($arg && $optarg{
  424.                 $cmd .= ($short '' '='escapeshellarg($optarg);
  425.             }
  426.         }
  427.         foreach ($files as $file{
  428.             $cmd .= ' ' escapeshellarg($file);
  429.         }
  430.         if ($this->config->get('verbose'> 1{
  431.             $this->output .= "$cmd\n";
  432.         }
  433.         if ($execute{
  434.             $fp popen($cmd"r");
  435.             while ($line fgets($fp1024)) {
  436.                 $this->output .= rtrim($line)."\n";
  437.             }
  438.             pclose($fp);
  439.         }
  440.         $this->ui->outputData($this->output$command);
  441.         return true;
  442.     }
  443.  
  444.     // }}}
  445.     // {{{ doRunTests()
  446.  
  447.     function doRunTests($command$options$params)
  448.     {
  449.         include_once 'PEAR/RunTest.php';
  450.         $log = new PEAR_Common;
  451.         $log->ui = &$this->ui// slightly hacky, but it will work
  452.         $run = new PEAR_RunTest($log);
  453.         $tests = array();
  454.         if (isset($options['recur'])) {
  455.             $depth = 4;
  456.         else {
  457.             $depth = 1;
  458.         }
  459.         if (!count($params)) {
  460.             $params['.';
  461.         }
  462.         foreach ($params as $p{
  463.             if (is_dir($p)) {
  464.                 $dir System::find(array($p'-type''f',
  465.                                             '-maxdepth'$depth,
  466.                                             '-name''*.phpt'));
  467.                 $tests array_merge($tests$dir);
  468.             else {
  469.                 if (!@file_exists($p)) {
  470.                     if (!preg_match('/\.phpt$/'$p)) {
  471.                         $p .= '.phpt';
  472.                     }
  473.                     $dir System::find(array(dirname($p)'-type''f',
  474.                                                 '-maxdepth'$depth,
  475.                                                 '-name'$p));
  476.                     $tests array_merge($tests$dir);
  477.                 else {
  478.                     $tests[$p;
  479.                 }
  480.             }
  481.         }
  482.         $ini_settings '';
  483.         if (isset($options['ini'])) {
  484.             $ini_settings .= $options['ini'];
  485.         }
  486.         if (isset($_ENV['TEST_PHP_INCLUDE_PATH'])) {
  487.             $ini_settings .= " -d include_path={$_ENV['TEST_PHP_INCLUDE_PATH']}";
  488.         }
  489.         if ($ini_settings{
  490.             $this->ui->outputData('Using INI settings: "' $ini_settings '"');
  491.         }
  492.         $skipped $passed $failed = array();
  493.         $this->ui->outputData('Running ' count($tests' tests'$command);
  494.         $start time();
  495.         if (isset($options['realtimelog'])) {
  496.             @unlink('run-tests.log');
  497.         }
  498.         foreach ($tests as $t{
  499.             if (isset($options['realtimelog'])) {
  500.                 $fp @fopen('run-tests.log''a');
  501.                 if ($fp{
  502.                     fwrite($fp"Running test $t...");
  503.                     fclose($fp);
  504.                 }
  505.             }
  506.             $result $run->run($t$ini_settings);
  507.             if (OS_WINDOWS{
  508.                 for($i=0;$i<2000;$i++{
  509.                     $i $i// delay - race conditions on windows
  510.                 }
  511.             }
  512.             if (isset($options['realtimelog'])) {
  513.                 $fp @fopen('run-tests.log''a');
  514.                 if ($fp{
  515.                     fwrite($fp"$result\n");
  516.                     fclose($fp);
  517.                 }
  518.             }
  519.             if ($result == 'FAILED'{
  520.                 $failed[$t;
  521.             }
  522.             if ($result == 'PASSED'{
  523.                 $passed[$t;
  524.             }
  525.             if ($result == 'SKIPPED'{
  526.                 $skipped[$t;
  527.             }
  528.         }
  529.         $total date('i:s'time($start);
  530.         if (count($failed)) {
  531.             $output = "TOTAL TIME: $total\n";
  532.             $output .= count($passed" PASSED TESTS\n";
  533.             $output .= count($skipped" SKIPPED TESTS\n";
  534.             $output .= count($failed" FAILED TESTS:\n";
  535.             foreach ($failed as $failure{
  536.                 $output .= $failure "\n";
  537.             }
  538.             if (isset($options['realtimelog'])) {
  539.                 $fp @fopen('run-tests.log''a');
  540.             else {
  541.                 $fp @fopen('run-tests.log''w');
  542.             }
  543.             if ($fp{
  544.                 fwrite($fp$outputstrlen($output));
  545.                 fclose($fp);
  546.                 $this->ui->outputData('wrote log to "' realpath('run-tests.log''"'$command);
  547.             }
  548.         elseif (@file_exists('run-tests.log'&& !@is_dir('run-tests.log')) {
  549.             @unlink('run-tests.log');
  550.         }
  551.         $this->ui->outputData('TOTAL TIME: ' $total);
  552.         $this->ui->outputData(count($passed' PASSED TESTS'$command);
  553.         $this->ui->outputData(count($skipped' SKIPPED TESTS'$command);
  554.         if (count($failed)) {
  555.             $this->ui->outputData(count($failed' FAILED TESTS:'$command);
  556.             foreach ($failed as $failure{
  557.                 $this->ui->outputData($failure$command);
  558.             }
  559.         }
  560.  
  561.         return true;
  562.     }
  563.  
  564.     // }}}
  565.     // {{{ doPackageDependencies()
  566.  
  567.     function doPackageDependencies($command$options$params)
  568.     {
  569.         // $params[0] -> the PEAR package to list its information
  570.         if (sizeof($params!= 1{
  571.             return $this->raiseError("bad parameter(s), try \"help $command\"");
  572.         }
  573.  
  574.         $obj = new PEAR_Common();
  575.         if (PEAR::isError($info $obj->infoFromAny($params[0]))) {
  576.             return $this->raiseError($info);
  577.         }
  578.  
  579.         if (is_array($info['release_deps'])) {
  580.             $data = array(
  581.                 'caption' => 'Dependencies for ' $info['package'],
  582.                 'border' => true,
  583.                 'headline' => array("Type""Name""Relation""Version"),
  584.                 );
  585.  
  586.             foreach ($info['release_deps'as $d{
  587.  
  588.                 if (isset($this->_deps_rel_trans[$d['rel']])) {
  589.                     $rel $this->_deps_rel_trans[$d['rel']];
  590.                 else {
  591.                     $rel $d['rel'];
  592.                 }
  593.  
  594.                 if (isset($this->_deps_type_trans[$d['type']])) {
  595.                     $type ucfirst($this->_deps_type_trans[$d['type']]);
  596.                 else {
  597.                     $type $d['type'];
  598.                 }
  599.  
  600.                 if (isset($d['name'])) {
  601.                     $name $d['name'];
  602.                 else {
  603.                     $name '';
  604.                 }
  605.  
  606.                 if (isset($d['version'])) {
  607.                     $version $d['version'];
  608.                 else {
  609.                     $version '';
  610.                 }
  611.  
  612.                 $data['data'][= array($type$name$rel$version);
  613.             }
  614.  
  615.             $this->ui->outputData($data$command);
  616.             return true;
  617.         }
  618.  
  619.         // Fallback
  620.         $this->ui->outputData("This package does not have any dependencies."$command);
  621.     }
  622.  
  623.     // }}}
  624.     // {{{ doSign()
  625.  
  626.     function doSign($command$options$params)
  627.     {
  628.         // should move most of this code into PEAR_Packager
  629.         // so it'll be easy to implement "pear package --sign"
  630.         if (sizeof($params!= 1{
  631.             return $this->raiseError("bad parameter(s), try \"help $command\"");
  632.         }
  633.         if (!file_exists($params[0])) {
  634.             return $this->raiseError("file does not exist: $params[0]");
  635.         }
  636.         $obj = new PEAR_Common;
  637.         $info $obj->infoFromTgzFile($params[0]);
  638.         if (PEAR::isError($info)) {
  639.             return $this->raiseError($info);
  640.         }
  641.         include_once "Archive/Tar.php";
  642.         include_once "System.php";
  643.         $tar = new Archive_Tar($params[0]);
  644.         $tmpdir System::mktemp('-d pearsign');
  645.         if (!$tar->extractList('package.xml package.sig'$tmpdir)) {
  646.             return $this->raiseError("failed to extract tar file");
  647.         }
  648.         if (file_exists("$tmpdir/package.sig")) {
  649.             return $this->raiseError("package already signed");
  650.         }
  651.         @unlink("$tmpdir/package.sig");
  652.         $input $this->ui->userDialog($command,
  653.                                        array('GnuPG Passphrase'),
  654.                                        array('password'));
  655.         $gpg popen("gpg --batch --passphrase-fd 0 --armor --detach-sign --output $tmpdir/package.sig $tmpdir/package.xml 2>/dev/null""w");
  656.         if (!$gpg{
  657.             return $this->raiseError("gpg command failed");
  658.         }
  659.         fwrite($gpg"$input[0]\r");
  660.         if (pclose($gpg|| !file_exists("$tmpdir/package.sig")) {
  661.             return $this->raiseError("gpg sign failed");
  662.         }
  663.         $tar->addModify("$tmpdir/package.sig"''$tmpdir);
  664.         return true;
  665.     }
  666.  
  667.     // }}}
  668.     // {{{ doMakeRPM()
  669.  
  670.     /*
  671.  
  672.     (cox)
  673.  
  674.     TODO:
  675.  
  676.         - Fill the rpm dependencies in the template file.
  677.  
  678.     IDEAS:
  679.  
  680.         - Instead of mapping the role to rpm vars, perhaps it's better
  681.  
  682.           to use directly the pear cmd to install the files by itself
  683.  
  684.           in %postrun so:
  685.  
  686.           pear -d php_dir=%{_libdir}/php/pear -d test_dir=.. <package>
  687.  
  688.     */
  689.  
  690.     function doMakeRPM($command$options$params)
  691.     {
  692.         if (sizeof($params!= 1{
  693.             return $this->raiseError("bad parameter(s), try \"help $command\"");
  694.         }
  695.         if (!file_exists($params[0])) {
  696.             return $this->raiseError("file does not exist: $params[0]");
  697.         }
  698.         include_once "Archive/Tar.php";
  699.         include_once "PEAR/Installer.php";
  700.         include_once "System.php";
  701.         $tar = new Archive_Tar($params[0]);
  702.         $tmpdir System::mktemp('-d pear2rpm');
  703.         $instroot System::mktemp('-d pear2rpm');
  704.         $tmp $this->config->get('verbose');
  705.         $this->config->set('verbose'0);
  706.         $installer = new PEAR_Installer($this->ui);
  707.         $info $installer->install($params[0],
  708.                                     array('installroot' => $instroot,
  709.                                           'nodeps' => true));
  710.         $pkgdir = "$info[package]-$info[version]";
  711.         $info['rpm_xml_dir''/var/lib/pear';
  712.         $this->config->set('verbose'$tmp);
  713.         if (!$tar->extractList("package.xml"$tmpdir$pkgdir)) {
  714.             return $this->raiseError("failed to extract $params[0]");
  715.         }
  716.         if (!file_exists("$tmpdir/package.xml")) {
  717.             return $this->raiseError("no package.xml found in $params[0]");
  718.         }
  719.         if (isset($options['spec-template'])) {
  720.             $spec_template $options['spec-template'];
  721.         else {
  722.             $spec_template $this->config->get('data_dir'.
  723.                 '/PEAR/template.spec';
  724.         }
  725.         if (isset($options['rpm-pkgname'])) {
  726.             $rpm_pkgname_format $options['rpm-pkgname'];
  727.         else {
  728.             $rpm_pkgname_format "PEAR::%s";
  729.         }
  730.  
  731.         $info['extra_headers''';
  732.         $info['doc_files''';
  733.         $info['files''';
  734.         $info['rpm_package'sprintf($rpm_pkgname_format$info['package']);
  735.         $srcfiles = 0;
  736.         foreach ($info['filelist'as $name => $attr{
  737.  
  738.             if (!isset($attr['role'])) {
  739.                 continue;
  740.             }
  741.             $name preg_replace('![/:\\\\]!''/'$name);
  742.             if ($attr['role'== 'doc'{
  743.                 $info['doc_files'.= " $name";
  744.  
  745.             // Map role to the rpm vars
  746.             else {
  747.  
  748.                 $c_prefix '%{_libdir}/php/pear';
  749.  
  750.                 switch ($attr['role']{
  751.  
  752.                     case 'php':
  753.  
  754.                         $prefix $c_prefix; break;
  755.  
  756.                     case 'ext':
  757.  
  758.                         $prefix '%{_libdir}/php'; break; // XXX good place?
  759.  
  760.                     case 'src':
  761.  
  762.                         $srcfiles++;
  763.  
  764.                         $prefix '%{_includedir}/php'; break; // XXX good place?
  765.  
  766.                     case 'test':
  767.  
  768.                         $prefix = "$c_prefix/tests/" . $info['package']; break;
  769.  
  770.                     case 'data':
  771.  
  772.                         $prefix = "$c_prefix/data/" . $info['package']; break;
  773.  
  774.                     case 'script':
  775.  
  776.                         $prefix '%{_bindir}'; break;
  777.  
  778.                 }
  779.  
  780.                 $name str_replace('\\''/'$name);
  781.                 $info['files'.= "$prefix/$name\n";
  782.  
  783.             }
  784.         }
  785.         if ($srcfiles > 0{
  786.             include_once "OS/Guess.php";
  787.             $os = new OS_Guess;
  788.             $arch $os->getCpu();
  789.         else {
  790.             $arch 'noarch';
  791.         }
  792.         $cfg = array('master_server''php_dir''ext_dir''doc_dir',
  793.                      'bin_dir''data_dir''test_dir');
  794.         foreach ($cfg as $k{
  795.             $info[$k$this->config->get($k);
  796.         }
  797.         $info['arch'$arch;
  798.         $fp @fopen($spec_template"r");
  799.         if (!$fp{
  800.             return $this->raiseError("could not open RPM spec file template $spec_template$php_errormsg");
  801.         }
  802.         $spec_contents preg_replace('/@([a-z0-9_-]+)@/e''$info["\1"]'fread($fpfilesize($spec_template)));
  803.         fclose($fp);
  804.         $spec_file = "$info[rpm_package]-$info[version].spec";
  805.         $wp fopen($spec_file"wb");
  806.         if (!$wp{
  807.             return $this->raiseError("could not write RPM spec file $spec_file$php_errormsg");
  808.         }
  809.         fwrite($wp$spec_contents);
  810.         fclose($wp);
  811.         $this->ui->outputData("Wrote RPM spec file $spec_file"$command);
  812.  
  813.         return true;
  814.     }
  815.  
  816.     // }}}
  817. }
  818.  
  819. ?>

Documentation generated on Mon, 11 Mar 2019 14:23:58 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.