public function runUnitTests($tests) { // Build any unit tests $this->make('build-tests'); // Now find all the test programs $root = $this->getProjectRoot(); $test_dir = $root . "/tests/"; $futures = array(); if (!$tests) { $paths = glob($test_dir . "*.t"); } else { $paths = array(); foreach ($tests as $path) { $tpath = preg_replace('/\\.c$/', '.t', $path); if (preg_match("/\\.c\$/", $path) && file_exists($tpath)) { $paths[] = realpath($tpath); } } } foreach ($paths as $test) { $relname = substr($test, strlen($test_dir)); $futures[$relname] = new ExecFuture($test); } $results = array(); $futures = new FutureIterator($futures); foreach ($futures->limit(4) as $test => $future) { list($err, $stdout, $stderr) = $future->resolve(); $results[] = $this->parseTestResults($test, $err, $stdout, $stderr); } return $results; }
public function execute(HarbormasterBuild $build, HarbormasterBuildTarget $build_target) { $viewer = PhabricatorUser::getOmnipotentUser(); $settings = $this->getSettings(); $variables = $build_target->getVariables(); $artifact = $build_target->loadArtifact($settings['hostartifact']); $impl = $artifact->getArtifactImplementation(); $lease = $impl->loadArtifactLease($viewer); $this->platform = $lease->getAttribute('platform'); $command = $this->mergeVariables(array($this, 'escapeCommand'), $settings['command'], $variables); $this->platform = null; $interface = $lease->getInterface('command'); $future = $interface->getExecFuture('%C', $command); $log_stdout = $build->createLog($build_target, 'remote', 'stdout'); $log_stderr = $build->createLog($build_target, 'remote', 'stderr'); $start_stdout = $log_stdout->start(); $start_stderr = $log_stderr->start(); $build_update = 5; // Read the next amount of available output every second. $futures = new FutureIterator(array($future)); foreach ($futures->setUpdateInterval(1) as $key => $future_iter) { if ($future_iter === null) { // Check to see if we should abort. if ($build_update <= 0) { $build->reload(); if ($this->shouldAbort($build, $build_target)) { $future->resolveKill(); throw new HarbormasterBuildAbortedException(); } else { $build_update = 5; } } else { $build_update -= 1; } // Command is still executing. // Read more data as it is available. list($stdout, $stderr) = $future->read(); $log_stdout->append($stdout); $log_stderr->append($stderr); $future->discardBuffers(); } else { // Command execution is complete. // Get the return value so we can log that as well. list($err) = $future->resolve(); // Retrieve the last few bits of information. list($stdout, $stderr) = $future->read(); $log_stdout->append($stdout); $log_stderr->append($stderr); $future->discardBuffers(); break; } } $log_stdout->finalize($start_stdout); $log_stderr->finalize($start_stderr); if ($err) { throw new HarbormasterBuildFailureException(); } }
public function testAddingFuture() { $future1 = new ExecFuture('cat'); $future2 = new ExecFuture('cat'); $iterator = new FutureIterator(array($future1)); $iterator->limit(2); $results = array(); foreach ($iterator as $future) { if ($future === $future1) { $iterator->addFuture($future2); } $results[] = $future->resolve(); } $this->assertEqual(2, count($results)); }
public function execute() { while (true) { if ($this->exec) { $iterator = new FutureIterator($this->exec); $iterator->setUpdateInterval(0.05); foreach ($iterator as $key => $future) { if ($future === null) { break; } $this->resolveFuture($key, $future); break; } } else { PhutilChannel::waitForAny(array($this->getMaster())); } $this->processInput(); } }
protected function resolveFutures(HarbormasterBuild $build, HarbormasterBuildTarget $target, array $futures) { $futures = new FutureIterator($futures); foreach ($futures->setUpdateInterval(5) as $key => $future) { if ($future === null) { $build->reload(); if ($this->shouldAbort($build, $target)) { throw new HarbormasterBuildAbortedException(); } } } }
EOSYNOPSIS ); $args->parseStandardArguments(); if (posix_isatty(STDIN)) { echo phutil_console_format("%s\n", pht('Usage: %s', "find . -type f -name '*.php' | ./generate_php_symbols.php")); exit(1); } $input = file_get_contents('php://stdin'); $data = array(); $futures = array(); foreach (explode("\n", trim($input)) as $file) { $file = Filesystem::readablePath($file); $data[$file] = Filesystem::readFile($file); $futures[$file] = PhutilXHPASTBinary::getParserFuture($data[$file]); } $futures = new FutureIterator($futures); foreach ($futures->limit(8) as $file => $future) { $tree = XHPASTTree::newFromDataAndResolvedExecFuture($data[$file], $future->resolve()); $root = $tree->getRootNode(); $scopes = array(); $functions = $root->selectDescendantsOfType('n_FUNCTION_DECLARATION'); foreach ($functions as $function) { $name = $function->getChildByIndex(2); // Skip anonymous functions. if (!$name->getConcreteString()) { continue; } print_symbol($file, 'function', $name); } $classes = $root->selectDescendantsOfType('n_CLASS_DECLARATION'); foreach ($classes as $class) {