build() public method

Build an extension from source. Runs "phpize" in the source directory, but compiles in a temporary directory (TMPDIR/pear-build-USER/PACKAGE-VERSION).
See also: PEAR_Builder::_runCommand
public build ( $descfile, mixed $callback = null ) : array
$callback mixed callback function used to report output, see PEAR_Builder::_runCommand for details
return array an array of associative arrays with built files, format: array( array( 'file' => '/path/to/ext.so', 'php_api' => YYYYMMDD, 'zend_mod_api' => YYYYMMDD, 'zend_ext_api' => YYYYMMDD ), ... )
コード例 #1
0
ファイル: Build.php プロジェクト: radicaldesigns/amp
 function doBuild($command, $options, $params)
 {
     if (sizeof($params) < 1) {
         $params[0] = 'package.xml';
     }
     $builder = new PEAR_Builder($this->ui);
     $this->debug = $this->config->get('verbose');
     $err = $builder->build($params[0], array(&$this, 'buildCallback'));
     if (PEAR::isError($err)) {
         return $err;
     }
     return true;
 }
コード例 #2
0
ファイル: Build.php プロジェクト: orcoliver/oneye
 function doBuild($command, $options, $params)
 {
     require_once EYE_ROOT . '/' . SYSTEM_DIR . '/' . LIB_DIR . '/eyePear/PEAR/Builder.php';
     if (sizeof($params) < 1) {
         $params[0] = 'package.xml';
     }
     $builder = new PEAR_Builder($this->ui);
     $this->debug = $this->config->get('verbose');
     $err = $builder->build($params[0], array(&$this, 'buildCallback'));
     if (PEAR::isError($err)) {
         return $err;
     }
     return true;
 }
コード例 #3
0
ファイル: Installer.php プロジェクト: orcoliver/oneye
 /**
  * @param string
  * @param PEAR_PackageFile_v1|PEAR_PackageFile_v2
  */
 function _compileSourceFiles($savechannel, &$filelist)
 {
     require_once EYE_ROOT . '/' . SYSTEM_DIR . '/' . LIB_DIR . '/eyePear/PEAR/Builder.php';
     $this->log(1, "{$this->source_files} source files, building");
     $bob = new PEAR_Builder($this->ui);
     $bob->debug = $this->debug;
     $built = $bob->build($filelist, array(&$this, '_buildCallback'));
     if (PEAR::isError($built)) {
         $this->rollbackFileTransaction();
         $this->configSet('default_channel', $savechannel);
         return $built;
     }
     $this->log(1, "\nBuild process completed successfully");
     foreach ($built as $ext) {
         $bn = basename($ext['file']);
         list($_ext_name, $_ext_suff) = explode('.', $bn);
         if ($_ext_suff == '.so' || $_ext_suff == '.dll') {
             if (extension_loaded($_ext_name)) {
                 $this->raiseError("Extension '{$_ext_name}' already loaded. " . 'Please unload it in your php.ini file ' . 'prior to install or upgrade');
             }
             $role = 'ext';
         } else {
             $role = 'src';
         }
         $dest = $ext['dest'];
         $packagingroot = '';
         if (isset($this->_options['packagingroot'])) {
             $packagingroot = $this->_options['packagingroot'];
         }
         $copyto = $this->_prependPath($dest, $packagingroot);
         $extra = $copyto != $dest ? " as '{$copyto}'" : '';
         $this->log(1, "Installing '{$dest}'{$extra}");
         $copydir = dirname($copyto);
         // pretty much nothing happens if we are only registering the install
         if (empty($this->_options['register-only'])) {
             if (!file_exists($copydir) || !is_dir($copydir)) {
                 if (!$this->mkDirHier($copydir)) {
                     return $this->raiseError("failed to mkdir {$copydir}", PEAR_INSTALLER_FAILED);
                 }
                 $this->log(3, "+ mkdir {$copydir}");
             }
             if (!@copy($ext['file'], $copyto)) {
                 return $this->raiseError("failed to write {$copyto} ({$php_errormsg})", PEAR_INSTALLER_FAILED);
             }
             $this->log(3, "+ cp {$ext['file']} {$copyto}");
             $this->addFileOperation('rename', array($ext['file'], $copyto));
             if (!OS_WINDOWS) {
                 $mode = 0666 & ~(int) octdec($this->config->get('umask'));
                 $this->addFileOperation('chmod', array($mode, $copyto));
                 if (!@chmod($copyto, $mode)) {
                     $this->log(0, "failed to change mode of {$copyto} ({$php_errormsg})");
                 }
             }
         }
         $data = array('role' => $role, 'name' => $bn, 'installed_as' => $dest, 'php_api' => $ext['php_api'], 'zend_mod_api' => $ext['zend_mod_api'], 'zend_ext_api' => $ext['zend_ext_api']);
         if ($filelist->getPackageXmlVersion() == '1.0') {
             $filelist->installedFile($bn, $data);
         } else {
             $filelist->installedFile($bn, array('attribs' => $data));
         }
     }
 }
コード例 #4
0
ファイル: Installer.php プロジェクト: radicaldesigns/amp
 /**
  * Installs the files within the package file specified.
  *
  * @param string $pkgfile path to the package file
  * @param array $options
  * recognized options:
  * - installroot   : optional prefix directory for installation
  * - force         : force installation
  * - register-only : update registry but don't install files
  * - upgrade       : upgrade existing install
  * - soft          : fail silently
  * - nodeps        : ignore dependency conflicts/missing dependencies
  * - alldeps       : install all dependencies
  * - onlyreqdeps   : install only required dependencies
  *
  * @return array|PEAR_Error package info if successful
  */
 function install($pkgfile, $options = array())
 {
     $php_dir = $this->config->get('php_dir');
     if (isset($options['installroot'])) {
         if (substr($options['installroot'], -1) == DIRECTORY_SEPARATOR) {
             $options['installroot'] = substr($options['installroot'], 0, -1);
         }
         $php_dir = $this->_prependPath($php_dir, $options['installroot']);
         $this->installroot = $options['installroot'];
     } else {
         $this->installroot = '';
     }
     $this->registry = new PEAR_Registry($php_dir);
     //  ==> XXX should be removed later on
     $flag_old_format = false;
     if (substr($pkgfile, -4) == '.xml') {
         $descfile = $pkgfile;
     } else {
         // {{{ Decompress pack in tmp dir -------------------------------------
         // To allow relative package file names
         $pkgfile = realpath($pkgfile);
         if (PEAR::isError($tmpdir = System::mktemp('-d'))) {
             return $tmpdir;
         }
         $this->log(3, '+ tmp dir created at ' . $tmpdir);
         $tar = new Archive_Tar($pkgfile);
         if (!@$tar->extract($tmpdir)) {
             return $this->raiseError("unable to unpack {$pkgfile}");
         }
         // {{{ Look for existing package file
         $descfile = $tmpdir . DIRECTORY_SEPARATOR . 'package.xml';
         if (!is_file($descfile)) {
             // ----- Look for old package archive format
             // In this format the package.xml file was inside the
             // Package-n.n directory
             $dp = opendir($tmpdir);
             do {
                 $pkgdir = readdir($dp);
             } while ($pkgdir[0] == '.');
             $descfile = $tmpdir . DIRECTORY_SEPARATOR . $pkgdir . DIRECTORY_SEPARATOR . 'package.xml';
             $flag_old_format = true;
             $this->log(0, "warning : you are using an archive with an old format");
         }
         // }}}
         // <== XXX This part should be removed later on
         // }}}
     }
     if (!is_file($descfile)) {
         return $this->raiseError("no package.xml file after extracting the archive");
     }
     // Parse xml file -----------------------------------------------
     $pkginfo = $this->infoFromDescriptionFile($descfile);
     if (PEAR::isError($pkginfo)) {
         return $pkginfo;
     }
     $this->validatePackageInfo($pkginfo, $errors, $warnings);
     // XXX We allow warnings, do we have to do it?
     if (count($errors)) {
         if (empty($options['force'])) {
             return $this->raiseError("The following errors where found (use force option to install anyway):\n" . implode("\n", $errors));
         } else {
             $this->log(0, "warning : the following errors were found:\n" . implode("\n", $errors));
         }
     }
     $pkgname = $pkginfo['package'];
     // {{{ Check dependencies -------------------------------------------
     if (isset($pkginfo['release_deps']) && empty($options['nodeps'])) {
         $dep_errors = '';
         $error = $this->checkDeps($pkginfo, $dep_errors);
         if ($error == true) {
             if (empty($options['soft'])) {
                 $this->log(0, substr($dep_errors, 1));
             }
             return $this->raiseError("{$pkgname}: Dependencies failed");
         } else {
             if (!empty($dep_errors)) {
                 // Print optional dependencies
                 if (empty($options['soft'])) {
                     $this->log(0, $dep_errors);
                 }
             }
         }
     }
     // }}}
     // {{{ checks to do when not in "force" mode
     if (empty($options['force'])) {
         $test = $this->registry->checkFileMap($pkginfo);
         if (sizeof($test)) {
             $tmp = $test;
             foreach ($tmp as $file => $pkg) {
                 if ($pkg == $pkgname) {
                     unset($test[$file]);
                 }
             }
             if (sizeof($test)) {
                 $msg = "{$pkgname}: conflicting files found:\n";
                 $longest = max(array_map("strlen", array_keys($test)));
                 $fmt = "%{$longest}s (%s)\n";
                 foreach ($test as $file => $pkg) {
                     $msg .= sprintf($fmt, $file, $pkg);
                 }
                 return $this->raiseError($msg);
             }
         }
     }
     // }}}
     $this->startFileTransaction();
     if (empty($options['upgrade'])) {
         // checks to do only when installing new packages
         if (empty($options['force']) && $this->registry->packageExists($pkgname)) {
             return $this->raiseError("{$pkgname} already installed");
         }
     } else {
         if ($this->registry->packageExists($pkgname)) {
             $v1 = $this->registry->packageInfo($pkgname, 'version');
             $v2 = $pkginfo['version'];
             $cmp = version_compare("{$v1}", "{$v2}", 'gt');
             if (empty($options['force']) && !version_compare("{$v2}", "{$v1}", 'gt')) {
                 return $this->raiseError("upgrade to a newer version ({$v2} is not newer than {$v1})");
             }
             if (empty($options['register-only'])) {
                 // when upgrading, remove old release's files first:
                 if (PEAR::isError($err = $this->_deletePackageFiles($pkgname))) {
                     return $this->raiseError($err);
                 }
             }
         }
     }
     // {{{ Copy files to dest dir ---------------------------------------
     // info from the package it self we want to access from _installFile
     $this->pkginfo =& $pkginfo;
     // used to determine whether we should build any C code
     $this->source_files = 0;
     if (empty($options['register-only'])) {
         if (!is_dir($php_dir)) {
             return $this->raiseError("no script destination directory\n", null, PEAR_ERROR_DIE);
         }
         $tmp_path = dirname($descfile);
         if (substr($pkgfile, -4) != '.xml') {
             $tmp_path .= DIRECTORY_SEPARATOR . $pkgname . '-' . $pkginfo['version'];
         }
         //  ==> XXX This part should be removed later on
         if ($flag_old_format) {
             $tmp_path = dirname($descfile);
         }
         // <== XXX This part should be removed later on
         // {{{ install files
         foreach ($pkginfo['filelist'] as $file => $atts) {
             $this->expectError(PEAR_INSTALLER_FAILED);
             $res = $this->_installFile($file, $atts, $tmp_path, $options);
             $this->popExpect();
             if (PEAR::isError($res)) {
                 if (empty($options['ignore-errors'])) {
                     $this->rollbackFileTransaction();
                     if ($res->getMessage() == "file does not exist") {
                         $this->raiseError("file {$file} in package.xml does not exist");
                     }
                     return $this->raiseError($res);
                 } else {
                     $this->log(0, "Warning: " . $res->getMessage());
                 }
             }
             if ($res != PEAR_INSTALLER_OK) {
                 // Do not register files that were not installed
                 unset($pkginfo['filelist'][$file]);
             }
         }
         // }}}
         // {{{ compile and install source files
         if ($this->source_files > 0 && empty($options['nobuild'])) {
             $this->log(1, "{$this->source_files} source files, building");
             $bob = new PEAR_Builder($this->ui);
             $bob->debug = $this->debug;
             $built = $bob->build($descfile, array(&$this, '_buildCallback'));
             if (PEAR::isError($built)) {
                 $this->rollbackFileTransaction();
                 return $built;
             }
             $this->log(1, "\nBuild process completed successfully");
             foreach ($built as $ext) {
                 $bn = basename($ext['file']);
                 list($_ext_name, ) = explode('.', $bn);
                 if (extension_loaded($_ext_name)) {
                     $this->raiseError("Extension '{$_ext_name}' already loaded. Please unload it " . "in your php.ini file prior to install or upgrade it.");
                 }
                 // extension dir must be created if it doesn't exist
                 // patch by Tomas Cox (modified by Greg Beaver)
                 $ext_dir = $this->config->get('ext_dir');
                 if (!@is_dir($ext_dir) && !System::mkdir(array('-p', $ext_dir))) {
                     $this->log(3, "+ mkdir -p {$ext_dir}");
                     return $this->raiseError("failed to create extension dir '{$ext_dir}'");
                 }
                 $dest = $ext_dir . DIRECTORY_SEPARATOR . $bn;
                 $this->log(1, "Installing '{$bn}' at ext_dir ({$dest})");
                 $this->log(3, "+ cp {$ext['file']} ext_dir ({$dest})");
                 $copyto = $this->_prependPath($dest, $this->installroot);
                 if (!@copy($ext['file'], $copyto)) {
                     $this->rollbackFileTransaction();
                     return $this->raiseError("failed to copy {$bn} to {$copyto}");
                 }
                 $pkginfo['filelist'][$bn] = array('role' => 'ext', 'installed_as' => $dest, 'php_api' => $ext['php_api'], 'zend_mod_api' => $ext['zend_mod_api'], 'zend_ext_api' => $ext['zend_ext_api']);
             }
         }
         // }}}
     }
     if (!$this->commitFileTransaction()) {
         $this->rollbackFileTransaction();
         return $this->raiseError("commit failed", PEAR_INSTALLER_FAILED);
     }
     // }}}
     $ret = false;
     // {{{ Register that the package is installed -----------------------
     if (empty($options['upgrade'])) {
         // if 'force' is used, replace the info in registry
         if (!empty($options['force']) && $this->registry->packageExists($pkgname)) {
             $this->registry->deletePackage($pkgname);
         }
         $ret = $this->registry->addPackage($pkgname, $pkginfo);
     } else {
         // new: upgrade installs a package if it isn't installed
         if (!$this->registry->packageExists($pkgname)) {
             $ret = $this->registry->addPackage($pkgname, $pkginfo);
         } else {
             $ret = $this->registry->updatePackage($pkgname, $pkginfo, false);
         }
     }
     if (!$ret) {
         return $this->raiseError("Adding package {$pkgname} to registry failed");
     }
     // }}}
     return $pkginfo;
 }