1
0
Fork 0
mirror of https://we.phorge.it/source/arcanist.git synced 2024-11-22 06:42:41 +01:00

Port "arc version" to Toolsets

Summary: Ref T13395. Depends on D20992. Run "arc version" as a modern workflow, not a classic workflow.

Test Plan: Ran "arc version".

Maniphest Tasks: T13395

Differential Revision: https://secure.phabricator.com/D20993
This commit is contained in:
epriestley 2020-02-13 15:05:24 -08:00
parent cf9469e0d1
commit 0c6ae6bbcf
4 changed files with 84 additions and 86 deletions

View file

@ -471,7 +471,7 @@ phutil_register_library_map(array(
'ArcanistVariableReferenceSpacingXHPASTLinterRuleTestCase' => 'lint/linter/xhpast/rules/__tests__/ArcanistVariableReferenceSpacingXHPASTLinterRuleTestCase.php',
'ArcanistVariableVariableXHPASTLinterRule' => 'lint/linter/xhpast/rules/ArcanistVariableVariableXHPASTLinterRule.php',
'ArcanistVariableVariableXHPASTLinterRuleTestCase' => 'lint/linter/xhpast/rules/__tests__/ArcanistVariableVariableXHPASTLinterRuleTestCase.php',
'ArcanistVersionWorkflow' => 'workflow/ArcanistVersionWorkflow.php',
'ArcanistVersionWorkflow' => 'toolset/workflow/ArcanistVersionWorkflow.php',
'ArcanistWeldWorkflow' => 'workflow/ArcanistWeldWorkflow.php',
'ArcanistWhichWorkflow' => 'workflow/ArcanistWhichWorkflow.php',
'ArcanistWildConfigOption' => 'config/option/ArcanistWildConfigOption.php',

View file

@ -168,32 +168,21 @@ final class ArcanistRuntime {
// NOTE: We don't have phutil_is_windows() yet here.
$is_windows = (DIRECTORY_SEPARATOR != '/');
// We use stream_socket_pair() which is not available on Windows earlier.
$min_version = ($is_windows ? '5.3.0' : '5.2.3');
$cur_version = phpversion();
if (version_compare($cur_version, $min_version, '<')) {
$message = sprintf(
'You are running a version of PHP ("%s"), which is older than the '.
'minimum supported version ("%s"). Update PHP to continue.',
$cur_version,
$min_version);
throw new Exception($message);
}
// NOTE: There's a hard PHP version check earlier, in "init-script.php".
if ($is_windows) {
$need_functions = array(
'curl_init' => array('builtin-dll', 'php_curl.dll'),
'curl_init' => array('builtin-dll', 'php_curl.dll'),
);
} else {
$need_functions = array(
'curl_init' => array(
'curl_init' => array(
'text',
"You need to install the cURL PHP extension, maybe with ".
"'apt-get install php5-curl' or 'yum install php53-curl' or ".
"something similar.",
),
'json_decode' => array('flag', '--without-json'),
'json_decode' => array('flag', '--without-json'),
);
}
@ -483,6 +472,7 @@ final class ArcanistRuntime {
private function newWorkflows(ArcanistToolset $toolset) {
$workflows = id(new PhutilClassMapQuery())
->setAncestorClass('ArcanistWorkflow')
->setContinueOnFailure(true)
->execute();
foreach ($workflows as $key => $workflow) {

View file

@ -0,0 +1,78 @@
<?php
/**
* Display the current version of Arcanist.
*/
final class ArcanistVersionWorkflow extends ArcanistWorkflow {
public function supportsToolset(ArcanistToolset $toolset) {
return true;
}
public function getWorkflowName() {
return 'version';
}
public function getWorkflowInformation() {
// TOOLSETS: Expand this help.
$help = pht(<<<EOTEXT
Shows the current version.
EOTEXT
);
return $this->newWorkflowInformation()
->addExample(pht('**version**'))
->setHelp($help);
}
public function getWorkflowArguments() {
return array();
}
public function runWorkflow() {
// TOOLSETS: Show the toolset version, not just the "arc" version.
$console = PhutilConsole::getConsole();
if (!Filesystem::binaryExists('git')) {
throw new ArcanistUsageException(
pht(
'Cannot display current version without "%s" installed.',
'git'));
}
$roots = array(
'arcanist' => dirname(phutil_get_library_root('arcanist')),
);
foreach ($roots as $lib => $root) {
$working_copy = ArcanistWorkingCopy::newFromWorkingDirectory($root);
$repository_api = $working_copy->newRepositoryAPI();
if (!$repository_api instanceof ArcanistGitAPI) {
throw new ArcanistUsageException(
pht(
'Library "%s" is not a Git working copy, so no version '.
'information can be provided.',
$lib));
}
// NOTE: Carefully execute these commands in a way that works on Windows
// until T8298 is properly fixed. See PHI52.
list($commit) = $repository_api->execxLocal('log -1 --format=%%H');
$commit = trim($commit);
list($timestamp) = $repository_api->execxLocal('log -1 --format=%%ct');
$timestamp = trim($timestamp);
$console->writeOut(
"%s %s (%s)\n",
$lib,
$commit,
date('j M Y', (int)$timestamp));
}
}
}

View file

@ -1,70 +0,0 @@
<?php
/**
* Display the current version of Arcanist.
*/
final class ArcanistVersionWorkflow extends ArcanistWorkflow {
public function getWorkflowName() {
return 'version';
}
public function getCommandSynopses() {
return phutil_console_format(<<<EOTEXT
**version** [__options__]
EOTEXT
);
}
public function getCommandHelp() {
return phutil_console_format(pht(<<<EOTEXT
Supports: cli
Shows the current version of arcanist.
EOTEXT
));
}
public function run() {
$console = PhutilConsole::getConsole();
if (!Filesystem::binaryExists('git')) {
throw new ArcanistUsageException(
pht(
'Cannot display current version without having `%s` installed.',
'git'));
}
$roots = array(
'arcanist' => dirname(phutil_get_library_root('arcanist')),
);
foreach ($roots as $lib => $root) {
$working_copy = ArcanistWorkingCopyIdentity::newFromPath($root);
$configuration_manager = clone $this->getConfigurationManager();
$configuration_manager->setWorkingCopyIdentity($working_copy);
$repository = ArcanistRepositoryAPI::newAPIFromConfigurationManager(
$configuration_manager);
if (!Filesystem::pathExists($repository->getMetadataPath())) {
throw new ArcanistUsageException(
pht('%s is not a git working copy.', $lib));
}
// NOTE: Carefully execute these commands in a way that works on Windows
// until T8298 is properly fixed. See PHI52.
list($commit) = $repository->execxLocal('log -1 --format=%%H');
$commit = trim($commit);
list($timestamp) = $repository->execxLocal('log -1 --format=%%ct');
$timestamp = trim($timestamp);
$console->writeOut(
"%s %s (%s)\n",
$lib,
$commit,
date('j M Y', (int)$timestamp));
}
}
}