summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStig Bakken <ssb@php.net>2002-05-29 03:38:19 +0000
committerStig Bakken <ssb@php.net>2002-05-29 03:38:19 +0000
commitd766f3001af1c2e413262fd7f2ce2ba743cb0c79 (patch)
tree525af92e6d8b8fb7c99fa96d3904b1b7cc6541e8
parent887eee4c8ddea9a91b4a16a5d18128a56a71e387 (diff)
downloadphp-git-d766f3001af1c2e413262fd7f2ce2ba743cb0c79.tar.gz
* build extensions in /var/tmp/pear-build-$USER/extname-n.n
* copy built .so files
-rw-r--r--pear/PEAR/Builder.php114
-rw-r--r--pear/PEAR/Command/Build.php8
2 files changed, 107 insertions, 15 deletions
diff --git a/pear/PEAR/Builder.php b/pear/PEAR/Builder.php
index 8cf44b5f6d..22a141f74d 100644
--- a/pear/PEAR/Builder.php
+++ b/pear/PEAR/Builder.php
@@ -29,6 +29,14 @@ 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 $current_callback = null;
+
// }}}
// {{{ constructor
@@ -42,7 +50,7 @@ class PEAR_Builder extends PEAR_Common
*/
function PEAR_Builder(&$ui)
{
- $this->PEAR_Common();
+ parent::PEAR_Common();
$this->setFrontendObject($ui);
}
@@ -51,10 +59,29 @@ class PEAR_Builder extends PEAR_Common
if (PEAR::isError($info = $this->infoFromDescriptionFile($descfile))) {
return $info;
}
- $configure_command = "./configure";
+ $dir = dirname($descfile);
+ $old_cwd = getcwd();
+ if (!@chdir($dir)) {
+ return $this->raiseError("could not chdir to $dir");
+ }
+ $dir = getcwd();
+ $this->current_callback = $callback;
+ $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";
if (isset($info['configure_options'])) {
foreach ($info['configure_options'] as $o) {
- $r = $this->ui->userDialog($o['prompt'], 'text', @$o['default']);
+ list($r) = $this->ui->userDialog('build',
+ array($o['prompt']),
+ array('text'),
+ array(@$o['default']));
if (substr($o['name'], 0, 5) == 'with-' &&
($r == 'yes' || $r == 'autodetect')) {
$configure_command .= " --$o[name]";
@@ -63,43 +90,108 @@ class PEAR_Builder extends PEAR_Common
}
}
}
+ // end of interactive part
+
+ // make configurable
+ $build_basedir = "/var/tmp/pear-build-$_ENV[USER]";
+ $build_dir = "$build_basedir/$info[package]-$info[version]";
+ $this->log(1, "building in $build_dir");
+ if (PEAR::isError($err = System::rm("-rf $build_dir"))) {
+ return $err;
+ }
+ if (!System::mkDir("-p $build_dir")) {
+ return $this->raiseError("could not create build dir: $build_dir");
+ }
+
if (isset($_ENV['MAKE'])) {
$make_command = $_ENV['MAKE'];
} else {
$make_command = 'make';
}
$to_run = array(
- "phpize",
$configure_command,
$make_command,
);
+ if (!@chdir($build_dir)) {
+ return $this->raiseError("could not chdir to $build_dir");
+ }
foreach ($to_run as $cmd) {
$err = $this->_runCommand($cmd, $callback);
- if (PEAR::isError($err)) {
+ if (PEAR::isError($err) && !$err) {
+ chdir($old_cwd);
return $err;
}
- if (!$err) {
- break;
+ }
+ if (!($dp = opendir("modules"))) {
+ chdir($old_cwd);
+ return $this->raiseError("no `modules' directory found");
+ }
+ while ($ent = readdir($dp)) {
+ if ($ent{0} == '.' || substr($ent, -3) == '.la') {
+ continue;
+ }
+ // harvest!
+ if (@copy("modules/$ent", "$dir/$ent")) {
+ $this->log(1, "$ent copied to $dir/$ent");
+ } else {
+ chdir($old_cwd);
+ return $this->raiseError("failed copying $ent to $dir");
}
}
+ closedir($dp);
+ chdir($old_cwd);
return true;
-
}
// }}}
+ function phpizeCallback($what, $data)
+ {
+ if ($what != 'cmdoutput') {
+ return;
+ }
+ if (preg_match('/You should update your .aclocal.m4/', $data)) {
+ return;
+ }
+ $matches = array();
+ if (preg_match('/^\s+(\S[^:]+):\s+(\d{8})/', $data, $matches)) {
+ $member = preg_replace('/[^a-z]/', '_', strtolower($matches[1]));
+ $apino = (int)$matches[2];
+ if (isset($this->$member)) {
+ $this->$member = $apino;
+ $msg = sprintf("%-22s : %d", $matches[1], $apino);
+ $this->log(1, $msg);
+ }
+ }
+ }
function _runCommand($command, $callback = null)
{
+ $this->log(1, "running: $command");
$pp = @popen($command, "r");
if (!$pp) {
return $this->raiseError("failed to run `$command'");
}
while ($line = fgets($pp, 1024)) {
- call_user_func($callback, 'output', $line);
+ if ($callback) {
+ call_user_func($callback, 'cmdoutput', $line);
+ } else {
+ $this->log(2, rtrim($line));
+ }
}
- pclose($pp);
- return true;
+ $exitcode = @pclose($pp);
+ return ($exitcode == 0);
+ }
+
+ function log($level, $msg)
+ {
+ if ($this->current_callback) {
+ if ($this->debug >= $level) {
+ call_user_func($this->current_callback, 'output', $msg);
+ }
+ return;
+ }
+ return PEAR_Common::log($level, $msg);
}
}
diff --git a/pear/PEAR/Command/Build.php b/pear/PEAR/Command/Build.php
index ee03d09201..5b15d3c0cb 100644
--- a/pear/PEAR/Command/Build.php
+++ b/pear/PEAR/Command/Build.php
@@ -56,6 +56,7 @@ Builds one or more extensions contained in a package.'
$params[0] = 'package.xml';
}
$builder = &new PEAR_Builder($this->ui);
+ $this->verbose = $this->config->get('verbose');
$err = $builder->build($params[0], array(&$this, 'buildCallback'));
if (PEAR::isError($err)) {
return $err;
@@ -65,10 +66,9 @@ Builds one or more extensions contained in a package.'
function buildCallback($what, $data)
{
- switch ($what) {
- case 'output':
- $this->ui->displayLine(rtrim($data));
- break;
+ if (($what == 'cmdoutput' && $this->verbose > 1) ||
+ ($what == 'output' && $this->verbose > 0)) {
+ $this->ui->outputData(rtrim($data), 'build');
}
}
}