protected function process($url, $targetFilePath) { $this->logger->info('downloading via curl command'); //todo proxy setting $silent = $this->logger->isQuiet() ? '--silent ' : ''; $command = array('curl'); if ($proxy = $this->options->{'http-proxy'}) { $this->logger->warn('http proxy is not support by this download.'); } if ($proxyAuth = $this->options->{'http-proxy-auth'}) { $this->logger->warn('http proxy is not support by this download.'); } if ($this->enableContinueAt || $this->options->{'continue'}) { $command[] = '-C -'; } $command[] = '-L'; if ($this->logger->isQuiet()) { $command[] = '--silent'; } $command[] = '-o'; $command[] = escapeshellarg($targetFilePath); $command[] = escapeshellarg($url); $cmd = implode(' ', $command); $this->logger->debug($cmd); Utils::system($cmd); return true; }
public function install(Extension $ext, array $configureOptions = array()) { $sourceDir = $ext->getSourceDirectory(); $pwd = getcwd(); $buildLogPath = $sourceDir . DIRECTORY_SEPARATOR . 'build.log'; $make = new MakeTask($this->logger, $this->options); $make->setBuildLogPath($buildLogPath); $this->logger->info("Log stored at: {$buildLogPath}"); $this->logger->info("Changing directory to {$sourceDir}"); chdir($sourceDir); if (!$this->options->{'no-clean'} && $ext->isBuildable()) { $clean = new MakeTask($this->logger, $this->options); $clean->setQuiet(); $clean->clean($ext); } if ($ext->getConfigM4File() !== "config.m4" && !file_exists($sourceDir . DIRECTORY_SEPARATOR . 'config.m4')) { symlink($ext->getConfigM4File(), $sourceDir . DIRECTORY_SEPARATOR . 'config.m4'); } // If the php version is specified, we should get phpize with the correct version. $this->logger->info('===> Phpize...'); Utils::system("phpize > {$buildLogPath} 2>&1", $this->logger); // here we don't want to use closure, because // 5.2 does not support closure. We haven't decided whether to // support 5.2 yet. $escapeOptions = array_map('escapeshellarg', $configureOptions); $this->logger->info("===> Configuring..."); $phpConfig = Config::getCurrentPhpConfigBin(); if (file_exists($phpConfig)) { $this->logger->debug("Appending argument: --with-php-config={$phpConfig}"); $escapeOptions[] = '--with-php-config=' . $phpConfig; } // Utils::system('./configure ' . join(' ', $escapeOptions) . ' >> build.log 2>&1'); $cmd = './configure ' . join(' ', $escapeOptions); if (!$this->logger->isDebug()) { $cmd .= " >> {$buildLogPath} 2>&1"; } Utils::system($cmd, $this->logger); $this->logger->info("===> Building..."); if ($this->logger->isDebug()) { passthru('make'); } else { $make->run($ext); } $this->logger->info("===> Installing..."); // This function is disabled when PHP is running in safe mode. if ($this->logger->isDebug()) { passthru('make install'); } else { $make->install($ext); } // TODO: use getSharedLibraryPath() $this->logger->debug("Installed extension library: " . $ext->getSharedLibraryPath()); // Try to find the installed path by pattern // Installing shared extensions: /Users/c9s/.phpbrew/php/php-5.4.10/lib/php/extensions/debug-non-zts-20100525/ chdir($pwd); $this->logger->info("===> Extension is installed."); }
public function purgeExtension(Extension $ext) { if ($sourceDir = $ext->getSourceDirectory()) { $currentPhpExtensionDirectory = Config::getBuildDir() . '/' . Config::getCurrentPhpName() . '/ext'; $extName = $ext->getExtensionName(); $extensionDir = $currentPhpExtensionDirectory . DIRECTORY_SEPARATOR . $extName; if (file_exists($extensionDir)) { Utils::system("rm -rvf {$extensionDir}"); } } }
private function make($path, $target = 'all') { if (!file_exists($path . DIRECTORY_SEPARATOR . 'Makefile')) { $this->logger->error("Makefile not found in path {$path}"); return false; } $cmd = array("make", "-C", $path, $this->isQuiet() ? "--quiet" : "", $target); if (!$this->logger->isDebug() && $this->buildLogPath) { $cmd[] = " >> {$this->buildLogPath} 2>&1"; } $this->logger->info("===> Running make {$target}: " . join(' ', $cmd)); $ret = Utils::system($cmd, $this->logger); return $ret == 0; }
/** * @param string $url * * @return bool|string * * @throws \RuntimeException */ protected function process($url, $targetFilePath) { $this->logger->info("Downloading {$url} via wget command"); $proxy = ''; if (!empty($this->options->{'http-proxy'})) { if (!empty($this->options->{'http-proxy-auth'})) { $proxy = sprintf('-e use_proxy=on -e http_proxy=%s', $this->options->{'http-proxy'}); } else { $proxy = sprintf('-e use_proxy=on -e http_proxy=%s@%s', $this->options->{'http-proxy-auth'}, $this->options->{'http-proxy'}); } } $quiet = $this->logger->isQuiet() ? '--quiet' : ''; $continue = $this->enableContinueAt || $this->options->{'continue'} ? '-c' : ''; Utils::system(sprintf('wget --no-check-certificate %s %s %s -N -O %s %s', $continue, $quiet, $proxy, escapeshellarg($targetFilePath), escapeshellarg($url))); return true; }
/** * @param string $url * * @return bool|string * * @throws \RuntimeException */ public function download($url, $targetFilePath) { $this->logger->info("===> Downloading from {$url}"); if ($this->isCurlExtensionAvailable()) { $this->logger->debug('---> Found curl extension, using CurlDownloader'); $downloader = new CurlDownloader(); $seconds = $this->options->{'connect-timeout'}; if ($seconds || ($seconds = getenv('CONNECT_TIMEOUT'))) { $downloader->setConnectionTimeout($seconds); } if ($proxy = $this->options->{'http-proxy'}) { $downloader->setProxy($proxy); } if ($proxyAuth = $this->options->{'http-proxy-auth'}) { $downloader->setProxyAuth($proxyAuth); } // TODO: Get current instance instead of singleton to improve testing output $console = Console::getInstance(); if (!$console->options->{'no-progress'} && $this->logger->getLevel() > 2) { $downloader->setProgressHandler(new ProgressBar()); } $binary = $downloader->request($url); if (false === file_put_contents($targetFilePath, $binary)) { throw new RuntimeException("Can't write file {$targetFilePath}"); } } else { $this->logger->debug('Curl extension not found, fallback to wget or curl'); // check for wget or curl for downloading the php source archive if ($this->isWgetCommandAvailable()) { $quiet = $this->logger->isQuiet() ? '--quiet' : ''; Utils::system("wget --no-check-certificate -c {$quiet} -O" . $targetFilePath . ' ' . $url); } elseif ($this->isCurlCommandAvailable()) { $silent = $this->logger->isQuiet() ? '--silent ' : ''; Utils::system("curl -C - -L {$silent} -o" . $targetFilePath . ' ' . $url); } else { throw new RuntimeException("Download failed - neither wget nor curl was found"); } } // Verify the downloaded file. if (!file_exists($targetFilePath)) { throw new RuntimeException("Download failed."); } $this->logger->info("===> {$targetFilePath} downloaded."); return $targetFilePath; // return the filename }
public function patch($build, $options) { $this->logger->info('===> Applying patch - apxs2 module version name ...'); if ($options->dryrun) { return; } // patch for libphp$(PHP_MAJOR_VERSION).so $patch = <<<'EOS' perl -i.bak -pe 's# libphp\$\(PHP_MAJOR_VERSION\)\.#libphp\$\(PHP_VERSION\)\.#gx' configure Makefile.global EOS; Utils::system($patch) !== false or die('apxs2 patch failed.'); $patch = <<<'EOS' perl -i.bak -pe 's# libs/libphp\$PHP_MAJOR_VERSION\. #libs/libphp\$PHP_VERSION\.#gx' configure Makefile.global EOS; Utils::system($patch) !== false or die('apxs2 patch failed.'); // replace .so files $patch = <<<'EOS' perl -i.bak -pe 's# libs/libphp5.so #libs/libphp\$PHP_VERSION\.so#gx' configure Makefile.global EOS; Utils::system($patch) !== false or die('apxs2 patch failed.'); // patch for OVERALL_TARGET=libphp$PHP_MAJOR_VERSION.la // libphp$(PHP_VERSION).la: // replace .la files $patch = <<<'EOS' perl -i.bak -pe 's# libs/libphp5.la #libs/libphp\$PHP_VERSION\.la#gx' configure Makefile.global EOS; Utils::system($patch) !== false or die('apxs2 patch failed.'); $patch = <<<'EOS' perl -i.bak -pe 's# libphp\$PHP_MAJOR_VERSION\.#libphp\$PHP_VERSION\.#gx' configure Makefile.global EOS; Utils::system($patch) !== false or die('apxs2 patch failed.'); }
/** * @param Buildable $build can be PeclExtension or Build object. */ private function make($path, $target = 'all', $build = null) { if (!file_exists($path . DIRECTORY_SEPARATOR . 'Makefile')) { $this->logger->error("Makefile not found in path {$path}"); return false; } // FreeBSD make doesn't support --quiet option // We should prefer GNU make instead of BSD make. // @see https://github.com/phpbrew/phpbrew/issues/529 $gmake = Utils::findBin('gmake'); $make = null; if (!$gmake) { $make = Utils::findBin('make'); if ($make && $this->isGNUMake($make)) { $gmake = $make; } } // Prefer 'gmake' rather than 'make' $cmd = array($gmake ?: $make, '-C', escapeshellarg($path)); if ($this->isQuiet()) { if ($gmake) { $cmd[] = '--quiet'; } else { // make may be a link to gmake, we should prevent that. // append '-Q' only when we're really sure it is BSD make. if (php_uname('s') === 'FreeBSD') { $cmd[] = '-Q'; } } } $cmd[] = escapeshellarg($target); if (!$this->logger->isDebug() && $this->buildLogPath) { $cmd[] = ' >> ' . escapeshellarg($this->buildLogPath) . ' 2>&1'; } $this->logger->info("===> Running make {$target}: " . implode(' ', $cmd)); return Utils::system($cmd, $this->logger, $build) === 0; }
protected function detectBitness() { return intval(Utils::system('getconf LONG_BIT')); }
public function renameSourceDirectory(Extension $ext) { $currentPhpExtensionDirectory = Config::getBuildDir() . '/' . Config::getCurrentPhpName() . '/ext'; $extName = $ext->getExtensionName(); $name = $ext->getName(); $extensionDir = $currentPhpExtensionDirectory . DIRECTORY_SEPARATOR . $extName; $extensionExtractDir = $currentPhpExtensionDirectory . DIRECTORY_SEPARATOR . $name; if ($name != $extName) { $this->logger->info("===> Rename source directory to {$extensionDir}..."); $cmds = array("rm -rf {$extensionDir}", "mv {$extensionExtractDir} {$extensionDir}"); foreach ($cmds as $cmd) { $this->logger->debug($cmd); Utils::system($cmd); } // replace source directory to new source directory $sourceDir = str_replace($extensionExtractDir, $extensionDir, $ext->getSourceDirectory()); $ext->setSourceDirectory($sourceDir); $ext->setName($extName); } }
public function getOSVersion() { return Utils::system('sw_vers -productVersion'); }
public function runInstall($packageName, $dir, $configureOptions) { $this->logger->info("===> Phpizing..."); $directoryIterator = new \RecursiveDirectoryIterator($dir); $it = new \RecursiveIteratorIterator($directoryIterator); $extDir = array(); // search for config.m4 or config0.m4 and use them to determine // the directory of the extension's source, because it's not always // the root directory in the ext archive (example xhprof) foreach ($it as $file) { if (basename($file) == 'config.m4') { $extDir['config.m4'] = dirname(realpath($file)); break; } if (basename($file) == 'config0.m4') { $extDir['config0.m4'] = dirname(realpath($file)); } } if (isset($extDir['config.m4'])) { $sw = new DirectorySwitch(); $sw->cd($extDir['config.m4']); } elseif (isset($extDir['config0.m4'])) { $this->logger->warn("File config.m4 not found"); $this->logger->info("Found config.0.m4, copying to config.m4"); $sw = new DirectorySwitch(); $sw->cd($extDir['config0.m4']); if (false === copy('config0.m4', 'config.m4')) { throw new \Exception("Copy failed."); } } else { throw new \Exception('Neither config.m4 nor config0.m4 was found'); } Utils::system('phpize > build.log'); // here we don't want to use closure, because // 5.2 does not support closure. We haven't decided whether to // support 5.2 yet. $escapeOptions = array(); foreach ($configureOptions as $opt) { $escapeOptions[] = escapeshellarg($opt); } $this->logger->info("===> Configuring..."); Utils::system('./configure ' . join(' ', $escapeOptions) . ' >> build.log') !== false or die('Configure failed.'); $this->logger->info("===> Building..."); Utils::system('make >> build.log'); $this->logger->info("===> Installing..."); // This function is disabled when PHP is running in safe mode. $output = shell_exec('make install'); if (!$output) { throw new \Exception("Extension Install Failed."); } $this->logger->debug($output); $installedPath = null; if (preg_match('#Installing shared extensions:\\s+(\\S+)#', $output, $regs)) { $installedPath = $regs[1]; } $installedPath .= strtolower($packageName) . '.so'; $this->logger->debug("Installed extension: " . $installedPath); // Try to find the installed path by pattern // Installing shared extensions: /Users/c9s/.phpbrew/php/php-5.4.10/lib/php/extensions/debug-non-zts-20100525/ $sw->back(); $this->logger->info("===> Extension is installed."); return $dir . '/package.xml'; }