mirror of
https://github.com/crazywhalecc/static-php-cli.git
synced 2026-07-07 08:45:40 +08:00
Chore
This commit is contained in:
@@ -90,5 +90,11 @@ const SPC_SOURCE_ARCHIVE = 'archive'; // download as archive
|
||||
const SPC_SOURCE_GIT = 'git'; // download as git repository
|
||||
const SPC_SOURCE_LOCAL = 'local'; // download as local directory
|
||||
|
||||
// spc logs dir
|
||||
const SPC_LOGS_DIR = WORKING_DIR . DIRECTORY_SEPARATOR . 'log';
|
||||
const SPC_OUTPUT_LOG = SPC_LOGS_DIR . DIRECTORY_SEPARATOR . 'spc.output.log';
|
||||
const SPC_SHELL_LOG = SPC_LOGS_DIR . DIRECTORY_SEPARATOR . 'spc.shell.log';
|
||||
const SPC_ENV_LOG = SPC_LOGS_DIR . DIRECTORY_SEPARATOR . 'spc.env.log';
|
||||
|
||||
ConsoleLogger::$date_format = 'H:i:s';
|
||||
ConsoleLogger::$format = '[%date%] [%level_short%] %body%';
|
||||
|
||||
@@ -5,8 +5,8 @@ declare(strict_types=1);
|
||||
use Psr\Log\LoggerInterface;
|
||||
use SPC\builder\BuilderBase;
|
||||
use SPC\builder\BuilderProvider;
|
||||
use SPC\exception\ExecutionException;
|
||||
use SPC\exception\InterruptException;
|
||||
use SPC\exception\RuntimeException;
|
||||
use SPC\exception\WrongUsageException;
|
||||
use SPC\util\shell\UnixShell;
|
||||
use SPC\util\shell\WindowsCmd;
|
||||
@@ -165,7 +165,7 @@ function f_passthru(string $cmd): ?bool
|
||||
}
|
||||
$ret = passthru($cmd, $code);
|
||||
if ($code !== 0) {
|
||||
throw new RuntimeException('Command run failed with code[' . $code . ']: ' . $cmd, $code);
|
||||
throw new ExecutionException($cmd, "Direct command run failed with code: {$code}", $code);
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
@@ -203,7 +203,7 @@ function f_putenv(string $env): bool
|
||||
function get_cmake_version(): ?string
|
||||
{
|
||||
try {
|
||||
[,$output] = shell()->execWithResult('cmake --version', false);
|
||||
[,$output] = shell(false)->execWithResult('cmake --version', false);
|
||||
if (preg_match('/cmake version ([\d.]+)/i', $output[0], $matches)) {
|
||||
return $matches[1];
|
||||
}
|
||||
@@ -244,3 +244,42 @@ function clean_spaces(string $string): string
|
||||
{
|
||||
return trim(preg_replace('/\s+/', ' ', $string));
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a callback function to handle keyboard interrupts (Ctrl+C).
|
||||
*
|
||||
* @param callable $callback callback function to handle keyboard interrupts
|
||||
*/
|
||||
function keyboard_interrupt_register(callable $callback): void
|
||||
{
|
||||
if (PHP_OS_FAMILY === 'Windows') {
|
||||
sapi_windows_set_ctrl_handler($callback);
|
||||
} elseif (extension_loaded('pcntl')) {
|
||||
pcntl_signal(SIGINT, $callback);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Unregister the keyboard interrupt handler.
|
||||
*
|
||||
* This function is used to remove the previously registered keyboard interrupt handler.
|
||||
* It should be called when you no longer need to handle keyboard interrupts.
|
||||
*/
|
||||
function keyboard_interrupt_unregister(): void
|
||||
{
|
||||
if (PHP_OS_FAMILY === 'Windows') {
|
||||
sapi_windows_set_ctrl_handler(null);
|
||||
} elseif (extension_loaded('pcntl')) {
|
||||
pcntl_signal(SIGINT, SIG_IGN);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Strip ANSI color codes from a string.
|
||||
*/
|
||||
function strip_ansi_colors(string $text): string
|
||||
{
|
||||
// Regular expression to match ANSI escape sequences
|
||||
// Including color codes, cursor control, clear screen and other control sequences
|
||||
return preg_replace('/\e\[[0-9;]*[a-zA-Z]/', '', $text);
|
||||
}
|
||||
|
||||
@@ -8,7 +8,6 @@ use SPC\builder\macos\SystemUtil as MacOSSystemUtil;
|
||||
use SPC\builder\windows\SystemUtil as WindowsSystemUtil;
|
||||
use SPC\ConsoleApplication;
|
||||
use SPC\store\FileSystem;
|
||||
use SPC\util\GlobalEnvManager;
|
||||
|
||||
// static-php-cli version string
|
||||
const SPC_VERSION = ConsoleApplication::VERSION;
|
||||
@@ -47,15 +46,15 @@ define('SEPARATED_PATH', [
|
||||
]);
|
||||
|
||||
// add these to env vars with same name
|
||||
GlobalEnvManager::putenv('SPC_VERSION=' . SPC_VERSION);
|
||||
GlobalEnvManager::putenv('BUILD_ROOT_PATH=' . BUILD_ROOT_PATH);
|
||||
GlobalEnvManager::putenv('BUILD_INCLUDE_PATH=' . BUILD_INCLUDE_PATH);
|
||||
GlobalEnvManager::putenv('BUILD_LIB_PATH=' . BUILD_LIB_PATH);
|
||||
GlobalEnvManager::putenv('BUILD_BIN_PATH=' . BUILD_BIN_PATH);
|
||||
GlobalEnvManager::putenv('PKG_ROOT_PATH=' . PKG_ROOT_PATH);
|
||||
GlobalEnvManager::putenv('SOURCE_PATH=' . SOURCE_PATH);
|
||||
GlobalEnvManager::putenv('DOWNLOAD_PATH=' . DOWNLOAD_PATH);
|
||||
GlobalEnvManager::putenv('CPU_COUNT=' . CPU_COUNT);
|
||||
GlobalEnvManager::putenv('SPC_ARCH=' . php_uname('m'));
|
||||
GlobalEnvManager::putenv('GNU_ARCH=' . GNU_ARCH);
|
||||
GlobalEnvManager::putenv('MAC_ARCH=' . MAC_ARCH);
|
||||
putenv('SPC_VERSION=' . SPC_VERSION);
|
||||
putenv('BUILD_ROOT_PATH=' . BUILD_ROOT_PATH);
|
||||
putenv('BUILD_INCLUDE_PATH=' . BUILD_INCLUDE_PATH);
|
||||
putenv('BUILD_LIB_PATH=' . BUILD_LIB_PATH);
|
||||
putenv('BUILD_BIN_PATH=' . BUILD_BIN_PATH);
|
||||
putenv('PKG_ROOT_PATH=' . PKG_ROOT_PATH);
|
||||
putenv('SOURCE_PATH=' . SOURCE_PATH);
|
||||
putenv('DOWNLOAD_PATH=' . DOWNLOAD_PATH);
|
||||
putenv('CPU_COUNT=' . CPU_COUNT);
|
||||
putenv('SPC_ARCH=' . php_uname('m'));
|
||||
putenv('GNU_ARCH=' . GNU_ARCH);
|
||||
putenv('MAC_ARCH=' . MAC_ARCH);
|
||||
|
||||
Reference in New Issue
Block a user