From c05bbd7be67a53be0772d06e7d6cb107f566d839 Mon Sep 17 00:00:00 2001 From: epriestley Date: Tue, 18 Sep 2018 12:49:13 -0700 Subject: [PATCH] [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 --- resources/{ => php}/php_compat_info.json | 0 .../library-map.php} | 2 +- .../library-symbols.php} | 6 +- src/moduleutils/PhutilLibraryMapBuilder.php | 12 +-- src/workflow/ArcanistLiberateWorkflow.php | 77 +++++++++---------- 5 files changed, 49 insertions(+), 48 deletions(-) rename resources/{ => php}/php_compat_info.json (100%) rename scripts/{phutil_rebuild_map.php => library/library-map.php} (96%) rename scripts/{phutil_symbols.php => library/library-symbols.php} (98%) diff --git a/resources/php_compat_info.json b/resources/php/php_compat_info.json similarity index 100% rename from resources/php_compat_info.json rename to resources/php/php_compat_info.json diff --git a/scripts/phutil_rebuild_map.php b/scripts/library/library-map.php similarity index 96% rename from scripts/phutil_rebuild_map.php rename to scripts/library/library-map.php index 8fbdf7dc..9fc10dbc 100755 --- a/scripts/phutil_rebuild_map.php +++ b/scripts/library/library-map.php @@ -1,7 +1,7 @@ #!/usr/bin/env php setTagline(pht('rebuild the library map file')); diff --git a/scripts/phutil_symbols.php b/scripts/library/library-symbols.php similarity index 98% rename from scripts/phutil_symbols.php rename to scripts/library/library-symbols.php index a3205d52..91c498eb 100755 --- a/scripts/phutil_symbols.php +++ b/scripts/library/library-symbols.php @@ -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(<<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()) { diff --git a/src/workflow/ArcanistLiberateWorkflow.php b/src/workflow/ArcanistLiberateWorkflow.php index 96b94f6d..ef81793a 100644 --- a/src/workflow/ArcanistLiberateWorkflow.php +++ b/src/workflow/ArcanistLiberateWorkflow.php @@ -73,51 +73,50 @@ 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( - 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"); - $this->liberateCreateDirectory($path); - $this->liberateCreateLibrary($path); - return; - } + return 0; + } + + private function liberatePath($path) { + if (!Filesystem::pathExists($path.'/__phutil_library_init__.php')) { + echo tsprintf( + "%s\n", + pht( + 'No library currently exists at the path "%s"...', + $path)); + $this->liberateCreateDirectory($path); + $this->liberateCreateLibrary($path); + return; } $version = $this->getLibraryFormatVersion($path); @@ -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; }