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 <m@pyc.ac>

---------

Co-authored-by: Marc <m@pyc.ac>
This commit is contained in:
Jerry Ma 2025-04-24 14:21:07 +08:00 committed by GitHub
parent 455ed7d503
commit 39953b5223
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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';
}
}