Source for file Package.php
Documentation is available at Package.php
// +----------------------------------------------------------------------+
// +----------------------------------------------------------------------+
// | Copyright (c) 1997-2004 The PHP Group |
// +----------------------------------------------------------------------+
// | This source file is subject to version 3.0 of the PHP license, |
// | that is bundled with this package in the file LICENSE, and is |
// | available through the world-wide-web at the following url: |
// | http://www.php.net/license/3_0.txt. |
// | If you did not receive a copy of the PHP license and are unable to |
// | obtain it through the world-wide-web, please send a note to |
// | license@php.net so we can mail you a copy immediately. |
// +----------------------------------------------------------------------+
// | Authors: Stig Bakken <ssb@php.net> |
// | Martin Jansen <mj@php.net> |
// | Greg Beaver <cellog@php.net> |
// +----------------------------------------------------------------------+
// $Id: Package.php,v 1.61.2.7 2005/02/17 17:47:55 cellog Exp $
require_once 'PEAR/Common.php';
require_once 'PEAR/Command/Common.php';
class PEAR_Command_Package extends PEAR_Command_Common
'summary' => 'Build Package',
'function' => 'doPackage',
'doc' => 'Do not gzip the package file'
'doc' => 'Print the name of the packaged file.',
Creates a PEAR package from its description file (usually called
'package-validate' => array (
'summary' => 'Validate Package Consistency',
'function' => 'doPackageValidate',
'summary' => 'Run a "cvs diff" for all files in a package',
'function' => 'doCvsDiff',
'doc' => 'Be really quiet',
'doc' => 'Diff against revision of DATE',
'doc' => 'Diff against tag for package release REL',
'doc' => 'Diff against revision REV',
'doc' => 'Generate context diff',
'doc' => 'Generate unified diff',
'doc' => 'Ignore case, consider upper- and lower-case letters equivalent',
'ignore-whitespace' => array (
'doc' => 'Ignore changes in amount of white space',
'ignore-blank-lines' => array (
'doc' => 'Ignore changes that insert or delete blank lines',
'doc' => 'Report only whether the files differ, no details',
'doc' => 'Don\'t do anything, just pretend',
Compares all the files in a package. Without any options, this
command will compare the current code with the last checked-in code.
Using the -r or -R option you may compare the current code with that
'summary' => 'Set CVS Release Tag',
'function' => 'doCvsTag',
'doc' => 'Be really quiet',
'doc' => 'Move (slide) tag if it exists',
'doc' => 'Don\'t do anything, just pretend',
Sets a CVS tag on all files in a package. Use this command after you have
packaged a distribution tarball with the "package" command to tag what
revisions of what files were in that release. If need to fix something
after running cvstag once, but before the tarball is released to the public,
use the "slide" option to move the release tag.
'summary' => 'Run Regression Tests',
'function' => 'doRunTests',
'doc' => 'Run tests in child directories, recursively. 4 dirs deep maximum',
'doc' => 'actual string of settings to pass to php in format " -d setting=blah"',
'doc' => 'Log test runs/results as they are run',
'doc' => '[testfile|dir ...]
Run regression tests with PHP\'s regression testing script (run-tests.php).',
'package-dependencies' => array (
'summary' => 'Show package dependencies',
'function' => 'doPackageDependencies',
List all depencies the package has.'
'summary' => 'Sign a package distribution file',
Signs a package distribution (.tar or .tgz) file with GnuPG.',
'summary' => 'Builds an RPM spec file from a PEAR package',
'function' => 'doMakeRPM',
'spec-template' => array (
'doc' => 'Use FILE as RPM spec file template'
'doc' => 'Use FORMAT as format string for RPM package name, %s is replaced
by the PEAR package name, defaults to "PEAR::%s".',
Creates an RPM .spec file for wrapping a PEAR package inside an RPM
package. Intended to be used from the SPECS directory, with the PEAR
package tarball in the SOURCES directory:
$ pear makerpm ../SOURCES/Net_Socket-1.0.tgz
Wrote RPM spec file PEAR::Net_Geo-1.0.spec
$ rpm -bb PEAR::Net_Socket-1.0.spec
Wrote: /usr/src/redhat/RPMS/i386/PEAR::Net_Socket-1.0-1.i386.rpm
* PEAR_Command_Package constructor.
function PEAR_Command_Package (&$ui, &$config)
parent ::PEAR_Command_Common ($ui, $config);
// {{{ _displayValidationResults()
function _displayValidationResults ($err, $warn, $strict = false )
$this->output .= " Error: $e\n";
$this->output .= " Warning: $w\n";
$this->output .= sprintf('Validation: %d error(s), %d warning(s)'. "\n",
if ($strict && sizeof($err) > 0 ) {
$this->output .= "Fix these errors and try again.";
function doPackage ($command, $options, $params)
include_once 'PEAR/Packager.php';
$params[0 ] = "package.xml";
$pkginfofile = isset ($params[0 ]) ? $params[0 ] : 'package.xml';
$packager = & new PEAR_Packager ();
$compress = empty ($options['nocompress']) ? true : false;
$result = $packager->package ($pkginfofile, $compress);
if (PEAR ::isError ($result)) {
$this->ui->outputData ($this->output, $command);
return $this->raiseError ($result);
// Don't want output, only the package file name just created
if (isset ($options['showname'])) {
if (PEAR ::isError ($result)) {
$this->output .= "Package failed: ". $result->getMessage ();
$this->ui->outputData ($this->output, $command);
// {{{ doPackageValidate()
function doPackageValidate ($command, $options, $params)
$params[0 ] = "package.xml";
if ($fp = @fopen($params[0 ], "r")) {
$info = $obj->infoFromDescriptionFile ($params[0 ]);
$info = $obj->infoFromTgzFile ($params[0 ]);
if (PEAR ::isError ($info)) {
return $this->raiseError ($info);
$obj->validatePackageInfo ($info, $err, $warn);
$this->_displayValidationResults ($err, $warn);
$this->ui->outputData ($this->output, $command);
function doCvsTag ($command, $options, $params)
$help = $this->getHelp ($command);
return $this->raiseError (" $command: missing parameter: $help[0]" );
$info = $obj->infoFromDescriptionFile ($params[0 ]);
if (PEAR ::isError ($info)) {
return $this->raiseError ($info);
$obj->validatePackageInfo ($info, $err, $warn);
if (!$this->_displayValidationResults ($err, $warn, true )) {
$this->ui->outputData ($this->output, $command);
$version = $info['version'];
$cvstag = " RELEASE_$cvsversion";
if (isset ($options['quiet'])) {
if (isset ($options['reallyquiet'])) {
if (isset ($options['slide'])) {
if (isset ($options['delete'])) {
foreach ($files as $file) {
if ($this->config->get ('verbose') > 1 ) {
$this->output .= " + $command\n";
$this->output .= " + $command\n";
if (empty ($options['dry-run'])) {
$fp = popen($command, "r");
while ($line = fgets($fp, 1024 )) {
$this->output .= rtrim($line). "\n";
$this->ui->outputData ($this->output, $_cmd);
function doCvsDiff ($command, $options, $params)
$help = $this->getHelp ($command);
return $this->raiseError (" $command: missing parameter: $help[0]" );
$info = $obj->infoFromDescriptionFile ($params[0 ]);
if (PEAR ::isError ($info)) {
return $this->raiseError ($info);
if (isset ($options['quiet'])) {
unset ($options['quiet']);
if (isset ($options['reallyquiet'])) {
unset ($options['reallyquiet']);
if (isset ($options['release'])) {
$cvsversion = preg_replace('/[^a-z0-9]/i', '_', $options['release']);
$cvstag = " RELEASE_$cvsversion";
$options['revision'] = $cvstag;
unset ($options['release']);
if (isset ($options['dry-run'])) {
unset ($options['dry-run']);
// the rest of the options are passed right on to "cvs diff"
foreach ($options as $option => $optarg) {
$arg = @$this->commands[$command]['options'][$option]['arg'];
$short = @$this->commands[$command]['options'][$option]['shortopt'];
$cmd .= $short ? " -$short" : " --$option";
foreach ($files as $file) {
if ($this->config->get ('verbose') > 1 ) {
$this->output .= " + $cmd\n";
while ($line = fgets($fp, 1024 )) {
$this->output .= rtrim($line). "\n";
$this->ui->outputData ($this->output, $command);
function doRunTests ($command, $options, $params)
include_once 'PEAR/RunTest.php';
$log->ui = &$this->ui; // slightly hacky, but it will work
$run = new PEAR_RunTest ($log);
if (isset ($options['recur'])) {
foreach ($params as $p) {
if (isset ($options['ini'])) {
$ini_settings .= $options['ini'];
if (isset ($_ENV['TEST_PHP_INCLUDE_PATH'])) {
$ini_settings .= " -d include_path={$_ENV['TEST_PHP_INCLUDE_PATH']}";
$this->ui->outputData ('Using INI settings: "' . $ini_settings . '"');
$skipped = $passed = $failed = array ();
$this->ui->outputData ('Running ' . count($tests) . ' tests', $command);
if (isset ($options['realtimelog'])) {
if (isset ($options['realtimelog'])) {
$fp = @fopen('run-tests.log', 'a');
fwrite($fp, " Running test $t..." );
$result = $run->run ($t, $ini_settings);
$i = $i; // delay - race conditions on windows
if (isset ($options['realtimelog'])) {
$fp = @fopen('run-tests.log', 'a');
if ($result == 'FAILED') {
if ($result == 'PASSED') {
if ($result == 'SKIPPED') {
$output = " TOTAL TIME: $total\n";
$output .= count($passed) . " PASSED TESTS\n";
$output .= count($skipped) . " SKIPPED TESTS\n";
$output .= count($failed) . " FAILED TESTS:\n";
foreach ($failed as $failure) {
$output .= $failure . "\n";
if (isset ($options['realtimelog'])) {
$fp = @fopen('run-tests.log', 'a');
$fp = @fopen('run-tests.log', 'w');
$this->ui->outputData ('wrote log to "' . realpath('run-tests.log') . '"', $command);
$this->ui->outputData ('TOTAL TIME: ' . $total);
$this->ui->outputData (count($passed) . ' PASSED TESTS', $command);
$this->ui->outputData (count($skipped) . ' SKIPPED TESTS', $command);
$this->ui->outputData (count($failed) . ' FAILED TESTS:', $command);
foreach ($failed as $failure) {
$this->ui->outputData ($failure, $command);
// {{{ doPackageDependencies()
function doPackageDependencies ($command, $options, $params)
// $params[0] -> the PEAR package to list its information
return $this->raiseError (" bad parameter(s), try \"help $command\"" );
$obj = new PEAR_Common ();
if (PEAR ::isError ($info = $obj->infoFromAny ($params[0 ]))) {
return $this->raiseError ($info);
'caption' => 'Dependencies for ' . $info['package'],
'headline' => array ("Type", "Name", "Relation", "Version"),
foreach ($info['release_deps'] as $d) {
if (isset ($this->_deps_rel_trans[$d['rel']])) {
$rel = $this->_deps_rel_trans[$d['rel']];
if (isset ($this->_deps_type_trans[$d['type']])) {
$type = ucfirst($this->_deps_type_trans[$d['type']]);
if (isset ($d['version'])) {
$version = $d['version'];
$data['data'][] = array ($type, $name, $rel, $version);
$this->ui->outputData ($data, $command);
$this->ui->outputData ("This package does not have any dependencies.", $command);
function doSign ($command, $options, $params)
// should move most of this code into PEAR_Packager
// so it'll be easy to implement "pear package --sign"
return $this->raiseError (" bad parameter(s), try \"help $command\"" );
return $this->raiseError (" file does not exist: $params[0]" );
$info = $obj->infoFromTgzFile ($params[0 ]);
if (PEAR ::isError ($info)) {
return $this->raiseError ($info);
include_once "Archive/Tar.php";
include_once "System.php";
$tar = new Archive_Tar ($params[0 ]);
if (!$tar->extractList ('package.xml package.sig', $tmpdir)) {
return $this->raiseError ("failed to extract tar file");
return $this->raiseError ("package already signed");
@unlink(" $tmpdir/package.sig" );
$input = $this->ui->userDialog ($command,
array ('GnuPG Passphrase'),
$gpg = popen(" gpg --batch --passphrase-fd 0 --armor --detach-sign --output $tmpdir/package.sig $tmpdir/package.xml 2>/dev/null" , "w");
return $this->raiseError ("gpg command failed");
return $this->raiseError ("gpg sign failed");
$tar->addModify (" $tmpdir/package.sig" , '', $tmpdir);
- Fill the rpm dependencies in the template file.
- Instead of mapping the role to rpm vars, perhaps it's better
to use directly the pear cmd to install the files by itself
pear -d php_dir=%{_libdir}/php/pear -d test_dir=.. <package>
function doMakeRPM ($command, $options, $params)
return $this->raiseError (" bad parameter(s), try \"help $command\"" );
return $this->raiseError (" file does not exist: $params[0]" );
include_once "Archive/Tar.php";
include_once "PEAR/Installer.php";
include_once "System.php";
$tar = new Archive_Tar ($params[0 ]);
$tmp = $this->config->get ('verbose');
$this->config->set ('verbose', 0 );
$installer = new PEAR_Installer ($this->ui);
$info = $installer->install ($params[0 ],
array ('installroot' => $instroot,
$pkgdir = " $info[package]-$info[version]";
$info['rpm_xml_dir'] = '/var/lib/pear';
$this->config->set ('verbose', $tmp);
if (!$tar->extractList ("package.xml", $tmpdir, $pkgdir)) {
return $this->raiseError (" failed to extract $params[0]" );
return $this->raiseError (" no package.xml found in $params[0]" );
if (isset ($options['spec-template'])) {
$spec_template = $options['spec-template'];
$spec_template = $this->config->get ('data_dir') .
if (isset ($options['rpm-pkgname'])) {
$rpm_pkgname_format = $options['rpm-pkgname'];
$rpm_pkgname_format = "PEAR::%s";
$info['extra_headers'] = '';
$info['rpm_package'] = sprintf($rpm_pkgname_format, $info['package']);
foreach ($info['filelist'] as $name => $attr) {
if (!isset ($attr['role'])) {
if ($attr['role'] == 'doc') {
$info['doc_files'] .= " $name";
// Map role to the rpm vars
$c_prefix = '%{_libdir}/php/pear';
$prefix = $c_prefix; break;
$prefix = '%{_libdir}/php'; break; // XXX good place?
$prefix = '%{_includedir}/php'; break; // XXX good place?
$prefix = " $c_prefix/tests/" . $info['package']; break;
$prefix = " $c_prefix/data/" . $info['package']; break;
$prefix = '%{_bindir}'; break;
$info['files'] .= " $prefix/$name\n";
include_once "OS/Guess.php";
$cfg = array ('master_server', 'php_dir', 'ext_dir', 'doc_dir',
'bin_dir', 'data_dir', 'test_dir');
$info[$k] = $this->config->get ($k);
$fp = @fopen($spec_template, "r");
return $this->raiseError (" could not open RPM spec file template $spec_template: $php_errormsg" );
$spec_file = " $info[rpm_package]-$info[version].spec";
$wp = fopen($spec_file, "wb");
return $this->raiseError (" could not write RPM spec file $spec_file: $php_errormsg" );
$this->ui->outputData (" Wrote RPM spec file $spec_file" , $command);
Documentation generated on Mon, 11 Mar 2019 14:23:58 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.
|