public function run(Build $build, $targets = array()) { if ($build->getState() >= Build::STATE_BUILD) { $this->info("===> Already built, skipping..."); return; } $this->info("===> Building..."); $cmd = new CommandBuilder('make'); $cmd->setAppendLog(true); $cmd->setLogPath($build->getBuildLogPath()); $cmd->setStdout($this->options->{'stdout'}); if (!empty($targets)) { foreach ($targets as $t) { $cmd->addArg($t); } } if ($this->options->nice) { $cmd->nice($this->options->nice); } if ($makeJobs = $this->options->{'jobs'}) { $cmd->addArg("-j{$makeJobs}"); } $this->debug($cmd->getCommand()); if (!$this->options->dryrun) { $startTime = microtime(true); $code = $cmd->execute(); if ($code != 0) { throw new SystemCommandException('Make failed.', $build, $build->getBuildLogPath()); } $buildTime = round((microtime(true) - $startTime) / 60, 1); $this->info("Build finished: {$buildTime} minutes."); } $build->setState(Build::STATE_BUILD); }
public function install(Build $build) { $this->info('Installing...'); if ($this->options->sudo) { $cmd = new CommandBuilder('sudo make install'); if (!$this->options->dryrun) { $code = $cmd->passthru($lastline); if ($code !== 0) { throw new SystemCommandException("Install failed: {$lastline}", $build, $build->getBuildLogPath()); } } } else { $cmd = new CommandBuilder('make install'); $cmd->setAppendLog(true); $cmd->setLogPath($build->getBuildLogPath()); $cmd->setStdout($this->options->{'stdout'}); if (!$this->options->dryrun) { $code = $cmd->execute($lastline); if ($code !== 0) { throw new SystemCommandException("Install failed: {$lastline}", $build, $build->getBuildLogPath()); } } } $build->setState(Build::STATE_INSTALL); }
/** * Unpacks the source tarball file. * * @param string $targetFilePath absolute file path * @param string $extractDir (the build dir) */ public function extract(Build $build, $targetFilePath, $extractDir = null) { if (empty($extractDir)) { $extractDir = dirname($targetFilePath); } $extractDirTemp = $extractDir . DIRECTORY_SEPARATOR . 'tmp.' . time(); if (!file_exists($extractDirTemp)) { mkdir($extractDirTemp, 0755, true); } // This converts: '/opt/phpbrew/distfiles/php-7.0.2.tar.bz2' // to just '/opt/phpbrew/tmp/distfiles/php-7.0.2' $distBasename = preg_replace('#\\.tar\\.(gz|bz2)$#', '', basename($targetFilePath)); $extractedDirTemp = $extractDirTemp . DIRECTORY_SEPARATOR . $distBasename; $extractedDir = $extractDir . DIRECTORY_SEPARATOR . $build->getName(); if ($build->getState() >= Build::STATE_EXTRACT && file_exists($extractedDir . DIRECTORY_SEPARATOR . 'configure')) { $this->info('===> Distribution file was successfully extracted, skipping...'); return $extractedDir; } // NOTICE: Always extract to tmp directory prevent incomplete extraction $this->info("===> Extracting {$targetFilePath} to {$extractedDirTemp}"); $lastline = system('tar -C ' . escapeshellarg($extractDirTemp) . ' -xf ' . escapeshellarg($targetFilePath), $ret); if ($ret !== 0) { throw new SystemCommandException("Extract failed: {$lastline}", $build); } clearstatcache(true); if (!is_dir($extractedDirTemp)) { // retry with github extracted dir path $extractedDirTemp = $extractDirTemp . DIRECTORY_SEPARATOR . 'php-src-' . $distBasename; if (!is_dir($extractedDirTemp)) { throw new SystemCommandException("Unable to find {$extractedDirTemp}", $build); } } if (is_dir($extractedDir)) { $this->info("===> Found existing build directory, removing {$extractedDir} ..."); $lastline = system('rm -rf ' . escapeshellarg($extractedDir), $ret); if ($ret !== 0) { throw new SystemCommandException("Unable to remove {$extractedDir}: {$lastline}", $build); } } $this->info("===> Moving {$extractedDirTemp} to {$extractedDir}"); if (!rename($extractedDirTemp, $extractedDir)) { throw new SystemCommandException("Unable to move {$extractedDirTemp} to {$extractedDir}", $build); } @rmdir($extractDirTemp); $build->setState(Build::STATE_EXTRACT); return $extractedDir; /* * XXX: unless we have a fast way to verify the extraction. if ($this->options->force || ! file_exists($extractedDir . DIRECTORY_SEPARATOR . 'configure')) { $this->info("===> Extracting $targetFilePath..."); system("tar -C $dir -xjf $targetFilePath", $ret); if ($ret != 0) { die('Extract failed.'); } } else { $this->info("Found existing $extractedDir, Skip extracting."); } */ }
/** * Unpacks the source tarball file. * * @param string $targetFilePath absolute file path */ public function extract(Build $build, $targetFilePath, $extractDir = NULL) { $extractDirTemp = Config::getTempFileDir(); if (!$extractDir) { $extractDir = dirname($targetFilePath); } $extractedDirTemp = $extractDirTemp . DIRECTORY_SEPARATOR . preg_replace('#\\.tar\\.(gz|bz2)$#', '', basename($targetFilePath)); $extractedDir = $extractDir . DIRECTORY_SEPARATOR . $build->getName(); if ($build->getState() >= Build::STATE_EXTRACT && file_exists($extractedDir . DIRECTORY_SEPARATOR . 'configure')) { $this->info("===> Distribution file was successfully extracted, skipping..."); return $extractedDir; } // NOTICE: Always extract to prevent incomplete extraction $this->info("===> Extracting {$targetFilePath} to {$extractedDirTemp}"); system("tar -C {$extractDirTemp} -xf {$targetFilePath}", $ret); if ($ret != 0) { throw new RuntimeException('Extract failed.'); } clearstatcache(true); if (!is_dir($extractedDirTemp)) { // retry with github extracted dir path $extractedDirTemp = $extractDirTemp . DIRECTORY_SEPARATOR . 'php-src-' . preg_replace('#\\.tar\\.(gz|bz2)$#', '', basename($targetFilePath)); if (!is_dir($extractedDirTemp)) { throw new RuntimeException("Unable to find {$extractedDirTemp}"); } } if (is_dir($extractedDir)) { $this->info("===> Removing {$extractedDir}"); system("rm -rf {$extractedDir}", $ret); if ($ret !== 0) { throw new RuntimeException("Unable to remove {$extractedDir}."); } } $this->info("===> Moving {$extractedDirTemp} to {$extractedDir}"); if (!rename($extractedDirTemp, $extractedDir)) { throw new RuntimeException("Unable to move {$extractedDirTemp} to {$extractedDir}"); } $build->setState(Build::STATE_EXTRACT); return $extractedDir; /* * XXX: unless we have a fast way to verify the extraction. if ($this->options->force || ! file_exists($extractedDir . DIRECTORY_SEPARATOR . 'configure')) { $this->info("===> Extracting $targetFilePath..."); system("tar -C $dir -xjf $targetFilePath", $ret); if ($ret != 0) { die('Extract failed.'); } } else { $this->info("Found existing $extractedDir, Skip extracting."); } */ }
public function install(Build $build) { $this->info("Installing..."); $cmd = new CommandBuilder('make install'); $cmd->setAppendLog(true); $cmd->setLogPath($build->getBuildLogPath()); $cmd->setStdout($this->options->{'stdout'}); if (!$this->options->dryrun) { $code = $cmd->execute(); if ($code != 0) { throw new SystemCommandException('Install failed.', $build->getBuildLogPath()); } } $build->setState(Build::STATE_INSTALL); }
public function run(Build $build, $variantOptions) { $extra = $build->getExtraOptions(); $prefix = $build->getInstallPrefix(); // append cflags if ($this->optimizationLevel) { $o = $this->optimizationLevel; $cflags = getenv('CFLAGS'); putenv("CFLAGS={$cflags} -O{$o}"); $_ENV['CFLAGS'] = "{$cflags} -O{$o}"; } $args = array(); if (!$this->options->{'no-config-cache'}) { // $args[] = "-C"; // project wise cache (--config-cache) $args[] = '--cache-file=' . escapeshellarg(Config::getCacheDir() . DIRECTORY_SEPARATOR . 'config.cache'); } $args[] = '--prefix=' . $prefix; if ($this->options->{'user-config'}) { $args[] = "--with-config-file-path={$prefix}/etc"; $args[] = "--with-config-file-scan-dir={$prefix}/var/db"; } else { $args[] = "--with-config-file-path={$prefix}/etc"; $args[] = "--with-config-file-scan-dir={$prefix}/var/db"; } if ($variantOptions) { $args = array_merge($args, $variantOptions); } $this->debug('Enabled variants: [' . implode(', ', array_keys($build->getVariants())) . ']'); $this->debug('Disabled variants: [' . implode(', ', array_keys($build->getDisabledVariants())) . ']'); // todo: move to pear variant $args[] = "--with-pear={$prefix}/lib/php"; // Options for specific versions // todo: extract to BuildPlan class: PHP53 BuildPlan, PHP54 BuildPlan, PHP55 BuildPlan ? if ($build->compareVersion('5.4') == -1) { // copied from https://github.com/Homebrew/homebrew-php/blob/master/Formula/php53.rb $args[] = '--enable-sqlite-utf8'; $args[] = '--enable-zend-multibyte'; } elseif ($build->compareVersion('5.6') == -1) { $args[] = '--enable-zend-signals'; } foreach ($extra as $a) { $args[] = $a; } $cmd = new CommandBuilder('./configure'); $cmd->args($args); $buildLogPath = $build->getBuildLogPath(); if (file_exists($buildLogPath)) { $newPath = $buildLogPath . '.' . filemtime($buildLogPath); $this->info("Found existing build.log, renaming it to {$newPath}"); rename($buildLogPath, $newPath); } $this->info("===> Configuring {$build->version}..."); $cmd->setAppendLog(true); $cmd->setLogPath($buildLogPath); $cmd->setStdout($this->options->{'stdout'}); if (!$this->options->{'stdout'}) { $this->logger->info("\n"); $this->logger->info("Use tail command to see what's going on:"); $this->logger->info(" \$ tail -F {$buildLogPath}\n\n"); } $this->debug($cmd->buildCommand()); if ($this->options->nice) { $cmd->nice($this->options->nice); } if (!$this->options->dryrun) { $code = $cmd->execute($lastline); if ($code !== 0) { throw new SystemCommandException("Configure failed: {$lastline}", $build, $buildLogPath); } } $build->setState(Build::STATE_CONFIGURE); }