Changeset View
Changeset View
Standalone View
Standalone View
support/ArcanistRuntime.php
<?php | <?php | ||||
final class ArcanistRuntime { | final class ArcanistRuntime { | ||||
private $workflows; | |||||
public function execute(array $argv) { | public function execute(array $argv) { | ||||
try { | try { | ||||
$this->checkEnvironment(); | $this->checkEnvironment(); | ||||
} catch (Exception $ex) { | } catch (Exception $ex) { | ||||
echo "CONFIGURATION ERROR\n\n"; | echo "CONFIGURATION ERROR\n\n"; | ||||
echo $ex->getMessage(); | echo $ex->getMessage(); | ||||
echo "\n\n"; | echo "\n\n"; | ||||
▲ Show 20 Lines • Show All 63 Lines • ▼ Show 20 Lines | private function executeCore(array $argv) { | ||||
$config->setConfigOptions($config_engine->newConfigOptionsMap()); | $config->setConfigOptions($config_engine->newConfigOptionsMap()); | ||||
$config->validateConfiguration(); | $config->validateConfiguration(); | ||||
$toolset = $this->newToolset($argv); | $toolset = $this->newToolset($argv); | ||||
$args->parsePartial($toolset->getToolsetArguments()); | $args->parsePartial($toolset->getToolsetArguments()); | ||||
$workflows = $this->newWorkflows($toolset); | $workflows = $this->newWorkflows($toolset); | ||||
$this->workflows = $workflows; | |||||
$phutil_workflows = array(); | $phutil_workflows = array(); | ||||
foreach ($workflows as $key => $workflow) { | foreach ($workflows as $key => $workflow) { | ||||
$phutil_workflows[$key] = $workflow->newPhutilWorkflow(); | $phutil_workflows[$key] = $workflow->newPhutilWorkflow(); | ||||
$workflow | $workflow | ||||
->setRuntime($this) | |||||
->setConfigurationEngine($config_engine) | ->setConfigurationEngine($config_engine) | ||||
->setConfigurationSourceList($config); | ->setConfigurationSourceList($config); | ||||
} | } | ||||
$unconsumed_argv = $args->getUnconsumedArgumentVector(); | $unconsumed_argv = $args->getUnconsumedArgumentVector(); | ||||
if (!$unconsumed_argv) { | if (!$unconsumed_argv) { | ||||
// TOOLSETS: This means the user just ran "arc" or some other top-level | // TOOLSETS: This means the user just ran "arc" or some other top-level | ||||
// toolset without any workflow argument. We should give them a summary | // toolset without any workflow argument. We should give them a summary | ||||
// of the toolset, a list of workflows, and a pointer to "arc help" for | // of the toolset, a list of workflows, and a pointer to "arc help" for | ||||
// more details. | // more details. | ||||
// A possible exception is "arc --help", which should perhaps pass | // A possible exception is "arc --help", which should perhaps pass | ||||
// through and act like "arc help". | // through and act like "arc help". | ||||
throw new PhutilArgumentUsageException(pht('Choose a workflow!')); | throw new PhutilArgumentUsageException(pht('Choose a workflow!')); | ||||
} | } | ||||
$result = $this->resolveAliases($workflows, $unconsumed_argv, $config); | $alias_effects = id(new ArcanistAliasEngine()) | ||||
if (is_int($result)) { | ->setRuntime($this) | ||||
return $result; | ->setToolset($toolset) | ||||
} | ->setWorkflows($workflows) | ||||
->setConfigurationSourceList($config) | |||||
->resolveAliases($unconsumed_argv); | |||||
$result_argv = $this->applyAliasEffects($alias_effects, $unconsumed_argv); | |||||
$args->setUnconsumedArgumentVector($result); | $args->setUnconsumedArgumentVector($result_argv); | ||||
return $args->parseWorkflows($phutil_workflows); | return $args->parseWorkflows($phutil_workflows); | ||||
} | } | ||||
/** | /** | ||||
* Perform some sanity checks against the possible diversity of PHP builds in | * Perform some sanity checks against the possible diversity of PHP builds in | ||||
* the wild, like very old versions and builds that were compiled with flags | * the wild, like very old versions and builds that were compiled with flags | ||||
▲ Show 20 Lines • Show All 342 Lines • ▼ Show 20 Lines | foreach ($workflows as $workflow) { | ||||
} | } | ||||
$map[$key] = id(clone $workflow) | $map[$key] = id(clone $workflow) | ||||
->setToolset($toolset); | ->setToolset($toolset); | ||||
} | } | ||||
return $map; | return $map; | ||||
} | } | ||||
private function resolveAliases( | private function logTrace($label, $message) { | ||||
array $workflows, | echo tsprintf( | ||||
array $argv, | "**<bg:magenta> %s </bg>** %s\n", | ||||
ArcanistConfigurationSourceList $config) { | $label, | ||||
$message); | |||||
return $argv; | |||||
$command = head($argv); | |||||
// If this is a match for a recognized workflow, just return the arguments | |||||
// unmodified. You aren't allowed to alias over real workflows. | |||||
if (isset($workflows[$command])) { | |||||
return $argv; | |||||
} | } | ||||
amckinley: Did this bleed over from the log cleanup diff? | |||||
Done Inline ActionsThis gets cleaned up in that diff (which happens later). In this diff, it just moved up, but the diff algorithm kind of highlighted it weird since the code sort of changed from "AliasStuff, LogTrace" to "LogTrace, AliasStuff2". epriestley: This gets cleaned up in that diff (which happens later). In this diff, it just moved up, but… | |||||
$aliases = ArcanistAliasWorkflow::getAliases($config); | public function getWorkflows() { | ||||
list($new_command, $new_args) = ArcanistAliasWorkflow::resolveAliases( | return $this->workflows; | ||||
$command, | |||||
$this, | |||||
array_slice($argv, 1), | |||||
$config); | |||||
// You can't alias something to itself, so if the new command isn't new, | |||||
// we're all done resolving aliases. | |||||
if ($new_command === $command) { | |||||
return $argv; | |||||
} | } | ||||
$full_alias = idx($aliases, $command, array()); | private function applyAliasEffects(array $effects, array $argv) { | ||||
$full_alias = implode(' ', $full_alias); | assert_instances_of($effects, 'ArcanistAliasEffect'); | ||||
// Run shell command aliases. | $command = null; | ||||
if (ArcanistAliasWorkflow::isShellCommandAlias($new_command)) { | $arguments = null; | ||||
fwrite( | foreach ($effects as $effect) { | ||||
STDERR, | $message = $effect->getMessage(); | ||||
tsprintf( | |||||
'**<bg:green> %s </bg>** arc %s -> $ %s', | |||||
pht('ALIAS'), | |||||
$command, | |||||
$shell_cmd)); | |||||
$shell_cmd = substr($full_alias, 1); | |||||
return phutil_passthru('%C %Ls', $shell_cmd, $args); | |||||
} | |||||
fwrite( | if ($message !== null) { | ||||
fprintf( | |||||
STDERR, | STDERR, | ||||
tsprintf( | tsprintf( | ||||
'**<bg:green> %s </bg>** arc %s -> arc %s', | "**<bg:yellow> %s </bg>** %s\n", | ||||
pht('ALIAS'), | pht('ALIAS'), | ||||
$command, | $message)); | ||||
$new_command)); | } | ||||
$new_argv = array_merge(array($new_command), $new_args); | if ($effect->getCommand()) { | ||||
$command = $effect->getCommand(); | |||||
$arguments = $effect->getArguments(); | |||||
} | |||||
} | |||||
return $this->resolveAliases($workflows, $new_argv, $config); | if ($command !== null) { | ||||
$argv = array_merge(array($command), $arguments); | |||||
} | } | ||||
private function logTrace($label, $message) { | return $argv; | ||||
echo tsprintf( | |||||
"**<bg:magenta> %s </bg>** %s\n", | |||||
$label, | |||||
$message); | |||||
} | } | ||||
} | } |
Did this bleed over from the log cleanup diff?