From 2a69369ebf6e177d513336405f35e4364d369916 Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Thu, 5 Dec 2024 15:48:09 +0800 Subject: [PATCH 1/5] Add extension configure tests --- .github/workflows/ext-configure-tests.yml | 137 ++++++++++++++++++++++ src/SPC/builder/BuilderBase.php | 9 ++ src/SPC/exception/InterruptException.php | 7 ++ src/globals/functions.php | 6 + tests/configure.php | 13 ++ 5 files changed, 172 insertions(+) create mode 100644 .github/workflows/ext-configure-tests.yml create mode 100644 src/SPC/exception/InterruptException.php create mode 100644 tests/configure.php diff --git a/.github/workflows/ext-configure-tests.yml b/.github/workflows/ext-configure-tests.yml new file mode 100644 index 000000000..cdc7e50e9 --- /dev/null +++ b/.github/workflows/ext-configure-tests.yml @@ -0,0 +1,137 @@ +name: "Extension configure tests" + +on: + workflow_dispatch: + pull_request: + branches: [ "main" ] + paths: + - '.github/workflows/ext-matrix-tests.yml' + +jobs: + test: + name: "${{ matrix.extension }} (PHP ${{ matrix.php-version }} on ${{ matrix.operating-system }})" + runs-on: ${{ matrix.operating-system }} + strategy: + fail-fast: false + matrix: + extension: + - apcu + - bcmath + - bz2 + - calendar + - ctype + - curl + - dba + - dom + - exif + - fileinfo + - filter + - ftp + - gd + - gmp + - gettext + - iconv + - igbinary + - imagick + - intl + - ldap + - mbregex + - mbstring + - mysqli + - mysqlnd + - opcache + - openssl + - parallel + - pcntl + - pdo + - pdo_mysql + - pdo_pgsql + - pdo_sqlite + - pgsql + - phar + - posix + - protobuf + - readline + - redis + - session + - shmop + - simplexml + - soap + - sockets + - sodium + - sqlite3 + - ssh2 + - sysvmsg + - sysvsem + - sysvshm + - tidy + - tokenizer + - xlswriter + - xml + - xmlreader + - xmlwriter + - zip + - zlib + - yaml + - zstd + php-version: + - "8.4" + operating-system: + - "ubuntu-latest" + + steps: + - name: "Checkout" + uses: "actions/checkout@v4" + + - name: OS type + id: os-type + run: | + OS="" + if [ "${{ matrix.operating-system }}" = "ubuntu-latest" ]; then + OS="linux-x86_64" + elif [ "${{ matrix.operating-system }}" = "macos-13" ]; then + OS="macos-x86_64" + elif [ "${{ matrix.operating-system }}" = "debian-arm64-self-hosted" ]; then + OS="linux-aarch64" + elif [ "${{ matrix.operating-system }}" = "macos-14" ]; then + OS="macos-aarch64" + fi + echo "OS=$OS" >> $GITHUB_ENV + + - name: "Setup PHP" + uses: shivammathur/setup-php@v2 + with: + php-version: 8.2 + tools: pecl, composer + extensions: curl, openssl, mbstring + ini-values: memory_limit=-1 + env: + phpts: nts + + - name: "Install Dependencies" + run: composer update -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist + + - id: cache-download + uses: actions/cache@v4 + with: + path: downloads + key: php-${{ matrix.php-version }}-dependencies-for-tests + + # If there's no dependencies cache, fetch sources + - name: "Download sources" + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: ./bin/spc download --with-php=${{ matrix.php-version }} --for-extensions=${{ matrix.extension }} --debug --ignore-cache-sources=php-src + + - name: "Build library: ${{ matrix.library }}" + run: | + SPC_USE_SUDO=yes ./bin/spc doctor --auto-fix + if [ "${{ env.OS }}" = "linux-x86_64" ]; then + ./bin/spc install-pkg upx + UPX=--with-upx-pack + elif [ "${{ env.OS }}" = "linux-aarch64" ]; then + ./bin/spc install-pkg upx + UPX=--with-upx-pack + fi + + ./bin/spc build --build-cli --build-micro ${{ matrix.extension }} -P tests/configure.php diff --git a/src/SPC/builder/BuilderBase.php b/src/SPC/builder/BuilderBase.php index 33d187c23..8fba69cf7 100644 --- a/src/SPC/builder/BuilderBase.php +++ b/src/SPC/builder/BuilderBase.php @@ -6,6 +6,7 @@ use SPC\exception\ExceptionHandler; use SPC\exception\FileSystemException; +use SPC\exception\InterruptException; use SPC\exception\RuntimeException; use SPC\exception\WrongUsageException; use SPC\store\Config; @@ -407,6 +408,13 @@ public function emitPatchPoint(string $point_name): void } logger()->debug('Running additional patch script: ' . $patch); require $patch; + } catch (InterruptException $e) { + if ($e->getCode() === 0) { + logger()->notice('Patch script ' . $patch . ' interrupted' . ($e->getMessage() ? (': ' . $e->getMessage()) : '.')); + } else { + logger()->error('Patch script ' . $patch . ' interrupted with error code [' . $e->getCode() . ']' . ($e->getMessage() ? (': ' . $e->getMessage()) : '.')); + } + exit($e->getCode()); } catch (\Throwable $e) { logger()->critical('Patch script ' . $patch . ' failed to run.'); if ($this->getOption('debug')) { @@ -414,6 +422,7 @@ public function emitPatchPoint(string $point_name): void } else { logger()->critical('Please check with --debug option to see more details.'); } + exit(1); } } } diff --git a/src/SPC/exception/InterruptException.php b/src/SPC/exception/InterruptException.php new file mode 100644 index 000000000..b004f47f6 --- /dev/null +++ b/src/SPC/exception/InterruptException.php @@ -0,0 +1,7 @@ +getPatchPoint(); } +function patch_point_interrupt(int $retcode, string $msg = ''): InterruptException +{ + return new InterruptException(message: $msg, code: $retcode); +} + // ------- function f_* part ------- // f_ means standard function wrapper diff --git a/tests/configure.php b/tests/configure.php new file mode 100644 index 000000000..6811b631b --- /dev/null +++ b/tests/configure.php @@ -0,0 +1,13 @@ + Date: Thu, 5 Dec 2024 15:49:18 +0800 Subject: [PATCH 2/5] Add extension configure tests --- .github/workflows/ext-configure-tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ext-configure-tests.yml b/.github/workflows/ext-configure-tests.yml index cdc7e50e9..33d39931b 100644 --- a/.github/workflows/ext-configure-tests.yml +++ b/.github/workflows/ext-configure-tests.yml @@ -5,7 +5,7 @@ on: pull_request: branches: [ "main" ] paths: - - '.github/workflows/ext-matrix-tests.yml' + - '.github/workflows/ext-configure-tests.yml' jobs: test: From 2e7fa44df6761d78db11c39d05ec22f9c5a96f40 Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Thu, 5 Dec 2024 15:52:59 +0800 Subject: [PATCH 3/5] Fix patch point tests --- src/SPC/builder/BuilderBase.php | 2 +- tests/SPC/builder/BuilderTest.php | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/SPC/builder/BuilderBase.php b/src/SPC/builder/BuilderBase.php index 8fba69cf7..b61a10e5d 100644 --- a/src/SPC/builder/BuilderBase.php +++ b/src/SPC/builder/BuilderBase.php @@ -422,7 +422,7 @@ public function emitPatchPoint(string $point_name): void } else { logger()->critical('Please check with --debug option to see more details.'); } - exit(1); + throw $e; } } } diff --git a/tests/SPC/builder/BuilderTest.php b/tests/SPC/builder/BuilderTest.php index fe46b785c..5796f5dfe 100644 --- a/tests/SPC/builder/BuilderTest.php +++ b/tests/SPC/builder/BuilderTest.php @@ -246,6 +246,7 @@ public function testEmitPatchPoint(string $point) public function testEmitPatchPointNotExists() { $this->expectOutputRegex('/failed to run/'); + $this->expectException(RuntimeException::class); $this->builder->setOption('with-added-patch', ['/tmp/patch-point.not_exsssists.php']); $this->builder->emitPatchPoint('not-exists'); } From 2640b7d3401c609c03f5cb196086f18a906afa02 Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Thu, 5 Dec 2024 16:59:22 +0800 Subject: [PATCH 4/5] Fix patch point tests --- .github/workflows/ext-configure-tests.yml | 70 ++--------------------- 1 file changed, 5 insertions(+), 65 deletions(-) diff --git a/.github/workflows/ext-configure-tests.yml b/.github/workflows/ext-configure-tests.yml index 33d39931b..d1f629ec1 100644 --- a/.github/workflows/ext-configure-tests.yml +++ b/.github/workflows/ext-configure-tests.yml @@ -15,69 +15,17 @@ jobs: fail-fast: false matrix: extension: - - apcu - - bcmath - - bz2 - - calendar - - ctype - - curl - - dba - - dom - - exif - - fileinfo - - filter - - ftp - - gd - - gmp - - gettext - - iconv - - igbinary - - imagick - - intl - - ldap - - mbregex - - mbstring - - mysqli - - mysqlnd - - opcache - - openssl - parallel - - pcntl - - pdo - - pdo_mysql - pdo_pgsql - - pdo_sqlite - pgsql - - phar - - posix - - protobuf - - readline - - redis - - session - - shmop - - simplexml - - soap - - sockets - - sodium - - sqlite3 - - ssh2 - - sysvmsg - - sysvsem - - sysvshm - - tidy - - tokenizer - - xlswriter - - xml - - xmlreader - - xmlwriter - - zip - - zlib - - yaml - - zstd php-version: - "8.4" + - "8.3" + - "8.2" + - "8.1" operating-system: - "ubuntu-latest" + - "macos-14" steps: - name: "Checkout" @@ -126,12 +74,4 @@ jobs: - name: "Build library: ${{ matrix.library }}" run: | SPC_USE_SUDO=yes ./bin/spc doctor --auto-fix - if [ "${{ env.OS }}" = "linux-x86_64" ]; then - ./bin/spc install-pkg upx - UPX=--with-upx-pack - elif [ "${{ env.OS }}" = "linux-aarch64" ]; then - ./bin/spc install-pkg upx - UPX=--with-upx-pack - fi - - ./bin/spc build --build-cli --build-micro ${{ matrix.extension }} -P tests/configure.php + ./bin/spc build --build-cli --build-micro ${{ matrix.extension }} -P tests/configure.php --debug --enable-zts From 6ebfe5ee3980ff631e34056970a7b1e8f845eb7d Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Thu, 5 Dec 2024 18:43:31 +0800 Subject: [PATCH 5/5] Fix parallel config.m4 --- .github/workflows/ext-configure-tests.yml | 77 ----------------------- src/SPC/builder/extension/parallel.php | 7 +++ src/globals/test-extensions.php | 4 +- tests/configure.php | 13 ---- 4 files changed, 9 insertions(+), 92 deletions(-) delete mode 100644 .github/workflows/ext-configure-tests.yml delete mode 100644 tests/configure.php diff --git a/.github/workflows/ext-configure-tests.yml b/.github/workflows/ext-configure-tests.yml deleted file mode 100644 index d1f629ec1..000000000 --- a/.github/workflows/ext-configure-tests.yml +++ /dev/null @@ -1,77 +0,0 @@ -name: "Extension configure tests" - -on: - workflow_dispatch: - pull_request: - branches: [ "main" ] - paths: - - '.github/workflows/ext-configure-tests.yml' - -jobs: - test: - name: "${{ matrix.extension }} (PHP ${{ matrix.php-version }} on ${{ matrix.operating-system }})" - runs-on: ${{ matrix.operating-system }} - strategy: - fail-fast: false - matrix: - extension: - - parallel - - pdo_pgsql - - pgsql - php-version: - - "8.4" - - "8.3" - - "8.2" - - "8.1" - operating-system: - - "ubuntu-latest" - - "macos-14" - - steps: - - name: "Checkout" - uses: "actions/checkout@v4" - - - name: OS type - id: os-type - run: | - OS="" - if [ "${{ matrix.operating-system }}" = "ubuntu-latest" ]; then - OS="linux-x86_64" - elif [ "${{ matrix.operating-system }}" = "macos-13" ]; then - OS="macos-x86_64" - elif [ "${{ matrix.operating-system }}" = "debian-arm64-self-hosted" ]; then - OS="linux-aarch64" - elif [ "${{ matrix.operating-system }}" = "macos-14" ]; then - OS="macos-aarch64" - fi - echo "OS=$OS" >> $GITHUB_ENV - - - name: "Setup PHP" - uses: shivammathur/setup-php@v2 - with: - php-version: 8.2 - tools: pecl, composer - extensions: curl, openssl, mbstring - ini-values: memory_limit=-1 - env: - phpts: nts - - - name: "Install Dependencies" - run: composer update -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist - - - id: cache-download - uses: actions/cache@v4 - with: - path: downloads - key: php-${{ matrix.php-version }}-dependencies-for-tests - - # If there's no dependencies cache, fetch sources - - name: "Download sources" - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: ./bin/spc download --with-php=${{ matrix.php-version }} --for-extensions=${{ matrix.extension }} --debug --ignore-cache-sources=php-src - - - name: "Build library: ${{ matrix.library }}" - run: | - SPC_USE_SUDO=yes ./bin/spc doctor --auto-fix - ./bin/spc build --build-cli --build-micro ${{ matrix.extension }} -P tests/configure.php --debug --enable-zts diff --git a/src/SPC/builder/extension/parallel.php b/src/SPC/builder/extension/parallel.php index f50dffb26..de4e5d88c 100644 --- a/src/SPC/builder/extension/parallel.php +++ b/src/SPC/builder/extension/parallel.php @@ -6,6 +6,7 @@ use SPC\builder\Extension; use SPC\exception\WrongUsageException; +use SPC\store\FileSystem; use SPC\util\CustomExt; #[CustomExt('parallel')] @@ -17,4 +18,10 @@ public function validate(): void throw new WrongUsageException('ext-parallel must be built with ZTS builds. Use "--enable-zts" option!'); } } + + public function patchBeforeBuildconf(): bool + { + FileSystem::replaceFileRegex(SOURCE_PATH . '/php-src/ext/parallel/config.m4', '/PHP_VERSION=.*/m', ''); + return true; + } } diff --git a/src/globals/test-extensions.php b/src/globals/test-extensions.php index 6bf021590..a08ebc7f5 100644 --- a/src/globals/test-extensions.php +++ b/src/globals/test-extensions.php @@ -26,7 +26,7 @@ ]; // whether enable thread safe -$zts = false; +$zts = true; $no_strip = false; @@ -38,7 +38,7 @@ // If you want to test your added extensions and libs, add below (comma separated, example `bcmath,openssl`). $extensions = match (PHP_OS_FAMILY) { - 'Linux', 'Darwin' => 'grpc,openssl,pgsql', + 'Linux', 'Darwin' => 'parallel', 'Windows' => 'amqp,apcu,bcmath,bz2,calendar,ctype,curl,dba,dom,ds,exif,ffi,fileinfo,filter,ftp,gd,iconv,igbinary,libxml,mbregex,mbstring,mysqli,mysqlnd,opcache,openssl,pdo,pdo_mysql,pdo_sqlite,pdo_sqlsrv,phar,rar,redis,session,shmop,simdjson,simplexml,soap,sockets,sqlite3,sqlsrv,ssh2,swow,sysvshm,tokenizer,xml,xmlreader,xmlwriter,yac,yaml,zip,zlib', }; diff --git a/tests/configure.php b/tests/configure.php deleted file mode 100644 index 6811b631b..000000000 --- a/tests/configure.php +++ /dev/null @@ -1,13 +0,0 @@ -