mirror of
https://we.phorge.it/source/arcanist.git
synced 2024-11-09 00:12:40 +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
|
#!/usr/bin/env php
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
require_once dirname(__FILE__).'/__init_script__.php';
|
require_once dirname(dirname(__FILE__)).'/init/init-script.php';
|
||||||
|
|
||||||
$args = new PhutilArgumentParser($argv);
|
$args = new PhutilArgumentParser($argv);
|
||||||
$args->setTagline(pht('rebuild the library map file'));
|
$args->setTagline(pht('rebuild the library map file'));
|
|
@ -5,12 +5,12 @@
|
||||||
// built-in symbol list through introspection.
|
// built-in symbol list through introspection.
|
||||||
$builtins = phutil_symbols_get_builtins();
|
$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 = new PhutilArgumentParser($argv);
|
||||||
$args->setTagline(pht('identify symbols in a PHP source file'));
|
$args->setTagline(pht('identify symbols in a PHP source file'));
|
||||||
$args->setSynopsis(<<<EOHELP
|
$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
|
Identify the symbols (clases, functions and interfaces) in a PHP
|
||||||
source file. Symbols are divided into "have" symbols (symbols the file
|
source file. Symbols are divided into "have" symbols (symbols the file
|
||||||
declares) and "need" symbols (symbols the file depends on). For example,
|
declares) and "need" symbols (symbols the file depends on). For example,
|
||||||
|
@ -524,7 +524,7 @@ function phutil_symbols_get_builtins() {
|
||||||
|
|
||||||
$compat = json_decode(
|
$compat = json_decode(
|
||||||
file_get_contents(
|
file_get_contents(
|
||||||
dirname(__FILE__).'/../resources/php_compat_info.json'),
|
dirname(dirname(__FILE__)).'/../resources/php/php_compat_info.json'),
|
||||||
true);
|
true);
|
||||||
|
|
||||||
foreach (array('functions', 'classes', 'interfaces') as $type) {
|
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.
|
* Load the library symbol cache, if it exists and is readable and valid.
|
||||||
*
|
*
|
||||||
* @return dict Map of content hashes to cache of output from
|
* @return dict Map of content hashes to cache of output from
|
||||||
* `phutil_symbols.php`.
|
* `library-symbols.php`.
|
||||||
*
|
*
|
||||||
* @task symbol
|
* @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.
|
* file.
|
||||||
*
|
*
|
||||||
* @param string Relative path to the source file to analyze.
|
* @param string Relative path to the source file to analyze.
|
||||||
|
@ -266,9 +266,11 @@ final class PhutilLibraryMapBuilder extends Phobject {
|
||||||
*/
|
*/
|
||||||
private function buildSymbolAnalysisFuture($file) {
|
private function buildSymbolAnalysisFuture($file) {
|
||||||
$absolute_file = $this->getPath($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();
|
$symbol_cache = $this->loadSymbolCache();
|
||||||
|
|
||||||
// If the XHPAST binary is not up-to-date, build it now. Otherwise,
|
// 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
|
// miserably because it will be trying to build the same file multiple
|
||||||
// times in parallel.
|
// times in parallel.
|
||||||
if (!PhutilXHPASTBinary::isAvailable()) {
|
if (!PhutilXHPASTBinary::isAvailable()) {
|
||||||
|
|
|
@ -73,52 +73,51 @@ EOTEXT
|
||||||
if (count($argv) > 1) {
|
if (count($argv) > 1) {
|
||||||
throw new ArcanistUsageException(
|
throw new ArcanistUsageException(
|
||||||
pht(
|
pht(
|
||||||
"Provide only one path to '%s'. The path should be a directory ".
|
'Provide only one path to "arc liberate". The path should identify '.
|
||||||
"where you want to create or update a libphutil library.",
|
'a directory where you want to create or update a library.'));
|
||||||
'arc liberate'));
|
} else if (!$argv) {
|
||||||
} else if (count($argv) == 0) {
|
$init_files = id(new FileFinder(getcwd()))
|
||||||
$path = 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 {
|
} else {
|
||||||
$path = reset($argv);
|
$paths = array(
|
||||||
|
Filesystem::resolvePath(head($argv)),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
$is_remap = $this->getArgument('remap');
|
$is_remap = $this->getArgument('remap');
|
||||||
$is_verify = $this->getArgument('verify');
|
$is_verify = $this->getArgument('verify');
|
||||||
|
|
||||||
$path = Filesystem::resolvePath($path);
|
foreach ($paths as $path) {
|
||||||
|
$this->liberatePath($path);
|
||||||
if (Filesystem::pathExists($path) && is_dir($path)) {
|
|
||||||
$init = id(new FileFinder($path))
|
|
||||||
->withPath('*/__phutil_library_init__.php')
|
|
||||||
->find();
|
|
||||||
} else {
|
|
||||||
$init = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($init) {
|
return 0;
|
||||||
if (count($init) > 1) {
|
}
|
||||||
throw new ArcanistUsageException(
|
|
||||||
|
private function liberatePath($path) {
|
||||||
|
if (!Filesystem::pathExists($path.'/__phutil_library_init__.php')) {
|
||||||
|
echo tsprintf(
|
||||||
|
"%s\n",
|
||||||
pht(
|
pht(
|
||||||
'Specified directory contains more than one libphutil library. '.
|
'No library currently exists at the path "%s"...',
|
||||||
'Use a more specific path.'));
|
$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");
|
|
||||||
$this->liberateCreateDirectory($path);
|
$this->liberateCreateDirectory($path);
|
||||||
$this->liberateCreateLibrary($path);
|
$this->liberateCreateLibrary($path);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
$version = $this->getLibraryFormatVersion($path);
|
$version = $this->getLibraryFormatVersion($path);
|
||||||
switch ($version) {
|
switch ($version) {
|
||||||
|
@ -161,7 +160,7 @@ EOTEXT
|
||||||
}
|
}
|
||||||
|
|
||||||
private function liberateVersion2($path) {
|
private function liberateVersion2($path) {
|
||||||
$bin = $this->getScriptPath('scripts/phutil_rebuild_map.php');
|
$bin = $this->getScriptPath('scripts/library/library-map.php');
|
||||||
|
|
||||||
return phutil_passthru(
|
return phutil_passthru(
|
||||||
'php %s %C %s',
|
'php %s %C %s',
|
||||||
|
@ -244,7 +243,7 @@ EOTEXT
|
||||||
|
|
||||||
|
|
||||||
private function getScriptPath($script) {
|
private function getScriptPath($script) {
|
||||||
$root = dirname(phutil_get_library_root('phutil'));
|
$root = dirname(phutil_get_library_root('arcanist'));
|
||||||
return $root.'/'.$script;
|
return $root.'/'.$script;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue