public function testPatch() { if (PHP_OS !== "Darwin") { return $this->markTestSkipped('openssl DSO patch test only runs on darwin platform'); } $logger = new Logger(); $logger->setQuiet(); $fromVersion = '5.5.17'; $sourceFixtureDirectory = getenv('PHPBREW_FIXTURES_PHP_DIR') . DIRECTORY_SEPARATOR . $fromVersion; $sourceDirectory = getenv('PHPBREW_BUILD_PHP_DIR'); $this->setupBuildDirectory($fromVersion); $build = new Build($fromVersion); $build->setSourceDirectory($sourceDirectory); $build->enableVariant('openssl'); $this->assertTrue($build->hasVariant('openssl'), 'openssl enabled'); $patch = new OpenSSLDSOPatch(); $matched = $patch->match($build, $logger); $this->assertTrue($matched, 'patch matched'); $patchedCount = $patch->apply($build, $logger); $this->assertEquals(10, $patchedCount); /* We can't assume the file equals because the test may be run on different platform and openssl may be installed into different locations. $sourceExpectedDirectory = getenv('PHPBREW_EXPECTED_PHP_DIR') . DIRECTORY_SEPARATOR . '5.5.17-openssl-dso-patch'; $this->assertFileEquals($sourceExpectedDirectory. '/Makefile', $sourceDirectory . '/Makefile'); */ }
public function testPatch() { $logger = new Logger(); $logger->setQuiet(); $fromVersion = '5.3.29'; $sourceFixtureDirectory = getenv('PHPBREW_FIXTURES_PHP_DIR') . DIRECTORY_SEPARATOR . $fromVersion; $sourceDirectory = getenv('PHPBREW_BUILD_PHP_DIR'); if (!is_dir($sourceDirectory)) { return $this->markTestSkipped("{$sourceDirectory} does not exist."); } // Copy the source Makefile to the Makefile // copy($sourceFixtureDirectory . '/Makefile', $sourceDirectory . '/Makefile'); $this->setupBuildDirectory($fromVersion); $build = new Build($fromVersion); $build->setSourceDirectory($sourceDirectory); $build->enableVariant('intl'); $this->assertTrue($build->hasVariant('intl'), 'intl enabled'); $patch = new IntlWith64bitPatch(); $matched = $patch->match($build, $logger); $this->assertTrue($matched, 'patch matched'); $patchedCount = $patch->apply($build, $logger); $this->assertEquals(3, $patchedCount); $sourceExpectedDirectory = getenv('PHPBREW_EXPECTED_PHP_DIR') . DIRECTORY_SEPARATOR . $fromVersion; $this->assertFileEquals($sourceExpectedDirectory . '/Makefile', $sourceDirectory . '/Makefile'); }
public function testApply() { $version = '5.3.29'; $fixture = new TemporaryFileFixture($this, getenv('PHPBREW_FIXTURES_PHP_DIR') . "/{$version}/Makefile.in"); $fixture->withFile('Makefile', function ($self, $fixturePath) use($version) { $build = new Build($version); $build->setSourceDirectory(dirname($fixturePath)); $patch = new RegexpPatch($self->logger, $build, array(basename($fixturePath)), array(RegexpPatchRule::always('/LIBTOOL/', ''))); $patch->apply(); $self->assertFileEquals($fixturePath, getenv('PHPBREW_EXPECTED_PHP_DIR') . '/5.3.29/Makefile.in'); }); }
public function execute($version) { $buildDir = Config::getBuildDir() . DIRECTORY_SEPARATOR . $version; if ($this->options->all) { if (!file_exists($buildDir)) { $this->logger->info("Source directory " . $buildDir . " does not exist."); } else { $this->logger->info("Source directory " . $buildDir . " found, deleting..."); Utils::recursive_unlink($buildDir, $this->logger); } } else { $make = new MakeTask($this->logger); $make->setQuiet(); $build = new Build($version); $build->setSourceDirectory($buildDir); if ($make->clean($build)) { $this->logger->info("Distribution is cleaned up. Woof! "); } } }
public function testPatch() { $logger = new Logger(); $logger->setQuiet(); $fromVersion = '5.5.17'; $sourceFixtureDirectory = getenv('PHPBREW_FIXTURES_PHP_DIR') . DIRECTORY_SEPARATOR . $fromVersion; $sourceDirectory = getenv('PHPBREW_BUILD_PHP_DIR'); if (!is_dir($sourceDirectory)) { return $this->markTestSkipped("{$sourceDirectory} does not exist."); } $this->setupBuildDirectory($fromVersion); $build = new Build($fromVersion); $build->setSourceDirectory($sourceDirectory); $build->enableVariant('apxs2'); $this->assertTrue($build->hasVariant('apxs2'), 'apxs2 enabled'); $patch = new Apache2ModuleNamePatch(); $matched = $patch->match($build, $logger); $this->assertTrue($matched, 'patch matched'); $patchedCount = $patch->apply($build, $logger); $this->assertEquals(107, $patchedCount); $sourceExpectedDirectory = getenv('PHPBREW_EXPECTED_PHP_DIR') . DIRECTORY_SEPARATOR . '5.5.17-apxs-patch'; $this->assertFileEquals($sourceExpectedDirectory . '/Makefile.global', $sourceDirectory . '/Makefile.global'); $this->assertFileEquals($sourceExpectedDirectory . '/configure', $sourceDirectory . '/configure'); }
public function execute($version) { if (!preg_match('/^php-/', $version)) { $version = 'php-' . $version; } $version = $this->getLatestMinorVersion($version, $this->options->old); $options = $this->options; $logger = $this->logger; // get options and variants for building php $args = func_get_args(); // the first argument is the target version. array_shift($args); $name = $this->options->name ?: $version; // find inherited variants $inheritedVariants = array(); if ($this->options->like) { $inheritedVariants = VariantParser::getInheritedVariants($this->options->like); } // ['extra_options'] => the extra options to be passed to ./configure command // ['enabled_variants'] => enabeld variants // ['disabled_variants'] => disabled variants $variantInfo = VariantParser::parseCommandArguments($args, $inheritedVariants); $info = PhpSource::getVersionInfo($version, $this->options->old); if (!$info) { throw new Exception("Version {$version} not found."); } $prepare = new PrepareDirectoryTask($this->logger); $prepare->prepareForVersion($version); // convert patch to realpath if ($this->options->patch) { $patchPaths = array(); foreach ($this->options->patch as $patch) { /** @var \SplFileInfo $patch */ $patchPath = realpath($patch); if ($patchPath !== false) { $patchPaths[(string) $patch] = $patchPath; } } // rewrite patch paths $this->options->keys['patch']->value = $patchPaths; } // Move to to build directory, because we are going to download distribution. $buildDir = Config::getBuildDir(); chdir($buildDir); $download = new DownloadTask($this->logger); $targetDir = $download->downloadByVersionString($version, $this->options->old, $this->options->force); if (!file_exists($targetDir)) { throw new Exception("Download failed."); } // Change directory to the downloaded source directory. chdir($targetDir); $buildPrefix = Config::getVersionBuildPrefix($version); if (!file_exists($buildPrefix)) { mkdir($buildPrefix, 0755, true); } // write variants info. $variantInfoFile = $buildPrefix . DIRECTORY_SEPARATOR . 'phpbrew.variants'; $this->logger->debug("Writing variant info to {$variantInfoFile}"); file_put_contents($variantInfoFile, serialize($variantInfo)); // The build object, contains the information to build php. $build = new Build($version, $name, $buildPrefix); $build->setInstallPrefix($buildPrefix); $build->setSourceDirectory($targetDir); $builder = new Builder($targetDir, $version); $builder->logger = $this->logger; $builder->options = $this->options; $this->logger->debug('Build Directory: ' . realpath($targetDir)); foreach ($variantInfo['enabled_variants'] as $name => $value) { $build->enableVariant($name, $value); } foreach ($variantInfo['disabled_variants'] as $name => $value) { $build->disableVariant($name); if ($build->hasVariant($name)) { $this->logger->warn("Removing variant {$name} since we've disabled it from command."); $build->removeVariant($name); } } $build->setExtraOptions($variantInfo['extra_options']); if ($options->clean) { $clean = new CleanTask($this->logger); $clean->cleanByVersion($version); } $buildLogFile = Config::getVersionBuildLogPath($version); $configure = new \PhpBrew\Tasks\ConfigureTask($this->logger); $configure->configure($build, $this->options); $buildTask = new BuildTask($this->logger); $buildTask->setLogPath($buildLogFile); $buildTask->build($build, $this->options); if ($options->{'test'}) { $test = new TestTask($this->logger); $test->setLogPath($buildLogFile); $test->test($build, $this->options); } $install = new InstallTask($this->logger); $install->setLogPath($buildLogFile); $install->install($build, $this->options); if ($options->{'post-clean'}) { $clean = new CleanTask($this->logger); $clean->cleanByVersion($version); } /** POST INSTALLATION **/ $dsym = new DSymTask($this->logger); $dsym->patch($build, $this->options); // copy php-fpm config $this->logger->info("---> Creating php-fpm.conf"); $phpFpmConfigPath = "sapi/fpm/php-fpm.conf"; $phpFpmTargetConfigPath = Config::getVersionEtcPath($version) . DIRECTORY_SEPARATOR . 'php-fpm.conf'; if (file_exists($phpFpmConfigPath)) { if (!file_exists($phpFpmTargetConfigPath)) { copy($phpFpmConfigPath, $phpFpmTargetConfigPath); } else { $this->logger->notice("Found existing {$phpFpmTargetConfigPath}."); } } $phpConfigPath = $options->production ? 'php.ini-production' : 'php.ini-development'; $this->logger->info("---> Copying {$phpConfigPath} "); if (file_exists($phpConfigPath)) { $targetConfigPath = Config::getVersionEtcPath($version) . DIRECTORY_SEPARATOR . 'php.ini'; if (file_exists($targetConfigPath)) { $this->logger->notice("Found existing {$targetConfigPath}."); } else { // TODO: Move this to PhpConfigPatchTask // move config file to target location copy($phpConfigPath, $targetConfigPath); // replace current timezone $timezone = ini_get('date.timezone'); $pharReadonly = ini_get('phar.readonly'); if ($timezone || $pharReadonly) { // patch default config $content = file_get_contents($targetConfigPath); if ($timezone) { $this->logger->info("---> Found date.timezone, patch config timezone with {$timezone}"); $content = preg_replace('/^date.timezone\\s*=\\s*.*/im', "date.timezone = {$timezone}", $content); } if (!$pharReadonly) { $this->logger->info("---> Disable phar.readonly option."); $content = preg_replace('/^phar.readonly\\s*=\\s*.*/im', "phar.readonly = 0", $content); } file_put_contents($targetConfigPath, $content); } } } $this->logger->info("Initializing pear config..."); $home = Config::getPhpbrewHome(); @mkdir("{$home}/tmp/pear/temp", 0755, true); @mkdir("{$home}/tmp/pear/cache_dir", 0755, true); @mkdir("{$home}/tmp/pear/download_dir", 0755, true); system("pear config-set temp_dir {$home}/tmp/pear/temp"); system("pear config-set cache_dir {$home}/tmp/pear/cache_dir"); system("pear config-set download_dir {$home}/tmp/pear/download_dir"); $this->logger->info("Enabling pear auto-discover..."); system("pear config-set auto_discover 1"); $this->logger->debug("Source directory: " . $targetDir); $this->logger->info("Congratulations! Now you have PHP with {$version}."); echo <<<EOT To use the newly built PHP, try the line(s) below: \$ phpbrew use {$version} Or you can use switch command to switch your default php version to {$version}: \$ phpbrew switch {$version} Enjoy! EOT; }