cvs: php4(NEW_UI_API) /pear/PEAR Builder.php /pear/PEAR/Command Build.php

From: Date: Wed, 29 May 2002 03:38:20 +0000
Subject: cvs: php4(NEW_UI_API) /pear/PEAR Builder.php /pear/PEAR/Command Build.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-4226@lists.php.net to get a copy of this message
ssb Tue May 28 23:38:20 2002 EDT Modified files: (Branch: NEW_UI_API) /php4/pear/PEAR Builder.php /php4/pear/PEAR/Command Build.php Log: * build extensions in /var/tmp/pear-build-$USER/extname-n.n * copy built .so files Index: php4/pear/PEAR/Builder.php diff -u php4/pear/PEAR/Builder.php:1.1 php4/pear/PEAR/Builder.php:1.1.2.1 --- php4/pear/PEAR/Builder.php:1.1 Mon May 27 21:01:42 2002 +++ php4/pear/PEAR/Builder.php Tue May 28 23:38:19 2002 @@ -16,7 +16,7 @@ // | Authors: Stig Sæther Bakken <ssb@fast.no> | // +----------------------------------------------------------------------+ // -// $Id: Builder.php,v 1.1 2002/05/28 01:01:42 ssb Exp $ +// $Id: Builder.php,v 1.1.2.1 2002/05/29 03:38:19 ssb Exp $ require_once 'PEAR/Common.php'; @@ -29,6 +29,14 @@ { // {{{ 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 @@ */ function PEAR_Builder(&$ui) { - $this->PEAR_Common(); + parent::PEAR_Common(); $this->setFrontendObject($ui); } @@ -51,10 +59,29 @@ 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 @@ } } } + // 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); } } Index: php4/pear/PEAR/Command/Build.php diff -u php4/pear/PEAR/Command/Build.php:1.2 php4/pear/PEAR/Command/Build.php:1.2.2.1 --- php4/pear/PEAR/Command/Build.php:1.2 Mon May 27 21:01:43 2002 +++ php4/pear/PEAR/Command/Build.php Tue May 28 23:38:19 2002 @@ -18,7 +18,7 @@ // | | // +----------------------------------------------------------------------+ // -// $Id: Build.php,v 1.2 2002/05/28 01:01:43 ssb Exp $ +// $Id: Build.php,v 1.2.2.1 2002/05/29 03:38:19 ssb Exp $ require_once "PEAR/Command/Common.php"; require_once "PEAR/Builder.php"; @@ -56,6 +56,7 @@ $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 @@ 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'); } } }

« previous php.pear.cvs (#4226) next »