1
0
Fork 0
mirror of https://we.phorge.it/source/arcanist.git synced 2024-11-08 07:52:39 +01:00

Update "arc liberate" to fix error with PHP 8 and add "--verbose" argument to adjust it

Summary:
Reported at the phorge project (https://we.phorge.it/D25017), running `arc liberate` fails on PHP 8 due to the `log()` function using `fwrite()` incorrectly assuming a format pattern can be used.

This updates to remove most of these status messages are they are largely uninformative and instead we can report progress.
- Remove the `--quiet` argument
- Always display the progress
- Remove all informational/status log statements

Test Plan:
Tested using both PHP 7.3 and PHP 8:
1. I ran `arc liberate` and saw the standard output:
```lang=console
 SCAN  Searching for libraries in the current working directory...
 WORK  Updating library: src/
Done.
 DONE  Updated library.
```
2. I ran deleted `phabricator/src/.phutil_module_cache` and ran `arc liberate /src`, verifying that progress was displayed while the map was computed.

Reviewers: #blessed_reviewers, epriestley

Reviewed By: #blessed_reviewers, epriestley

Subscribers: Korvin, epriestley

Differential Revision: https://secure.phabricator.com/D21718
This commit is contained in:
Christopher Speck 2021-09-04 12:59:40 -04:00
parent f993b1fbda
commit cd17e84412
3 changed files with 29 additions and 68 deletions

View file

@ -12,7 +12,6 @@
final class PhutilLibraryMapBuilder extends Phobject {
private $root;
private $quiet = true;
private $subprocessLimit = 8;
private $fileSymbolMap;
@ -38,19 +37,6 @@ final class PhutilLibraryMapBuilder extends Phobject {
$this->root = $root;
}
/**
* Control status output. Use `--quiet` to set this.
*
* @param bool If true, don't show status output.
* @return this
*
* @task map
*/
public function setQuiet($quiet) {
$this->quiet = $quiet;
return $this;
}
/**
* Control subprocess parallelism limit. Use `--limit` to set this.
*
@ -108,25 +94,9 @@ final class PhutilLibraryMapBuilder extends Phobject {
public function buildAndWriteMap() {
$library_map = $this->buildMap();
$this->log(pht('Writing map...'));
$this->writeLibraryMap($library_map);
}
/**
* Write a status message to the user, if not running in quiet mode.
*
* @param string Message to write.
* @return this
*
* @task map
*/
private function log($message) {
if (!$this->quiet) {
@fwrite(STDERR, "%s\n", $message);
}
return $this;
}
/* -( Path Management )---------------------------------------------------- */
@ -236,11 +206,7 @@ final class PhutilLibraryMapBuilder extends Phobject {
}
$json = json_encode($cache);
try {
Filesystem::writeFile($cache_file, $json);
} catch (FilesystemException $ex) {
$this->log(pht('Unable to save the cache!'));
}
Filesystem::writeFile($cache_file, $json);
}
/**
@ -251,7 +217,6 @@ final class PhutilLibraryMapBuilder extends Phobject {
* @task symbol
*/
public function dropSymbolCache() {
$this->log(pht('Dropping symbol cache...'));
Filesystem::remove($this->getPathForSymbolCache());
}
@ -451,14 +416,10 @@ EOPHP;
*/
private function analyzeLibrary() {
// Identify all the ".php" source files in the library.
$this->log(pht('Finding source files...'));
$source_map = $this->loadSourceFileMap();
$this->log(
pht('Found %s files.', new PhutilNumber(count($source_map))));
// Load the symbol cache with existing parsed symbols. This allows us
// to remap libraries quickly by analyzing only changed files.
$this->log(pht('Loading symbol cache...'));
$symbol_cache = $this->loadSymbolCache();
// If the XHPAST binary is not up-to-date, build it now. Otherwise,
@ -481,23 +442,12 @@ EOPHP;
}
$futures[$file] = $this->buildSymbolAnalysisFuture($file);
}
$this->log(
pht('Found %s files in cache.', new PhutilNumber(count($symbol_map))));
// Run the analyzer on any files which need analysis.
if ($futures) {
$limit = $this->subprocessLimit;
$this->log(
pht(
'Analyzing %s file(s) with %s subprocess(es)...',
phutil_count($futures),
new PhutilNumber($limit)));
$progress = new PhutilConsoleProgressBar();
if ($this->quiet) {
$progress->setQuiet(true);
}
$progress->setTotal(count($futures));
$futures = id(new FutureIterator($futures))
@ -525,8 +475,6 @@ EOPHP;
$this->writeSymbolCache($symbol_map, $source_map);
// Our map is up to date, so either show it on stdout or write it to disk.
$this->log(pht('Building library map...'));
$this->librarySymbolMap = $this->buildLibraryMap($symbol_map);
}

