From: Stig Bakken Date: Tue, 9 Apr 2002 08:10:12 +0000 (+0000) Subject: * implemented role="script" and substitution during install X-Git-Tag: php-4.3.0dev-ZendEngine2-Preview1~779 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=894cbdf3d22c1bd46d0d24120102ce2c04fbdcaf;p=php * implemented role="script" and substitution during install --- diff --git a/pear/PEAR/Command/Install.php b/pear/PEAR/Command/Install.php index 471ed03b61..e037c0a1bb 100644 --- a/pear/PEAR/Command/Install.php +++ b/pear/PEAR/Command/Install.php @@ -93,9 +93,7 @@ class PEAR_Command_Install extends PEAR_Command_Common function run($command, $options, $params) { - $installer = &new PEAR_Installer($this->config->get('php_dir'), - $this->config->get('ext_dir'), - $this->config->get('doc_dir')); + $installer = &new PEAR_Installer($this->config); $installer->setFrontend($this->ui); $installer->debug = $this->config->get('verbose'); diff --git a/pear/PEAR/Common.php b/pear/PEAR/Common.php index 9d846ceb1f..f522d12fae 100644 --- a/pear/PEAR/Common.php +++ b/pear/PEAR/Common.php @@ -84,7 +84,13 @@ class PEAR_Common extends PEAR * Valid file roles * @var array */ - var $file_roles = array('php','ext','test','doc','data','extsrc'); + var $file_roles = array('php','ext','test','doc','data','extsrc','script'); + + /** + * Valid replacement types + * @var array + */ + var $replacement_types = array('php-const', 'pear-config'); /** * User Interface object (PEAR_Frontend_* class). If null, @@ -93,6 +99,8 @@ class PEAR_Common extends PEAR */ var $ui = null; + var $current_path = null; + // }}} // {{{ constructor @@ -322,6 +330,34 @@ class PEAR_Common extends PEAR $this->dir_role = $attribs['role']; } break; + case 'file': + if (isset($attribs['name'])) { + $path = ''; + if (count($this->dir_names)) { + foreach ($this->dir_names as $dir) { + $path .= $dir . DIRECTORY_SEPARATOR; + } + } + $path .= $attribs['name']; + unset($attribs['name']); + $this->current_path = $path; + $this->filelist[$path] = $attribs; + // Set the baseinstalldir only if the file don't have this attrib + if (!isset($this->filelist[$path]['baseinstalldir']) && + isset($this->dir_install)) + { + $this->filelist[$path]['baseinstalldir'] = $this->dir_install; + } + // Set the Role + if (!isset($this->filelist[$path]['role']) && isset($this->dir_role)) { + $this->filelist[$path]['role'] = $this->dir_role; + } + } + break; + case 'replace': + $this->filelist[$this->current_path]['replacements'][] = $attribs; + break; + case 'libfile': $this->lib_atts = $attribs; $this->lib_atts['role'] = 'extsrc'; @@ -452,24 +488,25 @@ class PEAR_Common extends PEAR array_pop($this->dir_names); break; case 'file': - $this->current_file = $data; - $path = ''; - if (count($this->dir_names)) { - foreach ($this->dir_names as $dir) { - $path .= $dir . DIRECTORY_SEPARATOR; + if ($data) { + $path = ''; + if (count($this->dir_names)) { + foreach ($this->dir_names as $dir) { + $path .= $dir . DIRECTORY_SEPARATOR; + } + } + $path .= $data; + $this->filelist[$path] = $this->current_attributes; + // Set the baseinstalldir only if the file don't have this attrib + if (!isset($this->filelist[$path]['baseinstalldir']) && + isset($this->dir_install)) + { + $this->filelist[$path]['baseinstalldir'] = $this->dir_install; + } + // Set the Role + if (!isset($this->filelist[$path]['role']) && isset($this->dir_role)) { + $this->filelist[$path]['role'] = $this->dir_role; } - } - $path .= $this->current_file; - $this->filelist[$path] = $this->current_attributes; - // Set the baseinstalldir only if the file don't have this attrib - if (!isset($this->filelist[$path]['baseinstalldir']) && - isset($this->dir_install)) - { - $this->filelist[$path]['baseinstalldir'] = $this->dir_install; - } - // Set the Role - if (!isset($this->filelist[$path]['role']) && isset($this->dir_role)) { - $this->filelist[$path]['role'] = $this->dir_role; } break; case 'libfile': @@ -769,20 +806,41 @@ class PEAR_Common extends PEAR if (isset($pkginfo['filelist'])) { $ret .= "$indent \n"; foreach ($pkginfo['filelist'] as $file => $fa) { - if ($fa['role'] == 'extsrc') { + if (@$fa['role'] == 'extsrc') { $ret .= "$indent \n"; $ret .= "$indent $file\n"; $ret .= "$indent $fa[sources]\n"; $ret .= "$indent \n"; } else { - $ret .= "$indent $v) { + $ret .= " $k=\"" . htmlspecialchars($v) .'"'; + } + $ret .= "/>\n"; + } + @$ret .= "$indent \n"; + } } } $ret .= "$indent \n"; diff --git a/pear/PEAR/Config.php b/pear/PEAR/Config.php index c9283046de..3efe113235 100644 --- a/pear/PEAR/Config.php +++ b/pear/PEAR/Config.php @@ -27,7 +27,7 @@ require_once 'PEAR.php'; $GLOBALS['_PEAR_Config_instance'] = null; define('PEAR_CONFIG_DEFAULT_DOCDIR', - PHP_DATADIR.DIRECTORY_SEPARATOR.'pear'.DIRECTORY_SEPARATOR.'doc'); + PHP_DATADIR.DIRECTORY_SEPARATOR.'doc'.DIRECTORY_SEPARATOR.'pear'); // in case a --without-pear PHP installation is used if (!defined('PEAR_INSTALL_DIR')) { @@ -38,21 +38,8 @@ if (!defined('PEAR_EXTENSION_DIR')) { } /** - * This is a class for storing simple configuration values keeping - * track of which are system-defined, user-defined or defaulted. By - * default, only user-defined settings are stored back to the user's - * configuration file. - * - * Configuration member is a simple associative array. Used keys: - * - * master_server which server to query for mirror lists etc. - * server which server/mirror we're currently using - * username PEAR username - * password PEAR password (stored base64-encoded) - * php_dir Where to install .php files - * ext_dir Directory to install compiled libs in - * doc_dir Directory to install documentation in - * + * This is a class for storing configuration data, keeping track of + * which are system-defined, user-defined or defaulted. */ class PEAR_Config extends PEAR { @@ -114,7 +101,12 @@ class PEAR_Config extends PEAR 'doc_dir' => array( 'type' => 'directory', 'default' => PEAR_CONFIG_DEFAULT_DOCDIR, - 'doc' => 'directory where documentation is located', + 'doc' => 'directory where documentation is installed', + ), + 'bin_dir' => array( + 'type' => 'directory', + 'default' => PHP_BINDIR, + 'doc' => 'directory where executables are installed', ), 'username' => array( 'type' => 'string', @@ -775,18 +767,21 @@ when installing packages without a version or state specified', } // }}} + // {{{ getLayers() /** - * Returns the layers defined (except the 'default' one) - * - * @return array of the defined layers - */ + * Returns the layers defined (except the 'default' one) + * + * @return array of the defined layers + */ function getLayers() { $cf = $this->configuration; unset($cf['default']); return array_keys($cf); } + + // }}} } ?> \ No newline at end of file diff --git a/pear/PEAR/Installer.php b/pear/PEAR/Installer.php index 1ca2929431..6f536c31e1 100644 --- a/pear/PEAR/Installer.php +++ b/pear/PEAR/Installer.php @@ -38,48 +38,60 @@ class PEAR_Installer extends PEAR_Common { // {{{ properties - /** name of the package directory, for example Foo-1.0 */ + /** name of the package directory, for example Foo-1.0 + * @var string + */ var $pkgdir; - /** directory where PHP code files go */ + /** directory where PHP code files go + * @var string + */ var $phpdir; - /** directory where PHP extension files go */ + /** directory where PHP extension files go + * @var string + */ var $extdir; - /** directory where documentation goes */ + /** directory where documentation goes + * @var string + */ var $docdir; /** directory where the package wants to put files, relative - * to one of the three previous dirs + * to one of the previous dirs + * @var string */ var $destdir = ''; - /** debug level (integer) */ + /** debug level + * @var int + */ var $debug = 1; - /** temporary directory */ + /** temporary directory + * @var string + */ var $tmpdir; - /** PEAR_Registry object used by the installer */ + /** PEAR_Registry object used by the installer + * @var object + */ var $registry; + /** PEAR_Config object used by the installer + * @var object + */ + var $config; + // }}} // {{{ constructor - function PEAR_Installer($phpdir = PEAR_INSTALL_DIR, - $extdir = PEAR_EXTENSION_DIR, - $docdir = null) + function PEAR_Installer(&$config) { $this->PEAR(); - $this->phpdir = $phpdir; - $this->extdir = $extdir; - if ($docdir === null) { - $docdir = PHP_DATADIR . DIRECTORY_SEPARATOR . 'pear' . - DIRECTORY_SEPARATOR . 'doc'; - } - $this->docdir = $docdir; + $this->config = &$config; } // }}} @@ -108,30 +120,40 @@ class PEAR_Installer extends PEAR_Common function _installFile($file, $atts, $tmp_path) { - $type = strtolower($atts['role']); - switch ($type) { - case 'test': + switch ($atts['role']) { + case 'test': case 'data': case 'ext': // don't install test files for now - $this->log(2, "+ Test file $file won't be installed yet"); + $this->log(2, "+ $file: $atts[role] file not installed yet"); return true; - break; case 'doc': - $dest_dir = $this->docdir . DIRECTORY_SEPARATOR . - $this->pkginfo['package']; + $dest_dir = $this->config->get('doc_dir') . + DIRECTORY_SEPARATOR . $this->pkginfo['package']; break; + case 'extsrc': + // don't install test files for now + $this->log(2, "+ $file: no support for building extensions yet"); + return true; case 'php': - default: { - $dest_dir = $this->phpdir; - if (isset($atts['baseinstalldir'])) { - $dest_dir .= DIRECTORY_SEPARATOR . $atts['baseinstalldir']; - } - if (dirname($file) != '.') { - $dest_dir .= DIRECTORY_SEPARATOR . dirname($file); - } + $dest_dir = $this->config->get('php_dir'); + break; + case 'script': { + $dest_dir = $this->config->get('bin_dir'); break; } + default: + break; + } + if (isset($atts['baseinstalldir'])) { + $dest_dir .= DIRECTORY_SEPARATOR . $atts['baseinstalldir']; + } + if (dirname($file) != '.') { + $dest_dir .= DIRECTORY_SEPARATOR . dirname($file); + } + if (empty($atts['install-as'])) { + $dest_file = $dest_dir . DIRECTORY_SEPARATOR . basename($file); + } else { + $dest_file = $dest_dir . DIRECTORY_SEPARATOR . $atts['install-as']; } - $dest_file = $dest_dir . DIRECTORY_SEPARATOR . basename($file); if (!@is_dir($dest_dir)) { if (!$this->mkDirHier($dest_dir)) { $this->log(0, "failed to mkdir $dest_dir"); @@ -140,13 +162,55 @@ class PEAR_Installer extends PEAR_Common $this->log(2, "+ created dir $dest_dir"); } $orig_file = $tmp_path . DIRECTORY_SEPARATOR . $file; - $orig_perms = fileperms($orig_file); - if (!@copy($orig_file, $dest_file)) { - $this->log(0, "failed to copy $orig_file to $dest_file"); - return false; + if (empty($atts['replacements'])) { + if (!@copy($orig_file, $dest_file)) { + $this->log(0, "failed to copy $orig_file to $dest_file"); + return false; + } + $this->log(2, "+ copy $orig_file to $dest_file"); + } else { + $fp = fopen($orig_file, "r"); + $contents = fread($fp, filesize($orig_file)); + fclose($fp); + $subst_from = $subst_to = array(); + foreach ($atts['replacements'] as $a) { + $to = ''; + if ($a['type'] == 'php-const') { + if (preg_match('/^[a-z0-9_]+$/i', $a['to'])) { + eval("\$to = $a[to];"); + } else { + $this->log(0, "invalid php-const replacement: $a[to]"); + continue; + } + } elseif ($a['type'] == 'pear-config') { + $to = $this->config->get($a['to']); + } + if ($to) { + $subst_from = $a['from']; + $subst_to = $to; + } + } + if (sizeof($subst_from)) { + $contents = str_replace($subst_from, $subst_to, $contents); + } + $wp = @fopen($dest_file, "w"); + if (!is_resource($wp)) { + $this->log(0, "failed to create $dest_file"); + return false; + } + fwrite($wp, $contents); + fclose($wp); + } + if (!OS_WINDOWS) { + if ($atts['role'] == 'script') { + $mode = 0755; + } else { + $mode = 0644; + } + if (!@chmod($dest_file, $mode)) { + $this->log(0, "failed to change mode of $dest_file"); + } } - chmod($dest_file, $orig_perms); - $this->log(2, "+ copy $orig_file to $dest_file"); // Store the full path where the file was installed for easy unistall $this->pkginfo['filelist'][$file]['installed_as'] = $dest_file; @@ -174,7 +238,7 @@ class PEAR_Installer extends PEAR_Common // - soft : fail silently // if (empty($this->registry)) { - $this->registry = new PEAR_Registry($this->phpdir); + $this->registry = new PEAR_Registry($this->config->get('php_dir')); } $oldcwd = getcwd(); $need_download = false; @@ -332,7 +396,7 @@ class PEAR_Installer extends PEAR_Common // info from the package it self we want to access from _installFile $this->pkginfo = $pkginfo; if (empty($options['register_only'])) { - if (!is_dir($this->phpdir)) { + if (!is_dir($this->config->get('php_dir'))) { chdir($oldcwd); return $this->raiseError("no script destination directory\n", null, PEAR_ERROR_DIE); @@ -374,7 +438,7 @@ class PEAR_Installer extends PEAR_Common function uninstall($package) { if (empty($this->registry)) { - $this->registry = new PEAR_Registry($this->phpdir); + $this->registry = new PEAR_Registry($this->config->get('php_dir')); } // Delete the files diff --git a/pear/package-pear.xml b/pear/package-pear.xml index 62f23d36ea..90e27d542c 100644 --- a/pear/package-pear.xml +++ b/pear/package-pear.xml @@ -48,32 +48,32 @@ First package release. Commands implemented: logout - + - - + + - - - - - - - + + + + + + + - - - + + + - + - - - - + + + + - + diff --git a/pear/package.dtd b/pear/package.dtd index 95fec39885..f80e766c13 100644 --- a/pear/package.dtd +++ b/pear/package.dtd @@ -1,5 +1,5 @@