From 839931d65fe0b06b907031ee58b02975a900f75b Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Sun, 4 Feb 2024 10:56:29 +0800 Subject: [PATCH] add static-php-cli.version ini for php-src --- src/SPC/ConsoleApplication.php | 2 +- src/SPC/command/BuildCliCommand.php | 3 +++ src/SPC/store/SourcePatcher.php | 16 ++++++++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/SPC/ConsoleApplication.php b/src/SPC/ConsoleApplication.php index 19cf3083..4d2db5fe 100644 --- a/src/SPC/ConsoleApplication.php +++ b/src/SPC/ConsoleApplication.php @@ -23,7 +23,7 @@ use Symfony\Component\Console\Command\ListCommand; */ final class ConsoleApplication extends Application { - public const VERSION = '2.1.0-beta.1'; + public const VERSION = '2.1.0-beta.2'; public function __construct() { diff --git a/src/SPC/command/BuildCliCommand.php b/src/SPC/command/BuildCliCommand.php index e79bc46b..9e90cc4c 100644 --- a/src/SPC/command/BuildCliCommand.php +++ b/src/SPC/command/BuildCliCommand.php @@ -104,6 +104,9 @@ class BuildCliCommand extends BuildCommand SourcePatcher::patchHardcodedINI($custom_ini); } + // add static-php-cli.version to main.c, in order to debug php failure more easily + SourcePatcher::patchSPCVersionToPHP($this->getApplication()->getVersion()); + // start to build $builder->buildPHP($rule); diff --git a/src/SPC/store/SourcePatcher.php b/src/SPC/store/SourcePatcher.php index 920d0564..a7a9bbca 100644 --- a/src/SPC/store/SourcePatcher.php +++ b/src/SPC/store/SourcePatcher.php @@ -296,4 +296,20 @@ class SourcePatcher $lines[$line_num + 1] = "\t" . '"$(LINK)" /nologo $(PHP_GLOBAL_OBJS_RESP) $(CLI_GLOBAL_OBJS_RESP) $(STATIC_EXT_OBJS_RESP) $(STATIC_EXT_LIBS) $(ASM_OBJS) $(LIBS) $(LIBS_CLI) $(BUILD_DIR)\php.exe.res /out:$(BUILD_DIR)\php.exe $(LDFLAGS) $(LDFLAGS_CLI) /ltcg /nodefaultlib:msvcrt /nodefaultlib:msvcrtd /ignore:4286'; FileSystem::writeFile(SOURCE_PATH . '/php-src/Makefile', implode("\r\n", $lines)); } + + /** + * Add additional `static-php-cli.version` ini value for PHP source. + * + * @throws FileSystemException + */ + public static function patchSPCVersionToPHP(string $version = 'unknown'): void + { + // detect patch + $file = FileSystem::readFile(SOURCE_PATH . '/php-src/main/main.c'); + if (!str_contains($file, 'static-php-cli.version')) { + logger()->debug('Inserting static-php-cli.version to php-src'); + $file = str_replace('PHP_INI_BEGIN()', "PHP_INI_BEGIN()\n\tPHP_INI_ENTRY(\"static-php-cli.version\",\t\"{$version}\",\tPHP_INI_ALL,\tNULL)", $file); + FileSystem::writeFile(SOURCE_PATH . '/php-src/main/main.c', $file); + } + } }