View file

@ -79,22 +79,35 @@ EOTEXT
);
}
$any_errors = false;
foreach ($paths as $path) {
$log->writeStatus(
pht('WORK'),
pht(
'Updating library: %s',
Filesystem::readablePath($path).DIRECTORY_SEPARATOR));
$this->liberatePath($path);
$exit_code = $this->liberatePath($path);
if ($exit_code !== 0) {
$any_errors = true;
$log->writeError(
pht('ERROR'),
pht('Failed to update library: %s', $path));
}
}
$log->writeSuccess(
pht('DONE'),
pht('Updated %s librarie(s).', phutil_count($paths)));
if (!$any_errors) {
$log->writeSuccess(
pht('DONE'),
pht('Updated %s librarie(s).', phutil_count($paths)));
}
return 0;
}
/**
* @return int The exit code of running the rebuild-map.php script, which
* will be 0 to indicate success or non-zero for failure.
*/
private function liberatePath($path) {
if (!Filesystem::pathExists($path.'/__phutil_library_init__.php')) {
echo tsprintf(
@ -103,8 +116,7 @@ EOTEXT
'No library currently exists at the path "%s"...',
$path));
$this->liberateCreateDirectory($path);
$this->liberateCreateLibrary($path);
return;
return $this->liberateCreateLibrary($path);
}
$version = $this->getLibraryFormatVersion($path);
@ -119,8 +131,6 @@ EOTEXT
throw new ArcanistUsageException(
pht("Unknown library version '%s'!", $version));
}
echo tsprintf("%s\n", pht('Done.'));
}
private function getLibraryFormatVersion($path) {
@ -140,6 +150,10 @@ EOTEXT
return 1;
}
/**
* @return int The exit code of running the rebuild-map.php script, which
* will be 0 to indicate success or non-zero for failure.
*/
private function liberateVersion2($path) {
$bin = $this->getScriptPath('support/lib/rebuild-map.php');
@ -181,10 +195,14 @@ EOTEXT
execx('mkdir -p %R', $path);
}
/**
* @return int The exit code of running the rebuild-map.php script, which
* will be 0 to indicate success or non-zero for failure.
*/
private function liberateCreateLibrary($path) {
$init_path = $path.'/__phutil_library_init__.php';
if (Filesystem::pathExists($init_path)) {
return;
return 0;
}
echo pht("Creating new libphutil library in '%s'.", $path)."\n";
@ -213,7 +231,7 @@ EOTEXT
'__phutil_library_init__.php',
$path);
Filesystem::writeFile($init_path, $template);
$this->liberateVersion2($path);
return $this->liberateVersion2($path);
}

View file

@ -16,10 +16,6 @@ EOHELP
$args->parseStandardArguments();
$args->parse(
array(
array(
'name' => 'quiet',
'help' => pht('Do not write status messages to stderr.'),
),
array(
'name' => 'drop-cache',
'help' => pht(
@ -56,7 +52,6 @@ if (count($root) !== 1) {
$root = Filesystem::resolvePath(head($root));
$builder = new PhutilLibraryMapBuilder($root);
$builder->setQuiet($args->getArg('quiet'));
$builder->setSubprocessLimit($args->getArg('limit'));
if ($args->getArg('drop-cache')) {