Create a PEAR_PackageFile_v* from a package.xml file.
public fromPackageFile ( string $descfile, integer $state, string | false $archive = false ) : PEAR_PackageFile_v1 | PEAR_PackageFile_v2 | ||
$descfile | string | name of package xml file |
$state | integer | package state (one of PEAR_VALIDATE_* constants) |
$archive | string | false | name of the archive this package.xml came from, if any |
Résultat | PEAR_PackageFile_v1 | PEAR_PackageFile_v2 |
/** * Constructor. * * Searches all installed applications and libraries for migration * directories and builds lists of migrateable modules and directories. * * @param string $basedir Base directory of a Git checkout. If provided * a framework/ sub directory is searched for * migration scripts too. * @param string $pearconf Path to a PEAR configuration file. */ public function __construct($basedir = null, $pearconf = null) { // Loop through all applications. foreach ($GLOBALS['registry']->listAllApps() as $app) { $dir = $GLOBALS['registry']->get('fileroot', $app) . '/migration'; if (is_dir($dir)) { $this->apps[] = $app; $this->_lower[] = Horde_String::lower($app); $this->dirs[] = realpath($dir); } } // Silence PEAR errors. $old_error_reporting = error_reporting(); error_reporting($old_error_reporting & ~E_DEPRECATED); $pear = new PEAR_Config($pearconf); // Loop through local framework checkout. if ($basedir) { $packageFile = new PEAR_PackageFile($pear); foreach (glob($basedir . '/framework/*/migration') as $dir) { $package = $packageFile->fromPackageFile(dirname($dir) . '/package.xml', PEAR_VALIDATE_NORMAL); if ($package instanceof PEAR_Error) { Horde::log(sprintf('%s: %s', $package->getMessage(), print_r($package->getUserInfo(), true)), Horde_Log::ERR); continue; } $this->apps[] = $package->getName(); $this->_lower[] = Horde_String::lower($package->getName()); $this->dirs[] = realpath($dir); } } // Loop through installed PEAR packages. $registry = $pear->getRegistry(); foreach (glob($pear->get('data_dir') . '/*/migration') as $dir) { $package = $registry->getPackage(basename(dirname($dir)), 'pear.horde.org'); if ($package == false) { Horde::log("Ignoring package in directory {$dir}", Horde_Log::WARN); continue; } $app = $package->getName(); if (!in_array($app, $this->apps)) { $this->apps[] = $app; $this->_lower[] = Horde_String::lower($app); $this->dirs[] = realpath($dir); } } error_reporting($old_error_reporting); }
/** * Returns information about a package file. Expects the name of * a package xml file as input. * * @param string $descfile name of package xml file * * @return array array with package information * * @access public * @deprecated use PEAR_PackageFile->fromPackageFile() instead * */ function infoFromDescriptionFile($descfile) { $packagefile = new PEAR_PackageFile($this->config); $pf =& $packagefile->fromPackageFile($descfile, PEAR_VALIDATE_NORMAL); if (PEAR::isError($pf)) { $errs = $pf->getUserinfo(); if (is_array($errs)) { foreach ($errs as $error) { $e = $this->raiseError($error['message'], $error['code'], null, null, $error); } } return $pf; } return $this->_postProcessValidPackagexml($pf); }
function package($pkgfile = null, $compress = true, $pkg2 = null) { // {{{ validate supplied package.xml file if (empty($pkgfile)) { $pkgfile = 'package.xml'; } PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN); $pkg = new PEAR_PackageFile($this->config, $this->debug); $pf =& $pkg->fromPackageFile($pkgfile, PEAR_VALIDATE_NORMAL); $main =& $pf; PEAR::staticPopErrorHandling(); if (PEAR::isError($pf)) { if (is_array($pf->getUserInfo())) { foreach ($pf->getUserInfo() as $error) { $this->log(0, 'Error: ' . $error['message']); } } $this->log(0, $pf->getMessage()); return $this->raiseError("Cannot package, errors in package file"); } foreach ($pf->getValidationWarnings() as $warning) { $this->log(1, 'Warning: ' . $warning['message']); } // }}} if ($pkg2) { $this->log(0, 'Attempting to process the second package file'); PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN); $pf2 =& $pkg->fromPackageFile($pkg2, PEAR_VALIDATE_NORMAL); PEAR::staticPopErrorHandling(); if (PEAR::isError($pf2)) { if (is_array($pf2->getUserInfo())) { foreach ($pf2->getUserInfo() as $error) { $this->log(0, 'Error: ' . $error['message']); } } $this->log(0, $pf2->getMessage()); return $this->raiseError("Cannot package, errors in second package file"); } foreach ($pf2->getValidationWarnings() as $warning) { $this->log(1, 'Warning: ' . $warning['message']); } if ($pf2->getPackagexmlVersion() == '2.0' || $pf2->getPackagexmlVersion() == '2.1') { $main =& $pf2; $other =& $pf; } else { $main =& $pf; $other =& $pf2; } if ($main->getPackagexmlVersion() != '2.0' && $main->getPackagexmlVersion() != '2.1') { return PEAR::raiseError('Error: cannot package two package.xml version 1.0, can ' . 'only package together a package.xml 1.0 and package.xml 2.0'); } if ($other->getPackagexmlVersion() != '1.0') { return PEAR::raiseError('Error: cannot package two package.xml version 2.0, can ' . 'only package together a package.xml 1.0 and package.xml 2.0'); } } $main->setLogger($this); if (!$main->validate(PEAR_VALIDATE_PACKAGING)) { foreach ($main->getValidationWarnings() as $warning) { $this->log(0, 'Error: ' . $warning['message']); } return $this->raiseError("Cannot package, errors in package"); } foreach ($main->getValidationWarnings() as $warning) { $this->log(1, 'Warning: ' . $warning['message']); } if ($pkg2) { $other->setLogger($this); $a = false; if (!$other->validate(PEAR_VALIDATE_NORMAL) || ($a = !$main->isEquivalent($other))) { foreach ($other->getValidationWarnings() as $warning) { $this->log(0, 'Error: ' . $warning['message']); } foreach ($main->getValidationWarnings() as $warning) { $this->log(0, 'Error: ' . $warning['message']); } if ($a) { return $this->raiseError('The two package.xml files are not equivalent!'); } return $this->raiseError("Cannot package, errors in package"); } foreach ($other->getValidationWarnings() as $warning) { $this->log(1, 'Warning: ' . $warning['message']); } $gen =& $main->getDefaultGenerator(); $tgzfile = $gen->toTgz2($this, $other, $compress); if (PEAR::isError($tgzfile)) { return $tgzfile; } $dest_package = basename($tgzfile); $pkgdir = dirname($pkgfile); // TAR the Package ------------------------------------------- $this->log(1, "Package {$dest_package} done"); if (file_exists("{$pkgdir}/CVS/Root")) { $cvsversion = preg_replace('/[^a-z0-9]/i', '_', $pf->getVersion()); $cvstag = "RELEASE_{$cvsversion}"; $this->log(1, 'Tag the released code with "pear cvstag ' . $main->getPackageFile() . '"'); $this->log(1, "(or set the CVS tag {$cvstag} by hand)"); } elseif (file_exists("{$pkgdir}/.svn")) { $svnversion = preg_replace('/[^a-z0-9]/i', '.', $pf->getVersion()); $svntag = $pf->getName() . "-{$svnversion}"; $this->log(1, 'Tag the released code with "pear svntag ' . $main->getPackageFile() . '"'); $this->log(1, "(or set the SVN tag {$svntag} by hand)"); } } else { // this branch is executed for single packagefile packaging $gen =& $pf->getDefaultGenerator(); $tgzfile = $gen->toTgz($this, $compress); if (PEAR::isError($tgzfile)) { $this->log(0, $tgzfile->getMessage()); return $this->raiseError("Cannot package, errors in package"); } $dest_package = basename($tgzfile); $pkgdir = dirname($pkgfile); // TAR the Package ------------------------------------------- $this->log(1, "Package {$dest_package} done"); if (file_exists("{$pkgdir}/CVS/Root")) { $cvsversion = preg_replace('/[^a-z0-9]/i', '_', $pf->getVersion()); $cvstag = "RELEASE_{$cvsversion}"; $this->log(1, "Tag the released code with `pear cvstag {$pkgfile}'"); $this->log(1, "(or set the CVS tag {$cvstag} by hand)"); } elseif (file_exists("{$pkgdir}/.svn")) { $svnversion = preg_replace('/[^a-z0-9]/i', '.', $pf->getVersion()); $svntag = $pf->getName() . "-{$svnversion}"; $this->log(1, "Tag the released code with `pear svntag {$pkgfile}'"); $this->log(1, "(or set the SVN tag {$svntag} by hand)"); } } return $dest_package; }
/** * Returns package information from different sources * * This method is able to extract information about a package * from a .tgz archive or from a XML package definition file. * * @access public * @return string * @static */ function &fromAnyFile($info, $state) { $fp = false; if (is_string($info) && strlen($info) < 255 && (file_exists($info) || ($fp = @fopen($info, 'r')))) { if ($fp) { fclose($fp); } $tmp = substr($info, -4); if ($tmp == '.xml') { $info =& PEAR_PackageFile::fromPackageFile($info, $state); } elseif ($tmp == '.tar' || $tmp == '.tgz') { $info =& PEAR_PackageFile::fromTgzFile($info, $state); } else { $fp = fopen($info, "r"); $test = fread($fp, 5); fclose($fp); if ($test == "<?xml") { $info =& PEAR_PackageFile::fromPackageFile($info, $state); } else { $info =& PEAR_PackageFile::fromTgzFile($info, $state); } } } else { return PEAR::raiseError("Cannot open '{$info}' for parsing"); } return $info; }
/** * Convert a package xml 1.0 to 2.0 with user and default options * * @param string $packagefile name of package file * @param array $options (optional) list of generation options * * @return PEAR_PackageFileManager2|PEAR_Error * @static * @access public * @since 1.6.0a1 */ function &importFromPackageFile1($packagefile, $options = array()) { $z =& PEAR_Config::singleton(); $pkg = new PEAR_PackageFile($z); $pf = $pkg->fromPackageFile($packagefile, PEAR_VALIDATE_NORMAL); if (PEAR::isError($pf)) { return $pf; } if ($pf->getPackagexmlVersion() == '1.0') { $packagefile =& $pf; } $a =& PEAR_PackageFileManager2::importOptions($packagefile, $options); return $a; }
/** * Return the PEAR Package representation. * * @param string $package_xml_path Path to the package.xml file. * @param Components_Pear_Environment $environment The PEAR environment. * * @return PEAR_PackageFile */ public function getPackageFile($package_xml_path, Components_Pear_Environment $environment) { $config = $environment->getPearConfig(); $pkg = new PEAR_PackageFile($config); return Components_Exception_Pear::catchError($pkg->fromPackageFile($package_xml_path, PEAR_VALIDATE_NORMAL)); }
/** * Returns information about a package file. Expects the name of * a package xml file as input. * * @param string $descfile name of package xml file * * @return array array with package information * * @access public * @deprecated use PEAR_PackageFile->fromPackageFile() instead * */ function infoFromDescriptionFile($descfile) { $packagefile = new PEAR_PackageFile($this->config); $pf =& $packagefile->fromPackageFile($descfile, PEAR_VALIDATE_NORMAL); return $this->_postProcessChecks($pf); }
die('Following packages were not available in tar format in go-pear-tarballs: ' . implode(', ', $required) . "\n"); } if (!file_exists("{$tardir}/tmp")) { mkdir("{$tardir}/tmp"); } // Use the tar files for required Phar files require_once 'Archive/Tar.php'; require_once 'System.php'; foreach ($packages as $package) { $name = substr($package, 0, -4); $tar = new Archive_Tar("{$tardir}/{$package}"); $tar->extractModify("{$tardir}/tmp", $name); } chdir(__DIR__); $pkg = new PEAR_PackageFile($config); $pf = $pkg->fromPackageFile(__DIR__ . DIRECTORY_SEPARATOR . 'package2.xml', PEAR_VALIDATE_NORMAL); if (PEAR::isError($pf)) { foreach ($pf->getUserInfo() as $warn) { echo $warn['message'] . "\n"; } die($pf->getMessage()); } $pearver = $pf->getVersion(); $creator = new PHP_Archive_Creator('index.php', $outputFile); // no compression $creator->useDefaultFrontController('PEAR.php'); $creator->useSHA1Signature(); $install_files = '$install_files = array('; foreach ($packages as $name => $package) { echo "{$name} => {$package}\n"; $install_files .= "'{$name}' => 'phar://" . $outputFile . "/{$package}'," . "\n";
$a = $registry->listAllApps(); /* Check for suspicious missing of migration data. */ if (!in_array('Horde_Core', $migration->apps)) { $notification->push(_("Database migration files not found. Please check PEAR's data_dir configuration setting."), 'horde.error'); } /* Check for versions if requested. */ $versions = array(); if ($vars->check_versions) { $pearConfig = PEAR_Config::singleton(); $packageFile = new PEAR_PackageFile($pearConfig); $packages = array(); foreach ($pearConfig->getRegistry()->packageInfo(null, null, 'pear.horde.org') as $package) { $packages[$package['name']] = $package['version']['release']; } foreach (glob(__DIR__ . '/../../../framework/*/package.xml') as $packagexml) { $package = $packageFile->fromPackageFile($packagexml, PEAR_VALIDATE_NORMAL); if (!$package instanceof PEAR_Error) { $packages[$package->getName()] = $package->getVersion(); } } try { $versions = $hconfig->checkVersions(); } catch (Horde_Exception $e) { $notification->push(_("Could not contact server. Try again later."), 'horde.error'); } } /* Update configurations if requested. */ if ($vars->action == 'config') { foreach ($a as $app) { $path = $registry->get('fileroot', $app) . '/config'; if (!file_exists($path . '/conf.xml') || file_exists($path . '/conf.php') && ($xml_ver = $hconfig->getVersion(@file_get_contents($path . '/conf.xml'))) !== false && ($php_ver = $hconfig->getVersion(@file_get_contents($path . '/conf.php'))) !== false && $xml_ver == $php_ver) {
/** * Loads and returns the PEAR package information. * * @return PEAR_PackageFile_v2 Package information object * * @throws BuildException When the package does not exist */ protected function loadPackageInfo() { $config = PEAR_Config::singleton($this->config); if (empty($this->packageFile)) { // loads informations from PEAR package installed $reg = $config->getRegistry(); if (!$reg->packageExists($this->package, $this->channel)) { throw new BuildException(sprintf('PEAR package %s/%s does not exist', $this->channel, $this->package)); } $packageInfo = $reg->getPackage($this->package, $this->channel); } else { // loads informations from PEAR package XML description file PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN); $pkg = new PEAR_PackageFile($config); $packageInfo = $pkg->fromPackageFile($this->packageFile, PEAR_VALIDATE_NORMAL); PEAR::staticPopErrorHandling(); if (PEAR::isError($packageInfo)) { throw new BuildException("Errors in package file"); } } return $packageInfo; }
#!/usr/bin/env php <?php error_reporting(E_ALL & ~(E_DEPRECATED | E_STRICT)); if ($argc < 2) { fprintf(STDERR, "Usage: %s <path/to/package.xml>\n", $argv[0]); exit(1); } require_once "PEAR/Config.php"; require_once "PEAR/PackageFile.php"; define("PACKAGE_XML", $argv[1]); define("PACKAGE_DIR", dirname(PACKAGE_XML)); $factory = new PEAR_PackageFile(PEAR_Config::singleton()); $pf = $factory->fromPackageFile($argv[1], PEAR_VALIDATE_NORMAL); if (PEAR::isError($pf)) { fprintf(STDERR, "ERROR: %s\n", $pf->getMessage()); exit(1); } foreach ($pf->getValidationWarnings() as $warning) { fprintf(STDERR, "%s: %s\n", strtoupper($warning["level"]), $warning["message"]); } $exit = 0; foreach ($pf->getFilelist() as $file => $attr) { if (!file_exists(PACKAGE_DIR . "/" . $file)) { $exit++; fprintf(STDERR, "File '%s' with role '%s' not found in '%s'\n", $file, $attr["role"], PACKAGE_DIR); } } if ($exit) { fprintf(STDERR, "%3d failure(s)\n", $exit); exit(1); }
/** * Build an extension from source. Runs "phpize" in the source * directory, but compiles in a temporary directory * (TMPDIR/pear-build-USER/PACKAGE-VERSION). * * @param string|PEAR_PackageFile_v* $descfile path to XML package description file, or * a PEAR_PackageFile object * * @param mixed $callback callback function used to report output, * see PEAR_Builder::_runCommand for details * * @return array an array of associative arrays with built files, * format: * array( array( 'file' => '/path/to/ext.so', * 'php_api' => YYYYMMDD, * 'zend_mod_api' => YYYYMMDD, * 'zend_ext_api' => YYYYMMDD ), * ... ) * * @access public * * @see PEAR_Builder::_runCommand */ function build($descfile, $callback = null) { if (preg_match('/(\\/|\\\\|^)([^\\/\\\\]+)?php([^\\/\\\\]+)?$/', $this->config->get('php_bin'), $matches)) { if (isset($matches[2]) && strlen($matches[2]) && trim($matches[2]) != trim($this->config->get('php_prefix'))) { $this->log(0, 'WARNING: php_bin ' . $this->config->get('php_bin') . ' appears to have a prefix ' . $matches[2] . ', but' . ' config variable php_prefix does not match'); } if (isset($matches[3]) && strlen($matches[3]) && trim($matches[3]) != trim($this->config->get('php_suffix'))) { $this->log(0, 'WARNING: php_bin ' . $this->config->get('php_bin') . ' appears to have a suffix ' . $matches[3] . ', but' . ' config variable php_suffix does not match'); } } $this->current_callback = $callback; if (PEAR_OS == "Windows") { return $this->_build_win32($descfile, $callback); } if (PEAR_OS != 'Unix') { return $this->raiseError("building extensions not supported on this platform"); } if (is_object($descfile)) { $pkg = $descfile; $descfile = $pkg->getPackageFile(); if (is_a($pkg, 'PEAR_PackageFile_v1')) { $dir = dirname($descfile); } else { $dir = $pkg->_config->get('temp_dir') . '/' . $pkg->getName(); // automatically delete at session end $this->addTempFile($dir); } } else { $pf = new PEAR_PackageFile($this->config); $pkg =& $pf->fromPackageFile($descfile, PEAR_VALIDATE_NORMAL); if (PEAR::isError($pkg)) { return $pkg; } $dir = dirname($descfile); } // Find config. outside of normal path - e.g. config.m4 foreach (array_keys($pkg->getInstallationFileList()) as $item) { if (stristr(basename($item), 'config.m4') && dirname($item) != '.') { $dir .= DIRECTORY_SEPARATOR . dirname($item); break; } } $old_cwd = getcwd(); if (!file_exists($dir) || !is_dir($dir) || !chdir($dir)) { return $this->raiseError("could not chdir to {$dir}"); } $vdir = $pkg->getPackage() . '-' . $pkg->getVersion(); if (is_dir($vdir)) { chdir($vdir); } $dir = getcwd(); $this->log(2, "building in {$dir}"); putenv('PATH=' . $this->config->get('bin_dir') . ':' . getenv('PATH')); $err = $this->_runCommand($this->config->get('php_prefix') . "phpize" . $this->config->get('php_suffix'), array(&$this, 'phpizeCallback')); if (PEAR::isError($err)) { return $err; } if (!$err) { return $this->raiseError("`phpize' failed"); } // {{{ start of interactive part $configure_command = "{$dir}/configure"; $phpConfigName = $this->config->get('php_prefix') . 'php-config' . $this->config->get('php_suffix'); $phpConfigPath = System::which($phpConfigName); if ($phpConfigPath !== false) { $configure_command .= ' --with-php-config=' . $phpConfigPath; } $configure_options = $pkg->getConfigureOptions(); if ($configure_options) { foreach ($configure_options as $o) { $default = array_key_exists('default', $o) ? $o['default'] : null; list($r) = $this->ui->userDialog('build', array($o['prompt']), array('text'), array($default)); if (substr($o['name'], 0, 5) == 'with-' && ($r == 'yes' || $r == 'autodetect')) { $configure_command .= " --{$o['name']}"; } else { $configure_command .= " --{$o['name']}=" . trim($r); } } } // }}} end of interactive part // FIXME make configurable if (!($user = getenv('USER'))) { $user = '******'; } $tmpdir = $this->config->get('temp_dir'); $build_basedir = System::mktemp(' -t "' . $tmpdir . '" -d "pear-build-' . $user . '"'); $build_dir = "{$build_basedir}/{$vdir}"; $inst_dir = "{$build_basedir}/install-{$vdir}"; $this->log(1, "building in {$build_dir}"); if (is_dir($build_dir)) { System::rm(array('-rf', $build_dir)); } if (!System::mkDir(array('-p', $build_dir))) { return $this->raiseError("could not create build dir: {$build_dir}"); } $this->addTempFile($build_dir); if (!System::mkDir(array('-p', $inst_dir))) { return $this->raiseError("could not create temporary install dir: {$inst_dir}"); } $this->addTempFile($inst_dir); $make_command = getenv('MAKE') ? getenv('MAKE') : 'make'; $to_run = array($configure_command, $make_command, "{$make_command} INSTALL_ROOT=\"{$inst_dir}\" install", "find \"{$inst_dir}\" | xargs ls -dils"); if (!file_exists($build_dir) || !is_dir($build_dir) || !chdir($build_dir)) { return $this->raiseError("could not chdir to {$build_dir}"); } putenv('PHP_PEAR_VERSION=1.10.1'); foreach ($to_run as $cmd) { $err = $this->_runCommand($cmd, $callback); if (PEAR::isError($err)) { chdir($old_cwd); return $err; } if (!$err) { chdir($old_cwd); return $this->raiseError("`{$cmd}' failed"); } } if (!($dp = opendir("modules"))) { chdir($old_cwd); return $this->raiseError("no `modules' directory found"); } $built_files = array(); $prefix = exec($this->config->get('php_prefix') . "php-config" . $this->config->get('php_suffix') . " --prefix"); $this->_harvestInstDir($prefix, $inst_dir . DIRECTORY_SEPARATOR . $prefix, $built_files); chdir($old_cwd); return $built_files; }
$a->addPackageDepWithChannel('required', 'Services_Trackback', 'pear.php.net', '0.4.0'); $a->addPackageDepWithChannel('required', 'HTML_QuickForm', 'pear.php.net', '3.2.3'); $a->addPackageDepWithChannel('required', 'HTML_QuickForm2', 'pear.php.net', '0.5.0'); // This is used in the admin menu for category $a->addPackageDepWithChannel('required', 'HTML_TreeMenu', 'pear.php.net', '1.2.0'); $a->addPackageDepWithChannel('required', 'MDB2_Driver_mysqli', 'pear.php.net'); $a->addExtensionDep('required', 'pcre'); $a->addExtensionDep('required', 'mysqli'); $a->addExtensionDep('required', 'fileinfo'); $a->addPackageDepWithChannel('required', 'Graph', 'components.ez.no'); include_once 'PEAR/Config.php'; include_once 'PEAR/PackageFile.php'; $config = PEAR_Config::singleton(); $p = new PEAR_PackageFile($config); // Specify subpackages $e = $p->fromPackageFile($dir . '/package-channel.xml', PEAR_VALIDATE_NORMAL); $a->specifySubpackage($e, false); $b = $p->fromPackageFile($dir . '/package-election.xml', PEAR_VALIDATE_NORMAL); $a->specifySubpackage($b, false); $f = $p->fromPackageFile($dir . '/package-gopear.xml', PEAR_VALIDATE_NORMAL); $a->specifySubpackage($f, false); $d = $p->fromPackageFile($dir . '/package-index.xml', PEAR_VALIDATE_NORMAL); $a->specifySubpackage($d, false); $h = $p->fromPackageFile($dir . '/package-manual.xml', PEAR_VALIDATE_NORMAL); $a->specifySubpackage($h, false); $c = $p->fromPackageFile($dir . '/package-pepr.xml', PEAR_VALIDATE_NORMAL); $a->specifySubpackage($c, false); $g = $p->fromPackageFile($dir . '/package-qa.xml', PEAR_VALIDATE_NORMAL); $a->specifySubpackage($g, false); $script =& $a->initPostinstallScript('pearweb.php'); $script->addParamGroup('askdb', array($script->getParam('yesno', 'Update pearweb database?', 'yesno', 'y')));
/** * Create a PEAR_PackageFile_v* from a .tgz archive or package.xml file. * * This method is able to extract information about a package from a .tgz * archive or from a XML package definition file. * * @access public * @param string $info file name * @param int $state package state (one of PEAR_VALIDATE_* constants) * @return PEAR_PackageFile_v1|PEAR_PackageFile_v2 * @uses fromPackageFile() if the file appears to be XML * @uses fromTgzFile() to load all non-XML files */ function &fromAnyFile($info, $state) { if (is_dir($info)) { $dir_name = realpath($info); if (file_exists($dir_name . '/package.xml')) { $info = PEAR_PackageFile::fromPackageFile($dir_name . '/package.xml', $state); } elseif (file_exists($dir_name . '/package2.xml')) { $info = PEAR_PackageFile::fromPackageFile($dir_name . '/package2.xml', $state); } else { $info = PEAR::raiseError("No package definition found in '{$info}' directory"); } return $info; } $fp = false; if (is_string($info) && strlen($info) < 255 && (file_exists($info) || ($fp = @fopen($info, 'r')))) { if ($fp) { fclose($fp); } $tmp = substr($info, -4); if ($tmp == '.xml') { $info =& PEAR_PackageFile::fromPackageFile($info, $state); } elseif ($tmp == '.tar' || $tmp == '.tgz') { $info =& PEAR_PackageFile::fromTgzFile($info, $state); } else { $fp = fopen($info, "r"); $test = fread($fp, 5); fclose($fp); if ($test == "<?xml") { $info =& PEAR_PackageFile::fromPackageFile($info, $state); } else { $info =& PEAR_PackageFile::fromTgzFile($info, $state); } } } else { $info = PEAR::raiseError("Cannot open '{$info}' for parsing"); return $info; } return $info; }
/** * Build an extension from source. Runs "phpize" in the source * directory, but compiles in a temporary directory * (/var/tmp/pear-build-USER/PACKAGE-VERSION). * * @param string|PEAR_PackageFile_v* $descfile path to XML package description file, or * a PEAR_PackageFile object * * @param mixed $callback callback function used to report output, * see PEAR_Builder::_runCommand for details * * @return array an array of associative arrays with built files, * format: * array( array( 'file' => '/path/to/ext.so', * 'php_api' => YYYYMMDD, * 'zend_mod_api' => YYYYMMDD, * 'zend_ext_api' => YYYYMMDD ), * ... ) * * @access public * * @see PEAR_Builder::_runCommand */ function build($descfile, $callback = null) { $this->current_callback = $callback; if (PEAR_OS == "Windows") { return $this->_build_win32($descfile, $callback); } if (PEAR_OS != 'Unix') { return $this->raiseError("building extensions not supported on this platform"); } if (is_object($descfile)) { $pkg = $descfile; $descfile = $pkg->getPackageFile(); } else { $pf = new PEAR_PackageFile($this->config); $pkg =& $pf->fromPackageFile($descfile, PEAR_VALIDATE_NORMAL); if (PEAR::isError($pkg)) { return $pkg; } } $dir = dirname($descfile); $old_cwd = getcwd(); if (!file_exists($dir) || !is_dir($dir) || !chdir($dir)) { return $this->raiseError("could not chdir to {$dir}"); } $vdir = $pkg->getPackage() . '-' . $pkg->getVersion(); if (is_dir($vdir)) { chdir($vdir); } $dir = getcwd(); $this->log(2, "building in {$dir}"); putenv('PATH=' . $this->config->get('bin_dir') . ':' . getenv('PATH')); $err = $this->_runCommand("phpize", array(&$this, 'phpizeCallback')); if (PEAR::isError($err)) { return $err; } if (!$err) { return $this->raiseError("`phpize' failed"); } // {{{ start of interactive part $configure_command = "{$dir}/configure"; $configure_options = $pkg->getConfigureOptions(); if ($configure_options) { foreach ($configure_options as $o) { $default = array_key_exists('default', $o) ? $o['default'] : null; list($r) = $this->ui->userDialog('build', array($o['prompt']), array('text'), array($default)); if (substr($o['name'], 0, 5) == 'with-' && ($r == 'yes' || $r == 'autodetect')) { $configure_command .= " --{$o['name']}"; } else { $configure_command .= " --{$o['name']}=" . trim($r); } } } // }}} end of interactive part // FIXME make configurable if (!($user = getenv('USER'))) { $user = '******'; } $build_basedir = "/var/tmp/pear-build-{$user}"; $build_dir = "{$build_basedir}/{$vdir}"; $inst_dir = "{$build_basedir}/install-{$vdir}"; $this->log(1, "building in {$build_dir}"); if (is_dir($build_dir)) { System::rm(array('-rf', $build_dir)); } if (!System::mkDir(array('-p', $build_dir))) { return $this->raiseError("could not create build dir: {$build_dir}"); } $this->addTempFile($build_dir); if (!System::mkDir(array('-p', $inst_dir))) { return $this->raiseError("could not create temporary install dir: {$inst_dir}"); } $this->addTempFile($inst_dir); if (getenv('MAKE')) { $make_command = getenv('MAKE'); } else { $make_command = 'make'; } $to_run = array($configure_command, $make_command, "{$make_command} INSTALL_ROOT=\"{$inst_dir}\" install", "find \"{$inst_dir}\" -ls"); if (!file_exists($build_dir) || !is_dir($build_dir) || !chdir($build_dir)) { return $this->raiseError("could not chdir to {$build_dir}"); } putenv('PHP_PEAR_VERSION=1.5.4'); foreach ($to_run as $cmd) { $err = $this->_runCommand($cmd, $callback); if (PEAR::isError($err)) { chdir($old_cwd); return $err; } if (!$err) { chdir($old_cwd); return $this->raiseError("`{$cmd}' failed"); } } if (!($dp = opendir("modules"))) { chdir($old_cwd); return $this->raiseError("no `modules' directory found"); } $built_files = array(); $prefix = exec("php-config --prefix"); $this->_harvestInstDir($prefix, $inst_dir . DIRECTORY_SEPARATOR . $prefix, $built_files); chdir($old_cwd); return $built_files; }
die('Following packages were not available in tar format in go-pear-tarballs: ' . implode(', ', $required) . "\n"); } if (!file_exists("{$tardir}/tmp")) { mkdir("{$tardir}/tmp"); } // Use the tar files for required Phar files require_once 'Archive/Tar.php'; require_once 'System.php'; foreach ($packages as $package) { $name = substr($package, 0, -4); $tar = new Archive_Tar("{$tardir}/{$package}"); $tar->extractModify("{$tardir}/tmp", $name); } chdir(__DIR__); $pkg = new PEAR_PackageFile($config); $pf = $pkg->fromPackageFile($tardir . '/tmp/package2.xml', PEAR_VALIDATE_NORMAL); if (PEAR::isError($pf)) { foreach ($pf->getUserInfo() as $warn) { echo $warn['message'] . "\n"; } die($pf->getMessage()); } $pearver = $pf->getVersion(); $creator = new PHP_Archive_Creator('index.php', $outputFile); // no compression $creator->useDefaultFrontController('PEAR.php'); $creator->useSHA1Signature(); foreach ($packages as $package) { echo "adding PEAR/go-pear-tarballs/{$package}\n"; $creator->addFile("go-pear-tarballs/{$package}", "PEAR/go-pear-tarballs/{$package}"); }
/** * Create a PEAR_PackageFile_v* from a .tgz archive or package.xml file. * * This method is able to extract information about a package from a .tgz * archive or from a XML package definition file. * * @access public * @param string $info file name * @param int $state package state (one of PEAR_VALIDATE_* constants) * @return PEAR_PackageFile_v1|PEAR_PackageFile_v2 * @uses fromPackageFile() if the file appears to be XML * @uses fromTgzFile() to load all non-XML files */ function &fromAnyFile($info, $state) { if (is_dir($info)) { $dir_name = realpath($info); if (file_exists($dir_name . '/package.xml')) { $fname = $dir_name . '/package.xml'; $info = PEAR_PackageFile::fromPackageFile($dir_name . '/package.xml', $state); } elseif (file_exists($dir_name . '/package2.xml')) { $fname = $dir_name . '/package2.xml'; $info = PEAR_PackageFile::fromPackageFile($dir_name . '/package2.xml', $state); } else { return PEAR::raiseError("No package definition found in '{$info}' directory"); } if (file_exists($dir_name . '/package.sig')) { require_once 'PEAR/Gnupg.php'; $gnupg = new PEAR_Gnupg($this->_config); $result = $gnupg->validateSig($fname, $dir_name . '/package.sig'); if (PEAR::isError($result)) { return $result; } } return $info; } $fp = false; if (is_string($info) && strlen($info) < 255 && (file_exists($info) || ($fp = @fopen($info, 'r')))) { if ($fp) { fclose($fp); } $tmp = substr($info, -4); if ($tmp == '.xml') { $info =& PEAR_PackageFile::fromPackageFile($info, $state); } elseif ($tmp == '.tar' || $tmp == '.tgz') { $info =& PEAR_PackageFile::fromTgzFile($info, $state); } else { $fp = fopen($info, 'r'); $test = fread($fp, 5); fclose($fp); if ($test == '<?xml') { $info =& PEAR_PackageFile::fromPackageFile($info, $state); } else { $info =& PEAR_PackageFile::fromTgzFile($info, $state); } } return $info; } $info = PEAR::raiseError("Cannot open '{$info}' for parsing"); return $info; }