Adjust function to protected (#315)

* add `--with-added-patch` command

* add BuilderProvider::getBuilder() function

* cs fix

* add builder() and patch_point() global functions

* bump version to 2.0.1

* adjust function prefix

* adjust function prefix
This commit is contained in:
Jerry Ma 2024-01-10 11:10:40 +08:00 committed by GitHub
parent a7d5a48b48
commit 8de942c274
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 56 additions and 52 deletions

View File

@ -41,6 +41,7 @@ abstract class BuilderBase
* @throws FileSystemException
* @throws RuntimeException
* @throws WrongUsageException
* @internal
*/
public function buildLibs(array $sorted_libraries): void
{
@ -181,6 +182,8 @@ abstract class BuilderBase
/**
* Set libs only mode.
*
* @internal
*/
public function setLibsOnly(bool $status = true): void
{
@ -194,6 +197,7 @@ abstract class BuilderBase
* @throws RuntimeException
* @throws \ReflectionException
* @throws WrongUsageException
* @internal
*/
public function proveExts(array $extensions): void
{

View File

@ -154,7 +154,7 @@ class BSDBuilder extends BuilderBase
* @throws RuntimeException
* @throws FileSystemException
*/
public function buildCli(): void
protected function buildCli(): void
{
$vars = SystemUtil::makeEnvVarString([
'EXTRA_CFLAGS' => '-g -Os', // with debug information, but optimize for size
@ -177,7 +177,7 @@ class BSDBuilder extends BuilderBase
* @throws RuntimeException
* @throws WrongUsageException
*/
public function buildMicro(): void
protected function buildMicro(): void
{
if ($this->getPHPVersionID() < 80000) {
throw new WrongUsageException('phpmicro only support PHP >= 8.0!');
@ -215,7 +215,7 @@ class BSDBuilder extends BuilderBase
* @throws RuntimeException
* @throws FileSystemException
*/
public function buildFpm(): void
protected function buildFpm(): void
{
$vars = SystemUtil::makeEnvVarString([
'EXTRA_CFLAGS' => '-g -Os', // with debug information, but optimize for size
@ -235,7 +235,7 @@ class BSDBuilder extends BuilderBase
*
* @throws RuntimeException
*/
public function buildEmbed(): void
protected function buildEmbed(): void
{
$vars = SystemUtil::makeEnvVarString([
'EXTRA_CFLAGS' => '-g -Os', // with debug information, but optimize for size

View File

@ -233,7 +233,7 @@ class LinuxBuilder extends BuilderBase
* @throws RuntimeException
* @throws FileSystemException
*/
public function buildCli(): void
protected function buildCli(): void
{
$vars = SystemUtil::makeEnvVarString($this->getBuildVars());
shell()->cd(SOURCE_PATH . '/php-src')
@ -254,7 +254,7 @@ class LinuxBuilder extends BuilderBase
* @throws RuntimeException
* @throws WrongUsageException
*/
public function buildMicro(): void
protected function buildMicro(): void
{
if ($this->getPHPVersionID() < 80000) {
throw new WrongUsageException('phpmicro only support PHP >= 8.0!');
@ -288,7 +288,7 @@ class LinuxBuilder extends BuilderBase
* @throws FileSystemException
* @throws RuntimeException
*/
public function buildFpm(): void
protected function buildFpm(): void
{
$vars = SystemUtil::makeEnvVarString($this->getBuildVars());
shell()->cd(SOURCE_PATH . '/php-src')
@ -307,7 +307,7 @@ class LinuxBuilder extends BuilderBase
*
* @throws RuntimeException
*/
public function buildEmbed(): void
protected function buildEmbed(): void
{
$vars = SystemUtil::makeEnvVarString($this->getBuildVars());

View File

@ -229,7 +229,7 @@ class MacOSBuilder extends BuilderBase
* @throws RuntimeException
* @throws FileSystemException
*/
public function buildCli(): void
protected function buildCli(): void
{
$vars = SystemUtil::makeEnvVarString($this->getBuildVars());
@ -248,7 +248,7 @@ class MacOSBuilder extends BuilderBase
* @throws RuntimeException
* @throws WrongUsageException
*/
public function buildMicro(): void
protected function buildMicro(): void
{
if ($this->getPHPVersionID() < 80000) {
throw new WrongUsageException('phpmicro only support PHP >= 8.0!');
@ -284,7 +284,7 @@ class MacOSBuilder extends BuilderBase
* @throws RuntimeException
* @throws FileSystemException
*/
public function buildFpm(): void
protected function buildFpm(): void
{
$vars = SystemUtil::makeEnvVarString($this->getBuildVars());
@ -301,7 +301,7 @@ class MacOSBuilder extends BuilderBase
*
* @throws RuntimeException
*/
public function buildEmbed(): void
protected function buildEmbed(): void
{
$vars = SystemUtil::makeEnvVarString($this->getBuildVars());

View File

@ -49,12 +49,49 @@ trait UnixBuilderTrait
return array_map(fn ($x) => realpath(BUILD_LIB_PATH . "/{$x}"), $libFiles);
}
/**
* Return generic cmake options when configuring cmake projects
*/
public function makeCmakeArgs(): string
{
$extra = $this instanceof LinuxBuilder ? '-DCMAKE_C_COMPILER=' . getenv('CC') . ' ' : '';
return $extra .
'-DCMAKE_BUILD_TYPE=Release ' .
'-DCMAKE_INSTALL_PREFIX=/ ' .
'-DCMAKE_INSTALL_BINDIR=/bin ' .
'-DCMAKE_INSTALL_LIBDIR=/lib ' .
'-DCMAKE_INSTALL_INCLUDEDIR=/include ' .
"-DCMAKE_TOOLCHAIN_FILE={$this->cmake_toolchain_file}";
}
/**
* Generate configure flags
*/
public function makeAutoconfFlags(int $flag = AUTOCONF_ALL): string
{
$extra = '';
// TODO: add auto pkg-config support
if (($flag & AUTOCONF_LIBS) === AUTOCONF_LIBS) {
$extra .= 'LIBS="' . BUILD_LIB_PATH . '" ';
}
if (($flag & AUTOCONF_CFLAGS) === AUTOCONF_CFLAGS) {
$extra .= 'CFLAGS="-I' . BUILD_INCLUDE_PATH . '" ';
}
if (($flag & AUTOCONF_CPPFLAGS) === AUTOCONF_CPPFLAGS) {
$extra .= 'CPPFLAGS="-I' . BUILD_INCLUDE_PATH . '" ';
}
if (($flag & AUTOCONF_LDFLAGS) === AUTOCONF_LDFLAGS) {
$extra .= 'LDFLAGS="-L' . BUILD_LIB_PATH . '" ';
}
return $extra;
}
/**
* Sanity check after build complete
*
* @throws RuntimeException
*/
public function sanityCheck(int $build_target): void
protected function sanityCheck(int $build_target): void
{
// sanity check for php-cli
if (($build_target & BUILD_TARGET_CLI) === BUILD_TARGET_CLI) {
@ -95,7 +132,7 @@ trait UnixBuilderTrait
* @throws RuntimeException
* @throws FileSystemException
*/
public function deployBinary(int $type): bool
protected function deployBinary(int $type): bool
{
$src = match ($type) {
BUILD_TARGET_CLI => SOURCE_PATH . '/php-src/sapi/cli/php',
@ -114,46 +151,9 @@ trait UnixBuilderTrait
*
* @throws RuntimeException
*/
public function cleanMake(): void
protected function cleanMake(): void
{
logger()->info('cleaning up');
shell()->cd(SOURCE_PATH . '/php-src')->exec('make clean');
}
/**
* Return generic cmake options when configuring cmake projects
*/
public function makeCmakeArgs(): string
{
$extra = $this instanceof LinuxBuilder ? '-DCMAKE_C_COMPILER=' . getenv('CC') . ' ' : '';
return $extra .
'-DCMAKE_BUILD_TYPE=Release ' .
'-DCMAKE_INSTALL_PREFIX=/ ' .
'-DCMAKE_INSTALL_BINDIR=/bin ' .
'-DCMAKE_INSTALL_LIBDIR=/lib ' .
'-DCMAKE_INSTALL_INCLUDEDIR=/include ' .
"-DCMAKE_TOOLCHAIN_FILE={$this->cmake_toolchain_file}";
}
/**
* Generate configure flags
*/
public function makeAutoconfFlags(int $flag = AUTOCONF_ALL): string
{
$extra = '';
// TODO: add auto pkg-config support
if (($flag & AUTOCONF_LIBS) === AUTOCONF_LIBS) {
$extra .= 'LIBS="' . BUILD_LIB_PATH . '" ';
}
if (($flag & AUTOCONF_CFLAGS) === AUTOCONF_CFLAGS) {
$extra .= 'CFLAGS="-I' . BUILD_INCLUDE_PATH . '" ';
}
if (($flag & AUTOCONF_CPPFLAGS) === AUTOCONF_CPPFLAGS) {
$extra .= 'CPPFLAGS="-I' . BUILD_INCLUDE_PATH . '" ';
}
if (($flag & AUTOCONF_LDFLAGS) === AUTOCONF_LDFLAGS) {
$extra .= 'LDFLAGS="-L' . BUILD_LIB_PATH . '" ';
}
return $extra;
}
}