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

Update arcanist to use the PhutilSymbolLoader.

Summary: This should also fix the bug with double help for certain commands

Test Plan:

Reviewers:

CC:
This commit is contained in:
epriestley 2011-01-12 15:45:17 -08:00
parent c8b303bc90
commit 3f13e36182
15 changed files with 81 additions and 69 deletions

View file

@ -23,7 +23,7 @@ phutil_require_module('phutil', 'conduit/client');
phutil_require_module('phutil', 'console'); phutil_require_module('phutil', 'console');
phutil_require_module('phutil', 'future/exec'); phutil_require_module('phutil', 'future/exec');
phutil_require_module('phutil', 'filesystem'); phutil_require_module('phutil', 'filesystem');
phutil_require_module('phutil', 'autoload'); phutil_require_module('phutil', 'symbols');
phutil_require_module('arcanist', 'exception/usage'); phutil_require_module('arcanist', 'exception/usage');
phutil_require_module('arcanist', 'configuration'); phutil_require_module('arcanist', 'configuration');
@ -69,7 +69,7 @@ try {
$config = $working_copy->getConfig('arcanist_configuration'); $config = $working_copy->getConfig('arcanist_configuration');
if ($config) { if ($config) {
phutil_autoload_class($config); PhutilSymbolLoader::loadClass($config);
$config = new $config(); $config = new $config();
} else { } else {
$config = new ArcanistConfiguration(); $config = new ArcanistConfiguration();

View file

@ -23,7 +23,9 @@ $builtin_functions = get_defined_functions();
$builtin_functions = $builtin_functions['internal']; $builtin_functions = $builtin_functions['internal'];
$builtin = array( $builtin = array(
'class' => array_fill_keys($builtin_classes, true), 'class' => array_fill_keys($builtin_classes, true) + array(
'PhutilBootloader' => true,
),
'function' => array_fill_keys($builtin_functions, true) + array( 'function' => array_fill_keys($builtin_functions, true) + array(
'empty' => true, 'empty' => true,
'isset' => true, 'isset' => true,
@ -31,8 +33,6 @@ $builtin = array(
'print' => true, 'print' => true,
'exit' => true, 'exit' => true,
'die' => true, 'die' => true,
'phutil_module_exists' => true,
), ),
'interface' => array_fill_keys($builtin_interfaces, true), 'interface' => array_fill_keys($builtin_interfaces, true),
); );

View file

@ -29,12 +29,7 @@ class ArcanistConfiguration {
return null; return null;
} }
if (!phutil_module_exists('arcanist', 'workflow/'.$command)) {
return null;
}
$workflow_class = 'Arcanist'.ucfirst($command).'Workflow'; $workflow_class = 'Arcanist'.ucfirst($command).'Workflow';
$workflow_class = preg_replace_callback( $workflow_class = preg_replace_callback(
'/-([a-z])/', '/-([a-z])/',
array( array(
@ -43,18 +38,31 @@ class ArcanistConfiguration {
), ),
$workflow_class); $workflow_class);
phutil_autoload_class($workflow_class); $symbols = id(new PhutilSymbolLoader())
->setType('class')
->setName($workflow_class)
->setLibrary('arcanist')
->selectAndLoadSymbols();
if (!$symbols) {
return null;
}
return newv($workflow_class, array()); return newv($workflow_class, array());
} }
public function buildAllWorkflows() { public function buildAllWorkflows() {
$classes = phutil_find_class_descendants('ArcanistBaseWorkflow'); $symbols = id(new PhutilSymbolLoader())
->setType('class')
->setAncestorClass('ArcanistBaseWorkflow')
->setLibrary('arcanist')
->selectAndLoadSymbols();
$workflows = array(); $workflows = array();
foreach ($classes as $class) { foreach ($symbols as $symbol) {
$class = $class['name'];
$name = preg_replace('/^Arcanist(\w+)Workflow$/', '\1', $class); $name = preg_replace('/^Arcanist(\w+)Workflow$/', '\1', $class);
$name = strtolower($name); $name = strtolower($name);
phutil_autoload_class($class);
$workflows[$name] = newv($class, array()); $workflows[$name] = newv($class, array());
} }

View file

@ -6,7 +6,7 @@
phutil_require_module('phutil', 'autoload'); phutil_require_module('phutil', 'symbols');
phutil_require_module('phutil', 'utils'); phutil_require_module('phutil', 'utils');

View file

@ -241,13 +241,16 @@ class ArcanistPhutilModuleLinter extends ArcanistLinter {
$places); $places);
if ($type == 'class' || $type == 'interface') { if ($type == 'class' || $type == 'interface') {
$class_spec = PhutilLibraryMapRegistry::findClass( $loader = new PhutilSymbolLoader();
$library = null, $loader->setType($type);
$name); $loader->setName($name);
if ($class_spec) { $symbols = $loader->selectSymbolsWithoutLoading();
if ($symbols) {
$class_spec = reset($symbols);
try { try {
$loaded = phutil_autoload_class($name); $loader->selectAndLoadSymbols();
} catch (PhutilLibraryLoadException $ex) { $loaded = true;
} catch (PhutilMissingSymbolException $ex) {
$loaded = false; $loaded = false;
} }
if ($loaded) { if ($loaded) {
@ -279,13 +282,16 @@ class ArcanistPhutilModuleLinter extends ArcanistLinter {
} }
} }
} else { } else {
$func_spec = PhutilLibraryMapRegistry::findFunction( $loader = new PhutilSymbolLoader();
$library = null, $loader->setType($type);
$name); $loader->setName($name);
if ($func_spec) { $symbols = $loader->selectSymbolsWithoutLoading();
if ($symbols) {
$func_spec = reset($symbols);
try { try {
$loaded = phutil_autoload_function($name); $loader->selectAndLoadSymbols();
} catch (PhutilLibraryLoadException $ex) { $loaded = true;
} catch (PhutilMissingSymbolException $ex) {
$loaded = false; $loaded = false;
} }
if ($loaded) { if ($loaded) {

View file

@ -9,12 +9,12 @@
phutil_require_module('arcanist', 'lint/linter/base'); phutil_require_module('arcanist', 'lint/linter/base');
phutil_require_module('arcanist', 'lint/severity'); phutil_require_module('arcanist', 'lint/severity');
phutil_require_module('phutil', 'autoload');
phutil_require_module('phutil', 'filesystem'); phutil_require_module('phutil', 'filesystem');
phutil_require_module('phutil', 'future'); phutil_require_module('phutil', 'future');
phutil_require_module('phutil', 'future/exec'); phutil_require_module('phutil', 'future/exec');
phutil_require_module('phutil', 'moduleutils'); phutil_require_module('phutil', 'moduleutils');
phutil_require_module('phutil', 'parser/xhpast/bin'); phutil_require_module('phutil', 'parser/xhpast/bin');
phutil_require_module('phutil', 'symbols');
phutil_require_source('ArcanistPhutilModuleLinter.php'); phutil_require_source('ArcanistPhutilModuleLinter.php');

View file

@ -20,6 +20,8 @@ class PhutilUnitTestEngine extends ArcanistBaseUnitTestEngine {
public function run() { public function run() {
$bootloader = PhutilBootloader::getInstance();
$tests = array(); $tests = array();
foreach ($this->getPaths() as $path) { foreach ($this->getPaths() as $path) {
$library_root = phutil_get_library_root_for_path($path); $library_root = phutil_get_library_root_for_path($path);
@ -41,7 +43,10 @@ class PhutilUnitTestEngine extends ArcanistBaseUnitTestEngine {
if (basename($library_path) == '__tests__') { if (basename($library_path) == '__tests__') {
// Okay, this is a __tests__ module. // Okay, this is a __tests__ module.
} else { } else {
if (phutil_module_exists($library_name, $library_path.'/__tests__')) { $exists = $bootloader->moduleExists(
$library_name,
$library_path.'/__tests__');
if ($exists) {
// This is a module which has a __tests__ module in it. // This is a module which has a __tests__ module in it.
$path .= '/__tests__'; $path .= '/__tests__';
} else { } else {
@ -72,14 +77,16 @@ class PhutilUnitTestEngine extends ArcanistBaseUnitTestEngine {
} }
$run_tests = array(); $run_tests = array();
$all_test_classes = phutil_find_class_descendants('ArcanistPhutilTestCase');
$all_test_classes = array_fill_keys($all_test_classes, true);
foreach ($tests as $test) { foreach ($tests as $test) {
$local_classes = phutil_find_classes_declared_in_module( $symbols = id(new PhutilSymbolLoader())
$test['library'], ->setType('class')
$test['module']); ->setLibrary($test['library'])
$local_classes = array_fill_keys($local_classes, true); ->setModule($test['module'])
$run_tests += array_intersect($local_classes, $all_test_classes); ->setAncestorClass('ArcanistPhutilTestCase')
->selectAndLoadSymbols();
foreach ($symbols as $symbol) {
$run_tests[$symbol['name']] = true;
}
} }
$run_tests = array_keys($run_tests); $run_tests = array_keys($run_tests);
@ -90,7 +97,7 @@ class PhutilUnitTestEngine extends ArcanistBaseUnitTestEngine {
$results = array(); $results = array();
foreach ($run_tests as $test_class) { foreach ($run_tests as $test_class) {
phutil_autoload_class($test_class); PhutilSymbolLoader::loadClass($test_class);
$test_case = newv($test_class, array()); $test_case = newv($test_class, array());
$results[] = $test_case->run(); $results[] = $test_case->run();
} }

View file

@ -9,9 +9,9 @@
phutil_require_module('arcanist', 'exception/usage/noeffect'); phutil_require_module('arcanist', 'exception/usage/noeffect');
phutil_require_module('arcanist', 'unit/engine/base'); phutil_require_module('arcanist', 'unit/engine/base');
phutil_require_module('phutil', 'autoload');
phutil_require_module('phutil', 'filesystem'); phutil_require_module('phutil', 'filesystem');
phutil_require_module('phutil', 'moduleutils'); phutil_require_module('phutil', 'moduleutils');
phutil_require_module('phutil', 'symbols');
phutil_require_module('phutil', 'utils'); phutil_require_module('phutil', 'utils');

View file

@ -136,11 +136,7 @@ EOTEXT
"specify a lint engine."); "specify a lint engine.");
} }
$ok = phutil_autoload_class($engine); PhutilSymbolLoader::loadClass($engine);
if (!$ok) {
throw new ArcanistUsageException(
"Configured lint engine '{$engine}' could not be loaded.");
}
$engine = newv($engine, array()); $engine = newv($engine, array());
$engine->setWorkingCopy($working_copy); $engine->setWorkingCopy($working_copy);

View file

@ -14,12 +14,12 @@ phutil_require_module('arcanist', 'lint/severity');
phutil_require_module('arcanist', 'repository/api/base'); phutil_require_module('arcanist', 'repository/api/base');
phutil_require_module('arcanist', 'workflow/base'); phutil_require_module('arcanist', 'workflow/base');
phutil_require_module('phutil', 'autoload');
phutil_require_module('phutil', 'console'); phutil_require_module('phutil', 'console');
phutil_require_module('phutil', 'filesystem'); phutil_require_module('phutil', 'filesystem');
phutil_require_module('phutil', 'filesystem/filelist'); phutil_require_module('phutil', 'filesystem/filelist');
phutil_require_module('phutil', 'filesystem/tempfile'); phutil_require_module('phutil', 'filesystem/tempfile');
phutil_require_module('phutil', 'future/exec'); phutil_require_module('phutil', 'future/exec');
phutil_require_module('phutil', 'symbols');
phutil_require_module('phutil', 'utils'); phutil_require_module('phutil', 'utils');
phutil_require_module('phutil', 'xsprintf/csprintf'); phutil_require_module('phutil', 'xsprintf/csprintf');

View file

@ -6,10 +6,11 @@
phutil_require_module('arcanist', 'exception/usage');
phutil_require_module('arcanist', 'workflow/base'); phutil_require_module('arcanist', 'workflow/base');
phutil_require_module('phutil', 'console'); phutil_require_module('phutil', 'console');
phutil_require_module('phutil', 'future/exec'); phutil_require_module('phutil', 'future/exec');
phutil_require_source('ArcanistSvnHoookPreCommitWorkflow.php'); phutil_require_source('ArcanistSvnHookPreCommitWorkflow.php');

View file

@ -62,12 +62,6 @@ EOTEXT
"to specify a unit test engine."); "to specify a unit test engine.");
} }
$ok = phutil_autoload_class($engine_class);
if (!$ok) {
throw new ArcanistUsageException(
"Configured unit test engine '{$engine_class}' could not be loaded.");
}
$repository_api = $this->getRepositoryAPI(); $repository_api = $this->getRepositoryAPI();
if ($this->getArgument('paths')) { if ($this->getArgument('paths')) {
@ -79,6 +73,7 @@ EOTEXT
$paths = array_keys($paths); $paths = array_keys($paths);
} }
PhutilSymbolLoader::loadClass($engine_class);
$engine = newv($engine_class, array()); $engine = newv($engine_class, array());
$engine->setWorkingCopy($working_copy); $engine->setWorkingCopy($working_copy);
$engine->setPaths($paths); $engine->setPaths($paths);

View file

@ -6,13 +6,12 @@
phutil_require_module('arcanist', 'exception/usage');
phutil_require_module('arcanist', 'exception/usage/noengine'); phutil_require_module('arcanist', 'exception/usage/noengine');
phutil_require_module('arcanist', 'unit/result'); phutil_require_module('arcanist', 'unit/result');
phutil_require_module('arcanist', 'workflow/base'); phutil_require_module('arcanist', 'workflow/base');
phutil_require_module('phutil', 'autoload');
phutil_require_module('phutil', 'console'); phutil_require_module('phutil', 'console');
phutil_require_module('phutil', 'symbols');
phutil_require_module('phutil', 'utils'); phutil_require_module('phutil', 'utils');