mirror of
https://github.com/crazywhalecc/static-php-cli.git
synced 2026-07-13 03:45:37 +08:00
fable output
This commit is contained in:
@@ -111,7 +111,7 @@ class ExceptionHandler
|
||||
|
||||
private static function logError($message, int $indent_space = 0, bool $output_log = true, string $color = 'red'): void
|
||||
{
|
||||
$spc_log = fopen(SPC_OUTPUT_LOG, 'a');
|
||||
$spc_log = spc_log_stream(SPC_OUTPUT_LOG);
|
||||
$msg = explode("\n", (string) $message);
|
||||
foreach ($msg as $v) {
|
||||
$line = str_pad($v, strlen($v) + $indent_space, ' ', STR_PAD_LEFT);
|
||||
|
||||
@@ -189,6 +189,10 @@ class WindowsCMakeExecutor extends Executor
|
||||
{
|
||||
return $this->custom_default_args ?? [
|
||||
'-A x64',
|
||||
// CMake 4.x hard-errors on projects requesting compatibility with CMake < 3.5
|
||||
// (e.g. wineditline). This is the documented escape hatch; modern projects and
|
||||
// older CMake releases ignore it.
|
||||
'-DCMAKE_POLICY_VERSION_MINIMUM=3.5',
|
||||
'-DCMAKE_BUILD_TYPE=Release',
|
||||
'-DBUILD_SHARED_LIBS=OFF',
|
||||
'-DBUILD_STATIC_LIBS=ON',
|
||||
|
||||
@@ -4,6 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace StaticPHP\Runtime\Shell;
|
||||
|
||||
use StaticPHP\Exception\ExecutionException;
|
||||
use StaticPHP\Exception\InterruptException;
|
||||
use StaticPHP\Exception\SPCInternalException;
|
||||
use StaticPHP\Runtime\SystemTarget;
|
||||
@@ -153,7 +154,7 @@ class DefaultShell extends Shell
|
||||
|
||||
$this->logCommandInfo($cmd);
|
||||
logger()->debug("[TAR EXTRACT] {$cmd}");
|
||||
$this->passthru($cmd, $this->console_putput);
|
||||
$this->passthruTolerateSymlinks($cmd);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -198,7 +199,7 @@ class DefaultShell extends Shell
|
||||
$run = function ($cmd) {
|
||||
$this->logCommandInfo($cmd);
|
||||
logger()->debug("[7Z EXTRACT] {$cmd}");
|
||||
$this->passthru($cmd, $this->console_putput);
|
||||
$this->passthruTolerateSymlinks($cmd);
|
||||
};
|
||||
|
||||
$extname = FileSystem::extname($archive_path);
|
||||
@@ -212,4 +213,67 @@ class DefaultShell extends Shell
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Run an extraction command, tolerating symbolic links that the host cannot create.
|
||||
*
|
||||
* Windows tar.exe (bsdtar) cannot create the symbolic links some archives ship (e.g. zstd's
|
||||
* tests/cli-tests/bin/unzstd -> zstd), failing each with "Can't create '...': Invalid argument"
|
||||
* and exiting non-zero. Those entries are never needed to build, so on Windows we swallow a
|
||||
* failure whose only errors are such symlink creations and continue. Any other failure still throws.
|
||||
*/
|
||||
private function passthruTolerateSymlinks(string $cmd): void
|
||||
{
|
||||
// Symlink creation only fails on a Windows host; elsewhere extraction handles symlinks fine.
|
||||
if (PHP_OS_FAMILY !== 'Windows') {
|
||||
$this->passthru($cmd, $this->console_putput);
|
||||
return;
|
||||
}
|
||||
|
||||
$result = $this->passthru($cmd, $this->console_putput, capture_output: true, throw_on_error: false);
|
||||
if ($result['code'] === 0) {
|
||||
return;
|
||||
}
|
||||
if ($this->isSymlinkOnlyExtractFailure($result['output'])) {
|
||||
logger()->warning('Some symbolic links could not be created during extraction and were skipped (not supported on this Windows host). This is harmless for building.');
|
||||
return;
|
||||
}
|
||||
throw new ExecutionException(
|
||||
cmd: $cmd,
|
||||
message: "Command exited with non-zero code: {$result['code']}",
|
||||
code: $result['code'],
|
||||
cd: $this->cd,
|
||||
env: $this->env,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Decide whether an extraction failure was caused solely by symbolic links that could not be
|
||||
* created on Windows. Returns true only when at least one such error is present and no other
|
||||
* error-looking output is found, so genuine extraction failures still propagate.
|
||||
*/
|
||||
private function isSymlinkOnlyExtractFailure(string $output): bool
|
||||
{
|
||||
$saw_symlink_error = false;
|
||||
foreach (preg_split('/\r\n|\r|\n/', $output) ?: [] as $line) {
|
||||
$line = trim($line);
|
||||
if ($line === '') {
|
||||
continue;
|
||||
}
|
||||
// bsdtar's trailing summary line; not an error on its own.
|
||||
if (str_contains($line, 'Error exit delayed from previous errors')) {
|
||||
continue;
|
||||
}
|
||||
// The symlink (or other unsupported special file) that Windows refused to create.
|
||||
if (str_contains($line, "Can't create") && str_contains($line, 'Invalid argument')) {
|
||||
$saw_symlink_error = true;
|
||||
continue;
|
||||
}
|
||||
// Any other error-looking line means this was not a clean symlink-only failure.
|
||||
if (preg_match('/\berror\b|cannot|can\'t|failed|denied|no space|not permitted/i', $line)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return $saw_symlink_error;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -114,8 +114,8 @@ abstract class Shell
|
||||
if (!$this->enable_log_file) {
|
||||
return;
|
||||
}
|
||||
// write executed command to log file using spc_write_log
|
||||
$log_file = fopen(SPC_SHELL_LOG, 'a');
|
||||
// write executed command to log file using spc_write_log (shared handle, see spc_log_stream)
|
||||
$log_file = spc_log_stream(SPC_SHELL_LOG);
|
||||
spc_write_log($log_file, "\n>>>>>>>>>>>>>>>>>>>>>>>>>> [" . date('Y-m-d H:i:s') . "]\n");
|
||||
spc_write_log($log_file, "> Executing command: {$cmd}\n");
|
||||
// get the backtrace to find the file and line number
|
||||
@@ -154,8 +154,8 @@ abstract class Shell
|
||||
): array {
|
||||
$file_res = null;
|
||||
if ($this->enable_log_file) {
|
||||
// write executed command to the log file using spc_write_log
|
||||
$file_res = fopen(SPC_SHELL_LOG, 'a');
|
||||
// write executed command to the log file using spc_write_log (shared handle, see spc_log_stream)
|
||||
$file_res = spc_log_stream(SPC_SHELL_LOG);
|
||||
}
|
||||
if ($console_output) {
|
||||
$console_res = STDOUT;
|
||||
@@ -263,9 +263,7 @@ abstract class Shell
|
||||
}
|
||||
fclose($pipes[1]);
|
||||
fclose($pipes[2]);
|
||||
if ($file_res !== null) {
|
||||
fclose($file_res);
|
||||
}
|
||||
// $file_res is a shared, process-wide handle (see spc_log_stream); do not close it here.
|
||||
proc_close($process);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user