fix: improve Windows patching logic and update file paths for xlsxwriter

This commit is contained in:
crazywhalecc
2026-07-06 16:46:29 +08:00
parent 0b02f62b7e
commit ab37b34fb5
3 changed files with 24 additions and 15 deletions

View File

@@ -32,12 +32,15 @@ class xlswriter extends PhpExtensionPackage
#[PatchDescription('Fix Windows build: apply win32 patch and add UTF-8 BOM to theme.c')]
public function patchBeforeMakeForWindows(): void
{
$source_dir = $this->getSourceDir();
$theme_file = "{$source_dir}/library/libxlsx/src/theme.c";
// fix windows build with openssl extension duplicate symbol bug
SourcePatcher::patchFile('spc_fix_xlswriter_win32.patch', $this->getSourceDir());
$content = file_get_contents($this->getSourceDir() . '/library/libxlsxwriter/src/theme.c');
SourcePatcher::patchFile('spc_fix_xlswriter_win32.patch', $source_dir);
$content = file_get_contents($theme_file);
$bom = pack('CCC', 0xEF, 0xBB, 0xBF);
if (!str_starts_with($content, $bom)) {
file_put_contents($this->getSourceDir() . '/library/libxlsxwriter/src/theme.c', $bom . $content);
file_put_contents($theme_file, $bom . $content);
}
}
}

View File

@@ -45,12 +45,18 @@ class SourcePatcher
file_put_contents(SOURCE_PATH . "/{$filename}", file_get_contents($patch_file));
$patch_str = FileSystem::convertPath(SOURCE_PATH . "/{$filename}");
}
$patch_cwd = FileSystem::convertPath($cwd);
$patch_arg = $patch_str;
if (PHP_OS_FAMILY === 'Windows') {
$patch_cwd = FileSystem::convertWinPathToMinGW($patch_cwd);
$patch_arg = FileSystem::convertWinPathToMinGW($patch_arg);
}
// Detect if patch is already applied (reverse detection)
$detect_reverse = !$reverse;
$detect_cmd = 'cd ' . escapeshellarg($cwd) . ' && '
. (PHP_OS_FAMILY === 'Windows' ? 'type' : 'cat') . ' ' . escapeshellarg($patch_str)
. ' | patch --dry-run -p1 -s -f ' . ($detect_reverse ? '-R' : '')
$detect_cmd = 'patch --dry-run -p1 -s -f -d ' . escapeshellarg($patch_cwd)
. ' -i ' . escapeshellarg($patch_arg)
. ($detect_reverse ? ' -R' : '')
. ' > ' . (PHP_OS_FAMILY === 'Windows' ? 'NUL' : '/dev/null') . ' 2>&1';
exec($detect_cmd, $output, $detect_status);
@@ -60,9 +66,9 @@ class SourcePatcher
}
// Apply patch
$apply_cmd = 'cd ' . escapeshellarg($cwd) . ' && '
. (PHP_OS_FAMILY === 'Windows' ? 'type' : 'cat') . ' ' . escapeshellarg($patch_str)
. ' | patch -p1 ' . ($reverse ? '-R' : '');
$apply_cmd = 'patch -p1 -d ' . escapeshellarg($patch_cwd)
. ' -i ' . escapeshellarg($patch_arg)
. ($reverse ? ' -R' : '');
exec($apply_cmd, $apply_output, $apply_status);
if ($apply_status !== 0) {

View File

@@ -1,7 +1,7 @@
diff --git a/library/libxlsxwriter/third_party/md5/md5.c b/library/libxlsxwriter/third_party/md5/md5.c
diff --git a/library/libxlsx/third_party/md5/md5.c b/library/libxlsx/third_party/md5/md5.c
index b235e17..ce98e18 100644
--- a/library/libxlsxwriter/third_party/md5/md5.c
+++ b/library/libxlsxwriter/third_party/md5/md5.c
--- a/library/libxlsx/third_party/md5/md5.c
+++ b/library/libxlsx/third_party/md5/md5.c
@@ -35,7 +35,11 @@
* compile-time configuration.
*/
@@ -15,10 +15,10 @@ index b235e17..ce98e18 100644
#include <string.h>
diff --git a/library/libxlsxwriter/third_party/md5/md5.h b/library/libxlsxwriter/third_party/md5/md5.h
diff --git a/library/libxlsx/third_party/md5/md5.h b/library/libxlsx/third_party/md5/md5.h
index 2da44bf..3cb0a98 100644
--- a/library/libxlsxwriter/third_party/md5/md5.h
+++ b/library/libxlsxwriter/third_party/md5/md5.h
--- a/library/libxlsx/third_party/md5/md5.h
+++ b/library/libxlsx/third_party/md5/md5.h
@@ -23,7 +23,7 @@
* See md5.c for more information.
*/