4,22 → 4,15 |
* |
* PHP versions 4 and 5 |
* |
* LICENSE: This source file is subject to version 3.0 of the PHP license |
* that is available through the world-wide-web at the following URI: |
* 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 web, please |
* send a note to license@php.net so we can mail you a copy immediately. |
* |
* @category pear |
* @package PEAR |
* @author Stig Bakken <ssb@php.net> |
* @author Greg Beaver <cellog@php.net> |
* @copyright 1997-2006 The PHP Group |
* @license http://www.php.net/license/3_0.txt PHP License 3.0 |
* @version CVS: $Id: Builder.php,v 1.31 2007/01/10 05:32:51 cellog Exp $ |
* @copyright 1997-2009 The Authors |
* @license http://opensource.org/licenses/bsd-license.php New BSD License |
* @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 |
*/ |
29,6 → 22,8 |
*/ |
require_once 'PEAR/Common.php'; |
require_once 'PEAR/PackageFile.php'; |
require_once 'System.php'; |
|
/** |
* Class to handle building (compiling) extensions. |
* |
36,9 → 31,9 |
* @package PEAR |
* @author Stig Bakken <ssb@php.net> |
* @author Greg Beaver <cellog@php.net> |
* @copyright 1997-2006 The PHP Group |
* @license http://www.php.net/license/3_0.txt PHP License 3.0 |
* @version Release: 1.5.1 |
* @copyright 1997-2009 The Authors |
* @license http://opensource.org/licenses/bsd-license.php New BSD License |
* @version Release: 1.10.1 |
* @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 |
45,8 → 40,6 |
*/ |
class PEAR_Builder extends PEAR_Common |
{ |
// {{{ properties |
|
var $php_api_version = 0; |
var $zend_module_api_no = 0; |
var $zend_extension_api_no = 0; |
62,8 → 55,6 |
// used for msdev builds |
var $_lastline = null; |
var $_firstline = null; |
// }}} |
// {{{ constructor |
|
/** |
* PEAR_Builder constructor. |
72,16 → 63,12 |
* |
* @access public |
*/ |
function PEAR_Builder(&$ui) |
function __construct(&$ui) |
{ |
parent::PEAR_Common(); |
parent::__construct(); |
$this->setFrontendObject($ui); |
} |
|
// }}} |
|
// {{{ _build_win32() |
|
/** |
* Build an extension from source on windows. |
* requires msdev |
92,7 → 79,7 |
$pkg = $descfile; |
$descfile = $pkg->getPackageFile(); |
} else { |
$pf = &new PEAR_PackageFile($this->config, $this->debug); |
$pf = new PEAR_PackageFile($this->config, $this->debug); |
$pkg = &$pf->fromPackageFile($descfile, PEAR_VALIDATE_NORMAL); |
if (PEAR::isError($pkg)) { |
return $pkg; |
104,14 → 91,15 |
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)) { |
$dir = getcwd(); |
} else { |
if (!chdir($vdir)) { |
return $this->raiseError("could not chdir to " . realpath($vdir)); |
} |
|
$dir = getcwd(); |
} |
|
$this->log(2, "building in $dir"); |
136,7 → 124,7 |
$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."); |
158,7 → 146,7 |
$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 { |
188,9 → 176,7 |
$this->_lastline = $data; |
call_user_func($this->current_callback, $what, $data); |
} |
// }}} |
|
// {{{ _harventInstDir |
/** |
* @param string |
* @param string |
231,14 → 217,10 |
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|PEAR_PackageFile_v* $descfile path to XML package description file, or |
* a PEAR_PackageFile object |
260,39 → 242,80 |
*/ |
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 (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); |
$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 (!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')); |
$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"); |
} |
299,6 → 322,16 |
|
// {{{ 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) { |
318,10 → 351,12 |
// }}} end of interactive part |
|
// FIXME make configurable |
if(!$user=getenv('USER')){ |
if (!$user=getenv('USER')) { |
$user='defaultuser'; |
} |
$build_basedir = "/var/tmp/pear-build-$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"); |
328,9 → 363,11 |
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"); |
337,21 → 374,18 |
} |
$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 (!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.1'); |
putenv('PHP_PEAR_VERSION=1.10.1'); |
foreach ($to_run as $cmd) { |
$err = $this->_runCommand($cmd, $callback); |
if (PEAR::isError($err)) { |
368,15 → 402,14 |
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 |
410,9 → 443,6 |
} |
} |
|
// }}} |
// {{{ _runCommand() |
|
/** |
* Run an external command, using a message callback to report |
* output. The command will be run through popen and output is |
451,18 → 481,12 |
if ($callback && isset($olddbg)) { |
$callback[0]->debug = $olddbg; |
} |
if (is_resource($pp)) { |
$exitcode = pclose($pp); |
} else { |
$exitcode = -1; |
} |
|
$exitcode = is_resource($pp) ? pclose($pp) : -1; |
return ($exitcode == 0); |
} |
|
// }}} |
// {{{ log() |
|
function log($level, $msg) |
function log($level, $msg, $append_crlf = true) |
{ |
if ($this->current_callback) { |
if ($this->debug >= $level) { |
470,10 → 494,6 |
} |
return; |
} |
return PEAR_Common::log($level, $msg); |
return parent::log($level, $msg, $append_crlf); |
} |
|
// }}} |
} |
|
?> |