getState() public method

public getState ( )
Esempio n. 1
0
 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);
 }
Esempio n. 2
0
 /**
  * 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.");
     }
     */
 }
Esempio n. 3
0
 /**
  * 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.");
     }
     */
 }