1
0
Fork 0
mirror of https://we.phorge.it/source/arcanist.git synced 2024-11-21 22:32: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

@ -171,7 +171,7 @@ class ArcanistSubversionAPI extends ArcanistRepositoryAPI {
// To reproduce, do: // To reproduce, do:
// //
// $ ln -s working_copy working_link // $ ln -s working_copy working_link
// $ svn info working_copy # ok // $ svn info working_copy # ok
// $ svn info working_link # fails // $ svn info working_link # fails
// //
// Work around this by cd-ing into the directory before executing // Work around this by cd-ing into the directory before executing
@ -411,7 +411,7 @@ EODIFF;
return $blame; return $blame;
} }
public function getOriginalFileData($path) { public function getOriginalFileData($path) {
// SVN issues warnings for nonexistent paths, directories, etc., but still // SVN issues warnings for nonexistent paths, directories, etc., but still
// returns no error code. However, for new paths in the working copy it // returns no error code. However, for new paths in the working copy it
@ -425,7 +425,7 @@ EODIFF;
} }
return $stdout; return $stdout;
} }
public function getCurrentFileData($path) { public function getCurrentFileData($path) {
$full_path = $this->getPath($path); $full_path = $this->getPath($path);
if (Filesystem::pathExists($full_path)) { if (Filesystem::pathExists($full_path)) {

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

@ -46,12 +46,12 @@ EOTEXT
// TODO: Do stuff with commit message. // TODO: Do stuff with commit message.
var_dump($commit_message); var_dump($commit_message);
list($changed) = execx( list($changed) = execx(
'svnlook changed --transaction %s %s', 'svnlook changed --transaction %s %s',
$transaction, $transaction,
$repository); $repository);
$paths = array(); $paths = array();
$changed = explode("\n", trim($changed)); $changed = explode("\n", trim($changed));
foreach ($changed as $line) { foreach ($changed as $line) {
@ -59,13 +59,13 @@ EOTEXT
preg_match('/^..\s*(.*)$/', $line, $matches); preg_match('/^..\s*(.*)$/', $line, $matches);
$paths[$matches[1]] = strlen($matches[1]); $paths[$matches[1]] = strlen($matches[1]);
} }
$resolved = array(); $resolved = array();
$failed = array(); $failed = array();
$missing = array(); $missing = array();
$found = array(); $found = array();
asort($paths); asort($paths);
foreach ($paths as $path => $length) { foreach ($paths as $path => $length) {
foreach ($resolved as $rpath => $root) { foreach ($resolved as $rpath => $root) {
if (!strncmp($path, $rpath, strlen($rpath))) { if (!strncmp($path, $rpath, strlen($rpath))) {
@ -74,12 +74,12 @@ EOTEXT
} }
} }
$config = $path; $config = $path;
if (basename($config) == '.arcconfig') { if (basename($config) == '.arcconfig') {
$resolved[$config] = $config; $resolved[$config] = $config;
continue; continue;
} }
$config = rtrim($config, '/'); $config = rtrim($config, '/');
$last_config = $config; $last_config = $config;
do { do {
@ -109,12 +109,12 @@ EOTEXT
} }
$last_config = $config; $last_config = $config;
} while (true); } while (true);
if (empty($resolved[$path])) { if (empty($resolved[$path])) {
$failed[] = $path; $failed[] = $path;
} }
} }
if ($failed && $resolved) { if ($failed && $resolved) {
$failed_paths = ' '.implode("\n ", $failed); $failed_paths = ' '.implode("\n ", $failed);
$resolved_paths = ' '.implode("\n ", array_keys($resolved)); $resolved_paths = ' '.implode("\n ", array_keys($resolved));
@ -127,12 +127,12 @@ EOTEXT
"Files not in projects:\n\n". "Files not in projects:\n\n".
$failed_paths); $failed_paths);
} }
if (!$resolved) { if (!$resolved) {
// None of the affected paths are beneath a .arcconfig file. // None of the affected paths are beneath a .arcconfig file.
return 3; return 3;
} }
$groups = array(); $groups = array();
foreach ($resolved as $path => $project) { foreach ($resolved as $path => $project) {
$groups[$project][] = $path; $groups[$project][] = $path;
@ -150,10 +150,10 @@ EOTEXT
"only that project.\n\n". "only that project.\n\n".
$message); $message);
} }
$project_root = key($groups); $project_root = key($groups);
$paths = reset($groups); $paths = reset($groups);
$data = array(); $data = array();
foreach ($paths as $path) { foreach ($paths as $path) {
list($err, $filedata) = exec_manual( list($err, $filedata) = exec_manual(
@ -163,7 +163,7 @@ EOTEXT
$path); $path);
$data[$path] = $err ? null : $filedata; $data[$path] = $err ? null : $filedata;
} }
// TODO: Do stuff with data. // TODO: Do stuff with data.
var_dump($data); var_dump($data);

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');