mirror of
https://github.com/crazywhalecc/static-php-cli.git
synced 2026-03-18 04:44:53 +08:00
Drop legacy phpmicro support
This commit is contained in:
parent
4fc081fcc6
commit
86e3e51b5a
@ -109,15 +109,6 @@ class LinuxBuilder extends UnixBuilderBase
|
|||||||
'LIBS' => $mimallocLibs . SPCTarget::getRuntimeLibs(),
|
'LIBS' => $mimallocLibs . SPCTarget::getRuntimeLibs(),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// process micro upx patch if micro sapi enabled
|
|
||||||
if ($enableMicro) {
|
|
||||||
if (version_compare($this->getMicroVersion(), '0.2.0') < 0) {
|
|
||||||
// for phpmicro 0.1.x
|
|
||||||
$this->processMicroUPXLegacy();
|
|
||||||
}
|
|
||||||
// micro latest needs do strip and upx pack later (strip, upx, cut binary manually supported)
|
|
||||||
}
|
|
||||||
|
|
||||||
$embed_type = getenv('SPC_CMD_VAR_PHP_EMBED_TYPE') ?: 'static';
|
$embed_type = getenv('SPC_CMD_VAR_PHP_EMBED_TYPE') ?: 'static';
|
||||||
if ($embed_type !== 'static' && SPCTarget::isStatic()) {
|
if ($embed_type !== 'static' && SPCTarget::isStatic()) {
|
||||||
throw new WrongUsageException(
|
throw new WrongUsageException(
|
||||||
@ -333,7 +324,7 @@ class LinuxBuilder extends UnixBuilderBase
|
|||||||
if (file_exists($target)) {
|
if (file_exists($target)) {
|
||||||
[, $output] = shell()->execWithResult('readelf -d ' . escapeshellarg($target));
|
[, $output] = shell()->execWithResult('readelf -d ' . escapeshellarg($target));
|
||||||
$output = join("\n", $output);
|
$output = join("\n", $output);
|
||||||
if (preg_match('/SONAME.*\[(.+)\]/', $output, $sonameMatch)) {
|
if (preg_match('/SONAME.*\[(.+)]/', $output, $sonameMatch)) {
|
||||||
$currentSoname = $sonameMatch[1];
|
$currentSoname = $sonameMatch[1];
|
||||||
if ($currentSoname !== basename($target)) {
|
if ($currentSoname !== basename($target)) {
|
||||||
shell()->exec(sprintf(
|
shell()->exec(sprintf(
|
||||||
@ -362,49 +353,12 @@ class LinuxBuilder extends UnixBuilderBase
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Apply option --no-strip and --with-upx-pack for micro sapi (only for phpmicro 0.1.x)
|
* Strip micro.sfx for Linux.
|
||||||
|
* The micro.sfx does not support UPX directly, but we can remove UPX-info segment to adapt.
|
||||||
|
* This will also make micro.sfx with upx-packed more like a malware fore antivirus :(
|
||||||
*
|
*
|
||||||
* @throws FileSystemException
|
* @throws RuntimeException
|
||||||
*/
|
*/
|
||||||
private function processMicroUPXLegacy(): void
|
|
||||||
{
|
|
||||||
// upx pack and strip for micro
|
|
||||||
// but always restore Makefile.frag.bak first
|
|
||||||
if (file_exists(SOURCE_PATH . '/php-src/sapi/micro/Makefile.frag.bak')) {
|
|
||||||
copy(SOURCE_PATH . '/php-src/sapi/micro/Makefile.frag.bak', SOURCE_PATH . '/php-src/sapi/micro/Makefile.frag');
|
|
||||||
}
|
|
||||||
if ($this->getOption('with-upx-pack', false)) {
|
|
||||||
// judge $(MAKE) micro_2s_objs SFX_FILESIZE=`$(STAT_SIZE) $(SAPI_MICRO_PATH)` count
|
|
||||||
// if 2, replace src/globals/extra/micro-triple-Makefile.frag file content
|
|
||||||
if (substr_count(FileSystem::readFile(SOURCE_PATH . '/php-src/sapi/micro/Makefile.frag'), '$(MAKE) micro_2s_objs SFX_FILESIZE=`$(STAT_SIZE) $(SAPI_MICRO_PATH)`') === 2) {
|
|
||||||
// bak first
|
|
||||||
copy(SOURCE_PATH . '/php-src/sapi/micro/Makefile.frag', SOURCE_PATH . '/php-src/sapi/micro/Makefile.frag.bak');
|
|
||||||
// replace Makefile.frag content
|
|
||||||
FileSystem::writeFile(SOURCE_PATH . '/php-src/sapi/micro/Makefile.frag', FileSystem::readFile(ROOT_DIR . '/src/globals/extra/micro-triple-Makefile.frag'));
|
|
||||||
}
|
|
||||||
// with upx pack always need strip
|
|
||||||
FileSystem::replaceFileRegex(
|
|
||||||
SOURCE_PATH . '/php-src/sapi/micro/Makefile.frag',
|
|
||||||
'/POST_MICRO_BUILD_COMMANDS=.*/',
|
|
||||||
'POST_MICRO_BUILD_COMMANDS=\$(STRIP) \$(MICRO_STRIP_FLAGS) \$(SAPI_MICRO_PATH) && ' . getenv('UPX_EXEC') . ' --best \$(SAPI_MICRO_PATH)',
|
|
||||||
);
|
|
||||||
} elseif (!$this->getOption('no-strip', false)) {
|
|
||||||
// not-no-strip means strip (default behavior)
|
|
||||||
FileSystem::replaceFileRegex(
|
|
||||||
SOURCE_PATH . '/php-src/sapi/micro/Makefile.frag',
|
|
||||||
'/POST_MICRO_BUILD_COMMANDS=.*/',
|
|
||||||
'POST_MICRO_BUILD_COMMANDS=\$(STRIP) \$(MICRO_STRIP_FLAGS) \$(SAPI_MICRO_PATH)',
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
// just no strip
|
|
||||||
FileSystem::replaceFileRegex(
|
|
||||||
SOURCE_PATH . '/php-src/sapi/micro/Makefile.frag',
|
|
||||||
'/POST_MICRO_BUILD_COMMANDS=.*/',
|
|
||||||
'POST_MICRO_BUILD_COMMANDS=true',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private function processMicroUPX(): void
|
private function processMicroUPX(): void
|
||||||
{
|
{
|
||||||
if (version_compare($this->getMicroVersion(), '0.2.0') >= 0 && !$this->getOption('no-strip', false)) {
|
if (version_compare($this->getMicroVersion(), '0.2.0') >= 0 && !$this->getOption('no-strip', false)) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user