From 8de942c27464546a67e24a6664e8e47e2c8d9e7d Mon Sep 17 00:00:00 2001 From: Jerry Ma Date: Wed, 10 Jan 2024 11:10:40 +0800 Subject: [PATCH] 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 --- src/SPC/builder/BuilderBase.php | 4 ++ src/SPC/builder/freebsd/BSDBuilder.php | 8 +-- src/SPC/builder/linux/LinuxBuilder.php | 8 +-- src/SPC/builder/macos/MacOSBuilder.php | 8 +-- src/SPC/builder/traits/UnixBuilderTrait.php | 80 ++++++++++----------- 5 files changed, 56 insertions(+), 52 deletions(-) diff --git a/src/SPC/builder/BuilderBase.php b/src/SPC/builder/BuilderBase.php index 175aaf41..729a46c5 100644 --- a/src/SPC/builder/BuilderBase.php +++ b/src/SPC/builder/BuilderBase.php @@ -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 { diff --git a/src/SPC/builder/freebsd/BSDBuilder.php b/src/SPC/builder/freebsd/BSDBuilder.php index ddad0ca9..b1fa8851 100644 --- a/src/SPC/builder/freebsd/BSDBuilder.php +++ b/src/SPC/builder/freebsd/BSDBuilder.php @@ -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 diff --git a/src/SPC/builder/linux/LinuxBuilder.php b/src/SPC/builder/linux/LinuxBuilder.php index e01028be..f99c9bca 100644 --- a/src/SPC/builder/linux/LinuxBuilder.php +++ b/src/SPC/builder/linux/LinuxBuilder.php @@ -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()); diff --git a/src/SPC/builder/macos/MacOSBuilder.php b/src/SPC/builder/macos/MacOSBuilder.php index c7ac7107..b74aaa60 100644 --- a/src/SPC/builder/macos/MacOSBuilder.php +++ b/src/SPC/builder/macos/MacOSBuilder.php @@ -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()); diff --git a/src/SPC/builder/traits/UnixBuilderTrait.php b/src/SPC/builder/traits/UnixBuilderTrait.php index 3fead06f..e369fb04 100644 --- a/src/SPC/builder/traits/UnixBuilderTrait.php +++ b/src/SPC/builder/traits/UnixBuilderTrait.php @@ -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; - } }