mirror of
https://github.com/crazywhalecc/static-php-cli.git
synced 2026-03-18 12:54:52 +08:00
add --with-added-patch command
This commit is contained in:
parent
12ea3218e8
commit
149e844d59
@ -4,6 +4,7 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace SPC\builder;
|
namespace SPC\builder;
|
||||||
|
|
||||||
|
use SPC\exception\ExceptionHandler;
|
||||||
use SPC\exception\FileSystemException;
|
use SPC\exception\FileSystemException;
|
||||||
use SPC\exception\RuntimeException;
|
use SPC\exception\RuntimeException;
|
||||||
use SPC\exception\WrongUsageException;
|
use SPC\exception\WrongUsageException;
|
||||||
@ -30,6 +31,9 @@ abstract class BuilderBase
|
|||||||
/** @var array<string, mixed> compile options */
|
/** @var array<string, mixed> compile options */
|
||||||
protected array $options = [];
|
protected array $options = [];
|
||||||
|
|
||||||
|
/** @var string patch point name */
|
||||||
|
protected string $patch_point = '';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Build libraries
|
* Build libraries
|
||||||
*
|
*
|
||||||
@ -78,9 +82,14 @@ abstract class BuilderBase
|
|||||||
$lib->calcDependency();
|
$lib->calcDependency();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// patch point
|
||||||
|
$this->emitPatchPoint('before-libs-extract');
|
||||||
|
|
||||||
// extract sources
|
// extract sources
|
||||||
SourceExtractor::initSource(libs: $sorted_libraries);
|
SourceExtractor::initSource(libs: $sorted_libraries);
|
||||||
|
|
||||||
|
$this->emitPatchPoint('after-libs-extract');
|
||||||
|
|
||||||
// build all libs
|
// build all libs
|
||||||
foreach ($this->libs as $lib) {
|
foreach ($this->libs as $lib) {
|
||||||
match ($lib->tryBuild($this->getOption('rebuild', false))) {
|
match ($lib->tryBuild($this->getOption('rebuild', false))) {
|
||||||
@ -189,11 +198,17 @@ abstract class BuilderBase
|
|||||||
public function proveExts(array $extensions): void
|
public function proveExts(array $extensions): void
|
||||||
{
|
{
|
||||||
CustomExt::loadCustomExt();
|
CustomExt::loadCustomExt();
|
||||||
|
$this->emitPatchPoint('before-php-extract');
|
||||||
SourceExtractor::initSource(sources: ['php-src']);
|
SourceExtractor::initSource(sources: ['php-src']);
|
||||||
|
$this->emitPatchPoint('after-php-extract');
|
||||||
if ($this->getPHPVersionID() >= 80000) {
|
if ($this->getPHPVersionID() >= 80000) {
|
||||||
|
$this->emitPatchPoint('before-micro-extract');
|
||||||
SourceExtractor::initSource(sources: ['micro']);
|
SourceExtractor::initSource(sources: ['micro']);
|
||||||
|
$this->emitPatchPoint('after-micro-extract');
|
||||||
}
|
}
|
||||||
|
$this->emitPatchPoint('before-exts-extract');
|
||||||
SourceExtractor::initSource(exts: $extensions);
|
SourceExtractor::initSource(exts: $extensions);
|
||||||
|
$this->emitPatchPoint('after-exts-extract');
|
||||||
foreach ($extensions as $extension) {
|
foreach ($extensions as $extension) {
|
||||||
$class = CustomExt::getExtClass($extension);
|
$class = CustomExt::getExtClass($extension);
|
||||||
$ext = new $class($extension, $this);
|
$ext = new $class($extension, $this);
|
||||||
@ -342,6 +357,39 @@ abstract class BuilderBase
|
|||||||
return implode(' ', $env);
|
return implode(' ', $env);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get builder patch point name.
|
||||||
|
*/
|
||||||
|
public function getPatchPoint(): string
|
||||||
|
{
|
||||||
|
return $this->patch_point;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function emitPatchPoint(string $point_name): void
|
||||||
|
{
|
||||||
|
$this->patch_point = $point_name;
|
||||||
|
if (($patches = $this->getOption('with-added-patch', [])) === []) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($patches as $patch) {
|
||||||
|
try {
|
||||||
|
if (!file_exists($patch)) {
|
||||||
|
throw new RuntimeException("Additional patch script file {$patch} not found!");
|
||||||
|
}
|
||||||
|
logger()->debug('Running additional patch script: ' . $patch);
|
||||||
|
require $patch;
|
||||||
|
} catch (\Throwable $e) {
|
||||||
|
logger()->critical('Patch script ' . $patch . ' failed to run.');
|
||||||
|
if ($this->getOption('debug')) {
|
||||||
|
ExceptionHandler::getInstance()->handle($e);
|
||||||
|
} else {
|
||||||
|
logger()->critical('Please check with --debug option to see more details.');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if all libs are downloaded.
|
* Check if all libs are downloaded.
|
||||||
* If not, throw exception.
|
* If not, throw exception.
|
||||||
|
|||||||
@ -140,7 +140,9 @@ abstract class LibraryBase
|
|||||||
if (!$this->patched && $this->patchBeforeBuild()) {
|
if (!$this->patched && $this->patchBeforeBuild()) {
|
||||||
file_put_contents($this->source_dir . '/.spc.patched', 'PATCHED!!!');
|
file_put_contents($this->source_dir . '/.spc.patched', 'PATCHED!!!');
|
||||||
}
|
}
|
||||||
|
$this->getBuilder()->emitPatchPoint('before-library[ ' . static::NAME . ']-build');
|
||||||
$this->build();
|
$this->build();
|
||||||
|
$this->getBuilder()->emitPatchPoint('after-library[ ' . static::NAME . ']-build');
|
||||||
return BUILD_STATUS_OK;
|
return BUILD_STATUS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -81,10 +81,12 @@ class BSDBuilder extends BuilderBase
|
|||||||
}
|
}
|
||||||
$this->setOption('extra-libs', $extra_libs);
|
$this->setOption('extra-libs', $extra_libs);
|
||||||
|
|
||||||
|
$this->emitPatchPoint('before-php-buildconf');
|
||||||
SourcePatcher::patchBeforeBuildconf($this);
|
SourcePatcher::patchBeforeBuildconf($this);
|
||||||
|
|
||||||
shell()->cd(SOURCE_PATH . '/php-src')->exec('./buildconf --force');
|
shell()->cd(SOURCE_PATH . '/php-src')->exec('./buildconf --force');
|
||||||
|
|
||||||
|
$this->emitPatchPoint('before-php-configure');
|
||||||
SourcePatcher::patchBeforeConfigure($this);
|
SourcePatcher::patchBeforeConfigure($this);
|
||||||
|
|
||||||
$json_74 = $this->getPHPVersionID() < 80000 ? '--enable-json ' : '';
|
$json_74 = $this->getPHPVersionID() < 80000 ? '--enable-json ' : '';
|
||||||
@ -115,6 +117,7 @@ class BSDBuilder extends BuilderBase
|
|||||||
$this->makeExtensionArgs()
|
$this->makeExtensionArgs()
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$this->emitPatchPoint('before-php-make');
|
||||||
SourcePatcher::patchBeforeMake($this);
|
SourcePatcher::patchBeforeMake($this);
|
||||||
|
|
||||||
$this->cleanMake();
|
$this->cleanMake();
|
||||||
@ -140,6 +143,7 @@ class BSDBuilder extends BuilderBase
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (php_uname('m') === $this->getOption('arch')) {
|
if (php_uname('m') === $this->getOption('arch')) {
|
||||||
|
$this->emitPatchPoint('before-sanity-check');
|
||||||
$this->sanityCheck($build_target);
|
$this->sanityCheck($build_target);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -147,10 +147,13 @@ class LinuxBuilder extends BuilderBase
|
|||||||
'LDFLAGS' => '-L' . BUILD_LIB_PATH,
|
'LDFLAGS' => '-L' . BUILD_LIB_PATH,
|
||||||
'LIBS' => '-ldl -lpthread',
|
'LIBS' => '-ldl -lpthread',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
$this->emitPatchPoint('before-php-buildconf');
|
||||||
SourcePatcher::patchBeforeBuildconf($this);
|
SourcePatcher::patchBeforeBuildconf($this);
|
||||||
|
|
||||||
shell()->cd(SOURCE_PATH . '/php-src')->exec('./buildconf --force');
|
shell()->cd(SOURCE_PATH . '/php-src')->exec('./buildconf --force');
|
||||||
|
|
||||||
|
$this->emitPatchPoint('before-php-configure');
|
||||||
SourcePatcher::patchBeforeConfigure($this);
|
SourcePatcher::patchBeforeConfigure($this);
|
||||||
|
|
||||||
$phpVersionID = $this->getPHPVersionID();
|
$phpVersionID = $this->getPHPVersionID();
|
||||||
@ -193,6 +196,7 @@ class LinuxBuilder extends BuilderBase
|
|||||||
' ' . $envs_build_php . ' '
|
' ' . $envs_build_php . ' '
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$this->emitPatchPoint('before-php-make');
|
||||||
SourcePatcher::patchBeforeMake($this);
|
SourcePatcher::patchBeforeMake($this);
|
||||||
|
|
||||||
$this->cleanMake();
|
$this->cleanMake();
|
||||||
@ -218,6 +222,7 @@ class LinuxBuilder extends BuilderBase
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (php_uname('m') === $this->getOption('arch')) {
|
if (php_uname('m') === $this->getOption('arch')) {
|
||||||
|
$this->emitPatchPoint('before-sanity-check');
|
||||||
$this->sanityCheck($build_target);
|
$this->sanityCheck($build_target);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -141,10 +141,12 @@ class MacOSBuilder extends BuilderBase
|
|||||||
}
|
}
|
||||||
$this->setOption('extra-libs', $extra_libs);
|
$this->setOption('extra-libs', $extra_libs);
|
||||||
|
|
||||||
|
$this->emitPatchPoint('before-php-buildconf');
|
||||||
SourcePatcher::patchBeforeBuildconf($this);
|
SourcePatcher::patchBeforeBuildconf($this);
|
||||||
|
|
||||||
shell()->cd(SOURCE_PATH . '/php-src')->exec('./buildconf --force');
|
shell()->cd(SOURCE_PATH . '/php-src')->exec('./buildconf --force');
|
||||||
|
|
||||||
|
$this->emitPatchPoint('before-php-configure');
|
||||||
SourcePatcher::patchBeforeConfigure($this);
|
SourcePatcher::patchBeforeConfigure($this);
|
||||||
|
|
||||||
$json_74 = $this->getPHPVersionID() < 80000 ? '--enable-json ' : '';
|
$json_74 = $this->getPHPVersionID() < 80000 ? '--enable-json ' : '';
|
||||||
@ -190,6 +192,7 @@ class MacOSBuilder extends BuilderBase
|
|||||||
$envs_build_php
|
$envs_build_php
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$this->emitPatchPoint('before-php-make');
|
||||||
SourcePatcher::patchBeforeMake($this);
|
SourcePatcher::patchBeforeMake($this);
|
||||||
|
|
||||||
$this->cleanMake();
|
$this->cleanMake();
|
||||||
@ -215,6 +218,7 @@ class MacOSBuilder extends BuilderBase
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (php_uname('m') === $this->getOption('arch')) {
|
if (php_uname('m') === $this->getOption('arch')) {
|
||||||
|
$this->emitPatchPoint('before-sanity-check');
|
||||||
$this->sanityCheck($build_target);
|
$this->sanityCheck($build_target);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -35,6 +35,8 @@ class BuildCliCommand extends BuildCommand
|
|||||||
$this->addOption('with-micro-fake-cli', null, null, 'Enable phpmicro fake cli');
|
$this->addOption('with-micro-fake-cli', null, null, 'Enable phpmicro fake cli');
|
||||||
$this->addOption('with-suggested-libs', 'L', null, 'Build with suggested libs for selected exts and libs');
|
$this->addOption('with-suggested-libs', 'L', null, 'Build with suggested libs for selected exts and libs');
|
||||||
$this->addOption('with-suggested-exts', 'E', null, 'Build with suggested extensions for selected exts');
|
$this->addOption('with-suggested-exts', 'E', null, 'Build with suggested extensions for selected exts');
|
||||||
|
$this->addOption('with-added-patch', 'P', InputOption::VALUE_IS_ARRAY | InputOption::VALUE_REQUIRED, 'Inject patch script outside');
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function handle(): int
|
public function handle(): int
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user