summaryrefslogtreecommitdiffstats
path: root/3rdparty/PEAR/Builder.php
diff options
context:
space:
mode:
authorRobin Appelman <icewind@owncloud.com>2012-05-11 17:57:55 +0200
committerRobin Appelman <icewind@owncloud.com>2012-05-11 17:57:55 +0200
commit9c2f1051646f1dfb2615065d79d9a76410152b1a (patch)
treeaeb2812f7f37fb58bc6920cd2b3ccdf08d9c1eec /3rdparty/PEAR/Builder.php
parent347ce2aafada161849dad8593100c40e14c641ce (diff)
downloadnextcloud-server-9c2f1051646f1dfb2615065d79d9a76410152b1a.tar.gz
nextcloud-server-9c2f1051646f1dfb2615065d79d9a76410152b1a.zip
update PEAR to 1.9.4
Diffstat (limited to '3rdparty/PEAR/Builder.php')
-rw-r--r--3rdparty/PEAR/Builder.php241
1 files changed, 152 insertions, 89 deletions
diff --git a/3rdparty/PEAR/Builder.php b/3rdparty/PEAR/Builder.php
index 4f6cc135d1e..90f3a145552 100644
--- a/3rdparty/PEAR/Builder.php
+++ b/3rdparty/PEAR/Builder.php
@@ -1,47 +1,60 @@
<?php
-//
-// +----------------------------------------------------------------------+
-// | PHP Version 5 |
-// +----------------------------------------------------------------------+
-// | 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 Sæther Bakken <ssb@php.net> |
-// +----------------------------------------------------------------------+
-//
-// $Id: Builder.php,v 1.16.2.3 2005/02/17 17:55:01 cellog Exp $
+/**
+ * PEAR_Builder for building PHP extensions (PECL packages)
+ *
+ * PHP versions 4 and 5
+ *
+ * @category pear
+ * @package PEAR
+ * @author Stig Bakken <ssb@php.net>
+ * @author Greg Beaver <cellog@php.net>
+ * @copyright 1997-2009 The Authors
+ * @license http://opensource.org/licenses/bsd-license.php New BSD License
+ * @version CVS: $Id: Builder.php 313024 2011-07-06 19:51:24Z dufuz $
+ * @link http://pear.php.net/package/PEAR
+ * @since File available since Release 0.1
+ *
+ * TODO: log output parameters in PECL command line
+ * TODO: msdev path in configuration
+ */
+/**
+ * Needed for extending PEAR_Builder
+ */
require_once 'PEAR/Common.php';
+require_once 'PEAR/PackageFile.php';
/**
* Class to handle building (compiling) extensions.
*
- * @author Stig Sæther Bakken <ssb@php.net>
+ * @category pear
+ * @package PEAR
+ * @author Stig Bakken <ssb@php.net>
+ * @author Greg Beaver <cellog@php.net>
+ * @copyright 1997-2009 The Authors
+ * @license http://opensource.org/licenses/bsd-license.php New BSD License
+ * @version Release: 1.9.4
+ * @link http://pear.php.net/package/PEAR
+ * @since Class available since PHP 4.0.2
+ * @see http://pear.php.net/manual/en/core.ppm.pear-builder.php
*/
class PEAR_Builder extends PEAR_Common
{
- // {{{ properties
-
var $php_api_version = 0;
var $zend_module_api_no = 0;
var $zend_extension_api_no = 0;
var $extensions_built = array();
+ /**
+ * @var string Used for reporting when it is not possible to pass function
+ * via extra parameter, e.g. log, msdevCallback
+ */
var $current_callback = null;
// used for msdev builds
var $_lastline = null;
var $_firstline = null;
- // }}}
- // {{{ constructor
/**
* PEAR_Builder constructor.
@@ -56,35 +69,48 @@ class PEAR_Builder extends PEAR_Common
$this->setFrontendObject($ui);
}
- // }}}
-
- // {{{ _build_win32()
-
/**
* Build an extension from source on windows.
* requires msdev
*/
function _build_win32($descfile, $callback = null)
{
- if (PEAR::isError($info = $this->infoFromDescriptionFile($descfile))) {
- return $info;
+ if (is_object($descfile)) {
+ $pkg = $descfile;
+ $descfile = $pkg->getPackageFile();
+ } else {
+ $pf = &new PEAR_PackageFile($this->config, $this->debug);
+ $pkg = &$pf->fromPackageFile($descfile, PEAR_VALIDATE_NORMAL);
+ if (PEAR::isError($pkg)) {
+ return $pkg;
+ }
}
$dir = dirname($descfile);
$old_cwd = getcwd();
- if (!@chdir($dir)) {
+ if (!file_exists($dir) || !is_dir($dir) || !chdir($dir)) {
return $this->raiseError("could not chdir to $dir");
}
+
+ // packages that were in a .tar have the packagefile in this directory
+ $vdir = $pkg->getPackage() . '-' . $pkg->getVersion();
+ if (file_exists($dir) && is_dir($vdir)) {
+ if (!chdir($vdir)) {
+ return $this->raiseError("could not chdir to " . realpath($vdir));
+ }
+
+ $dir = getcwd();
+ }
+
$this->log(2, "building in $dir");
- $dsp = $info['package'].'.dsp';
- if (!@is_file("$dir/$dsp")) {
+ $dsp = $pkg->getPackage().'.dsp';
+ if (!file_exists("$dir/$dsp")) {
return $this->raiseError("The DSP $dsp does not exist.");
}
// XXX TODO: make release build type configurable
- $command = 'msdev '.$dsp.' /MAKE "'.$info['package']. ' - Release"';
+ $command = 'msdev '.$dsp.' /MAKE "'.$pkg->getPackage(). ' - Release"';
- $this->current_callback = $callback;
$err = $this->_runCommand($command, array(&$this, 'msdevCallback'));
if (PEAR::isError($err)) {
return $err;
@@ -93,12 +119,12 @@ class PEAR_Builder extends PEAR_Common
// figure out the build platform and type
$platform = 'Win32';
$buildtype = 'Release';
- if (preg_match('/.*?'.$info['package'].'\s-\s(\w+)\s(.*?)-+/i',$this->_firstline,$matches)) {
+ if (preg_match('/.*?'.$pkg->getPackage().'\s-\s(\w+)\s(.*?)-+/i',$this->_firstline,$matches)) {
$platform = $matches[1];
$buildtype = $matches[2];
}
- if (preg_match('/(.*)?\s-\s(\d+).*?(\d+)/',$this->_lastline,$matches)) {
+ if (preg_match('/(.*)?\s-\s(\d+).*?(\d+)/', $this->_lastline, $matches)) {
if ($matches[2]) {
// there were errors in the build
return $this->raiseError("There were errors during compilation.");
@@ -115,18 +141,19 @@ class PEAR_Builder extends PEAR_Common
// this regex depends on the build platform and type having been
// correctly identified above.
$regex ='/.*?!IF\s+"\$\(CFG\)"\s+==\s+("'.
- $info['package'].'\s-\s'.
+ $pkg->getPackage().'\s-\s'.
$platform.'\s'.
$buildtype.'").*?'.
'\/out:"(.*?)"/is';
- if ($dsptext && preg_match($regex,$dsptext,$matches)) {
+ if ($dsptext && preg_match($regex, $dsptext, $matches)) {
// what we get back is a relative path to the output file itself.
$outfile = realpath($matches[2]);
} else {
return $this->raiseError("Could not retrieve output information from $dsp.");
}
- if (@copy($outfile, "$dir/$out")) {
+ // realpath returns false if the file doesn't exist
+ if ($outfile && copy($outfile, "$dir/$out")) {
$outfile = "$dir/$out";
}
@@ -147,10 +174,9 @@ class PEAR_Builder extends PEAR_Common
if (!$this->_firstline)
$this->_firstline = $data;
$this->_lastline = $data;
+ call_user_func($this->current_callback, $what, $data);
}
- // }}}
- // {{{ _harventInstDir
/**
* @param string
* @param string
@@ -191,16 +217,13 @@ class PEAR_Builder extends PEAR_Common
return $ret;
}
- // }}}
-
- // {{{ build()
-
/**
* Build an extension from source. Runs "phpize" in the source
* directory, but compiles in a temporary directory
- * (/var/tmp/pear-build-USER/PACKAGE-VERSION).
+ * (TMPDIR/pear-build-USER/PACKAGE-VERSION).
*
- * @param string $descfile path to XML package description file
+ * @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
@@ -216,48 +239,97 @@ class PEAR_Builder extends PEAR_Common
* @access public
*
* @see PEAR_Builder::_runCommand
- * @see PEAR_Common::infoFromDescriptionFile
*/
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);
+ return $this->_build_win32($descfile, $callback);
}
+
if (PEAR_OS != 'Unix') {
return $this->raiseError("building extensions not supported on this platform");
}
- if (PEAR::isError($info = $this->infoFromDescriptionFile($descfile))) {
- return $info;
+
+ 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);
}
- $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 (!@chdir($dir)) {
+ if (!file_exists($dir) || !is_dir($dir) || !chdir($dir)) {
return $this->raiseError("could not chdir to $dir");
}
- $vdir = "$info[package]-$info[version]";
+
+ $vdir = $pkg->getPackage() . '-' . $pkg->getVersion();
if (is_dir($vdir)) {
chdir($vdir);
}
+
$dir = getcwd();
$this->log(2, "building in $dir");
- $this->current_callback = $callback;
putenv('PATH=' . $this->config->get('bin_dir') . ':' . getenv('PATH'));
- $err = $this->_runCommand("phpize", array(&$this, 'phpizeCallback'));
+ $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";
- if (isset($info['configure_options'])) {
- foreach ($info['configure_options'] as $o) {
+ $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(@$o['default']));
+ array($default));
if (substr($o['name'], 0, 5) == 'with-' &&
($r == 'yes' || $r == 'autodetect')) {
$configure_command .= " --$o[name]";
@@ -269,40 +341,41 @@ class PEAR_Builder extends PEAR_Common
// }}} end of interactive part
// FIXME make configurable
- if(!$user=getenv('USER')){
+ if (!$user=getenv('USER')) {
$user='defaultuser';
}
- $build_basedir = "/var/tmp/pear-build-$user";
- $build_dir = "$build_basedir/$info[package]-$info[version]";
- $inst_dir = "$build_basedir/install-$info[package]-$info[version]";
+
+ $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('-rf', $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';
- }
+ $make_command = getenv('MAKE') ? getenv('MAKE') : 'make';
+
$to_run = array(
$configure_command,
$make_command,
"$make_command INSTALL_ROOT=\"$inst_dir\" install",
- "find \"$inst_dir\" -ls"
+ "find \"$inst_dir\" | xargs ls -dils"
);
- if (!@chdir($build_dir)) {
+ 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=@PEAR-VER@');
+ putenv('PHP_PEAR_VERSION=1.9.4');
foreach ($to_run as $cmd) {
$err = $this->_runCommand($cmd, $callback);
if (PEAR::isError($err)) {
@@ -319,15 +392,14 @@ class PEAR_Builder extends PEAR_Common
return $this->raiseError("no `modules' directory found");
}
$built_files = array();
- $prefix = exec("php-config --prefix");
+ $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;
}
- // }}}
- // {{{ phpizeCallback()
-
/**
* Message callback function used when running the "phpize"
* program. Extracts the API numbers used. Ignores other message
@@ -361,9 +433,6 @@ class PEAR_Builder extends PEAR_Common
}
}
- // }}}
- // {{{ _runCommand()
-
/**
* Run an external command, using a message callback to report
* output. The command will be run through popen and output is
@@ -383,7 +452,7 @@ class PEAR_Builder extends PEAR_Common
function _runCommand($command, $callback = null)
{
$this->log(1, "running: $command");
- $pp = @popen("$command 2>&1", "r");
+ $pp = popen("$command 2>&1", "r");
if (!$pp) {
return $this->raiseError("failed to run `$command'");
}
@@ -402,13 +471,11 @@ class PEAR_Builder extends PEAR_Common
if ($callback && isset($olddbg)) {
$callback[0]->debug = $olddbg;
}
- $exitcode = @pclose($pp);
+
+ $exitcode = is_resource($pp) ? pclose($pp) : -1;
return ($exitcode == 0);
}
- // }}}
- // {{{ log()
-
function log($level, $msg)
{
if ($this->current_callback) {
@@ -419,8 +486,4 @@ class PEAR_Builder extends PEAR_Common
}
return PEAR_Common::log($level, $msg);
}
-
- // }}}
-}
-
-?>
+} \ No newline at end of file