1
0
Fork 0
mirror of https://we.phorge.it/source/arcanist.git synced 2024-11-21 22:32:41 +01:00

Mostly remove "STDERR" and "STDOUT" constants from Arcanist

Summary:
Ref T13675. Ref T13556. The "STDOUT" and "STDERR" constants are defined by the PHP CLI SAPI, in `cli_register_file_handles()`.

The "native arc" embedded PHP wrapper doesn't define these, and there's no real reason to define them, since they're just defined in terms of the PHP stream wrappers ("php://stdin", etc) anyway.

This patch isn't exhaustive (and a subsequent change should add lint, rejecting these magic constants) but is just trying to make native `arc` functional.

Test Plan: Created this revision with a standalone native `arc` binary.

Subscribers: cspeckmim

Maniphest Tasks: T13675, T13556

Differential Revision: https://secure.phabricator.com/D21794
This commit is contained in:
epriestley 2022-04-28 14:50:46 -07:00
parent da206314cf
commit 8d487ed770
12 changed files with 116 additions and 27 deletions

View file

@ -22,25 +22,40 @@ final class PhutilConsoleFormatter extends Phobject {
public static function getDisableANSI() {
if (self::$disableANSI === null) {
$term = phutil_utf8_strtolower(getenv('TERM'));
// ansicon enables ANSI support on Windows
if (!$term && getenv('ANSICON')) {
$term = 'ansi';
}
if (phutil_is_windows() && $term !== 'cygwin' && $term !== 'ansi') {
self::$disableANSI = true;
} else if (!defined('STDOUT')) {
self::$disableANSI = true;
} else if (function_exists('posix_isatty') && !posix_isatty(STDOUT)) {
self::$disableANSI = true;
} else {
self::$disableANSI = false;
}
self::$disableANSI = self::newShouldDisableAnsi();
}
return self::$disableANSI;
}
private static function newShouldDisableANSI() {
$term = phutil_utf8_strtolower(getenv('TERM'));
// ansicon enables ANSI support on Windows
if (!$term && getenv('ANSICON')) {
$term = 'ansi';
}
if (phutil_is_windows()) {
if ($term !== 'cygwin' && $term !== 'ansi') {
return true;
}
}
$stdout = PhutilSystem::getStdoutHandle();
if ($stdout === null) {
return true;
}
if (function_exists('posix_isatty')) {
if (!posix_isatty($stdout)) {
return true;
}
}
return false;
}
public static function formatString($format /* ... */) {
$args = func_get_args();
$args[0] = self::interpretFormat($args[0]);

View file

@ -94,7 +94,7 @@ final class PhutilErrorLog
if (strlen($message)) {
$message = tsprintf("%B\n", $message);
@fwrite(STDERR, $message);
PhutilSystem::writeStderr($message);
}
}

View file

@ -53,10 +53,14 @@ final class PhutilExecPassthru extends PhutilExecutableFuture {
if ($is_write) {
$stdin_spec = array('pipe', 'r');
} else {
$stdin_spec = STDIN;
$stdin_spec = PhutilSystem::getStdinHandle();
}
$spec = array($stdin_spec, STDOUT, STDERR);
$spec = array(
$stdin_spec,
PhutilSystem::getStdoutHandle(),
PhutilSystem::getStderrHandle(),
);
$pipes = array();
$unmasked_command = $command->getUnmaskedString();

View file

@ -19,7 +19,7 @@ final class ArcanistLogEngine
}
private function writeBytes($bytes) {
fprintf(STDERR, '%s', $bytes);
PhutilSystem::writeStderr($bytes);
return $this;
}

View file

@ -33,7 +33,7 @@ final class ArcanistBaseCommitParser extends Phobject {
private function log($message) {
if ($this->verbose) {
fwrite(STDERR, $message."\n");
PhutilSystem::writeStderr($message."\n");
}
}

View file

@ -805,7 +805,7 @@ final class PhutilArgumentParser extends Phobject {
private function logMessage($message) {
fwrite(STDERR, $message);
PhutilSystem::writeStderr($message);
}

View file

@ -110,6 +110,6 @@ final class PhutilConsoleProgressSink
}
private function printLine($line) {
fprintf(STDERR, '%s', $line);
PhutilSystem::writeStderr($line);
}
}

View file

@ -296,11 +296,12 @@ final class PhutilSymbolLoader {
// library without breaking library startup.
if ($should_continue) {
// We may not have `pht()` yet.
fprintf(
STDERR,
$message = sprintf(
"%s: %s\n",
'IGNORING CLASS LOAD FAILURE',
$caught->getMessage());
@file_put_contents('php://stderr', $message);
} else {
throw $caught;
}

View file

@ -313,7 +313,7 @@ final class ArcanistFileUploader extends Phobject {
* @task internal
*/
private function writeStatus($message) {
fwrite(STDERR, $message."\n");
PhutilSystem::writeStderr($message."\n");
}
}

View file

@ -3,10 +3,76 @@
/**
* Interact with the operating system.
*
* @task stdio Interacting with Standard I/O
* @task memory Interacting with System Memory
*/
final class PhutilSystem extends Phobject {
private static $stdin = false;
private static $stderr = false;
private static $stdout = false;
/**
* @task stdio
*/
public static function getStdinHandle() {
if (self::$stdin === false) {
self::$stdin = self::newStdioHandle('php://stdin');
}
return self::$stdin;
}
/**
* @task stdio
*/
public static function getStdoutHandle() {
if (self::$stdout === false) {
self::$stdout = self::newStdioHandle('php://stdout');
}
return self::$stdout;
}
/**
* @task stdio
*/
public static function getStderrHandle() {
if (self::$stderr === false) {
self::$stderr = self::newStdioHandle('php://stderr');
}
return self::$stderr;
}
/**
* @task stdio
*/
public static function writeStderr($message) {
$stderr = self::getStderrHandle();
if ($stderr === null) {
return;
}
$message = phutil_string_cast($message);
@fwrite($stderr, $message);
}
/**
* @task stdio
*/
private static function newStdioHandle($ref) {
$ignored_mode = '';
$handle = @fopen($ref, $ignored_mode);
if ($handle === false) {
return null;
}
return $handle;
}
/**
* Get information about total and free memory on the system.

View file

@ -806,7 +806,10 @@ EOTEXT
if ($is_raw) {
if ($this->getArgument('raw')) {
fwrite(STDERR, pht('Reading diff from stdin...')."\n");
PhutilSystem::writeStderr(
tsprintf(
"%s\n",
pht('Reading diff from stdin...')));
$raw_diff = file_get_contents('php://stdin');
} else if ($this->getArgument('raw-command')) {
list($raw_diff) = execx('%C', $this->getArgument('raw-command'));

View file

@ -1565,7 +1565,7 @@ abstract class ArcanistWorkflow extends Phobject {
* @return void
*/
final protected function writeStatusMessage($msg) {
fwrite(STDERR, $msg);
PhutilSystem::writeStderr($msg);
}
final public function writeInfo($title, $message) {