From ba127f4e009daeff5a2631216cf5e468c2a0dcdf Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Sun, 30 Jun 2024 22:33:03 +0800 Subject: [PATCH] Use extra files instead of internal patch block for libyaml --- src/SPC/builder/unix/library/libyaml.php | 54 +++++++----------------- src/SPC/store/SourcePatcher.php | 13 ++++++ 2 files changed, 28 insertions(+), 39 deletions(-) diff --git a/src/SPC/builder/unix/library/libyaml.php b/src/SPC/builder/unix/library/libyaml.php index b1b545cf..53962e9b 100644 --- a/src/SPC/builder/unix/library/libyaml.php +++ b/src/SPC/builder/unix/library/libyaml.php @@ -10,51 +10,27 @@ use SPC\store\FileSystem; trait libyaml { + public function getLibVersion(): ?string + { + // Match version from CMakeLists.txt: + // Format: set (YAML_VERSION_MAJOR 0) + // set (YAML_VERSION_MINOR 2) + // set (YAML_VERSION_PATCH 5) + $content = FileSystem::readFile($this->source_dir . '/CMakeLists.txt'); + if (preg_match('/set \(YAML_VERSION_MAJOR (\d+)\)/', $content, $major) + && preg_match('/set \(YAML_VERSION_MINOR (\d+)\)/', $content, $minor) + && preg_match('/set \(YAML_VERSION_PATCH (\d+)\)/', $content, $patch)) { + return "{$major[1]}.{$minor[1]}.{$patch[1]}"; + } + return null; + } + /** * @throws RuntimeException * @throws FileSystemException */ protected function build(): void { - // prepare cmake/config.h.in - if (!is_file(SOURCE_PATH . '/libyaml/cmake/config.h.in')) { - f_mkdir(SOURCE_PATH . '/libyaml/cmake'); - file_put_contents( - SOURCE_PATH . '/libyaml/cmake/config.h.in', - <<<'EOF' -#define YAML_VERSION_MAJOR @YAML_VERSION_MAJOR@ -#define YAML_VERSION_MINOR @YAML_VERSION_MINOR@ -#define YAML_VERSION_PATCH @YAML_VERSION_PATCH@ -#define YAML_VERSION_STRING "@YAML_VERSION_STRING@" -EOF - ); - } - - // prepare yamlConfig.cmake.in - if (!is_file(SOURCE_PATH . '/libyaml/yamlConfig.cmake.in')) { - file_put_contents( - SOURCE_PATH . '/libyaml/yamlConfig.cmake.in', - <<<'EOF' -# Config file for the yaml library. -# -# It defines the following variables: -# yaml_LIBRARIES - libraries to link against - -@PACKAGE_INIT@ - -set_and_check(yaml_TARGETS "@PACKAGE_CONFIG_DIR_CONFIG@/yamlTargets.cmake") - -if(NOT yaml_TARGETS_IMPORTED) - set(yaml_TARGETS_IMPORTED 1) - include(${yaml_TARGETS}) -endif() - -set(yaml_LIBRARIES yaml) - -EOF - ); - } - [$lib, $include, $destdir] = SEPARATED_PATH; FileSystem::resetDir($this->source_dir . '/build'); diff --git a/src/SPC/store/SourcePatcher.php b/src/SPC/store/SourcePatcher.php index dc114fe2..0eb530c4 100644 --- a/src/SPC/store/SourcePatcher.php +++ b/src/SPC/store/SourcePatcher.php @@ -24,6 +24,7 @@ class SourcePatcher FileSystem::addSourceExtractHook('sqlsrv', [SourcePatcher::class, 'patchSQLSRVWin32']); FileSystem::addSourceExtractHook('pdo_sqlsrv', [SourcePatcher::class, 'patchSQLSRVWin32']); FileSystem::addSourceExtractHook('yaml', [SourcePatcher::class, 'patchYamlWin32']); + FileSystem::addSourceExtractHook('libyaml', [SourcePatcher::class, 'patchLibYaml']); } /** @@ -348,6 +349,18 @@ class SourcePatcher return true; } + public static function patchLibYaml(string $name, string $target): bool + { + if (!file_exists("{$target}\\cmake\\config.h.in")) { + FileSystem::createDir("{$target}\\cmake"); + copy(ROOT_DIR . '\src\globals\extra\libyaml_config.h.in', "{$target}\\cmake\\config.h.in"); + } + if (!file_exists("{$target}\\YamlConfig.cmake.in")) { + copy(ROOT_DIR . '\src\globals\extra\libyaml_YamlConfig.cmake.in', "{$target}\\YamlConfig.cmake.in"); + } + return true; + } + /** * Patch cli SAPI Makefile for Windows. *