From 39953b5223ea4595b8e7d09e42557ff593a17a00 Mon Sep 17 00:00:00 2001 From: Jerry Ma Date: Thu, 24 Apr 2025 14:21:07 +0800 Subject: [PATCH] Fix pack lib command with wrong compression (#710) * Fix pack lib command with wrong compression * Update src/SPC/command/dev/PackLibCommand.php Co-authored-by: Marc --------- Co-authored-by: Marc --- src/SPC/command/dev/PackLibCommand.php | 30 +++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/src/SPC/command/dev/PackLibCommand.php b/src/SPC/command/dev/PackLibCommand.php index d7eb750a..924c3171 100644 --- a/src/SPC/command/dev/PackLibCommand.php +++ b/src/SPC/command/dev/PackLibCommand.php @@ -79,9 +79,11 @@ class PackLibCommand extends BuildCommand '{libc}' => getenv('SPC_LIBC') ?: 'default', '{libcver}' => PHP_OS_FAMILY === 'Linux' ? (SystemUtil::getLibcVersionIfExists() ?? 'default') : 'default', ]; + // detect suffix, for proper tar option + $tar_option = $this->getTarOptionFromSuffix(Config::getPreBuilt('match-pattern')); $filename = str_replace(array_keys($replace), array_values($replace), $filename); $filename = WORKING_DIR . '/dist/' . $filename; - f_passthru('tar -czf ' . $filename . ' -T ' . WORKING_DIR . '/packlib_files.txt'); + f_passthru("tar {$tar_option} {$filename} -T " . WORKING_DIR . '/packlib_files.txt'); logger()->info('Pack library ' . $lib->getName() . ' to ' . $filename . ' complete.'); } } @@ -115,4 +117,30 @@ class PackLibCommand extends BuildCommand } } } + + /** + * Get tar compress options from suffix + * + * @param string $name Package file name + * @return string Tar options for packaging libs + */ + private function getTarOptionFromSuffix(string $name): string + { + if (str_ends_with($name, '.tar')) { + return '-cf'; + } + if (str_ends_with($name, '.tar.gz') || str_ends_with($name, '.tgz')) { + return '-czf'; + } + if (str_ends_with($name, '.tar.bz2') || str_ends_with($name, '.tbz2')) { + return '-cjf'; + } + if (str_ends_with($name, '.tar.xz') || str_ends_with($name, '.txz')) { + return '-cJf'; + } + if (str_ends_with($name, '.tar.lz') || str_ends_with($name, '.tlz')) { + return '-c --lzma -f'; + } + return '-cf'; + } }