mirror of
https://we.phorge.it/source/arcanist.git
synced 2024-11-08 16:02:39 +01:00
[Wilds] Allow "arc liberate" to liberate itself again
Summary: Ref T13098. After libphutil/ and arcanist/ merged, some paths need to be adjusted. Try to organize things a little better, too. Also, make `arc liberate` with no arguments just liberate all the libraries it can find. Test Plan: Ran `arc liberate` and got a valid map rebuild, although I needed to apply some hacks on top of this to make the workflow reachable. Reviewers: amckinley Reviewed By: amckinley Maniphest Tasks: T13098 Differential Revision: https://secure.phabricator.com/D19690
This commit is contained in:
parent
d936257018
commit
c05bbd7be6
5 changed files with 49 additions and 48 deletions
|
@ -1,7 +1,7 @@
|
|||
#!/usr/bin/env php
|
||||
<?php
|
||||
|
||||
require_once dirname(__FILE__).'/__init_script__.php';
|
||||
require_once dirname(dirname(__FILE__)).'/init/init-script.php';
|
||||
|
||||
$args = new PhutilArgumentParser($argv);
|
||||
$args->setTagline(pht('rebuild the library map file'));
|
|
@ -5,12 +5,12 @@
|
|||
// built-in symbol list through introspection.
|
||||
$builtins = phutil_symbols_get_builtins();
|
||||
|
||||
require_once dirname(__FILE__).'/__init_script__.php';
|
||||
require_once dirname(dirname(__FILE__)).'/init/init-script.php';
|
||||
|
||||
$args = new PhutilArgumentParser($argv);
|
||||
$args->setTagline(pht('identify symbols in a PHP source file'));
|
||||
$args->setSynopsis(<<<EOHELP
|
||||
**phutil_symbols.php** [__options__] __path.php__
|
||||
**library-symbols.php** [__options__] __path.php__
|
||||
Identify the symbols (clases, functions and interfaces) in a PHP
|
||||
source file. Symbols are divided into "have" symbols (symbols the file
|
||||
declares) and "need" symbols (symbols the file depends on). For example,
|
||||
|
@ -524,7 +524,7 @@ function phutil_symbols_get_builtins() {
|
|||
|
||||
$compat = json_decode(
|
||||
file_get_contents(
|
||||
dirname(__FILE__).'/../resources/php_compat_info.json'),
|
||||
dirname(dirname(__FILE__)).'/../resources/php/php_compat_info.json'),
|
||||
true);
|
||||
|
||||
foreach (array('functions', 'classes', 'interfaces') as $type) {
|
|
@ -183,7 +183,7 @@ final class PhutilLibraryMapBuilder extends Phobject {
|
|||
* Load the library symbol cache, if it exists and is readable and valid.
|
||||
*
|
||||
* @return dict Map of content hashes to cache of output from
|
||||
* `phutil_symbols.php`.
|
||||
* `library-symbols.php`.
|
||||
*
|
||||
* @task symbol
|
||||
*/
|
||||
|
@ -256,7 +256,7 @@ final class PhutilLibraryMapBuilder extends Phobject {
|
|||
}
|
||||
|
||||
/**
|
||||
* Build a future which returns a `phutil_symbols.php` analysis of a source
|
||||
* Build a future which returns a `library-symbols.php` analysis of a source
|
||||
* file.
|
||||
*
|
||||
* @param string Relative path to the source file to analyze.
|
||||
|
@ -266,9 +266,11 @@ final class PhutilLibraryMapBuilder extends Phobject {
|
|||
*/
|
||||
private function buildSymbolAnalysisFuture($file) {
|
||||
$absolute_file = $this->getPath($file);
|
||||
$bin = dirname(__FILE__).'/../../scripts/phutil_symbols.php';
|
||||
|
||||
return new ExecFuture('php %s --ugly -- %s', $bin, $absolute_file);
|
||||
$root = dirname(dirname(dirname(__FILE__)));
|
||||
$bin = $root.'/scripts/library/library-symbols.php';
|
||||
|
||||
return new ExecFuture('php %R --ugly -- %R', $bin, $absolute_file);
|
||||
}
|
||||
|
||||
|
||||
|
@ -439,7 +441,7 @@ EOPHP;
|
|||
$symbol_cache = $this->loadSymbolCache();
|
||||
|
||||
// If the XHPAST binary is not up-to-date, build it now. Otherwise,
|
||||
// `phutil_symbols.php` will attempt to build the binary and will fail
|
||||
// `library-symbols.php` will attempt to build the binary and will fail
|
||||
// miserably because it will be trying to build the same file multiple
|
||||
// times in parallel.
|
||||
if (!PhutilXHPASTBinary::isAvailable()) {
|
||||
|
|
|
@ -73,52 +73,51 @@ EOTEXT
|
|||
if (count($argv) > 1) {
|
||||
throw new ArcanistUsageException(
|
||||
pht(
|
||||
"Provide only one path to '%s'. The path should be a directory ".
|
||||
"where you want to create or update a libphutil library.",
|
||||
'arc liberate'));
|
||||
} else if (count($argv) == 0) {
|
||||
$path = getcwd();
|
||||
'Provide only one path to "arc liberate". The path should identify '.
|
||||
'a directory where you want to create or update a library.'));
|
||||
} else if (!$argv) {
|
||||
$init_files = id(new FileFinder(getcwd()))
|
||||
->withPath('*/__phutil_library_init__.php')
|
||||
->find();
|
||||
|
||||
if (!$init_files) {
|
||||
throw new ArcanistUsageException(
|
||||
pht(
|
||||
'Unable to find any libraries under the current working '.
|
||||
'directory. To create a library, provide a path.'));
|
||||
}
|
||||
|
||||
$paths = array();
|
||||
foreach ($init_files as $init) {
|
||||
$paths[] = Filesystem::resolvePath(dirname($init));
|
||||
}
|
||||
} else {
|
||||
$path = reset($argv);
|
||||
$paths = array(
|
||||
Filesystem::resolvePath(head($argv)),
|
||||
);
|
||||
}
|
||||
|
||||
$is_remap = $this->getArgument('remap');
|
||||
$is_verify = $this->getArgument('verify');
|
||||
|
||||
$path = Filesystem::resolvePath($path);
|
||||
|
||||
if (Filesystem::pathExists($path) && is_dir($path)) {
|
||||
$init = id(new FileFinder($path))
|
||||
->withPath('*/__phutil_library_init__.php')
|
||||
->find();
|
||||
} else {
|
||||
$init = null;
|
||||
foreach ($paths as $path) {
|
||||
$this->liberatePath($path);
|
||||
}
|
||||
|
||||
if ($init) {
|
||||
if (count($init) > 1) {
|
||||
throw new ArcanistUsageException(
|
||||
return 0;
|
||||
}
|
||||
|
||||
private function liberatePath($path) {
|
||||
if (!Filesystem::pathExists($path.'/__phutil_library_init__.php')) {
|
||||
echo tsprintf(
|
||||
"%s\n",
|
||||
pht(
|
||||
'Specified directory contains more than one libphutil library. '.
|
||||
'Use a more specific path.'));
|
||||
}
|
||||
$path = Filesystem::resolvePath(dirname(reset($init)), $path);
|
||||
} else {
|
||||
$found = false;
|
||||
foreach (Filesystem::walkToRoot($path) as $dir) {
|
||||
if (Filesystem::pathExists($dir.'/__phutil_library_init__.php')) {
|
||||
$path = $dir;
|
||||
$found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!$found) {
|
||||
echo pht("No library currently exists at that path...\n");
|
||||
'No library currently exists at the path "%s"...',
|
||||
$path));
|
||||
$this->liberateCreateDirectory($path);
|
||||
$this->liberateCreateLibrary($path);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
$version = $this->getLibraryFormatVersion($path);
|
||||
switch ($version) {
|
||||
|
@ -161,7 +160,7 @@ EOTEXT
|
|||
}
|
||||
|
||||
private function liberateVersion2($path) {
|
||||
$bin = $this->getScriptPath('scripts/phutil_rebuild_map.php');
|
||||
$bin = $this->getScriptPath('scripts/library/library-map.php');
|
||||
|
||||
return phutil_passthru(
|
||||
'php %s %C %s',
|
||||
|
@ -244,7 +243,7 @@ EOTEXT
|
|||
|
||||
|
||||
private function getScriptPath($script) {
|
||||
$root = dirname(phutil_get_library_root('phutil'));
|
||||
$root = dirname(phutil_get_library_root('arcanist'));
|
||||
return $root.'/'.$script;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue