diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md new file mode 100644 index 0000000..c4ef029 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -0,0 +1,54 @@ +--- +name: Bug report +about: Create a report to help us improve +title: '' +labels: bug +assignees: '' +--- + + + +### Describe the bug + + +### Reproduction steps + + +### Environment + + +#### Version of K2HASH PHP Extension being used ( package version ) +``` +``` + +#### Version of PHP (`php --version`) +``` +``` + +#### Distro (`cat /etc/os-release`) +``` +``` + +### Relevant Issues/Pull Requests (if applicable) + + +### Additional context + diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md new file mode 100644 index 0000000..4fe4232 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -0,0 +1,24 @@ +--- +name: Feature request +about: Suggest an idea for this project +title: '' +labels: enhancement +assignees: '' +--- + +### Feature request + + +### Relevant Issues/Pull Requests (if applicable) + + +### Additional context/explanation + diff --git a/.github/ISSUE_TEMPLATE/support_request.md b/.github/ISSUE_TEMPLATE/support_request.md new file mode 100644 index 0000000..820f6e9 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/support_request.md @@ -0,0 +1,18 @@ +--- +name: Support request +about: Request support for how to use, etc. +title: '' +labels: help wanted +assignees: '' +--- + +### What kind of support do you need? + + +### Relevant Issues/Pull Requests (if applicable) + diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 0000000..3550906 --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,10 @@ +### Relevant Issues/Pull Requests (if applicable) + + +### Details + diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..7856133 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,157 @@ +# +# k2hdkc PHP Extension library +# ----------------------------------------------------------------------- +# Utility tools for building configure/packages by AntPickax +# +# Copyright 2022 Yahoo Japan Corporation. +# +# AntPickax provides utility tools for supporting autotools +# builds. +# +# These tools retrieve the necessary information from the +# repository and appropriately set the setting values of +# configure, Makefile, spec,etc file and so on. +# These tools were recreated to reduce the number of fixes and +# reduce the workload of developers when there is a change in +# the project configuration. +# ----------------------------------------------------------------------- +# +# Copyright 2023 Yahoo Japan Corporation. +# +# Modified to work with K2HDKC PHP Extension library. The original source +# code is from K2HASH PHP Extension library, which is distibuted under +# MIT License as well as this program. See the LICENSE file for the full +# copyright and license information +# +# AUTHOR: Takeshi Nakatani +# CREATE: Fri, Feb 24 2022 +# REVISION: +# + +#---------------------------------------------------------- +# Github Actions +#---------------------------------------------------------- +name: PHP AntPickax CI + +# +# Events +# +on: + push: + pull_request: + # + # CRON event is fire on every sunday(UTC). + # + schedule: + - cron: '0 15 * * 0' + +# +# Jobs +# +jobs: + build: + runs-on: ubuntu-latest + + # + # build matrix for containers + # + strategy: + # + # do not stop jobs automatically if any of the jobs fail + # + fail-fast: false + + # + # matrix for containers + # + matrix: + container: + - ubuntu:22.04 + - ubuntu:20.04 + - ubuntu:18.04 + - debian:bullseye + - debian:buster + - centos:centos7 + - rockylinux:9 + - rockylinux:8 + - fedora:37 + - fedora:36 + - alpine:3.17 + + php: + - PHP80 + - PHP81 + - PHP82 + + container: + image: ${{ matrix.container }} + + env: + # + # Installation special environment variables for ubuntu(debian). + # + DEBIAN_FRONTEND: noninteractive + + # + # For PHP Unit test + # + NO_INTERACTION: 1 + + steps: + # + # Checks-out your repository under $GITHUB_WORKSPACE, so your + # job can access it + # + - name: Checkout sources + uses: actions/checkout@v3 + + # + # Set environments from secrets + # + # [NOTE] Secrets + # Use Secrets of organization or repository as parameters to + # pass to build_helper.sh for building and packaging, . + # + # The available Secret variables are listed below: + # PHPEXTTYPE_VARS_FILE : specify custom variables file + # BUILD_NUMBER : buld number for packaging + # DEVELOPER_FULLNAME : developer name for package + # DEVELOPER_EMAIL : developer e-mail for package + # FORCE_PUBLISH : true means force to publish packages, false means never publish + # USE_PACKAGECLOUD_REPO : true means using pacakgecloud.io repo, false is not using + # * PACKAGECLOUD_TOKEN : The token for publishing to packagcloud.io + # PACKAGECLOUD_OWNER : owner name as a part of path to packagcloud.io for publishing/downloading + # PACKAGECLOUD_PUBLISH_REPO : repo name as a part of path to packagcloud.io for publishing + # PACKAGECLOUD_DOWNLOAD_REPO : repo name as a part of path to packagcloud.io for downloading + # + # "PACKAGECLOUD_TOKEN" is a required variable to publish the + # package. + # + - name: Set environments from secrets + run: | + echo "ENV_PHPEXTTYPE_VARS_FILE=${{ secrets.PHPEXTTYPE_VARS_FILE }}" >> "${GITHUB_ENV}" + echo "ENV_BUILD_NUMBER=${{ secrets.BUILD_NUMBER }}" >> "${GITHUB_ENV}" + echo "ENV_DEVELOPER_FULLNAME=${{ secrets.DEVELOPER_FULLNAME }}" >> "${GITHUB_ENV}" + echo "ENV_DEVELOPER_EMAIL=${{ secrets.DEVELOPER_EMAIL }}" >> "${GITHUB_ENV}" + echo "ENV_FORCE_PUBLISH=${{ secrets.FORCE_PUBLISH }}" >> "${GITHUB_ENV}" + echo "ENV_USE_PACKAGECLOUD_REPO=${{ secrets.USE_PACKAGECLOUD_REPO }}" >> "${GITHUB_ENV}" + echo "ENV_PACKAGECLOUD_TOKEN=${{ secrets.PACKAGECLOUD_TOKEN }}" >> "${GITHUB_ENV}" + echo "ENV_PACKAGECLOUD_OWNER=${{ secrets.PACKAGECLOUD_OWNER }}" >> "${GITHUB_ENV}" + echo "ENV_PACKAGECLOUD_PUBLISH_REPO=${{ secrets.PACKAGECLOUD_PUBLISH_REPO }}" >> "${GITHUB_ENV}" + echo "ENV_PACKAGECLOUD_DOWNLOAD_REPO=${{ secrets.PACKAGECLOUD_DOWNLOAD_REPO }}" >> "${GITHUB_ENV}" + + # + # Run building and packaging helper + # + - name: Run building and packaging + run: | + /bin/sh -c "$GITHUB_WORKSPACE/.github/workflows/phpext_helper.sh -os ${{ matrix.container }} -php ${{ matrix.php }}" + +# +# Local variables: +# tab-width: 4 +# c-basic-offset: 4 +# End: +# vim600: expandtab sw=4 ts=4 fdm=marker +# vim<600: expandtab sw=4 ts=4 +# diff --git a/.github/workflows/phpext_helper.sh b/.github/workflows/phpext_helper.sh new file mode 100755 index 0000000..cb12857 --- /dev/null +++ b/.github/workflows/phpext_helper.sh @@ -0,0 +1,1832 @@ +#!/bin/sh + +# k2hdkc PHP Extension library +# ----------------------------------------------------------------------- +# Utility tools for building configure/packages by AntPickax +# +# Copyright 2022 Yahoo Japan Corporation. +# +# AntPickax provides utility tools for supporting autotools +# builds. +# +# These tools retrieve the necessary information from the +# repository and appropriately set the setting values of +# configure, Makefile, spec,etc file and so on. +# These tools were recreated to reduce the number of fixes and +# reduce the workload of developers when there is a change in +# the project configuration. +# ----------------------------------------------------------------------- +# +# Copyright 2023 Yahoo Japan Corporation. +# +# Modified to work with K2HDKC PHP Extension library. The original source +# code is from K2HASH PHP Extension library, which is distibuted under +# MIT License as well as this program. See the LICENSE file for the full +# copyright and license information. +# +# AUTHOR: Takeshi Nakatani +# CREATE: Fri, Feb 24 2022 +# REVISION: 1.1 +# + +#============================================================== +# Build helper for PHP Extension on Github Actions +#============================================================== +# +# Instead of pipefail(for shells not support "set -o pipefail") +# +PIPEFAILURE_FILE="/tmp/.pipefailure.$(od -An -tu4 -N4 /dev/random | tr -d ' \n')" + +# +# For shellcheck +# +if command -v locale >/dev/null 2>&1; then + if locale -a | grep -q -i '^[[:space:]]*C.utf8[[:space:]]*$'; then + LANG=$(locale -a | grep -i '^[[:space:]]*C.utf8[[:space:]]*$' | sed -e 's/^[[:space:]]*//g' -e 's/[[:space:]]*$//g' | tr -d '\n') + LC_ALL="${LANG}" + export LANG + export LC_ALL + elif locale -a | grep -q -i '^[[:space:]]*en_US.utf8[[:space:]]*$'; then + LANG=$(locale -a | grep -i '^[[:space:]]*en_US.utf8[[:space:]]*$' | sed -e 's/^[[:space:]]*//g' -e 's/[[:space:]]*$//g' | tr -d '\n') + LC_ALL="${LANG}" + export LANG + export LC_ALL + fi +fi + +#============================================================== +# Common variables +#============================================================== +PRGNAME=$(basename "$0") +SCRIPTDIR=$(dirname "$0") +SCRIPTDIR=$(cd "${SCRIPTDIR}" || exit 1; pwd) +SRCTOP=$(cd "${SCRIPTDIR}"/../.. || exit 1; pwd) + +# +# Message variables +# +IN_GHAGROUP_AREA=0 + +# +# Variables with default values +# +CI_OSTYPE="" +CI_PHPTYPE="" + +CI_PHPEXTTYPE_VARS_FILE="${SCRIPTDIR}/phpexttypevars.sh" +CI_BUILD_NUMBER=1 +CI_DEVELOPER_FULLNAME="" +CI_DEVELOPER_EMAIL="" +CI_FORCE_PUBLISH="" +CI_USE_PACKAGECLOUD_REPO=1 +CI_PACKAGECLOUD_TOKEN="" +CI_PACKAGECLOUD_OWNER="antpickax" +CI_PACKAGECLOUD_PUBLISH_REPO="stable" +CI_PACKAGECLOUD_DOWNLOAD_REPO="stable" +# +CI_IN_SCHEDULE_PROCESS=0 +CI_PUBLISH_TAG_NAME="" +CI_DO_PUBLISH=0 + +#============================================================== +# Utility functions and variables for messaging +#============================================================== +# +# Utilities for message +# +if [ -t 1 ] || { [ -n "${CI}" ] && [ "${CI}" = "true" ]; }; then + CBLD=$(printf '\033[1m') + CREV=$(printf '\033[7m') + CRED=$(printf '\033[31m') + CYEL=$(printf '\033[33m') + CGRN=$(printf '\033[32m') + CDEF=$(printf '\033[0m') +else + CBLD="" + CREV="" + CRED="" + CYEL="" + CGRN="" + CDEF="" +fi +if [ -n "${CI}" ] && [ "${CI}" = "true" ]; then + GHAGRP_START="::group::" + GHAGRP_END="::endgroup::" +else + GHAGRP_START="" + GHAGRP_END="" +fi + +PRNGROUPEND() +{ + if [ -n "${IN_GHAGROUP_AREA}" ] && [ "${IN_GHAGROUP_AREA}" -eq 1 ]; then + if [ -n "${GHAGRP_END}" ]; then + echo "${GHAGRP_END}" + fi + fi + IN_GHAGROUP_AREA=0 +} +PRNTITLE() +{ + PRNGROUPEND + echo "${GHAGRP_START}${CBLD}${CGRN}${CREV}[TITLE]${CDEF} ${CGRN}$*${CDEF}" + IN_GHAGROUP_AREA=1 +} +PRNINFO() +{ + echo "${CBLD}${CREV}[INFO]${CDEF} $*" +} +PRNWARN() +{ + echo "${CBLD}${CYEL}${CREV}[WARNING]${CDEF} ${CYEL}$*${CDEF}" +} +PRNERR() +{ + echo "${CBLD}${CRED}${CREV}[ERROR]${CDEF} ${CRED}$*${CDEF}" + PRNGROUPEND +} +PRNSUCCESS() +{ + echo "${CBLD}${CGRN}${CREV}[SUCCEED]${CDEF} ${CGRN}$*${CDEF}" + PRNGROUPEND +} +PRNFAILURE() +{ + echo "${CBLD}${CRED}${CREV}[FAILURE]${CDEF} ${CRED}$*${CDEF}" + PRNGROUPEND +} +RUNCMD() +{ + PRNINFO "Run \"$*\"" + if ! /bin/sh -c "$*"; then + PRNERR "Failed to run \"$*\"" + return 1 + fi + return 0 +} + +#---------------------------------------------------------- +# Helper for container on Github Actions +#---------------------------------------------------------- +func_usage() +{ + echo "" + echo "Usage: $1 [options...]" + echo "" + echo " Required option:" + echo " --help(-h) print help" + echo " --ostype(-os) specify os and version as like \"ubuntu:jammy\"" + echo " --phptype(-php) specify PHP and version as like \"PHP8.1\"/\"PHP8\"/\"8.1\"/\"8\"" + echo "" + echo " Option:" + echo " --phpexttype-vars-file(-f) specify the file that describes the package list to be installed before build(default is phpexttypevars.sh)" + echo " --force-publish(-p) force the release package to be uploaded. normally the package is uploaded only when it is tagged(determined from GITHUB_REF/GITHUB_EVENT_NAME)." + echo " --not-publish(-np) do not force publish the release package." + echo " --build-number(-num) build number for packaging(default 1)" + echo " --developer-fullname(-devname) specify developer name for debian and ubuntu packaging(default is null, it is specified in configure.ac)" + echo " --developer-email(-devmail) specify developer e-mail for debian and ubuntu packaging(default is null, it is specified in configure.ac)" + echo "" + echo " Option for packagecloud.io:" + echo " --use-packagecloudio-repo(-usepc) use packagecloud.io repository(default), exclusive -notpc option" + echo " --not-use-packagecloudio-repo(-notpc) not use packagecloud.io repository, exclusive -usepc option" + echo " --packagecloudio-token(-pctoken) packagecloud.io token for uploading(specify when uploading)" + echo " --packagecloudio-owner(-pcowner) owner name of uploading destination to packagecloud.io, this is part of the repository path(default is antpickax)" + echo " --packagecloudio-publish-repo(-pcprepo) repository name of uploading destination to packagecloud.io, this is part of the repository path(default is current)" + echo " --packagecloudio-download-repo(-pcdlrepo) repository name of installing packages in packagecloud.io, this is part of the repository path(default is stable)" + echo "" + echo " Environments:" + echo " ENV_PHPEXTTYPE_VARS_FILE the file that describes the package list ( same as option '--phpexttype-vars-file(-f)' )" + echo " ENV_BUILD_NUMBER build number ( same as option '--build-number(-num)' )" + echo " ENV_DEVELOPER_FULLNAME developer name ( same as option '--developer-fullname(-devname)' )" + echo " ENV_DEVELOPER_EMAIL developer e-mail ( same as option '--developer-email(-devmail)' )" + echo " ENV_FORCE_PUBLISH force the release package to be uploaded: true/false ( same as option '--force-publish(-p)' and '--not-publish(-np)' )" + echo " ENV_USE_PACKAGECLOUD_REPO use packagecloud.io repository: true/false ( same as option '--use-packagecloudio-repo(-usepc)' and '--not-use-packagecloudio-repo(-notpc)' )" + echo " ENV_PACKAGECLOUD_TOKEN packagecloud.io token ( same as option '--packagecloudio-token(-pctoken)' )" + echo " ENV_PACKAGECLOUD_OWNER owner name for uploading to packagecloud.io ( same as option '--packagecloudio-owner(-pcowner)' )" + echo " ENV_PACKAGECLOUD_PUBLISH_REPO repository name of uploading to packagecloud.io ( same as option '--packagecloudio-publish-repo(-pcprepo)' )" + echo " ENV_PACKAGECLOUD_DOWNLOAD_REPO repository name of installing packages in packagecloud.io ( same as option '--packagecloudio-download-repo(-pcdlrepo)' )" + echo " GITHUB_REF use internally for release tag" + echo " GITHUB_EVENT_NAME use internally for checking schedule processing" + echo "" + echo " Note:" + echo " Environment variables and options have the same parameter items." + echo " If both are specified, the option takes precedence." + echo " Environment variables are set from Github Actions Secrets, etc." + echo " GITHUB_REF and GITHUB_EVENT_NAME environments are used internally." + echo "" +} + +#============================================================== +# Default execution functions and variables +#============================================================== +# +# Execution flag ( default is for PHP Extension ) +# +RUN_PRE_CONFIG=1 +RUN_CONFIG=1 +RUN_PRE_CLEANUP=1 +RUN_CLEANUP=1 +RUN_POST_CLEANUP=0 +RUN_CPPCHECK=1 +RUN_SHELLCHECK=1 +RUN_CHECK_OTHER=0 +RUN_PRE_BUILD=0 +RUN_BUILD=1 +RUN_POST_BUILD=0 +RUN_PRE_TEST=0 +RUN_TEST=1 +RUN_POST_TEST=0 +RUN_PRE_PACKAGE=0 +RUN_PACKAGE=1 +RUN_POST_PACKAGE=0 +RUN_PUBLISH_PACKAGE=1 + +# +# Before configuration +# +run_pre_configuration() +{ + # [NOTICE] + # Current actions/checkout@v3 (Github Action) is not make ".git" directory. + # If there are a ".git" directory and no "Untracked files", you can use + # "git archive HEAD" to tar.gz the source code for package creation. + # But we need a way to create a ".git" directory if it doesn't exist. + # The PHP Extension uses "phpize(config.m4)" and this tool does not support + # "make dist", so we need to prepare a way as same as "make dist". + # Therefore, it is necessary to create a "tar.gz" file from only all source + # code before running "phpize". + # Once "actions/checkout" extracts the ".git" directory, we can use + # "git archive HEAD", but "make dist" is not supported, so this process + # will remain permanent. + # This source code "tar.gz" file is required for processing "php_rpm_build.sh" + # and "php_debian_build.sh". + # + _SOURCECODE_DIRNAME=$(basename "${SRCTOP}") + _ALL_SOURCE_TARGZ_FILENAME="${_SOURCECODE_DIRNAME}_allsource.tar.gz" + if ! (cd .. || exit 1; touch "${_SOURCECODE_DIRNAME}/${_ALL_SOURCE_TARGZ_FILENAME}"; tar cvfz "${_SOURCECODE_DIRNAME}/${_ALL_SOURCE_TARGZ_FILENAME}" --exclude="${_SOURCECODE_DIRNAME}/${_ALL_SOURCE_TARGZ_FILENAME}" "${_SOURCECODE_DIRNAME}"); then + PRNERR "Failed to creating all source code tar.gz file for backup(packaging)." + return 1 + fi + + if ! /bin/sh -c "${SWITCH_PHP_COMMAND} phpize"; then + PRNERR "Failed to run \"phpize\" before configration." + return 1 + fi + return 0 +} + +# +# Configuration +# +run_configuration() +{ + if ! /bin/sh -c "${SWITCH_PHP_COMMAND} ./configure"; then + PRNERR "Failed to run \"configure\"." + return 1 + fi + return 0 +} + +# +# Before Cleanup +# +run_pre_cleanup() +{ + if [ -n "${PRE_CLEANUP_FILES_DIRS}" ]; then + for _pre_cleanup_file_dir in ${PRE_CLEANUP_FILES_DIRS}; do + rm -rf "${_pre_cleanup_file_dir}" + done + else + PRNINFO "Nothing to cleanup files or directories." + fi + return 0 +} + +# +# Cleanup +# +run_cleanup() +{ + if ! /bin/sh -c "${SWITCH_PHP_COMMAND} make clean"; then + PRNWARN "Failed to run \"make clean\", but continue because this command is failed if there is no Makefile." + fi + return 0 +} + +# +# After Cleanup +# +run_post_cleanup() +{ + PRNWARN "Not implement process after cleanup." + return 0 +} + +# +# Check before building : CppCheck +# +run_cppcheck() +{ + # + # Targets + # + if [ -z "${CPPCHECK_TARGET}" ]; then + PRNERR "Failed to run \"cppcheck\", target files/dirs is not specified." + return 1 + fi + + CPPCHECK_ENABLE_OPT="" + for _one_opt in ${CPPCHECK_ENABLE_VALUES}; do + if [ -n "${_one_opt}" ]; then + if [ -z "${CPPCHECK_ENABLE_OPT}" ]; then + CPPCHECK_ENABLE_OPT="--enable=" + else + CPPCHECK_ENABLE_OPT="${CPPCHECK_ENABLE_OPT}," + fi + CPPCHECK_ENABLE_OPT="${CPPCHECK_ENABLE_OPT}${_one_opt}" + fi + done + + CPPCHECK_IGNORE_OPT="" + for _one_opt in ${CPPCHECK_IGNORE_VALUES}; do + if [ -n "${_one_opt}" ]; then + CPPCHECK_IGNORE_OPT="${CPPCHECK_IGNORE_OPT} --suppress=${_one_opt}" + fi + done + + CPPCHECK_BUILD_DIR_OPT="" + if [ -n "${CPPCHECK_BUILD_DIR}" ]; then + rm -rf "${CPPCHECK_BUILD_DIR}" + if ! mkdir -p "${CPPCHECK_BUILD_DIR}"; then + PRNERR "Failed to run \"cppcheck\", could not create ${CPPCHECK_BUILD_DIR} directory." + return 1 + fi + CPPCHECK_BUILD_DIR_OPT="--cppcheck-build-dir=${CPPCHECK_BUILD_DIR}" + fi + + if ! /bin/sh -c "cppcheck ${CPPCHECK_BASE_OPT} ${CPPCHECK_ENABLE_OPT} ${CPPCHECK_IGNORE_OPT} ${CPPCHECK_BUILD_DIR_OPT} ${CPPCHECK_TARGET}"; then + PRNERR "Failed to run \"cppcheck\"." + return 1 + fi + return 0 +} + +# +# Check before building : ShellCheck +# +run_shellcheck() +{ + # + # Targets + # + if [ -z "${SHELLCHECK_TARGET_DIRS}" ]; then + PRNERR "Failed to run \"shellcheck\", target files/dirs is not specified." + return 1 + fi + + # + # Exclude options + # + SHELLCHECK_IGN_OPT="" + for _one_opt in ${SHELLCHECK_IGN}; do + if [ -n "${_one_opt}" ]; then + if [ -z "${SHELLCHECK_IGN_OPT}" ]; then + SHELLCHECK_IGN_OPT="--exclude=" + else + SHELLCHECK_IGN_OPT="${SHELLCHECK_IGN_OPT}," + fi + SHELLCHECK_IGN_OPT="${SHELLCHECK_IGN_OPT}${_one_opt}" + fi + done + + SHELLCHECK_INCLUDE_IGN_OPT="${SHELLCHECK_IGN_OPT}" + for _one_opt in ${SHELLCHECK_INCLUDE_IGN}; do + if [ -n "${_one_opt}" ]; then + if [ -z "${SHELLCHECK_INCLUDE_IGN_OPT}" ]; then + SHELLCHECK_INCLUDE_IGN_OPT="--exclude=" + else + SHELLCHECK_INCLUDE_IGN_OPT="${SHELLCHECK_INCLUDE_IGN_OPT}," + fi + SHELLCHECK_INCLUDE_IGN_OPT="${SHELLCHECK_INCLUDE_IGN_OPT}${_one_opt}" + fi + done + + # + # Target file selection + # + # [NOTE] + # SHELLCHECK_FILES_NO_SH : Script files with file extension not ".sh" but with "#!" + # SHELLCHECK_FILES_SH : Script files with file extension ".sh" and "#!" + # SHELLCHECK_FILES_INCLUDE_SH : Files included in script files with file extension ".sh" but without "#!" + # + SHELLCHECK_EXCEPT_PATHS_CMD="| grep -v '\.sh\.' | grep -v '\.log' | grep -v '/\.git/'" + for _one_path in ${SHELLCHECK_EXCEPT_PATHS}; do + SHELLCHECK_EXCEPT_PATHS_CMD="${SHELLCHECK_EXCEPT_PATHS_CMD} | grep -v '${_one_path}'" + done + + SHELLCHECK_FILES_NO_SH="$(/bin/sh -c "grep -ril '^\#!/bin/sh' ${SHELLCHECK_TARGET_DIRS} | grep -v '\.sh' ${SHELLCHECK_EXCEPT_PATHS_CMD} | tr '\n' ' '")" + SHELLCHECK_FILES_SH="$(/bin/sh -c "grep -ril '^\#!/bin/sh' ${SHELLCHECK_TARGET_DIRS} | grep '\.sh' ${SHELLCHECK_EXCEPT_PATHS_CMD} | tr '\n' ' '")" + SHELLCHECK_FILES_INCLUDE_SH="$(/bin/sh -c "grep -Lir '^\#!/bin/sh' ${SHELLCHECK_TARGET_DIRS} | grep '\.sh' ${SHELLCHECK_EXCEPT_PATHS_CMD} | tr '\n' ' '")" + + # + # Check scripts + # + _SHELLCHECK_ERROR=0 + if [ -n "${SHELLCHECK_FILES_NO_SH}" ]; then + if ! /bin/sh -c "shellcheck ${SHELLCHECK_BASE_OPT} ${SHELLCHECK_IGN_OPT} ${SHELLCHECK_FILES_NO_SH}"; then + _SHELLCHECK_ERROR=1 + fi + fi + if [ -n "${SHELLCHECK_FILES_SH}" ]; then + if ! /bin/sh -c "shellcheck ${SHELLCHECK_BASE_OPT} ${SHELLCHECK_IGN_OPT} ${SHELLCHECK_FILES_SH}"; then + _SHELLCHECK_ERROR=1 + fi + fi + if [ -n "${SHELLCHECK_FILES_INCLUDE_SH}" ]; then + if ! /bin/sh -c "shellcheck ${SHELLCHECK_BASE_OPT} ${SHELLCHECK_INCLUDE_IGN_OPT} ${SHELLCHECK_FILES_INCLUDE_SH}"; then + _SHELLCHECK_ERROR=1 + fi + fi + + if [ "${_SHELLCHECK_ERROR}" -ne 0 ]; then + PRNERR "Failed to run \"shellcheck\"." + return 1 + fi + return 0 +} + +# +# Check before building : Other +# +run_othercheck() +{ + PRNWARN "Not implement other check before building." + return 0 +} + +# +# Before Build +# +run_pre_build() +{ + PRNWARN "Not implement process before building." + return 0 +} + +# +# Build +# +run_build() +{ + if ! /bin/sh -c "${SWITCH_PHP_COMMAND} make ${BUILD_MAKE_EXT_OPT}"; then + PRNERR "Failed to run \"make\"." + return 1 + fi + return 0 +} + +# +# After Build +# +run_post_build() +{ + PRNWARN "Not implement process after building." + return 0 +} + +# +# Before Test +# +run_pre_test() +{ + PRNWARN "Not implement process before testing." + return 0 +} + +# +# Test +# +run_test() +{ + if ! /bin/sh -c "${SWITCH_PHP_COMMAND} make ${MAKE_TEST_OPT}"; then + PRNERR "Failed to run \"make ${MAKE_TEST_OPT} ${MAKE_TEST_EXT_OPT}\"." + return 1 + fi + return 0 +} + +# +# After Test +# +run_post_test() +{ + PRNWARN "Not implement process after testing." + return 0 +} + +# +# Before Create Package +# +run_pre_create_package() +{ + PRNWARN "Not implement process before packaging." + return 0 +} + +# +# Create Package +# +run_create_package() +{ + if ! RUN_AS_SUBPROCESS="true" /bin/sh -c "${SWITCH_PHP_COMMAND} ${CREATE_PACKAGE_TOOL} ${CREATE_PACKAGE_TOOL_OPT_AUTO} --buildnum ${CI_BUILD_NUMBER} ${CREATE_PACKAGE_TOOL_OPT}"; then + PRNERR "Failed to create debian type packages" + return 1 + fi + return 0 +} + +# +# After Create Package +# +run_post_create_package() +{ + PRNWARN "Not implement process after packaging." + return 0 +} + +# +# Publish Package +# +run_publish_package() +{ + if [ "${CI_DO_PUBLISH}" -eq 1 ]; then + if [ -z "${CI_PACKAGECLOUD_TOKEN}" ]; then + PRNERR "Token for uploading to packagecloud.io is not specified." + return 1 + fi + if ! PACKAGECLOUD_TOKEN="${CI_PACKAGECLOUD_TOKEN}" /bin/sh -c "package_cloud push ${CI_PACKAGECLOUD_OWNER}/${CI_PACKAGECLOUD_PUBLISH_REPO}/${DIST_TAG} ${SRCTOP}/${PKG_OUTPUT_DIR}/*.${PKG_EXT}"; then + PRNERR "Failed to publish *.${PKG_EXT} packages to ${CI_PACKAGECLOUD_OWNER}/${CI_PACKAGECLOUD_PUBLISH_REPO}/${DIST_TAG}" + return 1 + fi + else + PRNINFO "Not need to publish packages" + fi + return 0 +} + +#============================================================== +# Check options and environments +#============================================================== +PRNTITLE "Start to check options and environments" + +# +# Parse options +# +OPT_OSTYPE="" +OPT_PHPTYPE="" +OPT_PHPEXTTYPE_VARS_FILE="" +OPT_BUILD_NUMBER= +OPT_DEVELOPER_FULLNAME="" +OPT_DEVELOPER_EMAIL="" +OPT_FORCE_PUBLISH="" +OPT_USE_PACKAGECLOUD_REPO= +OPT_PACKAGECLOUD_TOKEN="" +OPT_PACKAGECLOUD_OWNER="" +OPT_PACKAGECLOUD_PUBLISH_REPO="" +OPT_PACKAGECLOUD_DOWNLOAD_REPO="" + +while [ $# -ne 0 ]; do + if [ -z "$1" ]; then + break + + elif [ "$1" = "-h" ] || [ "$1" = "-H" ] || [ "$1" = "--help" ] || [ "$1" = "--HELP" ]; then + func_usage "${PRGNAME}" + exit 0 + + elif [ "$1" = "-os" ] || [ "$1" = "-OS" ] || [ "$1" = "--ostype" ] || [ "$1" = "--OSTYPE" ]; then + if [ -n "${OPT_OSTYPE}" ]; then + PRNERR "already set \"--ostype(-os)\" option." + exit 1 + fi + shift + if [ $# -eq 0 ]; then + PRNERR "\"--ostype(-os)\" option is specified without parameter." + exit 1 + fi + OPT_OSTYPE="$1" + + elif [ "$1" = "-php" ] || [ "$1" = "-PHP" ] || [ "$1" = "--phptype" ] || [ "$1" = "--PHPTYPE" ]; then + if [ -n "${OPT_PHPTYPE}" ]; then + PRNERR "already set \"--phptype(-php)\" option." + exit 1 + fi + shift + if [ $# -eq 0 ]; then + PRNERR "\"--phptype(-php)\" option is specified without parameter." + exit 1 + fi + OPT_PHPTYPE="$1" + + elif [ "$1" = "-f" ] || [ "$1" = "-F" ] || [ "$1" = "--phpexttype-vars-file" ] || [ "$1" = "--PHPEXTTYPE-VARS-FILE" ]; then + if [ -n "${OPT_PHPEXTTYPE_VARS_FILE}" ]; then + PRNERR "already set \"--phpexttype-vars-file(-f)\" option." + exit 1 + fi + shift + if [ $# -eq 0 ]; then + PRNERR "\"--phpexttype-vars-file(-f)\" option is specified without parameter." + exit 1 + fi + if [ ! -f "$1" ]; then + PRNERR "$1 file is not existed, it is specified \"--phpexttype-vars-file(-f)\" option." + exit 1 + fi + OPT_PHPEXTTYPE_VARS_FILE="$1" + + elif [ "$1" = "-p" ] || [ "$1" = "-P" ] || [ "$1" = "--force-publish" ] || [ "$1" = "--FORCE-PUBLISH" ]; then + if [ -n "${OPT_FORCE_PUBLISH}" ]; then + PRNERR "already set \"--force-publish(-p)\" or \"--not-publish(-np)\" option." + exit 1 + fi + OPT_FORCE_PUBLISH="true" + + elif [ "$1" = "-np" ] || [ "$1" = "-NP" ] || [ "$1" = "--not-publish" ] || [ "$1" = "--NOT-PUBLISH" ]; then + if [ -n "${OPT_FORCE_PUBLISH}" ]; then + PRNERR "already set \"--force-publish(-p)\" or \"--not-publish(-np)\" option." + exit 1 + fi + OPT_FORCE_PUBLISH="false" + + elif [ "$1" = "-num" ] || [ "$1" = "-NUM" ] || [ "$1" = "--build-number" ] || [ "$1" = "--BUILD-NUMBER" ]; then + if [ -n "${OPT_BUILD_NUMBER}" ]; then + PRNERR "already set \"--build-number(-num)\" option." + exit 1 + fi + shift + if [ $# -eq 0 ]; then + PRNERR "\"--build-number(-num)\" option is specified without parameter." + exit 1 + fi + if echo "$1" | grep -q '[^0-9]'; then + PRNERR "\"--build-number(-num)\" option specify with positive NUMBER parameter." + exit 1 + fi + OPT_BUILD_NUMBER="$1" + + elif [ "$1" = "-devname" ] || [ "$1" = "-DEVNAME" ] || [ "$1" = "--developer-fullname" ] || [ "$1" = "--DEVELOPER-FULLNAME" ]; then + if [ -n "${OPT_DEVELOPER_EMAIL}" ]; then + PRNERR "already set \"--developer-fullname(-devname)\" option." + exit 1 + fi + shift + if [ $# -eq 0 ]; then + PRNERR "\"--developer-fullname(-devname)\" option is specified without parameter." + exit 1 + fi + OPT_DEVELOPER_EMAIL="$1" + + elif [ "$1" = "-devmail" ] || [ "$1" = "-DEVMAIL" ] || [ "$1" = "--developer-email" ] || [ "$1" = "--DEVELOPER-EMAIL" ]; then + if [ -n "${OPT_DEVELOPER_FULLNAME}" ]; then + PRNERR "already set \"--developer-email(-devmail)\" option." + exit 1 + fi + shift + if [ $# -eq 0 ]; then + PRNERR "\"--developer-email(-devmail)\" option is specified without parameter." + exit 1 + fi + OPT_DEVELOPER_FULLNAME="$1" + + elif [ "$1" = "-usepc" ] || [ "$1" = "-USEPC" ] || [ "$1" = "--use-packagecloudio-repo" ] || [ "$1" = "--USE-PACKAGECLOUDIO-REPO" ]; then + if [ -n "${OPT_USE_PACKAGECLOUD_REPO}" ]; then + PRNERR "already set \"--use-packagecloudio-repo(-usepc)\" or \"--not-use-packagecloudio-repo(-notpc)\" option." + exit 1 + fi + OPT_USE_PACKAGECLOUD_REPO=1 + + elif [ "$1" = "-notpc" ] || [ "$1" = "-NOTPC" ] || [ "$1" = "--not-use-packagecloudio-repo" ] || [ "$1" = "--NOT-USE-PACKAGECLOUDIO-REPO" ]; then + if [ -n "${OPT_USE_PACKAGECLOUD_REPO}" ]; then + PRNERR "already set \"--use-packagecloudio-repo(-usepc)\" or \"--not-use-packagecloudio-repo(-notpc)\" option." + exit 1 + fi + OPT_USE_PACKAGECLOUD_REPO=0 + + elif [ "$1" = "-pctoken" ] || [ "$1" = "-PCTOKEN" ] || [ "$1" = "--packagecloudio-token" ] || [ "$1" = "--PACKAGECLOUDIO-TOKEN" ]; then + if [ -n "${OPT_PACKAGECLOUD_TOKEN}" ]; then + PRNERR "already set \"--packagecloudio-token(-pctoken)\" option." + exit 1 + fi + shift + if [ $# -eq 0 ]; then + PRNERR "\"--packagecloudio-token(-pctoken)\" option is specified without parameter." + exit 1 + fi + OPT_PACKAGECLOUD_TOKEN="$1" + + elif [ "$1" = "-pcowner" ] || [ "$1" = "-PCOWNER" ] || [ "$1" = "--packagecloudio-owner" ] || [ "$1" = "--PACKAGECLOUDIO-OWNER" ]; then + if [ -n "${OPT_PACKAGECLOUD_OWNER}" ]; then + PRNERR "already set \"--packagecloudio-owner(-pcowner)\" option." + exit 1 + fi + shift + if [ $# -eq 0 ]; then + PRNERR "\"--packagecloudio-owner(-pcowner)\" option is specified without parameter." + exit 1 + fi + OPT_PACKAGECLOUD_OWNER="$1" + + elif [ "$1" = "-pcprepo" ] || [ "$1" = "-PCPREPO" ] || [ "$1" = "--packagecloudio-publish-repo" ] || [ "$1" = "--PACKAGECLOUDIO-PUBLICH-REPO" ]; then + if [ -n "${OPT_PACKAGECLOUD_PUBLISH_REPO}" ]; then + PRNERR "already set \"--packagecloudio-publish-repo(-pcprepo)\" option." + exit 1 + fi + shift + if [ $# -eq 0 ]; then + PRNERR "\"--packagecloudio-publish-repo(-pcprepo)\" option is specified without parameter." + exit 1 + fi + OPT_PACKAGECLOUD_PUBLISH_REPO="$1" + + elif [ "$1" = "-pcdlrepo" ] || [ "$1" = "-PCDLREPO" ] || [ "$1" = "--packagecloudio-download-repo" ] || [ "$1" = "--PACKAGECLOUDIO-DOWNLOAD-REPO" ]; then + if [ -n "${OPT_PACKAGECLOUD_DOWNLOAD_REPO}" ]; then + PRNERR "already set \"--packagecloudio-download-repo(-pcdlrepo)\" option." + exit 1 + fi + shift + if [ $# -eq 0 ]; then + PRNERR "\"--packagecloudio-download-repo(-pcdlrepo)\" option is specified without parameter." + exit 1 + fi + OPT_PACKAGECLOUD_DOWNLOAD_REPO="$1" + fi + shift +done + +# +# [Required option] check OS and version +# +if [ -z "${OPT_OSTYPE}" ]; then + PRNERR "\"--ostype(-os)\" option is not specified." + exit 1 +else + CI_OSTYPE="${OPT_OSTYPE}" +fi +if [ -z "${OPT_PHPTYPE}" ]; then + PRNERR "\"--phptype(-php)\" option is not specified." + exit 1 +else + CI_PHPTYPE="${OPT_PHPTYPE}" +fi + +# +# Check other options and enviroments +# +if [ -n "${OPT_PHPEXTTYPE_VARS_FILE}" ]; then + CI_PHPEXTTYPE_VARS_FILE="${OPT_PHPEXTTYPE_VARS_FILE}" +elif [ -n "${ENV_PHPEXTTYPE_VARS_FILE}" ]; then + CI_PHPEXTTYPE_VARS_FILE="${ENV_PHPEXTTYPE_VARS_FILE}" +fi + +if [ -n "${OPT_BUILD_NUMBER}" ]; then + CI_BUILD_NUMBER="${OPT_BUILD_NUMBER}" +elif [ -n "${ENV_BUILD_NUMBER}" ]; then + CI_BUILD_NUMBER="${ENV_BUILD_NUMBER}" +fi + +if [ -n "${OPT_DEVELOPER_FULLNAME}" ]; then + CI_DEVELOPER_FULLNAME="${OPT_DEVELOPER_FULLNAME}" +elif [ -n "${ENV_DEVELOPER_FULLNAME}" ]; then + CI_DEVELOPER_FULLNAME="${ENV_DEVELOPER_FULLNAME}" +fi + +if [ -n "${OPT_DEVELOPER_EMAIL}" ]; then + CI_DEVELOPER_EMAIL="${OPT_DEVELOPER_EMAIL}" +elif [ -n "${ENV_DEVELOPER_EMAIL}" ]; then + CI_DEVELOPER_EMAIL="${ENV_DEVELOPER_EMAIL}" +fi + +if [ -n "${OPT_FORCE_PUBLISH}" ]; then + if echo "${OPT_FORCE_PUBLISH}" | grep -q -i '^true$'; then + CI_FORCE_PUBLISH="true" + elif echo "${OPT_FORCE_PUBLISH}" | grep -q -i '^false$'; then + CI_FORCE_PUBLISH="false" + else + PRNERR "\"OPT_FORCE_PUBLISH\" value is wrong." + exit 1 + fi +elif [ -n "${ENV_FORCE_PUBLISH}" ]; then + if echo "${ENV_FORCE_PUBLISH}" | grep -q -i '^true$'; then + CI_FORCE_PUBLISH="true" + elif echo "${ENV_FORCE_PUBLISH}" | grep -q -i '^false$'; then + CI_FORCE_PUBLISH="false" + else + PRNERR "\"ENV_FORCE_PUBLISH\" value is wrong." + exit 1 + fi +fi + +if [ -n "${OPT_USE_PACKAGECLOUD_REPO}" ]; then + if [ "${OPT_USE_PACKAGECLOUD_REPO}" -eq 1 ]; then + CI_USE_PACKAGECLOUD_REPO=1 + elif [ "${OPT_USE_PACKAGECLOUD_REPO}" -eq 0 ]; then + CI_USE_PACKAGECLOUD_REPO=0 + else + PRNERR "\"OPT_USE_PACKAGECLOUD_REPO\" value is wrong." + exit 1 + fi +elif [ -n "${ENV_USE_PACKAGECLOUD_REPO}" ]; then + if echo "${ENV_USE_PACKAGECLOUD_REPO}" | grep -q -i '^true$'; then + CI_USE_PACKAGECLOUD_REPO=1 + elif echo "${ENV_USE_PACKAGECLOUD_REPO}" | grep -q -i '^false$'; then + CI_USE_PACKAGECLOUD_REPO=0 + else + PRNERR "\"ENV_USE_PACKAGECLOUD_REPO\" value is wrong." + exit 1 + fi +fi + +if [ -n "${OPT_PACKAGECLOUD_TOKEN}" ]; then + CI_PACKAGECLOUD_TOKEN="${OPT_PACKAGECLOUD_TOKEN}" +elif [ -n "${ENV_PACKAGECLOUD_TOKEN}" ]; then + CI_PACKAGECLOUD_TOKEN="${ENV_PACKAGECLOUD_TOKEN}" +fi + +if [ -n "${OPT_PACKAGECLOUD_OWNER}" ]; then + CI_PACKAGECLOUD_OWNER="${OPT_PACKAGECLOUD_OWNER}" +elif [ -n "${ENV_PACKAGECLOUD_OWNER}" ]; then + CI_PACKAGECLOUD_OWNER="${ENV_PACKAGECLOUD_OWNER}" +fi + +if [ -n "${OPT_PACKAGECLOUD_PUBLISH_REPO}" ]; then + CI_PACKAGECLOUD_PUBLISH_REPO="${OPT_PACKAGECLOUD_PUBLISH_REPO}" +elif [ -n "${ENV_PACKAGECLOUD_PUBLISH_REPO}" ]; then + CI_PACKAGECLOUD_PUBLISH_REPO="${ENV_PACKAGECLOUD_PUBLISH_REPO}" +fi + +if [ -n "${OPT_PACKAGECLOUD_DOWNLOAD_REPO}" ]; then + CI_PACKAGECLOUD_DOWNLOAD_REPO="${OPT_PACKAGECLOUD_DOWNLOAD_REPO}" +elif [ -n "${ENV_PACKAGECLOUD_DOWNLOAD_REPO}" ]; then + CI_PACKAGECLOUD_DOWNLOAD_REPO="${ENV_PACKAGECLOUD_DOWNLOAD_REPO}" +fi + +# +# Set environments for debian package +# +if [ -n "${CI_DEVELOPER_FULLNAME}" ]; then + export DEBEMAIL="${CI_DEVELOPER_FULLNAME}" +fi +if [ -n "${CI_DEVELOPER_EMAIL}" ]; then + export DEBFULLNAME="${CI_DEVELOPER_EMAIL}" +fi + +# [NOTE] for ubuntu/debian +# When start to update, it may come across an unexpected interactive interface. +# (May occur with time zone updates) +# Set environment variables to avoid this. +# +export DEBIAN_FRONTEND=noninteractive + +PRNSUCCESS "Start to check options and environments" + + +#============================================================== +# Set Variables +#============================================================== +# +# Default command parameters for each phase +# +PRE_CLEANUP_FILES_DIRS="" + +CPPCHECK_TARGET="." +CPPCHECK_BASE_OPT="--quiet --error-exitcode=1 --inline-suppr -j 4 --std=c++03 --xml --enable=warning,style,information,missingInclude" +CPPCHECK_ENABLE_VALUES="warning style information missingInclude" +CPPCHECK_IGNORE_VALUES="unmatchedSuppression" +CPPCHECK_BUILD_DIR="/tmp/cppcheck" + +SHELLCHECK_TARGET_DIRS="." +SHELLCHECK_BASE_OPT="--shell=sh" +SHELLCHECK_EXCEPT_PATHS="/\.libs/ /autom4te.cache/ /build/ /debian_build/ /rpmbuild/ /include/ /modules/ /packages/ /run-tests.php" +SHELLCHECK_IGN="SC1117 SC1090 SC1091" +SHELLCHECK_INCLUDE_IGN="SC2034 SC2148" + +BUILD_MAKE_EXT_OPT_RPM="" +BUILD_MAKE_EXT_OPT_DEBIAN="" +BUILD_MAKE_EXT_OPT_ALPINE="" +BUILD_MAKE_EXT_OPT_OTHER="" + +MAKE_TEST_OPT_RPM="test" +MAKE_TEST_OPT_DEBIAN="test" +MAKE_TEST_OPT_ALPINE="test" +MAKE_TEST_OPT_OTHER="test" + +CREATE_PACKAGE_TOOL_RPM="buildutils/php_rpm_build.sh" +CREATE_PACKAGE_TOOL_DEBIAN="buildutils/php_debian_build.sh" +CREATE_PACKAGE_TOOL_ALPINE="buildutils/php_alpine_build.sh" +CREATE_PACKAGE_TOOL_OTHER="" + +CREATE_PACKAGE_TOOL_OPT_AUTO="-y" +CREATE_PACKAGE_TOOL_OPT_RPM="" +CREATE_PACKAGE_TOOL_OPT_DEBIAN="" +CREATE_PACKAGE_TOOL_OPT_ALPINE="" +CREATE_PACKAGE_TOOL_OPT_OTHER="" + +# +# Load variables from file +# +PRNTITLE "Load local variables with an external file" + +# +# Load external variable file +# +if [ -f "${CI_PHPEXTTYPE_VARS_FILE}" ]; then + PRNINFO "Load ${CI_PHPEXTTYPE_VARS_FILE} file for local variables by os:type(${CI_OSTYPE}) php:type(${CI_PHPTYPE})" + . "${CI_PHPEXTTYPE_VARS_FILE}" +else + PRNWARN "${CI_PHPEXTTYPE_VARS_FILE} file is not existed." +fi +if [ -n "${NOT_PROVIDED_PHPVER}" ] && [ "${NOT_PROVIDED_PHPVER}" -eq 1 ]; then + # + # Not provided this combination of OS and PHP. + # + # [NOTE] + # Exit this script here with SUCCESS status. + # + PRNSUCCESS "Load local variables with an external file" + + PRNINFO "This OS and PHP combination is not provided, so stop all processing with success status." + + PRNSUCCESS "Finished all processing without error(not provoded this OS and PHP combination)." + exit 0 +fi + +# +# Check loading variables +# +if [ -z "${DIST_TAG}" ]; then + PRNERR "Distro/Version is not set, please check ${CI_PHPEXTTYPE_VARS_FILE} and check \"DIST_TAG\" varibale." + exit 1 +fi + +# +# Set command parameters +# +if [ "${IS_OS_UBUNTU}" -eq 1 ]; then + BUILD_MAKE_EXT_OPT="${BUILD_MAKE_EXT_OPT_DEBIAN}" + MAKE_TEST_OPT="${MAKE_TEST_OPT_DEBIAN}" + CREATE_PACKAGE_TOOL="${CREATE_PACKAGE_TOOL_DEBIAN}" + CREATE_PACKAGE_TOOL_OPT="${CREATE_PACKAGE_TOOL_OPT_DEBIAN}" + +elif [ "${IS_OS_DEBIAN}" -eq 1 ]; then + BUILD_MAKE_EXT_OPT="${BUILD_MAKE_EXT_OPT_DEBIAN}" + MAKE_TEST_OPT="${MAKE_TEST_OPT_DEBIAN}" + CREATE_PACKAGE_TOOL="${CREATE_PACKAGE_TOOL_DEBIAN}" + CREATE_PACKAGE_TOOL_OPT="${CREATE_PACKAGE_TOOL_OPT_DEBIAN}" + +elif [ "${IS_OS_CENTOS}" -eq 1 ]; then + BUILD_MAKE_EXT_OPT="${BUILD_MAKE_EXT_OPT_DEBIAN}" + MAKE_TEST_OPT="${MAKE_TEST_OPT_DEBIAN}" + CREATE_PACKAGE_TOOL="${CREATE_PACKAGE_TOOL_RPM}" + CREATE_PACKAGE_TOOL_OPT="${CREATE_PACKAGE_TOOL_OPT_RPM}" + +elif [ "${IS_OS_FEDORA}" -eq 1 ]; then + BUILD_MAKE_EXT_OPT="${BUILD_MAKE_EXT_OPT_RPM}" + MAKE_TEST_OPT="${MAKE_TEST_OPT_RPM}" + CREATE_PACKAGE_TOOL="${CREATE_PACKAGE_TOOL_RPM}" + CREATE_PACKAGE_TOOL_OPT="${CREATE_PACKAGE_TOOL_OPT_RPM}" + +elif [ "${IS_OS_ROCKY}" -eq 1 ]; then + BUILD_MAKE_EXT_OPT="${BUILD_MAKE_EXT_OPT_RPM}" + MAKE_TEST_OPT="${MAKE_TEST_OPT_RPM}" + CREATE_PACKAGE_TOOL="${CREATE_PACKAGE_TOOL_RPM}" + CREATE_PACKAGE_TOOL_OPT="${CREATE_PACKAGE_TOOL_OPT_RPM}" + +elif [ "${IS_OS_ALPINE}" -eq 1 ]; then + BUILD_MAKE_EXT_OPT="${BUILD_MAKE_EXT_OPT_ALPINE}" + MAKE_TEST_OPT="${MAKE_TEST_OPT_ALPINE}" + CREATE_PACKAGE_TOOL="${CREATE_PACKAGE_TOOL_ALPINE}" + CREATE_PACKAGE_TOOL_OPT="${CREATE_PACKAGE_TOOL_OPT_ALPINE}" + +else + BUILD_MAKE_EXT_OPT="${BUILD_MAKE_EXT_OPT_OTHER}" + MAKE_TEST_OPT="${MAKE_TEST_OPT_OTHER}" + CREATE_PACKAGE_TOOL="${CREATE_PACKAGE_TOOL_OTHER}" + CREATE_PACKAGE_TOOL_OPT="${CREATE_PACKAGE_TOOL_OPT_OTHER}" +fi + +PRNSUCCESS "Load local variables with an external file" + + +#---------------------------------------------------------- +# Check github actions environments +#---------------------------------------------------------- +PRNTITLE "Check github actions environments" + +# +# GITHUB_EVENT_NAME Environment +# +if [ -n "${GITHUB_EVENT_NAME}" ] && [ "${GITHUB_EVENT_NAME}" = "schedule" ]; then + CI_IN_SCHEDULE_PROCESS=1 +else + CI_IN_SCHEDULE_PROCESS=0 +fi + +# +# GITHUB_REF Environments +# +if [ -n "${GITHUB_REF}" ] && echo "${GITHUB_REF}" | grep -q 'refs/tags/'; then + CI_PUBLISH_TAG_NAME=$(echo "${GITHUB_REF}" | sed -e 's#refs/tags/##g' | tr -d '\n') +fi + +PRNSUCCESS "Check github actions environments" + +#---------------------------------------------------------- +# Check whether to publish +#---------------------------------------------------------- +PRNTITLE "Check whether to publish" + +# +# Check whether to publish +# +if [ -z "${CI_FORCE_PUBLISH}" ]; then + if [ -n "${CI_PUBLISH_TAG_NAME}" ] && [ "${CI_IN_SCHEDULE_PROCESS}" -ne 1 ]; then + CI_DO_PUBLISH=1 + else + CI_DO_PUBLISH=0 + fi +elif [ "${CI_FORCE_PUBLISH}" = "true" ]; then + # + # Force publishing + # + if [ -n "${CI_PUBLISH_TAG_NAME}" ] && [ "${CI_IN_SCHEDULE_PROCESS}" -ne 1 ]; then + PRNINFO "specified \"--force-publish(-p)\" option or set \"ENV_FORCE_PUBLISH=true\" environment, then forcibly publish" + CI_DO_PUBLISH=1 + else + PRNWARN "specified \"--force-publish(-p)\" option or set \"ENV_FORCE_PUBLISH=true\" environment, but Ci was launched by schedule or did not have tag name. Thus it do not run publishing." + CI_DO_PUBLISH=0 + fi +else + # + # FORCE NOT PUBLISH + # + PRNINFO "specified \"--not-publish(-np)\" option or set \"ENV_FORCE_PUBLISH=false\" environment, then it do not run publishing." + CI_DO_PUBLISH=0 +fi + +PRNSUCCESS "Check whether to publish" + +#---------------------------------------------------------- +# Show execution environment variables +#---------------------------------------------------------- +PRNTITLE "Show execution environment variables" + +# +# Information +# +echo " PRGNAME = ${PRGNAME}" +echo " SCRIPTDIR = ${SCRIPTDIR}" +echo " SRCTOP = ${SRCTOP}" +echo "" +echo " CI_OSTYPE = ${CI_OSTYPE}" +echo " CI_PHPTYPE = ${CI_PHPTYPE}" +echo " PHPVER_NOPERIOD = ${PHPVER_NOPERIOD}" +echo " PHPVER_WITHPERIOD = ${PHPVER_WITHPERIOD}" +echo "" +echo " CI_IN_SCHEDULE_PROCESS = ${CI_IN_SCHEDULE_PROCESS}" +echo " CI_PHPEXTTYPE_VARS_FILE = ${CI_PHPEXTTYPE_VARS_FILE}" +echo " CI_BUILD_NUMBER = ${CI_BUILD_NUMBER}" +echo " CI_DO_PUBLISH = ${CI_DO_PUBLISH}" +echo " CI_PUBLISH_TAG_NAME = ${CI_PUBLISH_TAG_NAME}" +echo " CI_USE_PACKAGECLOUD_REPO = ${CI_USE_PACKAGECLOUD_REPO}" +echo " CI_PACKAGECLOUD_TOKEN = **********" +echo " CI_PACKAGECLOUD_OWNER = ${CI_PACKAGECLOUD_OWNER}" +echo " CI_PACKAGECLOUD_PUBLISH_REPO = ${CI_PACKAGECLOUD_PUBLISH_REPO}" +echo " CI_PACKAGECLOUD_DOWNLOAD_REPO = ${CI_PACKAGECLOUD_DOWNLOAD_REPO}" +echo "" +echo " DEBEMAIL = ${DEBEMAIL}" +echo " DEBFULLNAME = ${DEBFULLNAME}" +echo "" +echo " DIST_TAG = ${DIST_TAG}" +echo " PKG_EXT = ${PKG_EXT}" +echo " PKG_OUTPUT_DIR = ${PKG_OUTPUT_DIR}" +echo "" +echo " INSTALLER_BIN = ${INSTALLER_BIN}" +echo " INSTALL_QUIET_ARG = ${INSTALL_QUIET_ARG}" +echo " INSTALL_PKG_LIST = ${INSTALL_PKG_LIST}" +echo " UPDATE_CMD = ${UPDATE_CMD}" +echo " UPDATE_CMD_ARG = ${UPDATE_CMD_ARG}" +echo " INSTALL_CMD = ${INSTALL_CMD}" +echo " INSTALL_CMD_ARG = ${INSTALL_CMD_ARG}" +echo " INSTALL_AUTO_ARG = ${INSTALL_AUTO_ARG}" +echo " INSTALL_QUIET_ARG = ${INSTALL_QUIET_ARG}" +echo "" +echo " INSTALL_PHP_PRE_ADD_REPO = ${INSTALL_PHP_PRE_ADD_REPO}" +echo " INSTALL_PHP_REPO = ${INSTALL_PHP_REPO}" +echo " INSTALL_PHP_PKG_LIST = ${INSTALL_PHP_PKG_LIST}" +echo " INSTALL_PHP_OPT = ${INSTALL_PHP_OPT}" +echo " INSTALL_PHP_POST_CONFIG = ${INSTALL_PHP_POST_CONFIG}" +echo " INSTALL_PHP_POST_BIN = ${INSTALL_PHP_POST_BIN}" +echo " SWITCH_PHP_COMMAND = ${SWITCH_PHP_COMMAND}" +echo "" +echo " IS_OS_UBUNTU = ${IS_OS_UBUNTU}" +echo " IS_OS_DEBIAN = ${IS_OS_DEBIAN}" +echo " IS_OS_CENTOS = ${IS_OS_CENTOS}" +echo " IS_OS_FEDORA = ${IS_OS_FEDORA}" +echo " IS_OS_ROCKY = ${IS_OS_ROCKY}" +echo " IS_OS_ALPINE = ${IS_OS_ALPINE}" +echo "" +echo " PRE_CLEANUP_FILES_DIRS = ${PRE_CLEANUP_FILES_DIRS}" +echo " BUILD_MAKE_EXT_OPT = ${BUILD_MAKE_EXT_OPT}" +echo " MAKE_TEST_OPT = ${MAKE_TEST_OPT}" +echo " CREATE_PACKAGE_TOOL = ${CREATE_PACKAGE_TOOL}" +echo " CREATE_PACKAGE_TOOL_OPT = ${CREATE_PACKAGE_TOOL_OPT}" +echo "" +echo " CPPCHECK_TARGET = ${CPPCHECK_TARGET}" +echo " CPPCHECK_BASE_OPT = ${CPPCHECK_BASE_OPT}" +echo " CPPCHECK_ENABLE_VALUES = ${CPPCHECK_ENABLE_VALUES}" +echo " CPPCHECK_IGNORE_VALUES = ${CPPCHECK_IGNORE_VALUES}" +echo " CPPCHECK_BUILD_DIR = ${CPPCHECK_BUILD_DIR}" +echo "" +echo " SHELLCHECK_TARGET_DIRS = ${SHELLCHECK_TARGET_DIRS}" +echo " SHELLCHECK_BASE_OPT = ${SHELLCHECK_BASE_OPT}" +echo " SHELLCHECK_EXCEPT_PATHS = ${SHELLCHECK_EXCEPT_PATHS}" +echo " SHELLCHECK_IGN = ${SHELLCHECK_IGN}" +echo " SHELLCHECK_INCLUDE_IGN = ${SHELLCHECK_INCLUDE_IGN}" +echo "" + +PRNSUCCESS "Show execution environment variables" + +#============================================================== +# Install all packages +#============================================================== +PRNTITLE "Update repository and Install curl" + +# +# Update local packages +# +PRNINFO "Update local packages" +if ({ RUNCMD "${INSTALLER_BIN}" "${UPDATE_CMD}" "${UPDATE_CMD_ARG}" "${INSTALL_AUTO_ARG}" "${INSTALL_QUIET_ARG}" || echo > "${PIPEFAILURE_FILE}"; } | sed -e 's/^/ /g') && rm "${PIPEFAILURE_FILE}" >/dev/null 2>&1; then + PRNERR "Failed to update local packages" + exit 1 +fi + +# +# Check and install curl +# +if ! CURLCMD=$(command -v curl); then + PRNINFO "Install curl command" + if ({ RUNCMD "${INSTALLER_BIN}" "${INSTALL_CMD}" "${INSTALL_CMD_ARG}" "${INSTALL_AUTO_ARG}" "${INSTALL_QUIET_ARG}" curl || echo > "${PIPEFAILURE_FILE}"; } | sed -e 's/^/ /g') && rm "${PIPEFAILURE_FILE}" >/dev/null 2>&1; then + PRNERR "Failed to install curl command" + exit 1 + fi + if ! CURLCMD=$(command -v curl); then + PRNERR "Not found curl command" + exit 1 + fi +else + PRNINFO "Already curl is insatlled." +fi +PRNSUCCESS "Update repository and Install curl" + +#-------------------------------------------------------------- +# Set package repository for packagecloud.io +#-------------------------------------------------------------- +PRNTITLE "Set package repository for packagecloud.io" + +if [ "${CI_USE_PACKAGECLOUD_REPO}" -eq 1 ]; then + # + # Setup packagecloud.io repository + # + if [ "${IS_OS_CENTOS}" -eq 1 ] || [ "${IS_OS_FEDORA}" -eq 1 ] || [ "${IS_OS_ROCKY}" -eq 1 ]; then + PC_REPO_ADD_SH="script.rpm.sh" + PC_REPO_ADD_SH_RUN="bash" + elif [ "${IS_OS_UBUNTU}" -eq 1 ] || [ "${IS_OS_DEBIAN}" -eq 1 ]; then + PC_REPO_ADD_SH="script.deb.sh" + PC_REPO_ADD_SH_RUN="bash" + elif [ "${IS_OS_ALPINE}" -eq 1 ]; then + PC_REPO_ADD_SH="script.alpine.sh" + PC_REPO_ADD_SH_RUN="sh" + else + PC_REPO_ADD_SH="" + PC_REPO_ADD_SH_RUN="" + fi + if [ -n "${PC_REPO_ADD_SH}" ]; then + PRNINFO "Download script and setup packagecloud.io reposiory" + if ({ RUNCMD "${CURLCMD} -s https://packagecloud.io/install/repositories/${CI_PACKAGECLOUD_OWNER}/${CI_PACKAGECLOUD_DOWNLOAD_REPO}/${PC_REPO_ADD_SH} | ${PC_REPO_ADD_SH_RUN}" || echo > "${PIPEFAILURE_FILE}"; } | sed -e 's/^/ /g') && rm "${PIPEFAILURE_FILE}" >/dev/null 2>&1; then + PRNERR "Failed to download script or setup packagecloud.io reposiory" + exit 1 + fi + else + PRNWARN "OS is not debian/ubuntu nor centos/fedora/rocky nor alpine, then we do not know which download script use. Thus skip to setup packagecloud.io repository." + fi +else + PRNINFO "Not set packagecloud.io repository." +fi +PRNSUCCESS "Set package repository for packagecloud.io" + +#---------------------------------------------------------- +# Install packages(repositories) before adding PHP repository +#---------------------------------------------------------- +PRNTITLE "Install packages(repositories) before adding PHP repository" + +if [ -n "${INSTALL_PHP_PRE_ADD_REPO}" ]; then + PRNINFO "Install packages" + if ({ RUNCMD "${INSTALLER_BIN}" "${INSTALL_CMD}" "${INSTALL_CMD_ARG}" "${INSTALL_AUTO_ARG}" "${INSTALL_QUIET_ARG}" "${INSTALL_PHP_PRE_ADD_REPO}" || echo > "${PIPEFAILURE_FILE}"; } | sed -e 's/^/ /g') && rm "${PIPEFAILURE_FILE}" >/dev/null 2>&1; then + PRNERR "Failed to install packages(repositories) before adding PHP repository." + exit 1 + fi +else + PRNINFO "Nothing to install packages(repositories) before adding PHP repository." +fi + +PRNSUCCESS "Install packages(repositories) before adding PHP repository" + +#---------------------------------------------------------- +# Add PHP repositories +#---------------------------------------------------------- +PRNTITLE "Add PHP repositories" + +if [ -n "${INSTALL_PHP_REPO}" ]; then + PRNINFO "PHP repositories" + if [ "${IS_OS_CENTOS}" -eq 1 ] || [ "${IS_OS_ROCKY}" -eq 1 ] || [ "${IS_OS_FEDORA}" -eq 1 ]; then + if ({ RUNCMD "${INSTALLER_BIN}" "${INSTALL_CMD}" "${INSTALL_CMD_ARG}" "${INSTALL_AUTO_ARG}" "${INSTALL_QUIET_ARG}" "${INSTALL_PHP_REPO}" || echo > "${PIPEFAILURE_FILE}"; } | sed -e 's/^/ /g') && rm "${PIPEFAILURE_FILE}" >/dev/null 2>&1; then + PRNERR "Failed to add PHP repository." + exit 1 + fi + elif [ "${IS_OS_UBUNTU}" -eq 1 ]; then + if ({ RUNCMD add-apt-repository "${INSTALL_AUTO_ARG}" "${INSTALL_PHP_REPO}" || echo > "${PIPEFAILURE_FILE}"; } | sed -e 's/^/ /g') && rm "${PIPEFAILURE_FILE}" >/dev/null 2>&1; then + PRNERR "Failed to add PHP repository." + exit 1 + fi + elif [ "${IS_OS_DEBIAN}" -eq 1 ]; then + # + # For debian more complicated than the others. + # + if [ -z "${INSTALL_PHP_REPO_GPG_URL}" ] || [ -z "${INSTALL_PHP_REPO_GPG_FILEPATH}" ]; then + PRNERR "\"INSTALL_PHP_REPO_GPG_URL\" or \"INSTALL_PHP_REPO_GPG_FILEPATH\" varibales are not specified." + exit 1 + fi + if ({ RUNCMD "${CURLCMD}" -sSLo "${INSTALL_PHP_REPO_GPG_FILEPATH}" "${INSTALL_PHP_REPO_GPG_URL}" || echo > "${PIPEFAILURE_FILE}"; } | sed -e 's/^/ /g') && rm "${PIPEFAILURE_FILE}" >/dev/null 2>&1; then + PRNERR "Failed to install gpg file." + exit 1 + fi + if ({ RUNCMD "echo 'deb [signed-by=${INSTALL_PHP_REPO_GPG_FILEPATH}] https://${INSTALL_PHP_REPO}/ $(lsb_release -sc) main' > /etc/apt/sources.list.d/php.list" || echo > "${PIPEFAILURE_FILE}"; } | sed -e 's/^/ /g') && rm "${PIPEFAILURE_FILE}" >/dev/null 2>&1; then + PRNERR "Failed to add repository for PHP" + exit 1 + fi + if ({ RUNCMD "${INSTALLER_BIN}" "${UPDATE_CMD}" "${UPDATE_CMD_ARG}" "${INSTALL_AUTO_ARG}" "${INSTALL_QUIET_ARG}" || echo > "${PIPEFAILURE_FILE}"; } | sed -e 's/^/ /g') && rm "${PIPEFAILURE_FILE}" >/dev/null 2>&1; then + PRNERR "Failed to re-update local packages" + exit 1 + fi + else + PRNINFO "Skip to add PHP repository, because unknown to add it." + fi +else + PRNINFO "Nothing to add PHP repository." +fi + +PRNSUCCESS "Added PHP repositories" + +#-------------------------------------------------------------- +# Install packages +#-------------------------------------------------------------- +PRNTITLE "Install packages for building/packaging" + +if [ -n "${INSTALL_PKG_LIST}" ]; then + PRNINFO "Install packages" + if ({ RUNCMD "${INSTALLER_BIN}" "${INSTALL_CMD}" "${INSTALL_CMD_ARG}" "${INSTALL_AUTO_ARG}" "${INSTALL_QUIET_ARG}" "${INSTALL_PKG_LIST}" || echo > "${PIPEFAILURE_FILE}"; } | sed -e 's/^/ /g') && rm "${PIPEFAILURE_FILE}" >/dev/null 2>&1; then + PRNERR "Failed to install packages" + exit 1 + fi +else + PRNINFO "Specified no packages for installing. " +fi + +PRNSUCCESS "Install packages for building/packaging" + +#-------------------------------------------------------------- +# Install PHP packages +#-------------------------------------------------------------- +PRNTITLE "Install PHP packages" + +if [ -n "${INSTALL_PHP_PKG_LIST}" ]; then + PRNINFO "Install packages" + if ({ RUNCMD "${INSTALLER_BIN}" "${INSTALL_CMD}" "${INSTALL_CMD_ARG}" "${INSTALL_AUTO_ARG}" "${INSTALL_QUIET_ARG}" "${INSTALL_PHP_OPT}" "${INSTALL_PHP_PKG_LIST}" || echo > "${PIPEFAILURE_FILE}"; } | sed -e 's/^/ /g') && rm "${PIPEFAILURE_FILE}" >/dev/null 2>&1; then + PRNERR "Failed to install PHP packages" + exit 1 + fi +else + PRNINFO "Specified no PHP packages for installing. " +fi + +if [ -n "${INSTALL_PHP_POST_CONFIG}" ]; then + PRNINFO "Set PHP configuration after installing PHP packages" + if ({ RUNCMD "${INSTALL_PHP_POST_CONFIG}" || echo > "${PIPEFAILURE_FILE}"; } | sed -e 's/^/ /g') && rm "${PIPEFAILURE_FILE}" >/dev/null 2>&1; then + PRNERR "Failed to set PHP configuration after installing PHP packages" + exit 1 + fi +else + PRNINFO "Specified no PHP configuration after installing PHP packages" +fi + +if [ -n "${INSTALL_PHP_POST_BIN}" ]; then + PRNINFO "Set PHP binary after installing PHP packages" + if ({ RUNCMD "${INSTALL_PHP_POST_BIN}" || echo > "${PIPEFAILURE_FILE}"; } | sed -e 's/^/ /g') && rm "${PIPEFAILURE_FILE}" >/dev/null 2>&1; then + PRNERR "Failed to set PHP binary after installing PHP packages" + exit 1 + fi +else + PRNINFO "Specified no PHP binary after installing PHP packages" +fi + +PRNSUCCESS "Install PHP packages for building/packaging" + +#-------------------------------------------------------------- +# Install published tools for uploading packages to packagecloud.io +#-------------------------------------------------------------- +PRNTITLE "Install published tools for uploading packages to packagecloud.io" + +if [ "${CI_DO_PUBLISH}" -eq 1 ]; then + PRNINFO "Install published tools for uploading packages to packagecloud.io" + GEM_BIN="gem" + GEM_INSTALL_CMD="install" + + if [ "${IS_OS_CENTOS}" -eq 1 ] && echo "${CI_OSTYPE}" | sed -e 's#:##g' | grep -q -i -e 'centos7' -e 'centos6'; then + # + # Case for CentOS + # + PRNWARN "OS is CentOS 7(6), so install ruby by special means(SCL)." + + if ({ RUNCMD "${INSTALLER_BIN}" "${INSTALL_CMD}" "${INSTALL_CMD_ARG}" "${INSTALL_AUTO_ARG}" "${INSTALL_QUIET_ARG}" centos-release-scl || echo > "${PIPEFAILURE_FILE}"; } | sed -e 's/^/ /g') && rm "${PIPEFAILURE_FILE}" >/dev/null 2>&1; then + PRNERR "Failed to install SCL packages" + exit 1 + fi + if ({ RUNCMD "${INSTALLER_BIN}" "${INSTALL_CMD}" "${INSTALL_CMD_ARG}" "${INSTALL_AUTO_ARG}" "${INSTALL_QUIET_ARG}" rh-ruby24 rh-ruby24-ruby-devel rh-ruby24-rubygem-rake || echo > "${PIPEFAILURE_FILE}"; } | sed -e 's/^/ /g') && rm "${PIPEFAILURE_FILE}" >/dev/null 2>&1; then + PRNERR "Failed to install ruby packages" + exit 1 + fi + . /opt/rh/rh-ruby24/enable + + if ({ RUNCMD "${GEM_BIN}" "${GEM_INSTALL_CMD}" package_cloud || echo > "${PIPEFAILURE_FILE}"; } | sed -e 's/^/ /g') && rm "${PIPEFAILURE_FILE}" >/dev/null 2>&1; then + PRNERR "Failed to install packagecloud.io upload tools" + exit 1 + fi + + elif [ "${IS_OS_ALPINE}" -eq 1 ]; then + # + # Case for Alpine + # + if ({ RUNCMD "${GEM_BIN}" "${GEM_INSTALL_CMD}" package_cloud || echo > "${PIPEFAILURE_FILE}"; } | sed -e 's/^/ /g') && rm "${PIPEFAILURE_FILE}" >/dev/null 2>&1; then + PRNERR "Failed to install packagecloud.io upload tools" + exit 1 + fi + + else + # + # Case for other than CentOS + # + if ({ RUNCMD "${GEM_BIN}" "${GEM_INSTALL_CMD}" rake package_cloud || echo > "${PIPEFAILURE_FILE}"; } | sed -e 's/^/ /g') && rm "${PIPEFAILURE_FILE}" >/dev/null 2>&1; then + PRNERR "Failed to install packagecloud.io upload tools" + exit 1 + fi + fi +else + PRNINFO "Skip to install published tools for uploading packages to packagecloud.io, because this CI process does not upload any packages." +fi +PRNSUCCESS "Install published tools for uploading packages to packagecloud.io" + +#-------------------------------------------------------------- +# Install cppcheck +#-------------------------------------------------------------- +PRNTITLE "Install cppcheck" + +IS_SET_ANOTHER_REPOSITORIES=0 +if [ "${RUN_CPPCHECK}" -eq 1 ]; then + PRNINFO "Install cppcheck package." + + if [ "${IS_OS_CENTOS}" -eq 1 ]; then + # + # CentOS + # + if ({ RUNCMD "${INSTALLER_BIN}" "${INSTALL_CMD}" "${INSTALL_CMD_ARG}" "${INSTALL_AUTO_ARG}" epel-release || echo > "${PIPEFAILURE_FILE}"; } | sed -e 's/^/ /g') && rm "${PIPEFAILURE_FILE}" >/dev/null 2>&1; then + PRNERR "Failed to install epel repository" + exit 1 + fi + if ({ RUNCMD yum-config-manager --disable epel || echo > "${PIPEFAILURE_FILE}"; } | sed -e 's/^/ /g') && rm "${PIPEFAILURE_FILE}" >/dev/null 2>&1; then + PRNERR "Failed to disable epel repository" + exit 1 + fi + if ({ RUNCMD "${INSTALLER_BIN}" --enablerepo=epel "${INSTALL_CMD}" "${INSTALL_CMD_ARG}" "${INSTALL_AUTO_ARG}" cppcheck || echo > "${PIPEFAILURE_FILE}"; } | sed -e 's/^/ /g') && rm "${PIPEFAILURE_FILE}" >/dev/null 2>&1; then + PRNERR "Failed to install cppcheck from epel repository" + exit 1 + fi + IS_SET_ANOTHER_REPOSITORIES=1 + + elif [ "${IS_OS_FEDORA}" -eq 1 ]; then + # + # Fedora + # + if ({ RUNCMD "${INSTALLER_BIN}" "${INSTALL_CMD}" "${INSTALL_CMD_ARG}" "${INSTALL_AUTO_ARG}" cppcheck || echo > "${PIPEFAILURE_FILE}"; } | sed -e 's/^/ /g') && rm "${PIPEFAILURE_FILE}" >/dev/null 2>&1; then + PRNERR "Failed to install cppcheck" + exit 1 + fi + + elif [ "${IS_OS_ROCKY}" -eq 1 ]; then + if echo "${CI_OSTYPE}" | sed -e 's#:##g' | grep -q -i 'rockylinux8'; then + # + # Rocky 8 + # + if ({ RUNCMD "${INSTALLER_BIN}" "${INSTALL_CMD}" "${INSTALL_CMD_ARG}" "${INSTALL_AUTO_ARG}" https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm || echo > "${PIPEFAILURE_FILE}"; } | sed -e 's/^/ /g') && rm "${PIPEFAILURE_FILE}" >/dev/null 2>&1; then + PRNERR "Failed to install epel repository" + exit 1 + fi + if ({ RUNCMD "${INSTALLER_BIN}" config-manager --enable epel || echo > "${PIPEFAILURE_FILE}"; } | sed -e 's/^/ /g') && rm "${PIPEFAILURE_FILE}" >/dev/null 2>&1; then + PRNERR "Failed to enable epel repository" + exit 1 + fi + if ({ RUNCMD "${INSTALLER_BIN}" config-manager --set-enabled powertools || echo > "${PIPEFAILURE_FILE}"; } | sed -e 's/^/ /g') && rm "${PIPEFAILURE_FILE}" >/dev/null 2>&1; then + PRNERR "Failed to enable powertools" + exit 1 + fi + else + # + # Rocky 9 or later + # + if ({ RUNCMD "${INSTALLER_BIN}" "${INSTALL_CMD}" "${INSTALL_CMD_ARG}" "${INSTALL_AUTO_ARG}" https://dl.fedoraproject.org/pub/epel/epel-release-latest-9.noarch.rpm || echo > "${PIPEFAILURE_FILE}"; } | sed -e 's/^/ /g') && rm "${PIPEFAILURE_FILE}" >/dev/null 2>&1; then + PRNERR "Failed to install epel repository" + exit 1 + fi + if ({ RUNCMD "${INSTALLER_BIN}" config-manager --enable epel || echo > "${PIPEFAILURE_FILE}"; } | sed -e 's/^/ /g') && rm "${PIPEFAILURE_FILE}" >/dev/null 2>&1; then + PRNERR "Failed to enable epel repository" + exit 1 + fi + fi + if ({ RUNCMD "${INSTALLER_BIN}" "${INSTALL_CMD}" "${INSTALL_CMD_ARG}" "${INSTALL_AUTO_ARG}" cppcheck || echo > "${PIPEFAILURE_FILE}"; } | sed -e 's/^/ /g') && rm "${PIPEFAILURE_FILE}" >/dev/null 2>&1; then + PRNERR "Failed to install cppcheck" + exit 1 + fi + IS_SET_ANOTHER_REPOSITORIES=1 + + elif [ "${IS_OS_UBUNTU}" -eq 1 ] || [ "${IS_OS_DEBIAN}" -eq 1 ]; then + # + # Ubuntu or Debian + # + if ({ RUNCMD "${INSTALLER_BIN}" "${INSTALL_CMD}" "${INSTALL_CMD_ARG}" "${INSTALL_AUTO_ARG}" cppcheck || echo > "${PIPEFAILURE_FILE}"; } | sed -e 's/^/ /g') && rm "${PIPEFAILURE_FILE}" >/dev/null 2>&1; then + PRNERR "Failed to install cppcheck" + exit 1 + fi + + elif [ "${IS_OS_ALPINE}" -eq 1 ]; then + # + # Alpine + # + if ({ RUNCMD "${INSTALLER_BIN}" "${INSTALL_CMD}" "${INSTALL_CMD_ARG}" "${INSTALL_AUTO_ARG}" cppcheck || echo > "${PIPEFAILURE_FILE}"; } | sed -e 's/^/ /g') && rm "${PIPEFAILURE_FILE}" >/dev/null 2>&1; then + PRNERR "Failed to install cppcheck" + exit 1 + fi + + else + PRNINFO "Skip to install cppcheck package, because unknown to install it." + fi +else + PRNINFO "Skip to install cppcheck package, because cppcheck process does not need." +fi +PRNSUCCESS "Install cppcheck" + +#-------------------------------------------------------------- +# Install shellcheck +#-------------------------------------------------------------- +PRNTITLE "Install shellcheck" + +if [ "${RUN_SHELLCHECK}" -eq 1 ]; then + PRNINFO "Install shellcheck package." + + if [ "${IS_OS_CENTOS}" -eq 1 ]; then + # + # CentOS + # + if [ "${IS_SET_ANOTHER_REPOSITORIES}" -eq 0 ]; then + if ({ RUNCMD "${INSTALLER_BIN}" "${INSTALL_CMD}" "${INSTALL_CMD_ARG}" "${INSTALL_AUTO_ARG}" epel-release || echo > "${PIPEFAILURE_FILE}"; } | sed -e 's/^/ /g') && rm "${PIPEFAILURE_FILE}" >/dev/null 2>&1; then + PRNERR "Failed to install epel repository" + exit 1 + fi + if ({ RUNCMD yum-config-manager --disable epel || echo > "${PIPEFAILURE_FILE}"; } | sed -e 's/^/ /g') && rm "${PIPEFAILURE_FILE}" >/dev/null 2>&1; then + PRNERR "Failed to disable epel repository" + exit 1 + fi + IS_SET_ANOTHER_REPOSITORIES=1 + fi + if ({ RUNCMD "${INSTALLER_BIN}" --enablerepo=epel "${INSTALL_CMD}" "${INSTALL_CMD_ARG}" "${INSTALL_AUTO_ARG}" ShellCheck || echo > "${PIPEFAILURE_FILE}"; } | sed -e 's/^/ /g') && rm "${PIPEFAILURE_FILE}" >/dev/null 2>&1; then + PRNERR "Failed to install ShellCheck from epel repository" + exit 1 + fi + + elif [ "${IS_OS_FEDORA}" -eq 1 ]; then + # + # Fedora + # + if ({ RUNCMD "${INSTALLER_BIN}" "${INSTALL_CMD}" "${INSTALL_CMD_ARG}" "${INSTALL_AUTO_ARG}" ShellCheck || echo > "${PIPEFAILURE_FILE}"; } | sed -e 's/^/ /g') && rm "${PIPEFAILURE_FILE}" >/dev/null 2>&1; then + PRNERR "Failed to install cppcheck" + exit 1 + fi + + elif [ "${IS_OS_ROCKY}" -eq 1 ]; then + # + # Rocky + # + if ! LATEST_SHELLCHECK_DOWNLOAD_URL=$("${CURLCMD}" -s -S https://api.github.com/repos/koalaman/shellcheck/releases/latest | grep '"browser_download_url"' | grep 'linux.x86_64' | sed -e 's|"||g' -e 's|^.*browser_download_url:[[:space:]]*||g' | tr -d '\n'); then + PRNERR "Failed to get shellcheck download url path" + exit 1 + fi + if ({ RUNCMD "${CURLCMD}" -s -S -L -o /tmp/shellcheck.tar.xz "${LATEST_SHELLCHECK_DOWNLOAD_URL}" || echo > "${PIPEFAILURE_FILE}"; } | sed -e 's/^/ /g') && rm "${PIPEFAILURE_FILE}" >/dev/null 2>&1; then + PRNERR "Failed to download latest shellcheck tar.xz" + exit 1 + fi + if ({ RUNCMD tar -C /usr/bin/ -xf /tmp/shellcheck.tar.xz --no-anchored 'shellcheck' --strip=1 || echo > "${PIPEFAILURE_FILE}"; } | sed -e 's/^/ /g') && rm "${PIPEFAILURE_FILE}" >/dev/null 2>&1; then + PRNERR "Failed to extract latest shellcheck binary" + exit 1 + fi + rm -f /tmp/shellcheck.tar.xz + + elif [ "${IS_OS_UBUNTU}" -eq 1 ] || [ "${IS_OS_DEBIAN}" -eq 1 ]; then + # + # Ubuntu or Debian + # + if ({ RUNCMD "${INSTALLER_BIN}" "${INSTALL_CMD}" "${INSTALL_CMD_ARG}" "${INSTALL_AUTO_ARG}" shellcheck || echo > "${PIPEFAILURE_FILE}"; } | sed -e 's/^/ /g') && rm "${PIPEFAILURE_FILE}" >/dev/null 2>&1; then + PRNERR "Failed to install cppcheck" + exit 1 + fi + + elif [ "${IS_OS_ALPINE}" -eq 1 ]; then + # + # Alpine + # + if ({ RUNCMD "${INSTALLER_BIN}" "${INSTALL_CMD}" "${INSTALL_CMD_ARG}" "${INSTALL_AUTO_ARG}" shellcheck || echo > "${PIPEFAILURE_FILE}"; } | sed -e 's/^/ /g') && rm "${PIPEFAILURE_FILE}" >/dev/null 2>&1; then + PRNERR "Failed to install cppcheck" + exit 1 + fi + + else + PRNINFO "Skip to install shellcheck package, because unknown to install it." + fi +else + PRNINFO "Skip to install shellcheck package, because shellcheck process does not need." +fi +PRNSUCCESS "Install shellcheck" + +#============================================================== +# Processing +#============================================================== +# +# Configuration +# +cd "${SRCTOP}" || exit 1 + +# +# Before configuration +# +if [ "${RUN_PRE_CONFIG}" -eq 1 ]; then + PRNTITLE "Before configration" + if ({ run_pre_configuration 2>&1 || echo > "${PIPEFAILURE_FILE}"; } | sed -e 's/^/ /g') && rm "${PIPEFAILURE_FILE}" >/dev/null 2>&1; then + PRNFAILURE "Failed \"Before configration\"." + exit 1 + fi + PRNSUCCESS "Before configration." +fi + +# +# Configuration +# +if [ "${RUN_CONFIG}" -eq 1 ]; then + PRNTITLE "Configration" + if ({ run_configuration 2>&1 || echo > "${PIPEFAILURE_FILE}"; } | sed -e 's/^/ /g') && rm "${PIPEFAILURE_FILE}" >/dev/null 2>&1; then + PRNFAILURE "Failed \"Configration\"." + exit 1 + fi + PRNSUCCESS "Configuration." +fi + +#-------------------------------------------------------------- +# Cleanup +#-------------------------------------------------------------- +# +# Before Cleanup +# +if [ "${RUN_PRE_CLEANUP}" -eq 1 ]; then + PRNTITLE "Before Cleanup" + if ({ run_pre_cleanup 2>&1 || echo > "${PIPEFAILURE_FILE}"; } | sed -e 's/^/ /g') && rm "${PIPEFAILURE_FILE}" >/dev/null 2>&1; then + PRNFAILURE "Failed \"Before Cleanup\"." + exit 1 + fi + PRNSUCCESS "Before Cleanup." +fi + +# +# Cleanup +# +if [ "${RUN_CLEANUP}" -eq 1 ]; then + PRNTITLE "Cleanup" + if ({ run_cleanup 2>&1 || echo > "${PIPEFAILURE_FILE}"; } | sed -e 's/^/ /g') && rm "${PIPEFAILURE_FILE}" >/dev/null 2>&1; then + PRNFAILURE "Failed \"Cleanup\"." + exit 1 + fi + PRNSUCCESS "Cleanup." +fi + +# +# After Cleanup +# +if [ "${RUN_POST_CLEANUP}" -eq 1 ]; then + PRNTITLE "After Cleanup" + if ({ run_post_cleanup 2>&1 || echo > "${PIPEFAILURE_FILE}"; } | sed -e 's/^/ /g') && rm "${PIPEFAILURE_FILE}" >/dev/null 2>&1; then + PRNFAILURE "Failed \"After Cleanup\"." + exit 1 + fi + PRNSUCCESS "After Cleanup." +fi + +#-------------------------------------------------------------- +# Check before building +#-------------------------------------------------------------- +# +# CppCheck +# +if [ "${RUN_CPPCHECK}" -eq 1 ]; then + PRNTITLE "Check before building : CppCheck" + if ({ run_cppcheck 2>&1 || echo > "${PIPEFAILURE_FILE}"; } | sed -e 's/^/ /g') && rm "${PIPEFAILURE_FILE}" >/dev/null 2>&1; then + PRNFAILURE "Failed \"Check before building : CppCheck\"." + exit 1 + fi + PRNSUCCESS "Check before building : CppCheck." +fi + +# +# ShellCheck +# +if [ "${RUN_SHELLCHECK}" -eq 1 ]; then + PRNTITLE "Check before building : ShellCheck" + if ({ run_shellcheck 2>&1 || echo > "${PIPEFAILURE_FILE}"; } | sed -e 's/^/ /g') && rm "${PIPEFAILURE_FILE}" >/dev/null 2>&1; then + PRNFAILURE "Failed \"Check before building : ShellCheck\"." + exit 1 + fi + PRNSUCCESS "Check before building : ShellCheck." +fi + +# +# Other check +# +if [ "${RUN_CHECK_OTHER}" -eq 1 ]; then + PRNTITLE "Check before building : Other" + if ({ run_othercheck 2>&1 || echo > "${PIPEFAILURE_FILE}"; } | sed -e 's/^/ /g') && rm "${PIPEFAILURE_FILE}" >/dev/null 2>&1; then + PRNFAILURE "Failed \"Check before building : Other\"." + exit 1 + fi + PRNSUCCESS "Check before building : Other." +fi + +#-------------------------------------------------------------- +# Build +#-------------------------------------------------------------- +# +# Before Build +# +if [ "${RUN_PRE_BUILD}" -eq 1 ]; then + PRNTITLE "Before Build" + if ({ run_pre_build 2>&1 || echo > "${PIPEFAILURE_FILE}"; } | sed -e 's/^/ /g') && rm "${PIPEFAILURE_FILE}" >/dev/null 2>&1; then + PRNFAILURE "Failed \"Before Build\"." + exit 1 + fi + PRNSUCCESS "Before Build." +fi + +# +# Build +# +if [ "${RUN_BUILD}" -eq 1 ]; then + PRNTITLE "Build" + if ({ run_build 2>&1 || echo > "${PIPEFAILURE_FILE}"; } | sed -e 's/^/ /g') && rm "${PIPEFAILURE_FILE}" >/dev/null 2>&1; then + PRNFAILURE "Failed \"Build\"." + exit 1 + fi + PRNSUCCESS "Build." +fi + +# +# After Build +# +if [ "${RUN_POST_BUILD}" -eq 1 ]; then + PRNTITLE "After Build" + if ({ run_post_build 2>&1 || echo > "${PIPEFAILURE_FILE}"; } | sed -e 's/^/ /g') && rm "${PIPEFAILURE_FILE}" >/dev/null 2>&1; then + PRNFAILURE "Failed \"After Build\"." + exit 1 + fi + PRNSUCCESS "After Build." +fi + +#-------------------------------------------------------------- +# Test +#-------------------------------------------------------------- +# +# Before Test +# +if [ "${RUN_PRE_TEST}" -eq 1 ]; then + PRNTITLE "Before Test" + if ({ run_pre_test 2>&1 || echo > "${PIPEFAILURE_FILE}"; } | sed -e 's/^/ /g') && rm "${PIPEFAILURE_FILE}" >/dev/null 2>&1; then + PRNFAILURE "Failed \"Before Test\"." + exit 1 + fi + PRNSUCCESS "Before Test." +fi + +# +# Test +# +if [ "${RUN_TEST}" -eq 1 ]; then + PRNTITLE "Test" + if ({ run_test 2>&1 || echo > "${PIPEFAILURE_FILE}"; } | sed -e 's/^/ /g') && rm "${PIPEFAILURE_FILE}" >/dev/null 2>&1; then + PRNFAILURE "Failed \"Test\"." + exit 1 + fi + PRNSUCCESS "Test." +fi + +# +# After Test +# +if [ "${RUN_POST_TEST}" -eq 1 ]; then + PRNTITLE "After Test" + if ({ run_post_test 2>&1 || echo > "${PIPEFAILURE_FILE}"; } | sed -e 's/^/ /g') && rm "${PIPEFAILURE_FILE}" >/dev/null 2>&1; then + PRNFAILURE "Failed \"After Test\"." + exit 1 + fi + PRNSUCCESS "After Test." +fi + +#-------------------------------------------------------------- +# Package +#-------------------------------------------------------------- +# +# Before Create Package +# +if [ "${RUN_PRE_PACKAGE}" -eq 1 ]; then + PRNTITLE "Before Create Package" + if ({ run_pre_create_package 2>&1 || echo > "${PIPEFAILURE_FILE}"; } | sed -e 's/^/ /g') && rm "${PIPEFAILURE_FILE}" >/dev/null 2>&1; then + PRNFAILURE "Failed \"Before Create Package\"." + exit 1 + fi + PRNSUCCESS "Before Create Package." +fi + +# +# Create Package +# +if [ "${RUN_PACKAGE}" -eq 1 ]; then + PRNTITLE "Create Package" + if ({ run_create_package 2>&1 || echo > "${PIPEFAILURE_FILE}"; } | sed -e 's/^/ /g') && rm "${PIPEFAILURE_FILE}" >/dev/null 2>&1; then + PRNFAILURE "Failed \"Create Package\"." + exit 1 + fi + PRNSUCCESS "Create Package." +fi + +# +# After Create Package +# +if [ "${RUN_POST_PACKAGE}" -eq 1 ]; then + PRNTITLE "After Create Package" + if ({ run_post_create_package 2>&1 || echo > "${PIPEFAILURE_FILE}"; } | sed -e 's/^/ /g') && rm "${PIPEFAILURE_FILE}" >/dev/null 2>&1; then + PRNFAILURE "Failed \"After Create Package\"." + exit 1 + fi + PRNSUCCESS "After Create Package." +fi + +#-------------------------------------------------------------- +# Publish Package +#-------------------------------------------------------------- +# +# Publish Package +# +if [ "${RUN_PUBLISH_PACKAGE}" -eq 1 ]; then + PRNTITLE "Publish Package" + if ({ run_publish_package 2>&1 || echo > "${PIPEFAILURE_FILE}"; } | sed -e 's/^/ /g') && rm "${PIPEFAILURE_FILE}" >/dev/null 2>&1; then + PRNFAILURE "Failed \"Publish Package\"." + exit 1 + fi + PRNSUCCESS "Publish Package." +fi + +#---------------------------------------------------------- +# Finish +#---------------------------------------------------------- +PRNSUCCESS "Finished all processing without error." + +exit 0 + +# +# Local variables: +# tab-width: 4 +# c-basic-offset: 4 +# End: +# vim600: noexpandtab sw=4 ts=4 fdm=marker +# vim<600: noexpandtab sw=4 ts=4 +# diff --git a/.github/workflows/phpexttypevars.sh b/.github/workflows/phpexttypevars.sh new file mode 100644 index 0000000..3f6f766 --- /dev/null +++ b/.github/workflows/phpexttypevars.sh @@ -0,0 +1,561 @@ +# +# k2hdkc PHP Extension library +# ----------------------------------------------------------------------- +# K2HASH PHP Extension library +# +# Copyright 2022 Yahoo Japan Corporation. +# +# K2HASH is key-valuew store base libraries. +# K2HASH is made for the purpose of the construction of +# original KVS system and the offer of the library. +# The characteristic is this KVS library which Key can +# layer. And can support multi-processing and multi-thread, +# and is provided safely as available KVS. +# ----------------------------------------------------------------------- +# +# Copyright 2023 Yahoo Japan Corporation. +# +# Modified to work with K2HDKC PHP Extension library. The original source +# code is from K2HASH PHP Extension library, which is distibuted under +# MIT License as well as this program. See the LICENSE file for the full +# copyright and license information. +# +# AUTHOR: Takeshi Nakatani +# CREATE: Fri, Feb 24 2022 +# REVISION: +# + +#=============================================================== +# Configuration for phpext_helper.sh +#=============================================================== +# This file is loaded into the phpext_helper.sh script. +# The phpext_helper.sh script is a Github Actions helper script +# that builds and packages the target repository. +# This file is mainly created to define variables that differ +# depending on the OS/PHP and version. +# It also contains different information(such as packages to +# install) for each repository. +# +# In the initial state, you need to set the following variables: +# DIST_TAG : "Distro/Version" for publishing packages +# INSTALL_PKG_LIST : A list of packages to be installed for +# build and packaging +# +# INSTALLER_BIN : Package management command +# UPDATE_CMD : Update sub command for package management +# command +# UPDATE_CMD_ARG : Update sub command arguments for package +# management command +# INSTALL_CMD : Install sub command for package management +# command +# INSTALL_CMD_ARG : Install sub command arguments for package +# management command +# INSTALL_AUTO_ARG : No interaption arguments for package +# management command +# INSTALL_QUIET_ARG : Quiet arguments for package management +# command +# PKG_OUTPUT_DIR : Set the directory path where the package +# will be created relative to the top +# directory of the source +# PKG_EXT : The extension of the package file +# +# INSTALL_PHP_PRE_ADD_REPO : Install packages(or repositories) before +# adding PHP repository +# INSTALL_PHP_REPO : PHP Repository +# INSTALL_PHP_REPO_GPG_URL : PHP Repository GPG file url for debian +# INSTALL_PHP_REPO_GPG_FILEPATH : PHP Repository GPG file path for debian +# INSTALL_PHP_PKG_LIST : PHP Packages +# INSTALL_PHP_OPT : Option for installing PHP packages +# INSTALL_PHP_POST_CONFIG : Configuration after installing PHP +# INSTALL_PHP_POST_BIN : Binary configuration after installing PHP +# SWITCH_PHP_COMMAND : Command for switching build environment +# (ex. SCL) +# +# IS_OS_UBUNTU : Set to 1 for Ubuntu, 0 otherwise +# IS_OS_DEBIAN : Set to 1 for Debian, 0 otherwise +# IS_OS_CENTOS : Set to 1 for CentOS, 0 otherwise +# IS_OS_FEDORA : Set to 1 for Fedora, 0 otherwise +# IS_OS_ROCKY : Set to 1 for Rocky, 0 otherwise +# IS_OS_ALPINE : Set to 1 for Alpine, 0 otherwise +# +# NOT_PROVIDED_PHPVER : Set to 1 if PHP * OS is not supported +# +# Set these variables according to the CI_OSTYPE and CI_PHPTYPE +# variable. +# The value of the CI_OSTYPE and CI_PHPTYPE variable matches the +# name of the Container(docker image) used in Github Actions. +# Check the ".github/workflow/***.yml" file for the value. +# +#---------------------------------------------------------- +# Default values +#---------------------------------------------------------- +DIST_TAG="" +PKG_EXT="" +PKG_OUTPUT_DIR="" + +INSTALLER_BIN="" +UPDATE_CMD="" +UPDATE_CMD_ARG="" +INSTALL_CMD="" +INSTALL_CMD_ARG="" +INSTALL_AUTO_ARG="" +INSTALL_QUIET_ARG="" +INSTALL_PKG_LIST="" + +INSTALL_PHP_PRE_ADD_REPO="" +INSTALL_PHP_REPO="" +INSTALL_PHP_PKG_LIST="" +INSTALL_PHP_OPT="" +INSTALL_PHP_POST_CONFIG="" +INSTALL_PHP_POST_BIN="" +SWITCH_PHP_COMMAND="" + +# +# Only debian +# +INSTALL_PHP_REPO_GPG_URL="" +INSTALL_PHP_REPO_GPG_FILEPATH="" + +PHPVER_NOPERIOD="" +PHPVER_WITHPERIOD="" + +IS_OS_UBUNTU=0 +IS_OS_DEBIAN=0 +IS_OS_CENTOS=0 +IS_OS_FEDORA=0 +IS_OS_ROCKY=0 +IS_OS_ALPINE=0 + +# +# Special variables +# +NOT_PROVIDED_PHPVER=0 + +#---------------------------------------------------------- +# Variables for each OS/PHP Type +#---------------------------------------------------------- +# +# PHP Version +# +if [ -z "${CI_PHPTYPE}" ]; then + # + # Unknown PHP version : Nothing to do + # + : +elif [ "${CI_PHPTYPE}" = "PHP7.4" ] || [ "${CI_PHPTYPE}" = "PHP74" ] || [ "${CI_PHPTYPE}" = "PHP7" ] || [ "${CI_PHPTYPE}" = "7.4" ] || [ "${CI_PHPTYPE}" = "74" ] || [ "${CI_PHPTYPE}" = "7" ]; then + PHPVER_NOPERIOD="74" + PHPVER_WITHPERIOD="7.4" +elif [ "${CI_PHPTYPE}" = "PHP8.0" ] || [ "${CI_PHPTYPE}" = "PHP80" ] || [ "${CI_PHPTYPE}" = "8.0" ] || [ "${CI_PHPTYPE}" = "80" ]; then + PHPVER_NOPERIOD="80" + PHPVER_WITHPERIOD="8.0" +elif [ "${CI_PHPTYPE}" = "PHP8.1" ] || [ "${CI_PHPTYPE}" = "PHP81" ] || [ "${CI_PHPTYPE}" = "8.1" ] || [ "${CI_PHPTYPE}" = "81" ]; then + PHPVER_NOPERIOD="81" + PHPVER_WITHPERIOD="8.1" +elif [ "${CI_PHPTYPE}" = "PHP8.2" ] || [ "${CI_PHPTYPE}" = "PHP82" ] || [ "${CI_PHPTYPE}" = "8.2" ] || [ "${CI_PHPTYPE}" = "82" ]; then + PHPVER_NOPERIOD="82" + PHPVER_WITHPERIOD="8.2" +fi + +# +# OS Type +# +if [ -z "${CI_OSTYPE}" ]; then + # + # Unknown OS : Nothing to do + # + : +elif [ "${CI_OSTYPE}" = "ubuntu:22.04" ] || [ "${CI_OSTYPE}" = "ubuntu:jammy" ]; then + DIST_TAG="ubuntu/jammy" + PKG_EXT="deb" + PKG_OUTPUT_DIR="packages" + + INSTALLER_BIN="apt-get" + UPDATE_CMD="update" + UPDATE_CMD_ARG="" + INSTALL_CMD="install" + INSTALL_CMD_ARG="" + INSTALL_AUTO_ARG="-y" + INSTALL_QUIET_ARG="-qq" + INSTALL_PKG_LIST="git lintian debhelper pkg-config ruby-dev rubygems rubygems-integration procps shtool k2hdkc-dev" + + INSTALL_PHP_PRE_ADD_REPO="ca-certificates apt-transport-https software-properties-common" + INSTALL_PHP_REPO="ppa:ondrej/php" + INSTALL_PHP_PKG_LIST="dh-php php${PHPVER_WITHPERIOD} php${PHPVER_WITHPERIOD}-dev libapache2-mod-php${PHPVER_WITHPERIOD}" + INSTALL_PHP_OPT="" + INSTALL_PHP_POST_CONFIG="update-alternatives --set php-config /usr/bin/php-config${PHPVER_WITHPERIOD}" + INSTALL_PHP_POST_BIN="update-alternatives --set php /usr/bin/php${PHPVER_WITHPERIOD}" + SWITCH_PHP_COMMAND="" + + IS_OS_UBUNTU=1 + +elif [ "${CI_OSTYPE}" = "ubuntu:20.04" ] || [ "${CI_OSTYPE}" = "ubuntu:focal" ]; then + DIST_TAG="ubuntu/focal" + PKG_EXT="deb" + PKG_OUTPUT_DIR="packages" + + INSTALLER_BIN="apt-get" + UPDATE_CMD="update" + UPDATE_CMD_ARG="" + INSTALL_CMD="install" + INSTALL_CMD_ARG="" + INSTALL_AUTO_ARG="-y" + INSTALL_QUIET_ARG="-qq" + INSTALL_PKG_LIST="git lintian debhelper pkg-config ruby-dev rubygems rubygems-integration procps shtool k2hdkc-dev" + + INSTALL_PHP_PRE_ADD_REPO="ca-certificates apt-transport-https software-properties-common" + INSTALL_PHP_REPO="ppa:ondrej/php" + INSTALL_PHP_PKG_LIST="dh-php php${PHPVER_WITHPERIOD} php${PHPVER_WITHPERIOD}-dev libapache2-mod-php${PHPVER_WITHPERIOD}" + INSTALL_PHP_OPT="" + INSTALL_PHP_POST_CONFIG="update-alternatives --set php-config /usr/bin/php-config${PHPVER_WITHPERIOD}" + INSTALL_PHP_POST_BIN="update-alternatives --set php /usr/bin/php${PHPVER_WITHPERIOD}" + SWITCH_PHP_COMMAND="" + + IS_OS_UBUNTU=1 + +elif [ "${CI_OSTYPE}" = "ubuntu:18.04" ] || [ "${CI_OSTYPE}" = "ubuntu:bionic" ]; then + DIST_TAG="ubuntu/bionic" + PKG_EXT="deb" + PKG_OUTPUT_DIR="packages" + + INSTALLER_BIN="apt-get" + UPDATE_CMD="update" + UPDATE_CMD_ARG="" + INSTALL_CMD="install" + INSTALL_CMD_ARG="" + INSTALL_AUTO_ARG="-y" + INSTALL_QUIET_ARG="-qq" + INSTALL_PKG_LIST="git lintian debhelper pkg-config ruby-dev rubygems rubygems-integration procps shtool k2hdkc-dev" + + INSTALL_PHP_PRE_ADD_REPO="ca-certificates apt-transport-https software-properties-common" + INSTALL_PHP_REPO="ppa:ondrej/php" + INSTALL_PHP_PKG_LIST="dh-php php${PHPVER_WITHPERIOD} php${PHPVER_WITHPERIOD}-dev libapache2-mod-php${PHPVER_WITHPERIOD}" + INSTALL_PHP_OPT="" + INSTALL_PHP_POST_CONFIG="update-alternatives --set php-config /usr/bin/php-config${PHPVER_WITHPERIOD}" + INSTALL_PHP_POST_BIN="update-alternatives --set php /usr/bin/php${PHPVER_WITHPERIOD}" + SWITCH_PHP_COMMAND="" + + IS_OS_UBUNTU=1 + +elif [ "${CI_OSTYPE}" = "debian:11" ] || [ "${CI_OSTYPE}" = "debian:bullseye" ]; then + DIST_TAG="debian/bullseye" + PKG_EXT="deb" + PKG_OUTPUT_DIR="packages" + + INSTALLER_BIN="apt-get" + UPDATE_CMD="update" + UPDATE_CMD_ARG="" + INSTALL_CMD="install" + INSTALL_CMD_ARG="" + INSTALL_AUTO_ARG="-y" + INSTALL_QUIET_ARG="-qq" + INSTALL_PKG_LIST="git lintian debhelper pkg-config ruby-dev rubygems rubygems-integration procps shtool k2hdkc-dev" + + INSTALL_PHP_PRE_ADD_REPO="ca-certificates apt-transport-https software-properties-common" + INSTALL_PHP_REPO="packages.sury.org/php" + INSTALL_PHP_REPO_GPG_URL="https://packages.sury.org/php/apt.gpg" + INSTALL_PHP_REPO_GPG_FILEPATH="/usr/share/keyrings/deb.sury.org-php.gpg" + INSTALL_PHP_PKG_LIST="dh-php php${PHPVER_WITHPERIOD} php${PHPVER_WITHPERIOD}-dev libapache2-mod-php${PHPVER_WITHPERIOD}" + INSTALL_PHP_OPT="" + INSTALL_PHP_POST_CONFIG="update-alternatives --set php-config /usr/bin/php-config${PHPVER_WITHPERIOD}" + INSTALL_PHP_POST_BIN="update-alternatives --set php /usr/bin/php${PHPVER_WITHPERIOD}" + SWITCH_PHP_COMMAND="" + + IS_OS_DEBIAN=1 + +elif [ "${CI_OSTYPE}" = "debian:10" ] || [ "${CI_OSTYPE}" = "debian:buster" ]; then + DIST_TAG="debian/buster" + PKG_EXT="deb" + PKG_OUTPUT_DIR="packages" + + INSTALLER_BIN="apt-get" + UPDATE_CMD="update" + UPDATE_CMD_ARG="" + INSTALL_CMD="install" + INSTALL_CMD_ARG="" + INSTALL_AUTO_ARG="-y" + INSTALL_QUIET_ARG="-qq" + INSTALL_PKG_LIST="git lintian debhelper pkg-config ruby-dev rubygems rubygems-integration procps shtool k2hdkc-dev" + + INSTALL_PHP_PRE_ADD_REPO="ca-certificates apt-transport-https software-properties-common" + INSTALL_PHP_REPO="packages.sury.org/php" + INSTALL_PHP_REPO_GPG_URL="https://packages.sury.org/php/apt.gpg" + INSTALL_PHP_REPO_GPG_FILEPATH="/usr/share/keyrings/deb.sury.org-php.gpg" + INSTALL_PHP_PKG_LIST="dh-php php${PHPVER_WITHPERIOD} php${PHPVER_WITHPERIOD}-dev libapache2-mod-php${PHPVER_WITHPERIOD}" + INSTALL_PHP_OPT="" + INSTALL_PHP_POST_CONFIG="update-alternatives --set php-config /usr/bin/php-config${PHPVER_WITHPERIOD}" + INSTALL_PHP_POST_BIN="update-alternatives --set php /usr/bin/php${PHPVER_WITHPERIOD}" + SWITCH_PHP_COMMAND="" + + IS_OS_DEBIAN=1 + +elif [ "${CI_OSTYPE}" = "rockylinux:9.0" ] || [ "${CI_OSTYPE}" = "rockylinux:9" ]; then + DIST_TAG="el/9" + PKG_EXT="rpm" + PKG_OUTPUT_DIR="packages" + + INSTALLER_BIN="dnf" + UPDATE_CMD="update" + UPDATE_CMD_ARG="" + INSTALL_CMD="install" + INSTALL_CMD_ARG="" + INSTALL_AUTO_ARG="-y" + INSTALL_QUIET_ARG="-q" + INSTALL_PKG_LIST="git make diffutils pkgconfig patch yum-utils rpmdevtools redhat-rpm-config rpm-build rpm-devel rpmlint scl-utils-build ruby-devel rubygems procps python3 k2hdkc-devel" + + INSTALL_PHP_PRE_ADD_REPO="" + INSTALL_PHP_REPO="https://rpms.remirepo.net/enterprise/remi-release-9.rpm" + INSTALL_PHP_PKG_LIST="php${PHPVER_NOPERIOD}-php-devel php${PHPVER_NOPERIOD}-scldevel php${PHPVER_NOPERIOD}-build" + INSTALL_PHP_OPT="" + INSTALL_PHP_POST_CONFIG="" + INSTALL_PHP_POST_BIN="" + SWITCH_PHP_COMMAND="scl enable php${PHPVER_NOPERIOD} --" + + IS_OS_ROCKY=1 + # + # Enable CRB repository for libyaml + # + if "${INSTALLER_BIN}" "${INSTALL_CMD}" "${INSTALL_AUTO_ARG}" 'dnf-command(config-manager)'; then + if ! "${INSTALLER_BIN}" config-manager --set-enabled crb; then + echo "[ERROR] Failed to enable CRB repository. The script doesn't break here, but fails to install the package." + fi + else + echo "[ERROR] Failed to install \"dnf-command(config-manager)\". The script doesn't break here, but fails to install the package." + fi + +elif [ "${CI_OSTYPE}" = "rockylinux:8.6" ] || [ "${CI_OSTYPE}" = "rockylinux:8" ]; then + DIST_TAG="el/8" + PKG_EXT="rpm" + PKG_OUTPUT_DIR="packages" + + INSTALLER_BIN="dnf" + UPDATE_CMD="update" + UPDATE_CMD_ARG="" + INSTALL_CMD="install" + INSTALL_CMD_ARG="" + INSTALL_AUTO_ARG="-y" + INSTALL_QUIET_ARG="-q" + INSTALL_PKG_LIST="git make diffutils pkgconfig patch yum-utils rpmdevtools redhat-rpm-config rpm-build rpm-devel rpmlint scl-utils-build ruby-devel rubygems procps python3 k2hdkc-devel" + + INSTALL_PHP_PRE_ADD_REPO="" + INSTALL_PHP_REPO="https://rpms.remirepo.net/enterprise/remi-release-8.rpm" + INSTALL_PHP_PKG_LIST="php${PHPVER_NOPERIOD}-php-devel php${PHPVER_NOPERIOD}-scldevel php${PHPVER_NOPERIOD}-build" + INSTALL_PHP_OPT="" + INSTALL_PHP_POST_CONFIG="" + INSTALL_PHP_POST_BIN="" + SWITCH_PHP_COMMAND="scl enable php${PHPVER_NOPERIOD} --" + IS_OS_ROCKY=1 + + # Enable PowerTools repository for libyaml + # + if "${INSTALLER_BIN}" "${INSTALL_CMD}" "${INSTALL_AUTO_ARG}" 'dnf-command(config-manager)'; then + if ! "${INSTALLER_BIN}" config-manager --set-enabled powertools; then + echo "[ERROR] Failed to enable PowerTools repository. The script doesn't break here, but fails to install the package." + fi + else + echo "[ERROR] Failed to install \"dnf-command(config-manager)\". The script doesn't break here, but fails to install the package." + fi + +elif [ "${CI_OSTYPE}" = "centos:7" ] || [ "${CI_OSTYPE}" = "centos:centos7" ]; then + DIST_TAG="el/7" + PKG_EXT="rpm" + PKG_OUTPUT_DIR="packages" + + INSTALLER_BIN="yum" + UPDATE_CMD="update" + UPDATE_CMD_ARG="" + INSTALL_CMD="install" + INSTALL_CMD_ARG="" + INSTALL_AUTO_ARG="-y" + INSTALL_QUIET_ARG="-q" + INSTALL_PKG_LIST="git make diffutils pkgconfig patch yum-utils rpmdevtools redhat-rpm-config rpm-build rpm-devel rpmlint scl-utils-build rubygems procps python k2hdkc-devel" + + INSTALL_PHP_PRE_ADD_REPO="centos-release-scl-rh centos-release-scl" + INSTALL_PHP_REPO="https://rpms.remirepo.net/enterprise/remi-release-7.rpm" + INSTALL_PHP_PKG_LIST="php${PHPVER_NOPERIOD}-php-devel php${PHPVER_NOPERIOD}-scldevel php${PHPVER_NOPERIOD}-build" + INSTALL_PHP_OPT="--enablerepo=remi-php${PHPVER_NOPERIOD}" + INSTALL_PHP_POST_CONFIG="" + INSTALL_PHP_POST_BIN="" + SWITCH_PHP_COMMAND="scl enable php${PHPVER_NOPERIOD} --" + + IS_OS_CENTOS=1 + +elif [ "${CI_OSTYPE}" = "fedora:37" ]; then + DIST_TAG="fedora/37" + PKG_EXT="rpm" + PKG_OUTPUT_DIR="packages" + + INSTALLER_BIN="dnf" + UPDATE_CMD="update" + UPDATE_CMD_ARG="" + INSTALL_CMD="install" + INSTALL_CMD_ARG="" + INSTALL_AUTO_ARG="-y" + INSTALL_QUIET_ARG="-q" + INSTALL_PKG_LIST="git make diffutils pkgconfig patch yum-utils rpmdevtools redhat-rpm-config rpm-build rpm-devel rpmlint scl-utils-build ruby-devel rubygems procps python3 k2hdkc-devel" + + INSTALL_PHP_PRE_ADD_REPO="" + INSTALL_PHP_REPO="https://rpms.remirepo.net/fedora/remi-release-37.rpm" + INSTALL_PHP_PKG_LIST="php${PHPVER_NOPERIOD}-php-devel php${PHPVER_NOPERIOD}-scldevel php${PHPVER_NOPERIOD}-build" + INSTALL_PHP_OPT="" + INSTALL_PHP_POST_CONFIG="" + INSTALL_PHP_POST_BIN="" + SWITCH_PHP_COMMAND="scl enable php${PHPVER_NOPERIOD} --" + + IS_OS_FEDORA=1 + +elif [ "${CI_OSTYPE}" = "fedora:36" ]; then + DIST_TAG="fedora/36" + PKG_EXT="rpm" + PKG_OUTPUT_DIR="packages" + + INSTALLER_BIN="dnf" + UPDATE_CMD="update" + UPDATE_CMD_ARG="" + INSTALL_CMD="install" + INSTALL_CMD_ARG="" + INSTALL_AUTO_ARG="-y" + INSTALL_QUIET_ARG="-q" + INSTALL_PKG_LIST="git make diffutils pkgconfig patch yum-utils rpmdevtools redhat-rpm-config rpm-build rpm-devel rpmlint scl-utils-build ruby-devel rubygems procps python3 k2hdkc-devel" + + INSTALL_PHP_PRE_ADD_REPO="" + INSTALL_PHP_REPO="https://rpms.remirepo.net/fedora/remi-release-36.rpm" + INSTALL_PHP_PKG_LIST="php${PHPVER_NOPERIOD}-php-devel php${PHPVER_NOPERIOD}-scldevel php${PHPVER_NOPERIOD}-build" + INSTALL_PHP_OPT="" + INSTALL_PHP_POST_CONFIG="" + INSTALL_PHP_POST_BIN="" + SWITCH_PHP_COMMAND="scl enable php${PHPVER_NOPERIOD} --" + + IS_OS_FEDORA=1 + +elif [ "${CI_OSTYPE}" = "alpine:3.17" ]; then + DIST_TAG="alpine/v3.17" + PKG_EXT="apk" + PKG_OUTPUT_DIR="packages" + + INSTALLER_BIN="apk" + UPDATE_CMD="update" + UPDATE_CMD_ARG="--no-progress" + INSTALL_CMD="add" + INSTALL_CMD_ARG="--no-progress --no-cache" + INSTALL_AUTO_ARG="" + INSTALL_QUIET_ARG="-q" + INSTALL_PKG_LIST="bash sudo alpine-sdk util-linux-misc musl-locales ruby-dev procps k2hdkc-dev" + + INSTALL_PHP_PRE_ADD_REPO="" + INSTALL_PHP_REPO="" + INSTALL_PHP_PKG_LIST="php${PHPVER_NOPERIOD} php${PHPVER_NOPERIOD}-dev" + INSTALL_PHP_OPT="" + INSTALL_PHP_POST_CONFIG="" + INSTALL_PHP_POST_BIN="" + SWITCH_PHP_COMMAND="" + + IS_OS_ALPINE=1 + + if [ "${PHPVER_NOPERIOD}" != "81" ]; then + NOT_PROVIDED_PHPVER=1 + fi +fi + +#--------------------------------------------------------------- +# Enable/Disable processing +#--------------------------------------------------------------- +# [NOTE] +# Specify the phase of processing to use. +# The phases that can be specified are the following values, and +# the default is set for PHP Extension processing. +# Setting this value to 1 enables the corresponding processing, +# setting it to 0 disables it. +# +# +# RUN_PRE_CONFIG 1 +# RUN_CONFIG 1 +# RUN_PRE_CLEANUP 1 +# RUN_CLEANUP 1 +# RUN_POST_CLEANUP 0 +# RUN_CPPCHECK 1 +# RUN_SHELLCHECK 1 +# RUN_CHECK_OTHER 0 +# RUN_PRE_BUILD 0 +# RUN_BUILD 1 +# RUN_POST_BUILD 0 +# RUN_PRE_TEST 0 +# RUN_TEST 1 +# RUN_POST_TEST 0 +# RUN_PRE_PACKAGE 0 +# RUN_PACKAGE 1 +# RUN_POST_PACKAGE 0 +# RUN_PUBLISH_PACKAGE 1 + +#--------------------------------------------------------------- +# Variables for each process +#--------------------------------------------------------------- +# [NOTE] +# Specify the following variables that can be specified in each phase. +# Each value has a default value for PHP Extension processing. +# +# PRE_CLEANUP_FILES_DIRS "" +# +# CPPCHECK_TARGET "." +# CPPCHECK_BASE_OPT "--quiet --error-exitcode=1 --inline-suppr -j 4 --std=c++03 --xml" +# CPPCHECK_ENABLE_VALUES "warning style information missingInclude" +# CPPCHECK_IGNORE_VALUES "unmatchedSuppression" +# CPPCHECK_BUILD_DIR "/tmp/cppcheck" +# +# SHELLCHECK_TARGET_DIRS "." +# SHELLCHECK_BASE_OPT "--shell=sh" +# SHELLCHECK_EXCEPT_PATHS "/\.libs/ /autom4te.cache/ /build/ /debian_build/ /rpmbuild/ /include/ /modules/ /packages/ /run-tests.php" +# SHELLCHECK_IGN "SC1117 SC1090 SC1091" +# SHELLCHECK_INCLUDE_IGN "SC2034 SC2148" +# +# BUILD_MAKE_EXT_OPT_RPM "" +# BUILD_MAKE_EXT_OPT_DEBIAN "" +# BUILD_MAKE_EXT_OPT_ALPINE "" +# BUILD_MAKE_EXT_OPT_OTHER "" +# +# MAKE_TEST_OPT_RPM "test" +# MAKE_TEST_OPT_DEBIAN "test" +# MAKE_TEST_OPT_ALPINE "test" +# MAKE_TEST_OPT_OTHER "test" +# +# CREATE_PACKAGE_TOOL_RPM "buildutils/php_rpm_build.sh" +# CREATE_PACKAGE_TOOL_DEBIAN "buildutils/php_debian_build.sh" +# CREATE_PACKAGE_TOOL_ALPINE "buildutils/php_alpine_build.sh" +# CREATE_PACKAGE_TOOL_OTHER "" +# +# CREATE_PACKAGE_TOOL_OPT_AUTO "-y" +# CREATE_PACKAGE_TOOL_OPT_RPM "" +# CREATE_PACKAGE_TOOL_OPT_DEBIAN "" +# CREATE_PACKAGE_TOOL_OPT_ALPINE "" +# CREATE_PACKAGE_TOOL_OPT_OTHER "" +# + +PRE_CLEANUP_FILES_DIRS=" + config.h.in~ + configure~ + core.* + rpmbuild + debian_build + apk_build + packages + tests/*.diff + tests/*.exp + tests/*.log + tests/*.out + tests/*.php + tests/*.sh + php-pecl-k2hdkc.spec" + +if [ "${PHPVER_NOPERIOD}" = "82" ]; then + if [ "${IS_OS_UBUNTU}" -eq 1 ] || [ "${IS_OS_DEBIAN}" -eq 1 ]; then + CREATE_PACKAGE_TOOL_OPT_DEBIAN="-ccp" + fi +fi + +# +# Local variables: +# tab-width: 4 +# c-basic-offset: 4 +# End: +# vim600: noexpandtab sw=4 ts=4 fdm=marker +# vim<600: noexpandtab sw=4 ts=4 +# diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..94591bb --- /dev/null +++ b/.gitignore @@ -0,0 +1,112 @@ +# +# K2HDKC PHP Extension library +# +# Copyright 2023 Yahoo Japan Corporation. +# +# K2HDKC is k2hash based distributed KVS cluster. +# K2HDKC uses K2HASH, CHMPX, FULLOCK libraries. K2HDKC supports +# distributed KVS cluster server program and client libraries. +# +# For the full copyright and license information, please view +# the license file that was distributed with this source code. +# +# AUTHOR: Hirotaka Wakabayashi +# CREATE: Tue, Feb 22 2022 +# REVISION: +# + +# +# Wildcards +# +*.dep +*.o +*.lo +*.a +*.la +*.so +*.gcno +*.gcda +*.rpm +*.deb +.*~ + +# +# Autotools Files +# +acinclude.m4 +aclocal.m4 +autom4te.cache +config.guess +config.h +config.h.in +config.h.in~ +config.log +config.nice +config.status +config.sub +configure +configure.in +configure.ac +install-sh +ltmain.sh +Makefile +Makefile.fragments +Makefile.global +Makefile.objects +missing +build +include +libtool + +# +# Created by configure +# +buildutils/k2hdkcpx.ini +buildutils/php-pecl-k2hdkc.spec +buildutils/control +buildutils/control.in +buildutils/copyright +buildutils/rules +buildutils/watch +buildutils/upstream/metadata + +# +# Directries +# +.libs +.deps +mkinstalldirs +modules +packages +packages/* + +# +# Files and Directories for packaging +# +run-tests.php +php-pecl-k2hdkc.spec +rpmbuild/ +rpmbuild/* +debian_build/ +debian_build/* +buildutils/APKBUILD.templ + +# +# Test files +# +tmp-php.ini +tests/*.diff +tests/*.out +tests/*.php +tests/*.exp +tests/*.log +tests/*.sh + +# +# Local variables: +# tab-width: 4 +# c-basic-offset: 4 +# End: +# vim600: noexpandtab sw=4 ts=4 fdm=marker +# vim<600: noexpandtab sw=4 ts=4 +# diff --git a/AUTHORS b/AUTHORS new file mode 100644 index 0000000..8838561 --- /dev/null +++ b/AUTHORS @@ -0,0 +1,7 @@ +1. Hirotaka Wakabayashi + +Wrote from scratch the initial version of extension for k2hdkc. + +2. Takeshi Nakatani + +Develops and other improvements. diff --git a/ChangeLog b/ChangeLog new file mode 100644 index 0000000..f24cae4 --- /dev/null +++ b/ChangeLog @@ -0,0 +1,5 @@ +php-pecl-k2hdkc (1.0.0) unstable; urgency=low + + * Initial Commit and publishing + + -- Hirotaka Wakabayashi Thu, 27 Apr 2023 15:53:14 +0900 diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..b0dd1b5 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright 2023 Yahoo Japan Corporation + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..361bf79 --- /dev/null +++ b/README.md @@ -0,0 +1,70 @@ +k2hdkc php extension +==================== +[![PHP AntPickax CI](https://github.com/yahoojapan/k2hdkc_phpext/workflows/PHP%20AntPickax%20CI/badge.svg)](https://github.com/yahoojapan/k2hdkc_phpext/actions) +[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/yahoojapan/k2hdkc_phpext/master/LICENSE) +[![GitHub forks](https://img.shields.io/github/forks/yahoojapan/k2hdkc_phpext.svg)](https://github.com/yahoojapan/k2hdkc_phpext/network) +[![GitHub stars](https://img.shields.io/github/stars/yahoojapan/k2hdkc_phpext.svg)](https://github.com/yahoojapan/k2hdkc_phpext/stargazers) +[![GitHub issues](https://img.shields.io/github/issues/yahoojapan/k2hdkc_phpext.svg)](https://github.com/yahoojapan/k2hdkc_phpext/issues) +[![debian packages](https://img.shields.io/badge/deb-packagecloud.io-844fec.svg)](https://packagecloud.io/antpickax/stable) +[![RPM packages](https://img.shields.io/badge/rpm-packagecloud.io-844fec.svg)](https://packagecloud.io/antpickax/stable) + +- K2HDKC PHP Extension library +K2HDKC is NoSQL Key Value Store(KVS) library by Yahoo! JAPAN. + +### Overview +K2HDKC is a free and open-source distributed KVS(Key Value Store) clustering system created in Yahoo! JAPAN. +This PHP Extension library is for using K2HDKC from PHP. + +By [K2HDKC PHP Extension](https://php.k2hdkc.antpick.ax/) library, you can easily incorporate the functions and features of K2HDKC into PHP based programs. +For the features and functions of K2HDKC, see the [k2hdkc documentation](https://k2hdkc.antpick.ax/). + +![k2HASH PHP Extension](https://php.k2hdkc.antpick.ax/images/top_k2hdkc_phpext.png) + +### Usage +K2HDKC PHP Extension library is provided as RPM and Debian package. +Before installing this package, you need the K2HDKC package(RPM or Debian). +First of all, please install the k2hdkc developer package as described [here](https://k2hdkc.antpick.ax/usage.html). +Next, install the K2HDKC PHP Extension library using the package manager command. + +- Debian based Linux users can install it by following the steps below: +``` +$ sudo apt-get update -y + +$ sudo apt-get install curl -y +$ curl -s https://packagecloud.io/install/repositories/antpickax/stable/script.deb.sh | sudo bash + +$ sudo apt-get install -y php8.2 libapache2-mod-php8.2 +$ sudo update-alternatives --set php-config /usr/bin/php-config8.2 +$ sudo update-alternatives --set php /usr/bin/php8.2 +$ sudo apt-get install -y k2hdkc php-pecl-k2hdkc +``` +- Fedora derived RPM based Linux(Fedora, CentOS, CentOS Stream, RHEL, etc.) users can install it by following the steps below: +``` +$ sudo dnf update -y + +$ curl -s https://packagecloud.io/install/repositories/antpickax/stable/script.rpm.sh | sudo bash + +$ sudo dnf install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm +$ sudo dnf install https://rpms.remirepo.net/enterprise/remi-release-8.rpm +$ sudo dnf module reset php +$ sudo dnf module install php:remi-8.2 +$ sudo dnf install -y php-pecl-k2hdkc +``` + +### Documents +- [Document top page](https://php.k2hdkc.antpick.ax/) +- [Github wiki page](https://github.com/yahoojapan/k2hdkc_phpext/wiki) +- [About K2HDKC](https://k2hdkc.antpick.ax/) +- [About AntPickax](https://antpick.ax/) + +### Packages +- [RPM packages(packagecloud.io)](https://packagecloud.io/antpickax/stable) +- [Debian packages(packagecloud.io)](https://packagecloud.io/antpickax/stable) + +### License +This software is released under the MIT License, see the license file. + +### AntPickax +K2HDKC PHP Extension is one of [AntPickax](https://antpick.ax/) products. + +Copyright(C) 2023 Yahoo Japan Corporation. diff --git a/buildutils/APKBUILD.templ.in b/buildutils/APKBUILD.templ.in new file mode 100644 index 0000000..c1f4db6 --- /dev/null +++ b/buildutils/APKBUILD.templ.in @@ -0,0 +1,116 @@ +# +# K2HDKC PHP Extension library +# +# Copyright 2023 Yahoo Japan Corporation. +# +# K2HDKC is k2hash based distributed KVS cluster. +# K2HDKC uses K2HASH, CHMPX, FULLOCK libraries. K2HDKC supports +# distributed KVS cluster server program and client libraries. +# +# For the full copyright and license information, please view +# the license file that was distributed with this source code. +# +# AUTHOR: Hirotaka Wakabayashi +# CREATE: Tue, Feb 22 2022 +# REVISION: +# + +#--------------------------------------------------------------- +# Local varibales as antpickax template +#--------------------------------------------------------------- +# +# Set variables by configure +# +_git_domain="@GIT_DOMAIN@" +_organization_name="@GIT_ORG@" +_repository_name="@GIT_REPO@" + +# +# Set variables by php_alpine_build.sh +# +_package_name=%%PACKAGE_PHPVER_NAME%% +_package_version=%%PACKAGE_VERSION%% +_package_revision=%%BUILD_NUMBER%% +_package_phpver=%%PACKAGE_PHPVERSION%% +_package_desc="%%PACKAGE_DESC%%" +_source_archive_url=%%SOURCE_ARCHIVE_URL%% + +#--------------------------------------------------------------- +# Main variables for APKBUILD +#--------------------------------------------------------------- +# Contributor: @DEV_NAME@ <@DEV_EMAIL@> +# Maintainer: @DEV_NAME@ <@DEV_EMAIL@> + +# [NOTE] +# The $_organization_name is "k2hdkc_phpext", but the $pkgname +# should be "phpXX-pecl-k2hdkc", so adjust with this variable. +# +pkgname=$_package_name +pkgver=$_package_version +pkgrel=$_package_revision +pkgdesc=$_package_desc + +url="https://php.k2hdkc.antpick.ax/" +arch="x86_64" +license="MIT" + +depends=" + php$_package_phpver + k2hdkc +" +depends_dev="" +makedepends=" + $depends_dev + musl-locales + procps + php$_package_phpver-dev + k2hdkc-dev +" + +install="" +subpackages="" + +source="$pkgname-$pkgver.tar.gz%%SOURCE_ARCHIVE_URL%%" + +builddir="$srcdir/$pkgname-$pkgver" + +#--------------------------------------------------------------- +# Build functions for APKBUILD +#--------------------------------------------------------------- +prepare() { + default_prepare + # this function can be omitted if no extra steps are needed +} + +unpack() { + default_unpack + + # [NOTE] + # A github release archive is unzipped as a directory with the + # repository name(k2hdkc_phpext) and version number. + # In this case, change the directory name to the package name + # (phpXX-pecl-k2hdkc) instead of the repository name. + # + if [ -d "$_repository_name-$pkgver" ]; then + mv "$_repository_name-$pkgver" "$pkgname-$pkgver" + fi +} + +build() { + phpize + ./configure --prefix=/usr + make +} + +check() { + TEST_PHP_ARGS='-q' make test +} + +package() { + install -Dm 0644 buildutils/k2hdkcpx.ini "$pkgdir"/etc/php"$_package_phpver"/conf.d/k2hdkcpx.ini + install -Dm 0755 modules/k2hdkcpx.so "$pkgdir"/usr/lib/php"$_package_phpver"/modules/k2hdkcpx.so +} + +# [NOTE] +# Subsequent lines print the checksum of the source archive. +# diff --git a/buildutils/control.in.in b/buildutils/control.in.in new file mode 100644 index 0000000..992d48c --- /dev/null +++ b/buildutils/control.in.in @@ -0,0 +1,61 @@ +Source: @K2HDKCPX_EXT_PKGNAME@ +Section: php +Priority: optional +Maintainer: @DEV_NAME@ <@DEV_EMAIL@> +Uploaders: @DEV_NAME@ <@DEV_EMAIL@> +Build-Depends: debhelper (>= 10~), debhelper-compat (= 11), dh-php (>= 4~), k2hdkc-dev, php@K2HDKCPX_PHP_MAJOR_VERSION@.@K2HDKCPX_PHP_MINOR_VERSION@-dev +Standards-Version: 4.5.1 +Homepage: @HOME_PAGE@ +Vcs-Git: https://@GIT_DOMAIN@/@GIT_ORG@/@GIT_REPO@.git +Vcs-Browser: https://@GIT_DOMAIN@/@GIT_ORG@/@GIT_REPO@ + +Package: php7.4-@PHP_PECL_BASE_NAME@ +Architecture: any +Pre-Depends: php-common (>= 2:69~) +Depends: ucf, ${misc:Depends}, ${pecl:Depends}, ${shlibs:Depends}, ${php:Depends} +Provides: ${pecl:Provides}, ${php:Provides} +Breaks: ${pecl:Breaks} +Replaces: ${pecl:Replaces} +Suggests: ${pecl:Suggests} +Recommends: ${pecl:Recommends} +Description: k2hdkc extension for PHP7.4 + This extension adds API for k2hdkc for PHP7.4. + This package is a metapackage of @K2HDKCPX_EXT_PKGNAME@. + +Package: php8.0-@PHP_PECL_BASE_NAME@ +Architecture: any +Pre-Depends: php-common (>= 2:69~) +Depends: ucf, ${misc:Depends}, ${pecl:Depends}, ${shlibs:Depends}, ${php:Depends} +Provides: ${pecl:Provides}, ${php:Provides} +Breaks: ${pecl:Breaks} +Replaces: ${pecl:Replaces} +Suggests: ${pecl:Suggests} +Recommends: ${pecl:Recommends} +Description: k2hdkc extension for PHP8.0 + This extension adds API for k2hdkc for PHP8.0. + This package is a metapackage of @K2HDKCPX_EXT_PKGNAME@. + +Package: php8.1-@PHP_PECL_BASE_NAME@ +Architecture: any +Pre-Depends: php-common (>= 2:69~) +Depends: ucf, ${misc:Depends}, ${pecl:Depends}, ${shlibs:Depends}, ${php:Depends} +Provides: ${pecl:Provides}, ${php:Provides} +Breaks: ${pecl:Breaks} +Replaces: ${pecl:Replaces} +Suggests: ${pecl:Suggests} +Recommends: ${pecl:Recommends} +Description: k2hdkc extension for PHP8.1 + This extension adds API for k2hdkc for PHP8.1. + This package is a metapackage of @K2HDKCPX_EXT_PKGNAME@. + +Package: @K2HDKCPX_EXT_PKGNAME@ +Architecture: any +Pre-Depends: php-common (>= 2:69~) +Depends: ucf, ${misc:Depends}, ${pecl:Depends}, ${shlibs:Depends}, ${php:Depends} +Provides: ${pecl:Provides}, ${php:Provides} +Breaks: ${pecl:Breaks} +Replaces: ${pecl:Replaces} +Suggests: ${pecl:Suggests} +Recommends: ${pecl:Recommends} +Description: k2hdkc extension for PHP + This extension adds API for k2hdkc for PHP. diff --git a/buildutils/copyright.in b/buildutils/copyright.in new file mode 100644 index 0000000..3caf4a9 --- /dev/null +++ b/buildutils/copyright.in @@ -0,0 +1,15 @@ +Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ +Upstream-Name: @PHP_PECL_BASE_NAME@ +Upstream-Contact: @DEV_NAME@ <@DEV_EMAIL@> +Source: https://@GIT_DOMAIN@/@GIT_ORG@/@GIT_REPO@ + +Files: * +Copyright: @DEBLICENSER@ +License: @PKGLICENSE@ + +Files: debian/* +Copyright: @DEBLICENSER@ +License: @PKGLICENSE@ + +License: @PKGLICENSE@ +@DEBCOPYING@ diff --git a/buildutils/k2hdkcpx.ini.in b/buildutils/k2hdkcpx.ini.in new file mode 100644 index 0000000..0b30fda --- /dev/null +++ b/buildutils/k2hdkcpx.ini.in @@ -0,0 +1,36 @@ +; +; K2HDKC PHP Extension library +; +; Copyright 2023 Yahoo Japan Corporation. +; +; K2HDKC is k2hash based distributed KVS cluster. +; K2HDKC uses K2HASH, CHMPX, FULLOCK libraries. K2HDKC supports +; distributed KVS cluster server program and client libraries. +; +; For the full copyright and license information, please view +; the license file that was distributed with this source code. +; +; AUTHOR: Hirotaka Wakabayashi +; CREATE: Tue, Feb 22 2022 +; REVISION: +; + +; Enable @PHP_SO_NAME@ extension module +extension = @PHP_SO_NAME@.so + +; k2hdkcpx_debug sets the serverity of k2hdkc library logger. +; silent means this library logs nothing. This is default. +; error means this library logs only error message. +; warning means this library logs warning and error message. +; info means this library logs normal, warning and error message. +; dump means this library logs all message. +k2hdkcpx.k2hdkcpx_debug = silent + +; +; Local variables: +; tab-width: 4 +; c-basic-offset: 4 +; End: +; vim600: noexpandtab sw=4 ts=4 fdm=marker +; vim<600: noexpandtab sw=4 ts=4 +; diff --git a/buildutils/make_rpm_changelog.sh b/buildutils/make_rpm_changelog.sh new file mode 100755 index 0000000..37c5e9e --- /dev/null +++ b/buildutils/make_rpm_changelog.sh @@ -0,0 +1,203 @@ +#!/bin/sh +# +# Utility tools for building configure/packages by AntPickax +# +# Copyright 2018 Yahoo Japan Corporation. +# +# AntPickax provides utility tools for supporting autotools +# builds. +# +# These tools retrieve the necessary information from the +# repository and appropriately set the setting values of +# configure, Makefile, spec,etc file and so on. +# These tools were recreated to reduce the number of fixes and +# reduce the workload of developers when there is a change in +# the project configuration. +# +# For the full copyright and license information, please view +# the license file that was distributed with this source code. +# +# AUTHOR: Takeshi Nakatani +# CREATE: Fri, Apr 13 2018 +# REVISION: +# + +# +# Convert ChangeLog to use it in spec file for rpm +# + +# +# Common variables +# +PRGNAME=$(basename "${0}") +MYSCRIPTDIR=$(dirname "${0}") +SRCTOP=$(cd "${MYSCRIPTDIR}/.." || exit 1; pwd) + +# +# Variables +# +DEFAULT_CHANGELOG_FILE="${SRCTOP}/ChangeLog" +CHANGELOG_FILE="" + +# +# Utility functions +# +func_usage() +{ + echo "" + echo "Usage: $1 [--help(-h)] " + echo " --help(-h) print help." + echo " specify ChnageLog file path. if not specify, use ChangeLog file in top directory as default." + echo "" + echo "Environment:" + echo " BUILD_NUMBER if specify a "build number" other than the default of 1, set it in this environment variable." + echo "" +} + +# +# Parse parameters +# +while [ $# -ne 0 ]; do + if [ -z "$1" ]; then + break + + elif [ "$1" = "-h" ] || [ "$1" = "-H" ] || [ "$1" = "--help" ] || [ "$1" = "--HELP" ]; then + func_usage "${PRGNAME}" + exit 0 + + else + if [ -n "${CHANGELOG_FILE}" ]; then + echo "[ERROR] already ChangeLog(${CHANGELOG_FILE}) file is specified." 1>&2 + exit 1 + fi + if [ ! -f "$1" ]; then + echo "[ERROR] $1 file is not existed." 1>&2 + exit 1 + fi + CHANGELOG_FILE="$1" + fi + shift +done +if [ -z "${CHANGELOG_FILE}" ]; then + if [ -f "${DEFAULT_CHANGELOG_FILE}" ]; then + echo "[ERROR] ${DEFAULT_CHANGELOG_FILE} file is not existed." 1>&2 + exit 1 + fi + CHANGELOG_FILE="${DEFAULT_CHANGELOG_FILE}" +fi + +# +# Check Build number +# +# If the environment variable BUILD_NUMBER is specified, set its value to the +# build number. If not specified(default), it is 1. +# +if [ -z "${BUILD_NUMBER}" ]; then + BUILD_NUMBER_STR="-1" +else + if echo "${BUILD_NUMBER}" | grep -q "[^0-9]"; then + echo "[ERROR] The BUILD_NUMBER environment has not number charactor(${BUILD_NUMBER})." 1>&2 + exit 1 + fi + BUILD_NUMBER_STR="-${BUILD_NUMBER}" +fi + +# +# Convert ChangeLog for RPM spec format +# +CONTENT_LINES_IN_VERSION=0 +SET_FIRST_VERSION=0 +OUTPUT_FIRST_LINE=0 +CONTENT_LINES="" +while IFS= read -r ONE_LINE; do + if [ -z "${ONE_LINE}" ]; then + continue + fi + + if ! echo "${ONE_LINE}" | grep -q "^[[:space:]]"; then + # + # new version line + # + if [ "${CONTENT_LINES_IN_VERSION}" -ne 0 ]; then + echo "[ERROR] Something is wrong with the format. The committer and date do not exist on the line immediately before \"${ONE_LINE}\"." 1>&2 + exit 1 + fi + PKG_VERSION=$(echo "${ONE_LINE}" | grep '^.*[(].*\..*[)].*[;].*$' | grep -o '[(].*[)]' | sed -e 's/[(|)]//g' -e 's/^[[:space:]]+//g' -e 's/[[:space:]]+$//g' | tr -d '\n') + + if [ -z "${PKG_VERSION}" ]; then + echo "[ERROR] Something is wrong with the format. The package version does not exist in \"${ONE_LINE}\"." 1>&2 + exit 1 + fi + + if [ "${SET_FIRST_VERSION}" -eq 0 ]; then + PKG_VERSION="${PKG_VERSION}${BUILD_NUMBER_STR}" + SET_FIRST_VERSION=1 + fi + CONTENT_LINES_IN_VERSION=1 + + else + # + # in version lines + # + if [ "${CONTENT_LINES_IN_VERSION}" -eq 0 ]; then + echo "[ERROR] Something is wrong with the format. The package name and version number do not exist in the line immediately before \"${ONE_LINE}\"." 1>&2 + exit 1 + fi + + if echo "${ONE_LINE}" | grep -q "^[[:space:]][-][-][[:space:]]"; then + # + # commiter/date line(last line) + # + PKG_COMMITTER=$(echo "${ONE_LINE}" | sed -e 's/^[[:space:]][-][-][[:space:]]//g' -e 's/[[:space:]][[:space:]].*$//g' -e 's/^[[:space:]]+//g' -e 's/[[:space:]]+$//g' | tr -d '\n') + PKG_RFC2822=$(echo "${ONE_LINE}" | sed -e 's/^[[:space:]][-][-][[:space:]].*[[:space:]][[:space:]]//g' -e 's/^[[:space:]]+//g' -e 's/[[:space:]]+$//g' | tr -d '\n') + + if [ -z "${PKG_COMMITTER}" ] || [ -z "${PKG_RFC2822}" ]; then + echo "[ERROR] Something is wrong with the format. The committer and date do not exist in \"${ONE_LINE}\"." 1>&2 + exit 1 + fi + PKG_DATE=$(echo "${PKG_RFC2822}" | sed 's/,/ /g' | awk '{print $1" "$3" "$2" "$4}' | tr -d '\n') + + if [ "${OUTPUT_FIRST_LINE}" -eq 0 ]; then + OUTPUT_FIRST_LINE=1 + else + printf '\n' + fi + printf '* %s %s %s\n%s\n' "${PKG_DATE}" "${PKG_COMMITTER}" "${PKG_VERSION}" "${CONTENT_LINES}" + + CONTENT_LINES_IN_VERSION=0 + CONTENT_LINES="" + + elif echo "${ONE_LINE}" | grep -q "^[[:space:]][[:space:]]\*[[:space:]]"; then + # + # content line + # + ONE_CONTENT=$(echo "${ONE_LINE}" | sed -e 's/^[[:space:]][[:space:]]\*[[:space:]]//g' -e 's/^[[:space:]]+//g' -e 's/[[:space:]]+$//g' | tr -d '\n') + + if [ -z "${ONE_CONTENT}" ]; then + echo "[ERROR] Something is wrong with the format. The content does not exist in \"${ONE_LINE}\"." 1>&2 + exit 1 + fi + + if [ -z "${CONTENT_LINES}" ]; then + CONTENT_LINES=$(printf '%s- %s' '' "${ONE_CONTENT}") + else + CONTENT_LINES=$(printf '%s\n- %s' "${CONTENT_LINES}" "${ONE_CONTENT}") + fi + + else + echo "[ERROR] Something is wrong with the format in \"${ONE_LINE}\"." 1>&2 + exit 1 + fi + fi +done < "${CHANGELOG_FILE}" + +exit 0 + +# +# Local variables: +# tab-width: 4 +# c-basic-offset: 4 +# End: +# vim600: noexpandtab sw=4 ts=4 fdm=marker +# vim<600: noexpandtab sw=4 ts=4 +# diff --git a/buildutils/php-pecl-k2hdkc.php b/buildutils/php-pecl-k2hdkc.php new file mode 100644 index 0000000..a97ae57 --- /dev/null +++ b/buildutils/php-pecl-k2hdkc.php @@ -0,0 +1 @@ +mod debian/k2hdkcpx.ini diff --git a/buildutils/php-pecl-k2hdkc.spec.in b/buildutils/php-pecl-k2hdkc.spec.in new file mode 100644 index 0000000..8c877e0 --- /dev/null +++ b/buildutils/php-pecl-k2hdkc.spec.in @@ -0,0 +1,207 @@ +# +# K2HDKC PHP Extension library +# +# Copyright 2023 Yahoo Japan Corporation. +# +# K2HDKC is k2hash based distributed KVS cluster. +# K2HDKC uses K2HASH, CHMPX, FULLOCK libraries. K2HDKC supports +# distributed KVS cluster server program and client libraries. +# +# For the full copyright and license information, please view +# the license file that was distributed with this source code. +# +# AUTHOR: Hirotaka Wakabayashi +# CREATE: Tue, Feb 22 2022 +# REVISION: +# + +# +# we don't want -z defs linker flag +# +%undefine _strict_symbol_defs_build + +# +# Local macros/define +# +%if %{undefined package_revision} +%global package_revision 1 +%endif + +%if 0%{?scl:1} +%global phproot /opt/remi/%scl_php/root +%global scl_vendor remi +%else +%global phproot / +%endif + +%if 0%{?scl:1} +%global sub_prefix %{scl_prefix} +%scl_package @K2HDKCPX_EXT_PKGNAME@ +%endif + +%global with_zts 0 +%global with_tests 1 +%global pecl_name @PHP_SO_NAME@ +%global ini_name 40-%{pecl_name}.ini +%global base_ini buildutils/%{pecl_name}.ini + +%global buildver %(pkg-config --silence-errors --modversion libk2hdkc 2>/dev/null || echo 65536) + +Summary: A k2hdkc PHP module written in C +Name: %{?sub_prefix}@K2HDKCPX_EXT_PKGNAME@ +Version: @K2HDKCPX_EXT_VERSION@ +Release: %{package_revision}%{?dist} +License: MIT +Group: Development/Languages +URL: https://@GIT_DOMAIN@/@GIT_ORG@/@GIT_REPO@/ +Source0: https://@GIT_DOMAIN@/@GIT_ORG@/@GIT_REPO@/archive/@K2HDKCPX_EXT_PKGNAME@-%{version}.tar.gz + +BuildRequires: %{?dtsprefix}gcc +BuildRequires: %{?scl_prefix}php-devel >= 7.4 +BuildRequires: k2hdkc-devel >= %{buildver} +Requires: k2hdkc%{?_isa} >= %{buildver} + +%if 0%{?php_zend_api} +Requires: %{?scl_prefix}php(zend-abi) = %{php_zend_api} +Requires: %{?scl_prefix}php(api) = %{php_core_api} +%endif +%{?_sclreq:Requires: %{?scl_prefix}runtime%{?_sclreq}%{?_isa}} + +Provides: %{?scl_prefix}php-%{pecl_name} = %{version} +Provides: %{?scl_prefix}php-%{pecl_name}%{?_isa} = %{version} +Provides: %{?scl_prefix}php-pecl(%{pecl_name}) = %{version} +Provides: %{?scl_prefix}php-pecl(%{pecl_name})%{?_isa} = %{version} +%if "%{?scl_prefix}" != "%{?sub_prefix}" +Provides: %{?scl_prefix}php-pecl-%{pecl_name} = %{version}-%{release} +Provides: %{?scl_prefix}php-pecl-%{pecl_name}%{?_isa} = %{version}-%{release} +%endif + +Provides: rh-php-%{pecl_name} = 1.1.0 +Provides: rh-php-%{pecl_name}%{?_isa} = 1.1.0 +Provides: rh-php-pecl(%{pecl_name}) = 1.1.0 +Provides: rh-php-pecl(%{pecl_name})%{?_isa} = 1.1.0 +%if "%{?scl_prefix}" != "%{?sub_prefix}" +Provides: rh-php-pecl-%{pecl_name} = 1.1.0-1 +Provides: rh-php-pecl-%{pecl_name}%{?_isa} = 1.1.0-1 +%endif + +# +# Description +# +%description +K2HDKC PHP Extension library + +@K2HDKCPX_EXT_PKGNAME@ implements a K2HDKC library as a PHP Extension +written in C. + +K2HDKC is NoSQL(key value store) library and tools for this +library by Yahoo! JAPAN. +This PHP Extension library is for using K2HDKC from PHP. + +By K2HDKC PHP Extension library, you can easily incorporate +the functions and features of K2HCKD into PHP based programs. +For the features of K2HDKC, see https://k2hdkc.antpick.ax/ + +Package built for PHP @K2HDKCPX_PHP_VERSION@%{?scl: as Software Collection (%{scl} by %{?scl_vendor}%{!?scl_vendor:rh})}. + +# +# Prep +# autosetup options +# -c Create Directory (and change to it) Before Unpacking +# -n Set Name of Build Directory +# +%prep +%autosetup -c -n @K2HDKCPX_EXT_PKGNAME@-%{version} + +mv @K2HDKCPX_EXT_PKGNAME@-%{version} NTS + +%if %{with_zts} +cp -pr NTS ZTS +%endif + +# +# Build +# +%build + +cd NTS +%{phproot}/usr/bin/phpize + +%if %{with_zts} +cd ../ZTS +%{phproot}/usr/bin/zts-phpize +%endif + +./configure +make %{?_smp_mflags} + +# +# Install +# +%install + +make -C NTS install INSTALL_ROOT=%{buildroot} + +# Drop in the bit of configuration +install -Dpm 644 NTS/%{base_ini} %{buildroot}%{php_inidir}/%{ini_name} + +%if %{with_zts} +make -C ZTS install INSTALL_ROOT=%{buildroot} +install -Dpm 644 ZTS/%{base_ini} %{buildroot}%{php_ztsinidir}/%{ini_name} +%endif + +# +# Check +# +%check +: Minimal load test for NTS extension +%{__php} --no-php-ini \ + --define extension=NTS/modules/%{pecl_name}.so \ + -m | grep %{pecl_name} + +%if %{with_zts} +: Minimal load test for ZTS extension +%{__ztsphp} --no-php-ini \ + --define extension=ZTS/modules/%{pecl_name}.so \ + -m | grep %{pecl_name} +%endif + +%if %{with_tests} +ret=0 +pushd NTS +: Run the upstream test Suite for NTS extension +TEST_PHP_EXECUTABLE=%{__php} \ +TEST_PHP_ARGS="-n -d extension=$PWD/modules/%{pecl_name}.so" \ +NO_INTERACTION=1 \ +REPORT_EXIT_STATUS=1 \ +%{__php} -n run-tests.php --show-diff || ret=1 +popd + +%if %{with_zts} +pushd ZTS +: Run the upstream test Suite for ZTS extension +TEST_PHP_EXECUTABLE=%{__ztsphp} \ +TEST_PHP_ARGS="-n -d extension=$PWD/modules/%{pecl_name}.so" \ +NO_INTERACTION=1 \ +REPORT_EXIT_STATUS=1 \ +%{__ztsphp} -n run-tests.php --show-diff || ret=1 +popd +%endif +exit $ret +%endif + +# +# Files +# +%files +%{?_licensedir:%license NTS/LICENSE} +%config(noreplace) %{php_inidir}/%{ini_name} +%{php_extdir}/%{pecl_name}.so + +%if %{with_zts} +%config(noreplace) %{php_ztsinidir}/%{ini_name} +%{php_ztsextdir}/%{pecl_name}.so +%endif + +%changelog +@K2HDKCPX_RPMCHANGELOG@ diff --git a/buildutils/php_alpine_build.sh b/buildutils/php_alpine_build.sh new file mode 100755 index 0000000..19d9ad7 --- /dev/null +++ b/buildutils/php_alpine_build.sh @@ -0,0 +1,728 @@ +#!/bin/sh +# +# Utility tools for building configure/packages by AntPickax +# +# Copyright 2018 Yahoo Japan Corporation. +# +# AntPickax provides utility tools for supporting autotools +# builds. +# +# These tools retrieve the necessary information from the +# repository and appropriately set the setting values of +# configure, Makefile, spec,etc file and so on. +# These tools were recreated to reduce the number of fixes and +# reduce the workload of developers when there is a change in +# the project configuration. +# +# For the full copyright and license information, please view +# the license file that was distributed with this source code. +# +# AUTHOR: Takeshi Nakatani +# CREATE: Fri, Jan 13 2023 +# REVISION: 1.1 +# + +#============================================================== +# Autobuild for apk package +#============================================================== +# +# Instead of pipefail(for shells not support "set -o pipefail") +# +PIPEFAILURE_FILE="/tmp/.pipefailure.$(od -An -tu4 -N4 /dev/random | tr -d ' \n')" + +# +# For shellcheck +# +if command -v locale >/dev/null 2>&1; then + if locale -a | grep -q -i '^[[:space:]]*C.utf8[[:space:]]*$'; then + LANG=$(locale -a | grep -i '^[[:space:]]*C.utf8[[:space:]]*$' | sed -e 's/^[[:space:]]*//g' -e 's/[[:space:]]*$//g' | tr -d '\n') + LC_ALL="${LANG}" + export LANG + export LC_ALL + elif locale -a | grep -q -i '^[[:space:]]*en_US.utf8[[:space:]]*$'; then + LANG=$(locale -a | grep -i '^[[:space:]]*en_US.utf8[[:space:]]*$' | sed -e 's/^[[:space:]]*//g' -e 's/[[:space:]]*$//g' | tr -d '\n') + LC_ALL="${LANG}" + export LANG + export LC_ALL + fi +fi + +#---------------------------------------------------------- +# Common variables +#---------------------------------------------------------- +PRGNAME=$(basename "$0") +SCRIPTDIR=$(dirname "$0") +SCRIPTDIR=$(cd "${SCRIPTDIR}" || exit 1; pwd) +SRCTOP=$(cd "${SCRIPTDIR}/.." || exit 1; pwd) + +SRCTOP_DIRNAME=$(basename "${SRCTOP}") +APK_TOPDIR="${SRCTOP}/apk_build" +PKG_TOPDIR="${SRCTOP}/packages" + +PRGNAME_NOEXT=$(echo "${PRGNAME}" | sed -e 's/[\.].*$//g' | tr -d '\n') +EXTRA_COPY_FILES_CONF="${SCRIPTDIR}/${PRGNAME_NOEXT}_copy.conf" + +APKBUILD_TEMPLATE_FILE="${SRCTOP}/buildutils/APKBUILD.templ" +APKBUILD_FILE="${APK_TOPDIR}/APKBUILD" +APKBUILD_CONFIG_DIR="${HOME}/.abuild" + +# +# Message variables +# +IN_GHAGROUP_AREA=0 + +# +# Variables +# +BUILD_NUMBER=0 +IS_CLEAN=0 +NO_INTERACTIVE=0 + +#============================================================== +# Utilities +#============================================================== +# +# Usage +# +func_usage() +{ + echo "" + echo "Usage: $1 [--help(-h)] [--clean(-c)] [--buildnum(-b) ] [--yes(-y)]" + echo " --help(-h) print help" + echo " --clean(-c) only clean work directory." + echo " --buildnum(-b) specify build number for packaging(default 1)" + echo " --yes(-y) runs no interactive mode." + echo "" + echo "Note: about " + echo " Specify a number starting from 1, just like other OS builds." + echo " However, ALPINE packages are 0-based, so the specified \" - 1\"" + echo " is the actual number of the package." + echo "" +} + +#-------------------------------------------------------------- +# Utilities for message +#-------------------------------------------------------------- +if [ -t 1 ] || { [ -n "${CI}" ] && [ "${CI}" = "true" ]; }; then + CBLD=$(printf '\033[1m') + CREV=$(printf '\033[7m') + CRED=$(printf '\033[31m') + CYEL=$(printf '\033[33m') + CGRN=$(printf '\033[32m') + CDEF=$(printf '\033[0m') +else + CBLD="" + CREV="" + CRED="" + CYEL="" + CGRN="" + CDEF="" +fi +if [ -n "${CI}" ] && [ "${CI}" = "true" ] && [ -z "${RUN_AS_SUBPROCESS}" ]; then + GHAGRP_START="::group::" + GHAGRP_END="::endgroup::" +else + GHAGRP_START="" + GHAGRP_END="" +fi + +PRNGROUPEND() +{ + if [ -n "${IN_GHAGROUP_AREA}" ] && [ "${IN_GHAGROUP_AREA}" -eq 1 ]; then + if [ -n "${GHAGRP_END}" ]; then + echo "${GHAGRP_END}" + fi + fi + IN_GHAGROUP_AREA=0 +} +PRNTITLE() +{ + PRNGROUPEND + echo "${GHAGRP_START}${CBLD}${CGRN}${CREV}[TITLE]${CDEF} ${CGRN}$*${CDEF}" + IN_GHAGROUP_AREA=1 +} +PRNINFO() +{ + echo "${CBLD}${CREV}[INFO]${CDEF} $*" +} +PRNWARN() +{ + echo "${CBLD}${CYEL}${CREV}[WARNING]${CDEF} ${CYEL}$*${CDEF}" +} +PRNERR() +{ + echo "${CBLD}${CRED}${CREV}[ERROR]${CDEF} ${CRED}$*${CDEF}" + PRNGROUPEND +} +PRNSUCCESS() +{ + echo "${CBLD}${CGRN}${CREV}[SUCCEED]${CDEF} ${CGRN}$*${CDEF}" + PRNGROUPEND +} +PRNFAILURE() +{ + echo "${CBLD}${CRED}${CREV}[FAILURE]${CDEF} ${CRED}$*${CDEF}" + PRNGROUPEND +} + +#============================================================== +# Parse options +#============================================================== +while [ $# -ne 0 ]; do + if [ -z "$1" ]; then + break + + elif [ "$1" = "-h" ] || [ "$1" = "-H" ] || [ "$1" = "--help" ] || [ "$1" = "--HELP" ]; then + func_usage "${PRGNAME}" + exit 0 + + elif [ "$1" = "-c" ] || [ "$1" = "-C" ] || [ "$1" = "--clean" ] || [ "$1" = "--CLEAN" ]; then + if [ "${IS_CLEAN}" -ne 0 ]; then + PRNERR "Already --clean(-c) option is specified." + exit 1 + fi + IS_CLEAN=1 + + elif [ "$1" = "-b" ] || [ "$1" = "-B" ] || [ "$1" = "--buildnum" ] || [ "$1" = "--BUILDNUM" ]; then + if [ "${BUILD_NUMBER}" -ne 0 ]; then + PRNERR "Already --buildnum(-b) option is specified(${BUILD_NUMBER})." + exit 1 + fi + shift + if [ -z "$1" ]; then + PRNERR "--buildnum(-b) option need parameter." + exit 1 + fi + if echo "$1" | grep -q "[^0-9]"; then + PRNERR "--buildnum(-b) option parameter must be number(and not equal zero)." + exit 1 + fi + if [ "$1" -eq 0 ]; then + PRNERR "--buildnum(-b) option parameter must be number(and not equal zero)." + exit 1 + fi + BUILD_NUMBER="$1" + + elif [ "$1" = "-y" ] || [ "$1" = "-Y" ] || [ "$1" = "--yes" ] || [ "$1" = "--YES" ]; then + if [ "${NO_INTERACTIVE}" -ne 0 ]; then + PRNERR "Already --yes(-y) option is specified." + exit 1 + fi + NO_INTERACTIVE=1 + + else + PRNERR "Unknown option $1." + exit 1 + fi + shift +done + +# +# Check parameters +# +# [NOTE] +# APK package revision starts "0", it is default value. +# +if [ -z "${BUILD_NUMBER}" ]; then + BUILD_NUMBER=0 +elif [ "${BUILD_NUMBER}" -gt 0 ]; then + BUILD_NUMBER=$((BUILD_NUMBER - 1)) +fi + +#-------------------------------------------------------------- +# Welcome message and confirming for interactive mode +#-------------------------------------------------------------- +if [ "${NO_INTERACTIVE}" -eq 0 ] && [ "${IS_CLEAN}" -ne 1 ]; then + echo "---------------------------------------------------------------" + echo " Do you change these file and commit to github?" + echo " - ChangeLog modify / add changes like dch tool format" + echo " - Git TAG stamp git tag for release" + echo "---------------------------------------------------------------" + IS_CONFIRMED=0 + while [ "${IS_CONFIRMED}" -eq 0 ]; do + printf '[INPUT] Confirm (y/n) : ' + read -r CONFIRM + + if [ "${CONFIRM}" = "y" ] || [ "${CONFIRM}" = "Y" ] || [ "${CONFIRM}" = "yes" ] || [ "${CONFIRM}" = "YES" ]; then + IS_CONFIRMED=1 + elif [ "${CONFIRM}" = "n" ] || [ "${CONFIRM}" = "N" ] || [ "${CONFIRM}" = "no" ] || [ "${CONFIRM}" = "NO" ]; then + PRNINFO "Interrupt this processing, bye..." + exit 0 + fi + done + echo "" +fi + +#============================================================== +# Remove directory for clenup +#============================================================== +PRNTITLE "Remove old work directory for packaging" + +if [ -d "${APK_TOPDIR}" ] || [ -f "${APK_TOPDIR}" ]; then + rm -rf "${APK_TOPDIR}" +fi +PRNSUCCESS "Removed ${APK_TOPDIR}" + +# +# Clean mode -> finish +# +if [ "${IS_CLEAN}" -eq 1 ]; then + exit 0 +fi + +#============================================================== +# Get package information +#============================================================== +PRNTITLE "Get package information" + +#-------------------------------------------------------------- +# Check Environments and variables +#-------------------------------------------------------------- +# [NOTE] +# This script sets variables in the APKBUILD file from environment +# and variables. +# Use the following environment variables and variables. +# +# DEBEMAIL : Used for creating RSA keys +# DEBFULLNAME : Used for creating RSA keys +# GITHUB_REF_TYPE : This environment variable is set by GithubActions. +# For release tagging, this value is set to "tag". +# Unset and otherwise("branch") indicate that the call was +# not made by the release process. +# ABUILD_OPT : abuild common option for running as root user. +# +PRNINFO "Check Environments and variables" + +if [ -z "${DEBEMAIL}" ]; then + PRNWARN "DEBEMAIL environment is not set, so set default \"${USER}@$(hostname)\"" + DEBEMAIL="${USER}@$(hostname)" +fi + +if [ -z "${DEBFULLNAME}" ]; then + PRNWARN "DEBFULLNAME environment is not set, so set default \"${USER}\"." + DEBFULLNAME="${USER}" +fi + +if [ -z "${GITHUB_REF_TYPE}" ] || [ "${GITHUB_REF_TYPE}" != "tag" ]; then + SOURCE_ARCHIVE_URL="" + SOURCE_ARCHIVE_SEPARATOR="" +else + SOURCE_ARCHIVE_URL="https://\$_git_domain/\$_organization_name/\$_repository_name/archive/refs/tags/v\$pkgver.tar.gz" + SOURCE_ARCHIVE_SEPARATOR="::" +fi + +#-------------------------------------------------------------- +# Check running as root user and Set APKBUILD option +#-------------------------------------------------------------- +# [NOTE] +# The abuild tool drains errors when run as root. +# To avoid this, the "-F" option is required. +# +PRNINFO "Check running as root user and Set APKBUILD option" + +RUN_USER_ID=$(id -u) +ABUILD_OPT="" + +if [ -n "${RUN_USER_ID}" ] && [ "${RUN_USER_ID}" -eq 0 ]; then + ABUILD_OPT="-F" +fi + +#-------------------------------------------------------------- +# Check package name and version +#-------------------------------------------------------------- +PRNINFO "Check package name and version" + +PACKAGE_NAME=$(head -n 1 "${SRCTOP}"/ChangeLog | awk '{print $1}' | tr -d '\n') +PACKAGE_VERSION=$(head -n 1 "${SRCTOP}"/ChangeLog | sed -e 's/[(]//g' -e 's/[)]//g' | awk '{print $2}' | sed -e 's/-.*$//g' | tr -d '\n') + +PACKAGE_PHPMAJORVERSION=$(php -r 'echo PHP_MAJOR_VERSION;') +PACKAGE_PHPMINORVERSION=$(php -r 'echo PHP_MINOR_VERSION;') + +if [ "${PACKAGE_PHPMAJORVERSION}" = "7" ]; then + # + # 7.4 -> 7 + # + PACKAGE_PHPVERSION="${PACKAGE_PHPMAJORVERSION}" +elif [ "${PACKAGE_PHPMAJORVERSION}" = "8" ] && [ "${PACKAGE_PHPMINORVERSION}" = "0" ]; then + # + # 8.0 -> 8 + # + PACKAGE_PHPVERSION="${PACKAGE_PHPMAJORVERSION}" +else + # + # 8.1/8.2/... -> 81/82/... + # + PACKAGE_PHPVERSION="${PACKAGE_PHPMAJORVERSION}${PACKAGE_PHPMINORVERSION}" +fi +PACKAGE_PHPVER_NAME=$(echo "${PACKAGE_NAME}" | sed -e "s/php/php${PACKAGE_PHPVERSION}/g") +PACKAGE_DESC="k2hash extension for PHP${PACKAGE_PHPMAJORVERSION}.${PACKAGE_PHPMINORVERSION}" + +if [ -z "${PACKAGE_NAME}" ] || [ -z "${PACKAGE_PHPVER_NAME}" ] || [ -z "${PACKAGE_VERSION}" ]; then + PRNERR "Failed to get Package name and version." + exit 1 +fi + +#-------------------------------------------------------------- +# Print information +#-------------------------------------------------------------- +# +# Information +# +PRNINFO "Information for building APK packages" +echo "" +echo " PACKAGE NAME = ${PACKAGE_NAME} / ${PACKAGE_PHPVER_NAME}" +echo " PACKAGE DESCRIPTION = ${PACKAGE_DESC}" +echo " PACKAGE VERSION = ${PACKAGE_VERSION}" +echo " BUILD NUMBER = ${BUILD_NUMBER}" +echo " PHP VERSION = ${PACKAGE_PHPVERSION}" +echo "" +echo " APK_TOPDIR = ${APK_TOPDIR}" +echo " NO_INTERACTIVE = ${NO_INTERACTIVE}" +echo "" +echo " GITHUB_REF_TYPE = ${GITHUB_REF_TYPE}" +echo " SOURCE_ARCHIVE_URL = ${SOURCE_ARCHIVE_URL}" +echo " BUILD_NUMBER = ${BUILD_NUMBER}" +echo " ABUILD_OPT = ${ABUILD_OPT}" +echo "" + +PRNSUCCESS "Got package information" + +#============================================================== +# Main processing +#============================================================== +cd "${SRCTOP}" || exit 1 + +#-------------------------------------------------------------- +# Check untracked files +#-------------------------------------------------------------- +PRNTITLE "Check untracked files" + +# [NOTE] +# When using actions/checkout@v1, suppress the following errors. +# "Error: fatal: unsafe repository ('...' is owned by someone else)" +# +git config --global --add safe.directory "${GITHUB_WORKSPACE}" + +if [ -n "$(git status --untracked-files=no --porcelain 2>&1)" ]; then + PRNWARN "Some files are in untracked state. Packages are created for testing, but must not be published." + PRNFAILURE "Check untracked files, but continue..." +else + PRNSUCCESS "No untracked files" +fi + +#-------------------------------------------------------------- +# Run phpize and configure +#-------------------------------------------------------------- +PRNTITLE "Run phpize" + +if ! phpize; then + PRNERR "Failed to run phpize." + exit 1 +fi +PRNSUCCESS "phpize done" + +PRNTITLE "Run configure" + +if ! ./configure; then + PRNERR "Failed to run configure." + exit 1 +fi +PRNSUCCESS "configure done" + +#-------------------------------------------------------------- +# Create package top directories +#-------------------------------------------------------------- +PRNTITLE "Create work directories for packaging" + +if ! mkdir "${APK_TOPDIR}"; then + PRNERR "Could not create ${APK_TOPDIR} dicretory." + exit 1 +fi + +PRNSUCCESS "Created ${APK_TOPDIR}" + +#--------------------------------------------------------------- +# Create RSA key for signing +#--------------------------------------------------------------- +PRNTITLE "Create RSA key for signing" + +# +# Check "${HOME}/.abuild" directory +# +if [ -d "${APKBUILD_CONFIG_DIR}" ] || [ -f "${APKBUILD_CONFIG_DIR}" ]; then + rm -rf "${APKBUILD_CONFIG_DIR}" +fi + +# +# Create temporary RSA key +# +# [NOTE] +# The keys that are created are the following files: +# ${APKBUILD_CONFIG_DIR}/${DEBEMAIL}-.rsa +# ${APKBUILD_CONFIG_DIR}/${DEBEMAIL}-.rsa.pub +# +if ({ PACKAGER="${DEBFULLNAME} <${DEBEMAIL}>" abuild-keygen -a -n 2>&1 || echo > "${PIPEFAILURE_FILE}"; } | sed -e 's#^# #') && rm "${PIPEFAILURE_FILE}" >/dev/null 2>&1; then + PRNERR "Failed to create temporary RSA key for building APK packages." + exit 1 +fi + +# +# Check and Copy RSA keys +# +if ! find "${APKBUILD_CONFIG_DIR}" -name "${DEBEMAIL}"-\*\.rsa | grep -q "${DEBEMAIL}"; then + PRNERR "Not found ${APKBUILD_CONFIG_DIR}/${DEBEMAIL}-.rsa files." + exit 1 +fi +if ! find "${APKBUILD_CONFIG_DIR}" -name "${DEBEMAIL}"-\*\.rsa\.pub | grep -q "${DEBEMAIL}"; then + PRNERR "Not found ${APKBUILD_CONFIG_DIR}/${DEBEMAIL}-.rsa.pub files." + exit 1 +fi +if ! cp -p "${APKBUILD_CONFIG_DIR}"/"${DEBEMAIL}"-*.rsa "${APK_TOPDIR}"; then + PRNERR "Failed to copy RSA private key(${APKBUILD_CONFIG_DIR}/${DEBEMAIL}-.rsa) to ${APK_TOPDIR} directory." + exit 1 +fi +if ! cp -p "${APKBUILD_CONFIG_DIR}"/"${DEBEMAIL}"-*.rsa.pub "${APK_TOPDIR}"; then + PRNERR "Failed to copy RSA public key(${APKBUILD_CONFIG_DIR}/${DEBEMAIL}-.rsa.pub) to ${APK_TOPDIR} directory." + exit 1 +fi + +# +# Remove abuild configuration directory(with abuild.conf) +# +# [NOTE] +# When building the package, the RSA key is specified by an environment +# variable, so the presence of this configuration file is misleading. +# +rm -rf "${APKBUILD_CONFIG_DIR}" + +# +# Set file name/key contents to variables +# +APK_PACKAGE_PRIV_KEYNAME="$(find "${APK_TOPDIR}" -name "${DEBEMAIL}"-\*\.rsa 2>/dev/null | head -1 | sed -e "s#${APK_TOPDIR}/##g" | tr -d '\n')" +APK_PACKAGE_PUB_KEYNAME="$(find "${APK_TOPDIR}" -name "${DEBEMAIL}"-\*\.rsa\.pub 2>/dev/null | head -1 | sed -e "s#${APK_TOPDIR}/##g" | tr -d '\n')" + +# +# Information +# +echo "" +echo " RSA private key : ${APK_TOPDIR}/${APK_PACKAGE_PRIV_KEYNAME}" +echo " RSA public key : ${APK_TOPDIR}/${APK_PACKAGE_PUB_KEYNAME}" +echo "" + +PRNSUCCESS "Created RSA keys" + +#-------------------------------------------------------------- +# Make source tar.gz +#-------------------------------------------------------------- +PRNTITLE "Create base tar ball of source files or URL" + +if [ -n "${GITHUB_REF_TYPE}" ] && [ "${GITHUB_REF_TYPE}" = "tag" ]; then + # + # Source archive is URL (not local archive file) + # + # ex. https://github.com/yahoojapan/xxx_phpext/archive/refs/tags/v1.0.0.tar.gz + # extracted top directory name -> xxx_phpext-1.0.0 + # + PRNSUCCESS "Created source code URL ${SOURCE_ARCHIVE_URL}" + +elif [ -d "${SRCTOP}/.git" ] && [ "$(git status -s 2>&1 | wc -l)" -eq 0 ]; then + # + # No untracked files, make source package(tar.gz) by git archive + # + if ! git archive HEAD --prefix="${PACKAGE_PHPVER_NAME}-${PACKAGE_VERSION}"/ --output="${APK_TOPDIR}/${PACKAGE_PHPVER_NAME}-${PACKAGE_VERSION}".tar.gz; then + PRNERR "Could not make source tar ball(${APK_TOPDIR}/${PACKAGE_PHPVER_NAME}-${PACKAGE_VERSION}.tar.gz) from github repository." + exit 1 + fi + PRNSUCCESS "Created ${APK_TOPDIR}/${PACKAGE_PHPVER_NAME}-${PACKAGE_VERSION}.tar.gz" + +else + # + # Found untracked files or Not have .git directory, source code package(tar.gz) like "make dist" and copy it + # + # [NOTICE] + # PHP Extension is built using "phpize(config.m4)". + # The "Makefile" created by "phpize" does not have "make dist", + # so the source code expanded by "Github Actions" is created in + # advance as "_allsource.tar.gz" with "phpext_helper.sh". + # Extract this "_allsource.tar.gz" and create a file + # similar to "make dist" here. + # + _SOURCECODE_DIRNAME=$(basename "${SRCTOP}") + _ALL_SOURCE_TARGZ_FILENAME="${_SOURCECODE_DIRNAME}_allsource.tar.gz" + + if [ ! -f "${SRCTOP}/${_ALL_SOURCE_TARGZ_FILENAME}" ]; then + PRNERR "Not found all source code tar.gz file(${SRCTOP}/${_ALL_SOURCE_TARGZ_FILENAME})." + exit 1 + fi + if ! tar xvfz "${SRCTOP}/${_ALL_SOURCE_TARGZ_FILENAME}" -C /tmp/ >/dev/null 2>&1; then + PRNERR "Failed to expand all source code tar.gz file(${SRCTOP}/${_ALL_SOURCE_TARGZ_FILENAME}) to /tmp." + exit 1 + fi + if [ ! -d /tmp/"${_SOURCECODE_DIRNAME}" ]; then + PRNERR "Not found expanded all source code directory(/tmp/${_SOURCECODE_DIRNAME}) from file(${SRCTOP}/${_ALL_SOURCE_TARGZ_FILENAME})." + exit 1 + fi + rm -rf /tmp/"${_SOURCECODE_DIRNAME}"/.git + + if ! mv /tmp/"${_SOURCECODE_DIRNAME}" /tmp/"${PACKAGE_PHPVER_NAME}-${PACKAGE_VERSION}"; then + PRNERR "Failed to rename from /tmp/${_SOURCECODE_DIRNAME} directory to /tmp/${PACKAGE_PHPVER_NAME}-${PACKAGE_VERSION}." + exit 1 + fi + if ! (cd /tmp || exit 1; tar cvfz "${APK_TOPDIR}/${PACKAGE_PHPVER_NAME}-${PACKAGE_VERSION}".tar.gz "${PACKAGE_PHPVER_NAME}-${PACKAGE_VERSION}"); then + PRNERR "Failed to create ${APK_TOPDIR}/${PACKAGE_PHPVER_NAME}-${PACKAGE_VERSION}.tar.gz." + exit 1 + fi + rm -rf /tmp/"${PACKAGE_PHPVER_NAME}-${PACKAGE_VERSION}" + + PRNSUCCESS "Created ${APK_TOPDIR}/${PACKAGE_PHPVER_NAME}-${PACKAGE_VERSION}.tar.gz" +fi + +#--------------------------------------------------------------- +# Copy extra files +#--------------------------------------------------------------- +# [NOTE] +# If you have files to copy under "/apk_build" +# directory(includes in your package), you can prepare +# "buildutils/alpine_build_copy.conf" file and lists target files +# int it. +# The file names in this configuration file list with relative paths +# from the source top directory. +# ex) src/myfile +# lib/mylib +# +if [ -f "${EXTRA_COPY_FILES_CONF}" ]; then + PRNTITLE "Copy extra files" + + EXTRA_COPY_FILES=$(sed -e 's/#.*$//g' -e 's/^[[:space:]]*//g' -e 's/[[:space:]]*$//g' -e '/^$/d' "${EXTRA_COPY_FILES_CONF}") + for _extra_file in ${EXTRA_COPY_FILES}; do + if [ ! -f "${SRCTOP}/${_extra_file}" ]; then + PRNERR "Not found ${SRCTOP}/${_extra_file} file for extra copy." + exit 1 + fi + if ! cp -p "${SRCTOP}/${_extra_file}" "${APK_TOPDIR}"; then + PRNERR "Failed to copy ${SRCTOP}/${_extra_file} file to ${APK_TOPDIR}." + exit 1 + fi + done + + PRNSUCCESS "Copied extra files" +fi + +#--------------------------------------------------------------- +# Create APKBUILD file +#--------------------------------------------------------------- +PRNTITLE "Create APKBUILD file" + +# +# Create APKBUILD file from template +# +PRNINFO "Create APKBUILD file from template" + +if ! sed -e "s#%%PACKAGE_PHPVER_NAME%%#${PACKAGE_PHPVER_NAME}#g" \ + -e "s#%%PACKAGE_VERSION%%#${PACKAGE_VERSION}#g" \ + -e "s#%%BUILD_NUMBER%%#${BUILD_NUMBER}#g" \ + -e "s#%%PACKAGE_DESC%%#${PACKAGE_DESC}#g" \ + -e "s#%%PACKAGE_PHPVERSION%%#${PACKAGE_PHPVERSION}#g" \ + -e "s#%%SOURCE_ARCHIVE_URL%%#${SOURCE_ARCHIVE_SEPARATOR}${SOURCE_ARCHIVE_URL}#g" \ + "${APKBUILD_TEMPLATE_FILE}" > "${APKBUILD_FILE}" ; then + + PRNERR "Failed to create APKBUILD file in ${APK_TOPDIR} directory." + exit 1 +fi + +# +# Add checksum to APKBUILD file +# +PRNINFO "Add checksum to APKBUILD file" + +cd "${APK_TOPDIR}" || exit 1 + +if ! /bin/sh -c "abuild ${ABUILD_OPT} checksum"; then + PRNERR "Failed to add checksum to APKBUILD file(${APKBUILD_FILE})." + exit 1 +fi + +# +# Get Arch name for a part of package directory path +# +PRNINFO "Get Arch name" + +ARCH_NAME=$(grep '^arch=' "${APKBUILD_FILE}" | sed -e 's#^arch=##g' -e 's#"##g' | tail -1 | tr -d '\n') + +# +# Print APKBUILD file +# +PRNSUCCESS "Created APKBUILD file(${APKBUILD_FILE})" +echo "" +sed -e 's#^# #g' "${APKBUILD_FILE}" +echo "" + +#--------------------------------------------------------------- +# Create packages +#--------------------------------------------------------------- +PRNTITLE "Build APK packages." + +# +# build APK packages +# +if ({ /bin/sh -c "PACKAGER_PRIVKEY=${APK_TOPDIR}/${APK_PACKAGE_PRIV_KEYNAME} abuild ${ABUILD_OPT} -r -P $(pwd)" || echo > "${PIPEFAILURE_FILE}"; } | sed -e 's#^# #') && rm "${PIPEFAILURE_FILE}" >/dev/null 2>&1; then + PRNERR "Failed to create APK packages." + exit 1 +fi +PRNSUCCESS "Built APK packages" + +# +# Show APK packages +# +for _one_pkg in "${APK_TOPDIR}"/"${SRCTOP_DIRNAME}"/"${ARCH_NAME}"/*.apk; do + echo "" + echo "[INFO] Dump APK package : ${_one_pkg}" + + if ({ tar tvfz "${_one_pkg}" 2>/dev/null || echo > "${PIPEFAILURE_FILE}"; } | sed -e 's#^# #') && rm "${PIPEFAILURE_FILE}" >/dev/null 2>&1; then + PRNERR "Failed to extract ${_one_pkg} APK package." + exit 1 + fi +done + +#---------------------------------------------------------- +# Copy packages +#---------------------------------------------------------- +if [ ! -d "${PKG_TOPDIR}" ]; then + PRNTITLE "Create ${PKG_TOPDIR} directory" + if ! mkdir -p "${PKG_TOPDIR}"; then + PRNERR "Failed to create ${PKG_TOPDIR} directory" + exit 1 + fi + PRNSUCCESS "Created ${PKG_TOPDIR} directory" +fi + +# +# Copy APK packages +# +PRNTITLE "Copy created APK packages to packages directory" + +if ! cp -p "${APK_TOPDIR}"/"${SRCTOP_DIRNAME}"/"${ARCH_NAME}"/*.apk "${PKG_TOPDIR}"; then + PRNERR "Failed to copy ${APK_TOPDIR}/${SRCTOP_DIRNAME}/${ARCH_NAME}/*.apk package to ${PKG_TOPDIR} directory." + exit 1 +fi +ls -la "${PKG_TOPDIR}" + +PRNSUCCESS "Copied created APK packages to packages directory" + +#--------------------------------------------------------------- +# Finish +#--------------------------------------------------------------- +echo "" +PRNSUCCESS "You can find APK package in ${PKG_TOPDIR} directory" +echo "" + +exit 0 + +# +# Local variables: +# tab-width: 4 +# c-basic-offset: 4 +# End: +# vim600: noexpandtab sw=4 ts=4 fdm=marker +# vim<600: noexpandtab sw=4 ts=4 +# diff --git a/buildutils/php_debian_build.sh b/buildutils/php_debian_build.sh new file mode 100755 index 0000000..db6ebb3 --- /dev/null +++ b/buildutils/php_debian_build.sh @@ -0,0 +1,689 @@ +#!/bin/sh +# +# Utility tools for building PHP packages by AntPickax +# +# Copyright 2022 Yahoo Japan Corporation. +# +# AntPickax provides utility tools for supporting autotools +# builds. +# +# These tools retrieve the necessary information from the +# repository and appropriately set the setting values of +# configure, Makefile, spec,etc file and so on. +# These tools were recreated to reduce the number of fixes and +# reduce the workload of developers when there is a change in +# the project configuration. +# +# For the full copyright and license information, please view +# the license file that was distributed with this source code. +# +# AUTHOR: Takeshi Nakatani +# CREATE: Tue, Feb 22 2022 +# REVISION: 1.1 +# + +#============================================================== +# Autobuild for PHP debian package +#============================================================== +# +# Instead of pipefail(for shells not support "set -o pipefail") +# +PIPEFAILURE_FILE="/tmp/.pipefailure.$(od -An -tu4 -N4 /dev/random | tr -d ' \n')" + +# +# For shellcheck +# +if command -v locale >/dev/null 2>&1; then + if locale -a | grep -q -i '^[[:space:]]*C.utf8[[:space:]]*$'; then + LANG=$(locale -a | grep -i '^[[:space:]]*C.utf8[[:space:]]*$' | sed -e 's/^[[:space:]]*//g' -e 's/[[:space:]]*$//g' | tr -d '\n') + LC_ALL="${LANG}" + export LANG + export LC_ALL + elif locale -a | grep -q -i '^[[:space:]]*en_US.utf8[[:space:]]*$'; then + LANG=$(locale -a | grep -i '^[[:space:]]*en_US.utf8[[:space:]]*$' | sed -e 's/^[[:space:]]*//g' -e 's/[[:space:]]*$//g' | tr -d '\n') + LC_ALL="${LANG}" + export LANG + export LC_ALL + fi +fi + +#---------------------------------------------------------- +# Common variables +#---------------------------------------------------------- +PRGNAME=$(basename "$0") +SCRIPTDIR=$(dirname "$0") +SCRIPTDIR=$(cd "${SCRIPTDIR}" || exit 1; pwd) +SRCTOP=$(cd "${SCRIPTDIR}"/.. || exit 1; pwd) + +BUILDDEBDIR="${SRCTOP}/debian_build" +DEBPKGDIR="${SRCTOP}/packages" + +PRGNAME_NOEXT=$(echo "${PRGNAME}" | sed -e 's/[\.].*$//g' | tr -d '\n') +EXTRA_COPY_FILES_CONF="${SCRIPTDIR}/${PRGNAME_NOEXT}_copy.conf" + +# +# Message variables +# +IN_GHAGROUP_AREA=0 + +# +# Variables +# +BUILD_NUMBER=0 +IS_CLEAN=0 +NO_INTERACTIVE=0 +IS_COPY_COMMON_PKGS=0 + +#---------------------------------------------------------- +# Utility: Usage +#---------------------------------------------------------- +func_usage() +{ + echo "" + echo "Usage: $1 [--help(-h)] [--clean(-c)] [--copy-common-package(-ccp)] [--buildnum(-b) ] [--yes(-y)]" + echo " --help(-h) print help" + echo " --clean(-c) only clean work directory." + echo " --copy-common-package(-ccp) copy common package to packages directory." + echo " --buildnum(-b) specify build number for packaging(default 1)" + echo " --yes(-y) runs no interactive mode." + echo "" + echo "Note: Only if \"--copy-common-package(-ccp)\" is specified, the following" + echo " packages will be copied to the packages directory." + echo " php-pecl-_X.Y.Z-N_****.deb" + echo " php-pecl--all-dev_X.Y.Z-N_all.deb" + echo " These packages are PHP version independent and common, so use this" + echo " option to avoid conflicts." + echo "" +} + +#---------------------------------------------------------- +# Utilities for message +#---------------------------------------------------------- +if [ -t 1 ] || { [ -n "${CI}" ] && [ "${CI}" = "true" ]; }; then + CBLD=$(printf '\033[1m') + CREV=$(printf '\033[7m') + CRED=$(printf '\033[31m') + CYEL=$(printf '\033[33m') + CGRN=$(printf '\033[32m') + CDEF=$(printf '\033[0m') +else + CBLD="" + CREV="" + CRED="" + CYEL="" + CGRN="" + CDEF="" +fi +if [ -n "${CI}" ] && [ "${CI}" = "true" ] && [ -z "${RUN_AS_SUBPROCESS}" ]; then + GHAGRP_START="::group::" + GHAGRP_END="::endgroup::" +else + GHAGRP_START="" + GHAGRP_END="" +fi + +PRNGROUPEND() +{ + if [ -n "${IN_GHAGROUP_AREA}" ] && [ "${IN_GHAGROUP_AREA}" -eq 1 ]; then + if [ -n "${GHAGRP_END}" ]; then + echo "${GHAGRP_END}" + fi + fi + IN_GHAGROUP_AREA=0 +} +PRNTITLE() +{ + PRNGROUPEND + echo "${GHAGRP_START}${CBLD}${CGRN}${CREV}[TITLE]${CDEF} ${CGRN}$*${CDEF}" + IN_GHAGROUP_AREA=1 +} +PRNINFO() +{ + echo "${CBLD}${CREV}[INFO]${CDEF} $*" +} +PRNWARN() +{ + echo "${CBLD}${CYEL}${CREV}[WARNING]${CDEF} ${CYEL}$*${CDEF}" +} +PRNERR() +{ + echo "${CBLD}${CRED}${CREV}[ERROR]${CDEF} ${CRED}$*${CDEF}" + PRNGROUPEND +} +PRNSUCCESS() +{ + echo "${CBLD}${CGRN}${CREV}[SUCCEED]${CDEF} ${CGRN}$*${CDEF}" + PRNGROUPEND +} +PRNFAILURE() +{ + echo "${CBLD}${CRED}${CREV}[FAILURE]${CDEF} ${CRED}$*${CDEF}" + PRNGROUPEND +} + +#---------------------------------------------------------- +# Parse options +#---------------------------------------------------------- +while [ $# -ne 0 ]; do + if [ -z "$1" ]; then + break + + elif [ "$1" = "-h" ] || [ "$1" = "-H" ] || [ "$1" = "--help" ] || [ "$1" = "--HELP" ]; then + func_usage "${PRGNAME}" + exit 0 + + elif [ "$1" = "-c" ] || [ "$1" = "-C" ] || [ "$1" = "--clean" ] || [ "$1" = "--CLEAN" ]; then + if [ "${IS_CLEAN}" -ne 0 ]; then + PRNERR "Already --clean(-c) option is specified." + exit 1 + fi + IS_CLEAN=1 + + elif [ "$1" = "-b" ] || [ "$1" = "-B" ] || [ "$1" = "--buildnum" ] || [ "$1" = "--BUILDNUM" ]; then + if [ "${BUILD_NUMBER}" -ne 0 ]; then + PRNERR "Already --buildnum(-b) option is specified(${BUILD_NUMBER})." + exit 1 + fi + shift + if [ -z "$1" ]; then + PRNERR "--buildnum(-b) option need parameter." + exit 1 + fi + if echo "$1" | grep -q "[^0-9]"; then + PRNERR "--buildnum(-b) option parameter must be number(and not equal zero)." + exit 1 + fi + if [ "$1" -eq 0 ]; then + PRNERR "--buildnum(-b) option parameter must be number(and not equal zero)." + exit 1 + fi + BUILD_NUMBER="$1" + + elif [ "$1" = "-ccp" ] || [ "$1" = "-CCP" ] || [ "$1" = "--copy-common-package" ] || [ "$1" = "--COPY-COMMON-PACKAGE" ]; then + if [ "${IS_COPY_COMMON_PKGS}" -ne 0 ]; then + PRNERR "Already --copy-common-package(-ccp) option is specified." + exit 1 + fi + IS_COPY_COMMON_PKGS=1 + + elif [ "$1" = "-y" ] || [ "$1" = "-Y" ] || [ "$1" = "--yes" ] || [ "$1" = "--YES" ]; then + if [ "${NO_INTERACTIVE}" -ne 0 ]; then + PRNERR "Already --yes(-y) option is specified." + exit 1 + fi + NO_INTERACTIVE=1 + + else + PRNERR "Unknown option - $1." + exit 1 + fi + shift +done + +# +# Check parameters +# +if [ "${BUILD_NUMBER}" -eq 0 ]; then + BUILD_NUMBER=1 +fi + +#---------------------------------------------------------- +# Welcome message and confirming for interactive mode +#---------------------------------------------------------- +if [ "${NO_INTERACTIVE}" -eq 0 ] && [ "${IS_CLEAN}" -ne 1 ]; then + echo "---------------------------------------------------------------" + echo " Do you change these file and commit to github?" + echo " - ChangeLog modify / add changes like dch tool format" + echo " - Git TAG stamp git tag for release" + echo "---------------------------------------------------------------" + IS_CONFIRMED=0 + while [ "${IS_CONFIRMED}" -eq 0 ]; do + printf '[INPUT] Confirm (y/n) : ' + read -r CONFIRM + + if [ "${CONFIRM}" = "y" ] || [ "${CONFIRM}" = "Y" ] || [ "${CONFIRM}" = "yes" ] || [ "${CONFIRM}" = "YES" ]; then + IS_CONFIRMED=1 + elif [ "${CONFIRM}" = "n" ] || [ "${CONFIRM}" = "N" ] || [ "${CONFIRM}" = "no" ] || [ "${CONFIRM}" = "NO" ]; then + PRNINFO "Interrupt this processing, bye..." + exit 0 + fi + done + echo "" +fi + +#---------------------------------------------------------- +# Remove directory for clenup +#---------------------------------------------------------- +PRNTITLE "Remove old work directory for packaging" + +rm -rf "${BUILDDEBDIR}" +PRNSUCCESS "Removed ${BUILDDEBDIR}" + +# +# Clean mode -> finish +# +if [ "${IS_CLEAN}" -eq 1 ]; then + exit 0 +fi + +#---------------------------------------------------------- +# Start building +#---------------------------------------------------------- +cd "${SRCTOP}" || exit 1 + +#---------------------------------------------------------- +# Check untracked files +#---------------------------------------------------------- +PRNTITLE "Check untracked files" + +# [NOTE] +# When using actions/checkout@v1, suppress the following errors. +# "Error: fatal: unsafe repository ('...' is owned by someone else)" +# +git config --global --add safe.directory "${GITHUB_WORKSPACE}" + +if [ -n "$(git status --untracked-files=no --porcelain 2>&1)" ]; then + PRNWARN "Some files are in untracked state. Packages are created for testing, but must not be published." + PRNFAILURE "Check untracked files, but continue..." +else + PRNSUCCESS "No untracked files" +fi + +#---------------------------------------------------------- +# Run phpize and configure +#---------------------------------------------------------- +PRNTITLE "Run phpize" + +if ! phpize; then + PRNERR "Failed to run phpize." + exit 1 +fi +PRNSUCCESS "phpize done" + +PRNTITLE "Run configure" + +if ! ./configure; then + PRNERR "Failed to run configure." + exit 1 +fi +PRNSUCCESS "configure done" + +#---------------------------------------------------------- +# Create package top directory +#---------------------------------------------------------- +PRNTITLE "Create work directory for packaging" + +if ! mkdir "${BUILDDEBDIR}"; then + PRNERR "Could not create ${BUILDDEBDIR} dicretory." + exit 1 +fi + +PRNSUCCESS "Created ${BUILDDEBDIR}" + +#---------------------------------------------------------- +# Get package name and version/build number +#---------------------------------------------------------- +PRNTITLE "Get package information" + +PACKAGE_NAME=$(head -n 1 ./ChangeLog | awk '{print $1}' | tr -d '\n') +PACKAGE_VERSION=$(head -n 1 ./ChangeLog | sed -e 's/[(]//g' -e 's/[)]//g' | awk '{print $2}' | sed -e 's/-.*$//g' | tr -d '\n') +PACKAGE_PHPVERSION=$(php -r 'echo "".PHP_MAJOR_VERSION.".".PHP_MINOR_VERSION;') +PACKAGE_PHPVER_NAME=$(echo "${PACKAGE_NAME}" | sed -s "s/php/php${PACKAGE_PHPVERSION}/g") + +echo "-----------------------------------------------------------" +echo " Package name : ${PACKAGE_NAME} / ${PACKAGE_PHPVER_NAME}" +echo " Package version : ${PACKAGE_VERSION}" +echo " Build number : ${BUILD_NUMBER}" +echo " PHP version : ${PACKAGE_PHPVERSION}" +echo "-----------------------------------------------------------" +PRNSUCCESS "Got package information" + +EXPANDDIR="${BUILDDEBDIR}/${PACKAGE_NAME}-${PACKAGE_VERSION}" + +#---------------------------------------------------------- +# Make source tar.gz +#---------------------------------------------------------- +PRNTITLE "Create base tar ball of source files" + +if [ -d "${SRCTOP}/.git" ] && [ "$(git status -s 2>&1 | wc -l)" -eq 0 ]; then + # + # No untracked files, make source package(tar.gz) by git archive + # + if ! git archive HEAD --prefix="${PACKAGE_NAME}-${PACKAGE_VERSION}"/ --output="${BUILDDEBDIR}/${PACKAGE_NAME}_${PACKAGE_VERSION}".tar.gz; then + PRNERR "Could not make source tar ball(${BUILDDEBDIR}/${PACKAGE_NAME}-${PACKAGE_VERSION}.tar.gz) from github repository." + exit 1 + fi +else + # + # Found untracked files or Not have .git directory, source code package(tar.gz) like "make dist" and copy it + # + # [NOTICE] + # PHP Extension is built using "phpize(config.m4)". + # The "Makefile" created by "phpize" does not have "make dist", + # so the source code expanded by "Github Actions" is created in + # advance as "_allsource.tar.gz" with "phpext_helper.sh". + # Extract this "_allsource.tar.gz" and create a file + # similar to "make dist" here. + # + _SOURCECODE_DIRNAME=$(basename "${SRCTOP}") + _ALL_SOURCE_TARGZ_FILENAME="${_SOURCECODE_DIRNAME}_allsource.tar.gz" + + if [ ! -f "${SRCTOP}/${_ALL_SOURCE_TARGZ_FILENAME}" ]; then + PRNERR "Not found all source code tar.gz file(${SRCTOP}/${_ALL_SOURCE_TARGZ_FILENAME})." + exit 1 + fi + if ! tar xvfz "${SRCTOP}/${_ALL_SOURCE_TARGZ_FILENAME}" -C /tmp/ >/dev/null 2>&1; then + PRNERR "Failed to expand all source code tar.gz file(${SRCTOP}/${_ALL_SOURCE_TARGZ_FILENAME}) to /tmp." + exit 1 + fi + if [ ! -d /tmp/"${_SOURCECODE_DIRNAME}" ]; then + PRNERR "Not found expanded all source code directory(/tmp/${_SOURCECODE_DIRNAME}) from file(${SRCTOP}/${_ALL_SOURCE_TARGZ_FILENAME})." + exit 1 + fi + rm -rf /tmp/"${_SOURCECODE_DIRNAME}"/.git + + if ! mv /tmp/"${_SOURCECODE_DIRNAME}" /tmp/"${PACKAGE_NAME}-${PACKAGE_VERSION}"; then + PRNERR "Failed to rename from /tmp/${_SOURCECODE_DIRNAME} directory to /tmp/${PACKAGE_NAME}-${PACKAGE_VERSION}." + exit 1 + fi + if ! (cd /tmp || exit 1; tar cvfz "${BUILDDEBDIR}/${PACKAGE_NAME}_${PACKAGE_VERSION}".tar.gz "${PACKAGE_NAME}-${PACKAGE_VERSION}"); then + PRNERR "Failed to create ${BUILDDEBDIR}/${PACKAGE_NAME}_${PACKAGE_VERSION}.tar.gz." + exit 1 + fi + rm -rf /tmp/"${PACKAGE_NAME}-${PACKAGE_VERSION}" +fi + +PRNSUCCESS "Created ${BUILDDEBDIR}/${PACKAGE_NAME}_${PACKAGE_VERSION}.tar.gz" + +#---------------------------------------------------------- +# Expand tar ball +#---------------------------------------------------------- +PRNTITLE "Expand base tar ball in work directory" + +if ! tar xvfz "${BUILDDEBDIR}/${PACKAGE_NAME}_${PACKAGE_VERSION}".tar.gz -C "${BUILDDEBDIR}"/; then + PRNERR "Could not expand tar ball(${BUILDDEBDIR}/${PACKAGE_NAME}_${PACKAGE_VERSION}.tar.gz)." + exit 1 +fi +PRNSUCCESS "Expanded to ${EXPANDDIR}" + +#---------------------------------------------------------- +# Delete unnecessary files and directories +#---------------------------------------------------------- +PRNTITLE "Remove unnecessary files and directories" + +rm -rf "${EXPANDDIR}/.git" +rm -rf "${EXPANDDIR}/.github" +rm -rf "${EXPANDDIR}/buildutils" +rm -f "${EXPANDDIR}/.gitignore" +PRNSUCCESS "Removed .git .github, .gitignore, buildutils/" + +#---------------------------------------------------------- +# Setup debian directory +#---------------------------------------------------------- +PRNTITLE "Setup debian directories" + +if ! mkdir -p "${EXPANDDIR}/debian"; then + PRNERR "Could not create ${EXPANDDIR}/debian dicretory." + exit 1 +fi +if ! mkdir -p "${EXPANDDIR}/debian/source"; then + PRNERR "Could not create ${EXPANDDIR}/debian/source dicretory." + exit 1 +fi +if ! mkdir -p "${EXPANDDIR}/debian/upstream"; then + PRNERR "Could not create ${EXPANDDIR}/debian/upstream dicretory." + exit 1 +fi +PRNSUCCESS "Created ${EXPANDDIR}/debian" + +PRNTITLE "Copy files under debian directory" +# +# copy extra file from php_debian_build_copy.conf +# +# [NOTE] +# If you have files to copy under "/debian" directory +# (includes in your package), you can prepare "buildutils/php_debian_build_copy.conf" +# file and lists target files int it. +# The file names in this configuration file list with relative paths from the source +# top directory. +# ex) src/myfile +# lib/mylib +# +if [ -f "${EXTRA_COPY_FILES_CONF}" ]; then + EXTRA_COPY_FILES=$(sed -e 's/#.*$//g' -e 's/^[[:space:]]*//g' -e 's/[[:space:]]*$//g' -e '/^$/d' "${EXTRA_COPY_FILES_CONF}") + for _extra_file in ${EXTRA_COPY_FILES}; do + if [ ! -f "${SRCTOP}/${_extra_file}" ]; then + PRNERR "${SRCTOP}/${_extra_file} file is not found." + exit 1 + fi + if ! cp -p "${SRCTOP}/${_extra_file}" "${EXPANDDIR}/debian"; then + PRNERR "Could not copy ${SRCTOP}/${_extra_file} to ${EXPANDDIR}/debian dicretories." + exit 1 + fi + done + EXTRA_COPY_FILES=" , $(echo "${EXTRA_COPY_FILES}" | sed -e 's/[[:space:]]\+/, /g')" +else + EXTRA_COPY_FILES="" +fi + +# +# convert and copy changelog +# +if ! OS_VERSION_NAME=$(grep '^[[:space:]]*VERSION_CODENAME[[:space:]]*=' /etc/os-release | sed -e 's/^[[:space:]]*VERSION_CODENAME[[:space:]]*=//g' -e 's/^[[:space:]]*//g' -e 's/[[:space:]]*$//g' | tr -d '\n'); then + PRNERR "Could not get OS VERSION CODENAME from /etc/os-release." + exit 1 +fi +if [ -z "${OS_VERSION_NAME}" ]; then + PRNERR "Could not get OS VERSION CODENAME from /etc/os-release." + exit 1 +fi +if ! sed -e "s/[\(]${PACKAGE_VERSION}[\)]/\(${PACKAGE_VERSION}-${BUILD_NUMBER}\)/g" -e "s/[\)] unstable; /\) ${OS_VERSION_NAME}; /g" ChangeLog > "${EXPANDDIR}/debian/changelog"; then + PRNERR "Could not convert and copy ChangeLog to ${EXPANDDIR}/debian dicretories." + exit 1 +fi + +# +# create files under source directory +# +if ! printf '3.0 (quilt)\n' > "${EXPANDDIR}/debian/source/format"; then + PRNERR "Could not create ${EXPANDDIR}/debian/source/format file." + exit 1 +fi +if ! printf '#abort-on-upstream-changes\n#unapply-patches\n' > "${EXPANDDIR}/debian/source/local-options"; then + PRNERR "Could not create ${EXPANDDIR}/debian/source/local-options file." + exit 1 +fi + +# +# copy other files +# +if ! cp buildutils/copyright "${EXPANDDIR}/debian/copyright"; then + PRNERR "Could not copy buildutils/copyright to ${EXPANDDIR}/debian dicretories." + exit 1 +fi +if ! cp buildutils/rules "${EXPANDDIR}/debian/rules"; then + PRNERR "Could not copy buildutils/rules to ${EXPANDDIR}/debian dicretories." + exit 1 +fi +if ! cp buildutils/watch "${EXPANDDIR}/debian/watch"; then + PRNERR "Could not copy buildutils/watch to ${EXPANDDIR}/debian dicretories." + exit 1 +fi +if ! cp buildutils/control.in "${EXPANDDIR}/debian/control.in"; then + PRNERR "Could not copy buildutils/control.in to ${EXPANDDIR}/debian dicretories." + exit 1 +fi +if ! cp buildutils/upstream/metadata "${EXPANDDIR}/debian/upstream/metadata"; then + PRNERR "Could not copy buildutils/upstream/metadata to ${EXPANDDIR}/debian dicretories." + exit 1 +fi + +PRNSUCCESS "Copied/Created changelog, copyright, rules, watch, control.in${EXTRA_COPY_FILES}, source/format, source/local-options, upstream/metadata" + +# [NOTE] +# The "control" file is created from "control.in", but when we run "dpkg-buildpackage", +# we need this file first. +# Thus, before running "dpkg-buildpackage", we need to prepare the "control" file. +# (But after running dpkg-buildpackage, the control file will be updated again) +# +PRNTITLE "Pre-run gen-control" + +cd "${EXPANDDIR}" || exit 1 +if ! /usr/share/dh-php/gen-control; then + PRNERR "Failed to run gen-control for initializing control file." + exit 1 +fi + +# [NOTICE] +# gen-control extracts the package of "Package: php-pecl-k2hash" part as a "dummy" +# package and as an "*-all-dev" package. +# And this tool is also called by dpkg-buildpackage. +# +# On debian(11), dh-php(5.2+0~20230112.20+debian11~1.gbp19bbdb)/gen-control adds +# unnecessary comments to control file. +# -------------------------------- +# +# . +# This is empty package that depends on default(all) PHP version. +# -------------------------------- +# Also, the above postscript may be added after a line feed, so be careful about +# the description in the control.in.in file. If added after a newline, the package +# build will fail. +# Write the package part of "Package: php-pecl-*****" at the end of the file. +# And don't put a newline on the last line. +# If you get an error near this part of this script, check the above statement first. + +PRNSUCCESS "Generated ${EXPANDDIR}/debian/control" + +#---------------------------------------------------------- +# Create "orig" tar ball +#---------------------------------------------------------- +PRNTITLE "Create tar ball of original source file" + +cd "${BUILDDEBDIR}" || exit 1 +if ! tar cvfz "${PACKAGE_NAME}_${PACKAGE_VERSION}.orig.tar.gz" "${PACKAGE_NAME}-${PACKAGE_VERSION}"; then + PRNERR "Failed to craete original source tar ball(${BUILDDEBDIR}/${PACKAGE_NAME}_${PACKAGE_VERSION}.orig.tar.gz)." + exit 1 +fi +PRNSUCCESS "Created ${BUILDDEBDIR}/${PACKAGE_NAME}_${PACKAGE_VERSION}.orig.tar.gz" + +#---------------------------------------------------------- +# Build packages +#---------------------------------------------------------- +PRNTITLE "Run dpkg-buildpackage for creating packages" + +cd "${EXPANDDIR}" || exit 1 +if ! dpkg-buildpackage -us -uc; then + PRNERR "Failed to create packages." + exit 1 +fi +PRNSUCCESS "Created package files" + +#---------------------------------------------------------- +# Check packages +#---------------------------------------------------------- +PRNTITLE "Check created debian packages" + +cd "${SRCTOP}" || exit 1 + +# +# Check and show debian package +# +# [NOTE] Check following files: +# ${PACKAGE_PHPVER_NAME}_${PACKAGE_VERSION}-${BUILD_NUMBER}_*.deb +# ${PACKAGE_NAME}_${PACKAGE_VERSION}-${BUILD_NUMBER}_*.deb +# ${PACKAGE_NAME}-all-dev_${PACKAGE_VERSION}-${BUILD_NUMBER}_all.deb +# +DEBIAN_PACKAGE_PHP=$(find "${BUILDDEBDIR}" -name "${PACKAGE_PHPVER_NAME}_${PACKAGE_VERSION}-${BUILD_NUMBER}_*.deb" 2>/dev/null) +DEBIAN_PACKAGE_NORM=$(find "${BUILDDEBDIR}" -name "${PACKAGE_NAME}_${PACKAGE_VERSION}-${BUILD_NUMBER}_*.deb" 2>/dev/null) +DEBIAN_PACKAGE_ALL=$(find "${BUILDDEBDIR}" -name "${PACKAGE_NAME}-all-dev_${PACKAGE_VERSION}-${BUILD_NUMBER}_all.deb" 2>/dev/null) + +FOUND_DEB_PACKAGES="${DEBIAN_PACKAGE_PHP} ${DEBIAN_PACKAGE_NORM} ${DEBIAN_PACKAGE_ALL}" + +if [ -z "${DEBIAN_PACKAGE_PHP}" ] || [ -z "${DEBIAN_PACKAGE_NORM}" ] || [ -z "${DEBIAN_PACKAGE_ALL}" ]; then + PRNERR "No debian package in ${BUILDDEBDIR}." + exit 1 +fi +if [ "$(echo "${FOUND_DEB_PACKAGES}" | sed -e 's/[[:space:]]/\n/g'| grep -c '\.deb')" -ne 3 ]; then + PRNERR "There are too or few created debian packages(*.deb) : ${FOUND_DEB_PACKAGES}" + exit 1 +fi + +for _one_pkg in ${FOUND_DEB_PACKAGES}; do + echo "" + echo "[INFO] ${_one_pkg} package information" + if ({ dpkg -c "${_one_pkg}" || echo > "${PIPEFAILURE_FILE}"; } | sed -e 's/^/ /') && rm "${PIPEFAILURE_FILE}" >/dev/null 2>&1; then + PRNERR "Failed to print ${_one_pkg} package insformation by \"dpkg -c\"." + exit 1 + fi + echo " ---------------------------" + + if ({ dpkg -I "${_one_pkg}" || echo > "${PIPEFAILURE_FILE}"; } | sed -e 's/^/ /') && rm "${PIPEFAILURE_FILE}" >/dev/null 2>&1; then + PRNERR "Failed to print ${_one_pkg} package insformation by \"dpkg -I\"." + exit 1 + fi +done + +PRNSUCCESS "Checked package files" + +#---------------------------------------------------------- +# Copy packages +#---------------------------------------------------------- +if [ ! -d "${DEBPKGDIR}" ]; then + PRNTITLE "Create ${DEBPKGDIR} directory" + + if ! mkdir -p "${DEBPKGDIR}"; then + PRNERR "Failed to create ${DEBPKGDIR} directory" + exit 1 + fi + PRNSUCCESS "Created ${DEBPKGDIR} directory" +fi + +PRNTITLE "Copy created debian packages to packages directory" + +if ! cp -p "${DEBIAN_PACKAGE_PHP}" "${DEBPKGDIR}"; then + PRNERR "Failed to copy ${DEBIAN_PACKAGE_PHP} packages to ${DEBPKGDIR}" + exit 1 +fi +echo "Copied ${DEBIAN_PACKAGE_PHP} package." + +if [ "${IS_COPY_COMMON_PKGS}" -eq 1 ]; then + if ! cp -p "${DEBIAN_PACKAGE_NORM}" "${DEBPKGDIR}"; then + PRNERR "Failed to copy ${DEBIAN_PACKAGE_NORM} packages to ${DEBPKGDIR}" + exit 1 + fi + echo "Copied ${DEBIAN_PACKAGE_NORM} package." +else + echo "Skip copying ${DEBIAN_PACKAGE_NORM} package." +fi + +if [ "${IS_COPY_COMMON_PKGS}" -eq 1 ]; then + if ! cp -p "${DEBIAN_PACKAGE_ALL}" "${DEBPKGDIR}"; then + PRNERR "Failed to copy ${DEBIAN_PACKAGE_ALL} packages to ${DEBPKGDIR}" + exit 1 + fi + PRNINFO "Copied ${DEBIAN_PACKAGE_ALL} package." +else + PRNINFO "Skip copying ${DEBIAN_PACKAGE_ALL} package." +fi +PRNSUCCESS "Copied debian packages to ${DEBPKGDIR}" + +#---------------------------------------------------------- +# finish +#---------------------------------------------------------- +PRNTITLE "Install Summary" + +PRNSUCCESS "All processing is succeed" +echo "[SUCCEED] You can find ${PACKAGE_NAME} ${PACKAGE_VERSION}-${BUILD_NUMBER} version debian package in ${DEBPKGDIR} directory." +echo "" + +exit 0 + +# +# Local variables: +# tab-width: 4 +# c-basic-offset: 4 +# End: +# vim600: noexpandtab sw=4 ts=4 fdm=marker +# vim<600: noexpandtab sw=4 ts=4 +# diff --git a/buildutils/php_debian_build_copy.conf b/buildutils/php_debian_build_copy.conf new file mode 100644 index 0000000..b029b54 --- /dev/null +++ b/buildutils/php_debian_build_copy.conf @@ -0,0 +1,36 @@ +# +# K2HDKC PHP Extension library +# +# Copyright 2023 Yahoo Japan Corporation. +# +# K2HDKC is k2hash based distributed KVS cluster. +# K2HDKC uses K2HASH, CHMPX, FULLOCK libraries. K2HDKC supports +# distributed KVS cluster server program and client libraries. +# +# For the full copyright and license information, please view +# the license file that was distributed with this source code. +# +# AUTHOR: Hirotaka Wakabayashi +# CREATE: Tue, Feb 22 2022 +# REVISION: +# + +# [NOTE] +# This file will be found by "php_debian_build.sh" when building +# a debian package. This file lists special files to copy to +# the "/debian" directory that +# cannot be specified in normal packaging. The file is specified +# with a relative path from the source top directory. +# + +buildutils/k2hdkcpx.ini +buildutils/php-pecl-k2hdkc.php + +# +# Local variables: +# tab-width: 4 +# c-basic-offset: 4 +# End: +# vim600: noexpandtab sw=4 ts=4 fdm=marker +# vim<600: noexpandtab sw=4 ts=4 +# diff --git a/buildutils/php_rpm_build.sh b/buildutils/php_rpm_build.sh new file mode 100755 index 0000000..c14a56a --- /dev/null +++ b/buildutils/php_rpm_build.sh @@ -0,0 +1,485 @@ +#!/bin/sh +# +# Utility tools for building PHP packages by AntPickax +# +# Copyright 2022 Yahoo Japan Corporation. +# +# AntPickax provides utility tools for supporting autotools +# builds. +# +# These tools retrieve the necessary information from the +# repository and appropriately set the setting values of +# configure, Makefile, spec,etc file and so on. +# These tools were recreated to reduce the number of fixes and +# reduce the workload of developers when there is a change in +# the project configuration. +# +# For the full copyright and license information, please view +# the license file that was distributed with this source code. +# +# AUTHOR: Takeshi Nakatani +# CREATE: Fri, Feb 18 2022 +# REVISION: 1.1 +# + +#============================================================== +# Autobuild for PHP rpm package +#============================================================== +# +# Instead of pipefail(for shells not support "set -o pipefail") +# +#PIPEFAILURE_FILE="/tmp/.pipefailure.$(od -An -tu4 -N4 /dev/random | tr -d ' \n')" + +# +# For shellcheck +# +if command -v locale >/dev/null 2>&1; then + if locale -a | grep -q -i '^[[:space:]]*C.utf8[[:space:]]*$'; then + LANG=$(locale -a | grep -i '^[[:space:]]*C.utf8[[:space:]]*$' | sed -e 's/^[[:space:]]*//g' -e 's/[[:space:]]*$//g' | tr -d '\n') + LC_ALL="${LANG}" + export LANG + export LC_ALL + elif locale -a | grep -q -i '^[[:space:]]*en_US.utf8[[:space:]]*$'; then + LANG=$(locale -a | grep -i '^[[:space:]]*en_US.utf8[[:space:]]*$' | sed -e 's/^[[:space:]]*//g' -e 's/[[:space:]]*$//g' | tr -d '\n') + LC_ALL="${LANG}" + export LANG + export LC_ALL + fi +fi + +#---------------------------------------------------------- +# Common variables +#---------------------------------------------------------- +PRGNAME=$(basename "$0") +SCRIPTDIR=$(dirname "$0") +SCRIPTDIR=$(cd "${SCRIPTDIR}" || exit 1; pwd) +SRCTOP=$(cd "${SCRIPTDIR}"/.. || exit 1; pwd) + +RPM_TOPDIR="${SRCTOP}/rpmbuild" +PKG_TOPDIR="${SRCTOP}/packages" + +# +# Message variables +# +IN_GHAGROUP_AREA=0 + +# +# Variables +# +BUILD_NUMBER=0 +IS_CLEAN=0 +NO_INTERACTIVE=0 + +#---------------------------------------------------------- +# Utility: Usage +#---------------------------------------------------------- +func_usage() +{ + echo "" + echo "Usage: $1 [--help(-h)] [--clean(-c)] [--buildnum(-b) ] [--yes(-y)]" + echo " --help(-h) print help" + echo " --clean(-c) only clean work directory." + echo " --buildnum(-b) specify build number for packaging(default 1)" + echo " --yes(-y) runs no interactive mode." + echo "" +} + +#---------------------------------------------------------- +# Utilities for message +#---------------------------------------------------------- +if [ -t 1 ] || { [ -n "${CI}" ] && [ "${CI}" = "true" ]; }; then + CBLD=$(printf '\033[1m') + CREV=$(printf '\033[7m') + CRED=$(printf '\033[31m') + CYEL=$(printf '\033[33m') + CGRN=$(printf '\033[32m') + CDEF=$(printf '\033[0m') +else + CBLD="" + CREV="" + CRED="" + CYEL="" + CGRN="" + CDEF="" +fi +if [ -n "${CI}" ] && [ "${CI}" = "true" ] && [ -z "${RUN_AS_SUBPROCESS}" ]; then + GHAGRP_START="::group::" + GHAGRP_END="::endgroup::" +else + GHAGRP_START="" + GHAGRP_END="" +fi + +PRNGROUPEND() +{ + if [ -n "${IN_GHAGROUP_AREA}" ] && [ "${IN_GHAGROUP_AREA}" -eq 1 ]; then + if [ -n "${GHAGRP_END}" ]; then + echo "${GHAGRP_END}" + fi + fi + IN_GHAGROUP_AREA=0 +} +PRNTITLE() +{ + PRNGROUPEND + echo "${GHAGRP_START}${CBLD}${CGRN}${CREV}[TITLE]${CDEF} ${CGRN}$*${CDEF}" + IN_GHAGROUP_AREA=1 +} +PRNINFO() +{ + echo "${CBLD}${CREV}[INFO]${CDEF} $*" +} +PRNWARN() +{ + echo "${CBLD}${CYEL}${CREV}[WARNING]${CDEF} ${CYEL}$*${CDEF}" +} +PRNERR() +{ + echo "${CBLD}${CRED}${CREV}[ERROR]${CDEF} ${CRED}$*${CDEF}" + PRNGROUPEND +} +PRNSUCCESS() +{ + echo "${CBLD}${CGRN}${CREV}[SUCCEED]${CDEF} ${CGRN}$*${CDEF}" + PRNGROUPEND +} +PRNFAILURE() +{ + echo "${CBLD}${CRED}${CREV}[FAILURE]${CDEF} ${CRED}$*${CDEF}" + PRNGROUPEND +} + +#---------------------------------------------------------- +# Parse options +#---------------------------------------------------------- +while [ $# -ne 0 ]; do + if [ -z "$1" ]; then + break + + elif [ "$1" = "-h" ] || [ "$1" = "-H" ] || [ "$1" = "--help" ] || [ "$1" = "--HELP" ]; then + func_usage "${PRGNAME}" + exit 0 + + elif [ "$1" = "-c" ] || [ "$1" = "-C" ] || [ "$1" = "--clean" ] || [ "$1" = "--CLEAN" ]; then + if [ "${IS_CLEAN}" -ne 0 ]; then + PRNERR "Already --clean(-c) option is specified." + exit 1 + fi + IS_CLEAN=1 + + elif [ "$1" = "-b" ] || [ "$1" = "-B" ] || [ "$1" = "--buildnum" ] || [ "$1" = "--BUILDNUM" ]; then + if [ "${BUILD_NUMBER}" -ne 0 ]; then + PRNERR "Already --buildnum(-b) option is specified(${BUILD_NUMBER})." + exit 1 + fi + shift + if [ -z "$1" ]; then + PRNERR "--buildnum(-b) option need parameter." + exit 1 + fi + if echo "$1" | grep -q "[^0-9]"; then + PRNERR "--buildnum(-b) option parameter must be number(and not equal zero)." + exit 1 + fi + if [ "$1" -eq 0 ]; then + PRNERR "--buildnum(-b) option parameter must be number(and not equal zero)." + exit 1 + fi + BUILD_NUMBER="$1" + + elif [ "$1" = "-y" ] || [ "$1" = "-Y" ] || [ "$1" = "--yes" ] || [ "$1" = "--YES" ]; then + if [ "${NO_INTERACTIVE}" -ne 0 ]; then + PRNERR "Already --yes(-y) option is specified." + exit 1 + fi + NO_INTERACTIVE=1 + + else + PRNERR "Unknown option $1." + exit 1 + fi + shift +done + +# +# Check parameters +# +if [ "${BUILD_NUMBER}" -eq 0 ]; then + BUILD_NUMBER=1 +fi + +#---------------------------------------------------------- +# Welcome message and confirming for interactive mode +#---------------------------------------------------------- +if [ "${NO_INTERACTIVE}" -eq 0 ] && [ "${IS_CLEAN}" -ne 1 ]; then + echo "---------------------------------------------------------------" + echo " Do you change these file and commit to github?" + echo " - ChangeLog modify / add changes like dch tool format" + echo " - Git TAG stamp git tag for release" + echo "---------------------------------------------------------------" + IS_CONFIRMED=0 + while [ "${IS_CONFIRMED}" -eq 0 ]; do + printf '[INPUT] Confirm (y/n) : ' + read -r CONFIRM + + if [ "${CONFIRM}" = "y" ] || [ "${CONFIRM}" = "Y" ] || [ "${CONFIRM}" = "yes" ] || [ "${CONFIRM}" = "YES" ]; then + IS_CONFIRMED=1 + elif [ "${CONFIRM}" = "n" ] || [ "${CONFIRM}" = "N" ] || [ "${CONFIRM}" = "no" ] || [ "${CONFIRM}" = "NO" ]; then + PRNINFO "Interrupt this processing, bye..." + exit 0 + fi + done + echo "" +fi + +#---------------------------------------------------------- +# Remove directory for clenup +#---------------------------------------------------------- +PRNTITLE "Remove old work directory for packaging" + +rm -rf "${RPM_TOPDIR}" +PRNSUCCESS "Removed ${RPM_TOPDIR}" + +# +# Clean mode -> finish +# +if [ "${IS_CLEAN}" -eq 1 ]; then + exit 0 +fi + +#---------------------------------------------------------- +# Start building +#---------------------------------------------------------- +cd "${SRCTOP}" || exit 1 + +#---------------------------------------------------------- +# Check ~/.rpmmacros file +#---------------------------------------------------------- +PRNTITLE "Check ~/.rpmmacros file" + +if [ -f "${HOME}/.rpmmacros" ]; then + PRNERR "Found \"${HOME}/.rpmmacros\" file." + echo " Checking with \"check-rpaths\" may result in an error due to the existence" + echo " of the \"${HOME}/.rpmmacros\" file." + echo " If you get that error, delete the \"${HOME}/.rpmmacros\" file" + echo " and try again." + echo "" + exit 1 +fi +PRNSUCCESS "${HOME}/.rpmmacros file does not exist." + +#---------------------------------------------------------- +# Check untracked files +#---------------------------------------------------------- +PRNTITLE "Check untracked files" + +# [NOTE] +# When using actions/checkout@v1, suppress the following errors. +# "Error: fatal: unsafe repository ('...' is owned by someone else)" +# +git config --global --add safe.directory "${GITHUB_WORKSPACE}" + +if [ -n "$(git status --untracked-files=no --porcelain 2>&1)" ]; then + PRNWARN "Some files are in untracked state. Packages are created for testing, but must not be published." + PRNFAILURE "Check untracked files, but continue..." +else + PRNSUCCESS "No untracked files" +fi + +#---------------------------------------------------------- +# Run phpize and configure +#---------------------------------------------------------- +PRNTITLE "Run phpize" + +if ! phpize; then + PRNERR "Failed to run phpize." + exit 1 +fi +PRNSUCCESS "phpize done" + +PRNTITLE "Run configure" + +if ! ./configure; then + PRNERR "Failed to run configure." + exit 1 +fi +PRNSUCCESS "configure done" + +#---------------------------------------------------------- +# Create package top directories +#---------------------------------------------------------- +PRNTITLE "Create work directories for packaging" + +_SUB_RPM_DIRS="BUILD BUILDROOT RPM SOURCES SPECS SRPMS" +for _SUB_RPM_DIR in ${_SUB_RPM_DIRS}; do + if ! mkdir -p "${RPM_TOPDIR}/${_SUB_RPM_DIR}"; then + PRNERR "Could not create ${RPM_TOPDIR}/${_SUB_RPM_DIR} directory." + exit 1 + fi +done + +PRNSUCCESS "Created ${RPM_TOPDIR}" + +#---------------------------------------------------------- +# Get package name and version/build number +#---------------------------------------------------------- +PRNTITLE "Get package information" + +PACKAGE_NAME=$(head -n 1 ./ChangeLog | awk '{print $1}' | tr -d '\n') +PACKAGE_VERSION=$(head -n 1 ./ChangeLog | sed -e 's/[(]//g' -e 's/[)]//g' | awk '{print $2}' | sed -e 's/-.*$//g' | tr -d '\n') + +echo "-----------------------------------------------------------" +echo " Package name : ${PACKAGE_NAME}" +echo " Package version : ${PACKAGE_VERSION}" +echo " Build number : ${BUILD_NUMBER}" +echo "-----------------------------------------------------------" +PRNSUCCESS "Got package information" + +#---------------------------------------------------------- +# Make source tar.gz +#---------------------------------------------------------- +PRNTITLE "Create base tar ball of source files" + +if [ -d "${SRCTOP}/.git" ] && [ "$(git status -s 2>&1 | wc -l)" -eq 0 ]; then + # + # No untracked files, make source package(tar.gz) by git archive + # + if ! git archive HEAD --prefix="${PACKAGE_NAME}-${PACKAGE_VERSION}"/ --output="${RPM_TOPDIR}/SOURCES/${PACKAGE_NAME}-${PACKAGE_VERSION}".tar.gz; then + PRNERR "Could not make source tar ball(${RPM_TOPDIR}/SOURCES/${PACKAGE_NAME}-${PACKAGE_VERSION}.tar.gz) from github repository." + exit 1 + fi +else + # + # Found untracked files or Not have .git directory, source code package(tar.gz) like "make dist" and copy it + # + # [NOTICE] + # PHP Extension is built using "phpize(config.m4)". + # The "Makefile" created by "phpize" does not have "make dist", + # so the source code expanded by "Github Actions" is created in + # advance as "_allsource.tar.gz" with "phpext_helper.sh". + # Extract this "_allsource.tar.gz" and create a file + # similar to "make dist" here. + # + _SOURCECODE_DIRNAME=$(basename "${SRCTOP}") + _ALL_SOURCE_TARGZ_FILENAME="${_SOURCECODE_DIRNAME}_allsource.tar.gz" + + if [ ! -f "${SRCTOP}/${_ALL_SOURCE_TARGZ_FILENAME}" ]; then + PRNERR "Not found all source code tar.gz file(${SRCTOP}/${_ALL_SOURCE_TARGZ_FILENAME})." + exit 1 + fi + if ! tar xvfz "${SRCTOP}/${_ALL_SOURCE_TARGZ_FILENAME}" -C /tmp/ >/dev/null 2>&1; then + PRNERR "Failed to expand all source code tar.gz file(${SRCTOP}/${_ALL_SOURCE_TARGZ_FILENAME}) to /tmp." + exit 1 + fi + if [ ! -d /tmp/"${_SOURCECODE_DIRNAME}" ]; then + PRNERR "Not found expanded all source code directory(/tmp/${_SOURCECODE_DIRNAME}) from file(${SRCTOP}/${_ALL_SOURCE_TARGZ_FILENAME})." + exit 1 + fi + rm -rf /tmp/"${_SOURCECODE_DIRNAME}"/.git + + if ! mv /tmp/"${_SOURCECODE_DIRNAME}" /tmp/"${PACKAGE_NAME}-${PACKAGE_VERSION}"; then + PRNERR "Failed to rename from /tmp/${_SOURCECODE_DIRNAME} directory to /tmp/${PACKAGE_NAME}-${PACKAGE_VERSION}." + exit 1 + fi + if ! (cd /tmp || exit 1; tar cvfz "${RPM_TOPDIR}/SOURCES/${PACKAGE_NAME}-${PACKAGE_VERSION}".tar.gz "${PACKAGE_NAME}-${PACKAGE_VERSION}"); then + PRNERR "Failed to create ${RPM_TOPDIR}/SOURCES/${PACKAGE_NAME}-${PACKAGE_VERSION}.tar.gz." + exit 1 + fi + rm -rf /tmp/"${PACKAGE_NAME}-${PACKAGE_VERSION}" +fi + +PRNSUCCESS "Created ${RPM_TOPDIR}/SOURCES/${PACKAGE_NAME}-${PACKAGE_VERSION}.tar.gz" + +#---------------------------------------------------------- +# Copy spec file +#---------------------------------------------------------- +PRNTITLE "Copy spec file to ${SRCTOP}" + +if ! cp "${SRCTOP}"/buildutils/*.spec "${SRCTOP}"/; then + PRNERR "Could not find and feiled to copy spec files." + exit 1 +fi +PRNSUCCESS "Copied spec file to ${SRCTOP}" + +#---------------------------------------------------------- +# Run rpmbuild +#---------------------------------------------------------- +PRNTITLE "Run rpmbuild" + +if ! rpmbuild -vv -ba --define "_topdir ${RPM_TOPDIR}" --define "_prefix /usr" --define "_mandir /usr/share/man" --define "_defaultdocdir /usr/share/doc" --define "package_revision ${BUILD_NUMBER}" ./*.spec; then + PRNERR "Failed to build rpm packages by rpmbuild." + exit 1 +fi +PRNSUCCESS "rpmbuild done" + +#---------------------------------------------------------- +# Check packages +#---------------------------------------------------------- +PRNTITLE "Check created RPM packages" + +echo "" +# shellcheck disable=SC2012 +ls -la "${RPM_TOPDIR}"/RPMS/*/*.rpm "${RPM_TOPDIR}"/SRPMS/*.rpm | sed -e 's/^/ /g' +echo "" + +# shellcheck disable=SC2012 +_rpm_package_count="$(ls -1 "${RPM_TOPDIR}"/RPMS/*/*.rpm "${RPM_TOPDIR}"/SRPMS/*.rpm 2>/dev/null | wc -l)" +if [ "${_rpm_package_count}" -ne 3 ] && [ "${_rpm_package_count}" -ne 4 ]; then + PRNERR "There are too or few created RPM packages(*.rpm)." + exit 1 +fi + +for _rpm_file in "${RPM_TOPDIR}"/RPMS/*/*.rpm "${RPM_TOPDIR}"/SRPMS/*.rpm; do + if test ! -e "${_rpm_file}"; then + continue + fi + echo "-----------------------------------------------------------" + echo "Package: ${_rpm_file}" + echo "-----------------------------------------------------------" + rpm -qpl "${_rpm_file}" | sed -e 's/^/ /g' + echo "" + rpm -qpi "${_rpm_file}" | sed -e 's/^/ /g' + echo "" +done + +PRNSUCCESS "Checked package files" + +#---------------------------------------------------------- +# Copy packages +#---------------------------------------------------------- +if [ ! -d "${PKG_TOPDIR}" ]; then + PRNTITLE "Create ${PKG_TOPDIR} directory" + if ! mkdir -p "${PKG_TOPDIR}"; then + PRNERR "Failed to create ${PKG_TOPDIR} directory" + exit 1 + fi + PRNSUCCESS "Created ${PKG_TOPDIR} directory" +fi + +PRNTITLE "Copy created RPM packages to packages directory" + +if ! cp -p "${RPM_TOPDIR}"/RPMS/*/*.rpm "${RPM_TOPDIR}"/SRPMS/*.rpm "${PKG_TOPDIR}"; then + PRNERR "Failed to copy packages to ${PKG_TOPDIR}" + exit 1 +fi +PRNSUCCESS "Copied RPM packages to ${PKG_TOPDIR}" + +#---------------------------------------------------------- +# finish +#---------------------------------------------------------- +PRNTITLE "Install Summary" + +PRNSUCCESS "All processing is succeed" +echo "[SUCCEED] You can find ${PACKAGE_NAME} ${PACKAGE_VERSION}-${BUILD_NUMBER} version rpm package in ${PKG_TOPDIR} directory." +echo "" + +exit 0 + +# +# Local variables: +# tab-width: 4 +# c-basic-offset: 4 +# End: +# vim600: noexpandtab sw=4 ts=4 fdm=marker +# vim<600: noexpandtab sw=4 ts=4 +# diff --git a/buildutils/rules.in b/buildutils/rules.in new file mode 100644 index 0000000..6a2dad6 --- /dev/null +++ b/buildutils/rules.in @@ -0,0 +1,57 @@ +#!/usr/bin/make -f +# +# K2HDKC PHP Extension library +# +# Copyright 2023 Yahoo Japan Corporation. +# +# K2HDKC is k2hash based distributed KVS cluster. +# K2HDKC uses K2HASH, CHMPX, FULLOCK libraries. K2HDKC supports +# distributed KVS cluster server program and client libraries. +# +# For the full copyright and license information, please view +# the license file that was distributed with this source code. +# +# AUTHOR: Hirotaka Wakabayashi +# CREATE: Tue, Feb 22 2022 +# REVISION: +# + +export REPORT_EXIT_STATUS:=0 +PECL_NAME_OVERRIDE := @PHP_PECL_BASE_NAME@ +PECL_CONFIGURE_MAINT_APPEND := --enable-@PHP_SO_NAME@ +DH_PHP_VERSIONS_OVERRIDE := @K2HDKCPX_PHP_VERSION@ +include /usr/share/dh-php/pkg-pecl.mk + +DIR_TARGETS = $(addprefix build-,$(DH_PHP_VERSIONS)) + +$(warning CONFIGURE_TARGETS: $(CONFIGURE_TARGETS)) +$(warning BUILD_TARGETS: $(BUILD_TARGETS)) +$(warning INSTALL_TARGETS: $(INSTALL_TARGETS)) + +PECL_SOURCE=$(filter-out debian $(DIR_TARGETS),$(wildcard *)) +$(foreach ver,$(DH_PHP_VERSIONS),$(eval PECL_SOURCE_$(ver) := $(PECL_SOURCE))) +$(foreach ver,$(DH_PHP_VERSIONS),$(mkdir build-$(ver))) + +override_dh_testdir: $(DIR_TARGETS) + dh_testdir + +build-%: + mkdir -p build-$(*) + +# [NOTE] +# The "control" file will be created without the following call, +# but it will output "php-pecl-" instead of "php<8.1>-pecl-" +# and the build will fail. +# To avoid this, make the following call. +# +debian/control: debian/control.in + /usr/share/dh-php/gen-control + +# +# Local variables: +# tab-width: 4 +# c-basic-offset: 4 +# End: +# vim600: noexpandtab sw=4 ts=4 fdm=marker +# vim<600: noexpandtab sw=4 ts=4 +# diff --git a/buildutils/upstream/metadata.in b/buildutils/upstream/metadata.in new file mode 100644 index 0000000..48fe725 --- /dev/null +++ b/buildutils/upstream/metadata.in @@ -0,0 +1,7 @@ +Bug-Database: https://@GIT_DOMAIN@/@GIT_ORG@/@GIT_REPO@/issues +Bug-Submit: https://@GIT_DOMAIN@/@GIT_ORG@/@GIT_REPO@/issues/new +Changelog: https://@GIT_DOMAIN@/@GIT_ORG@/@GIT_REPO@/blob/master/ChangeLog +Documentation: @HOME_PAGE@ +Other-References: https://@GIT_DOMAIN@/@GIT_ORG@/@GIT_REPO@/wiki +Repository-Browse: https://@GIT_DOMAIN@/@GIT_ORG@/@GIT_REPO@ +Repository: https://@GIT_DOMAIN@/@GIT_ORG@/@GIT_REPO@.git diff --git a/buildutils/watch.in b/buildutils/watch.in new file mode 100644 index 0000000..1cb9e3b --- /dev/null +++ b/buildutils/watch.in @@ -0,0 +1,3 @@ +version=4 +opts=filenamemangle=s/.+\/v?(\d\S*)\.tar\.gz/@GIT_REPO@-$1\.tar\.gz/ \ + https://@GIT_DOMAIN@/@GIT_ORG@/@GIT_REPO@/tags .*/v?(\d\S*)\.tar\.gz diff --git a/config.m4 b/config.m4 new file mode 100644 index 0000000..e74227e --- /dev/null +++ b/config.m4 @@ -0,0 +1,175 @@ +# +# K2HDKC PHP Extension library +# +# Copyright 2023 Yahoo Japan Corporation. +# +# K2HDKC is k2hash based distributed KVS cluster. +# K2HDKC uses K2HASH, CHMPX, FULLOCK libraries. K2HDKC supports +# distributed KVS cluster server program and client libraries. +# +# For the full copyright and license information, please view +# the license file that was distributed with this source code. +# +# AUTHOR: Hirotaka Wakabayashi +# CREATE: Tue, Feb 22 2022 +# REVISION: +# + +# +# Set k2hdkc php extension name +# +AC_SUBST([PHP_SO_NAME], "k2hdkcpx") +AC_SUBST([PHP_PECL_BASE_NAME], "pecl-k2hdkc") + +# +# Load customizable variables +# +AC_CHECK_FILE([configure.custom], + [ + configure_custom_file="configure.custom" + custom_git_domain="$(grep '^\s*GIT_DOMAIN\s*=' configure.custom | sed -e 's|^\s*GIT_DOMAIN\s*=\s*||g' -e 's|^\s*||g' -e 's|\s*$||g')" + custom_git_org="$(grep '^\s*GIT_ORG\s*=' configure.custom | sed -e 's|^\s*GIT_ORG\s*=\s*||g' -e 's|^\s*||g' -e 's|\s*$||g')" + custom_git_repo="$(grep '^\s*GIT_REPO\s*=' configure.custom | sed -e 's|^\s*GIT_REPO\s*=\s*||g' -e 's|^\s*||g' -e 's|\s*$||g')" + custom_dev_email="$(grep '^\s*DEV_EMAIL\s*=' configure.custom | sed -e 's|^\s*DEV_EMAIL\s*=\s*||g' -e 's|^\s*||g' -e 's|\s*$||g')" + custom_dev_name="$(grep '^\s*DEB_NAME\s*=' configure.custom | sed -e 's|^\s*DEB_NAME\s*=\s*||g' -e 's|^\s*||g' -e 's|\s*$||g')" + ], + [ + configure_custom_file="" + custom_git_domain="github.com" + custom_git_org="yahoojapan" + custom_git_repo="k2hdkc_phpext" + custom_dev_email="antpickax-support@mail.yahoo.co.jp" + custom_dev_name="K2HASH_DEVELOPER" + ] +) + +# +# Common variables +# +AC_SUBST([CONFIGURECUSTOM], "${configure_custom_file}") +AC_SUBST([GIT_DOMAIN], "${custom_git_domain}") +AC_SUBST([GIT_ORG], "${custom_git_org}") +AC_SUBST([GIT_REPO], "${custom_git_repo}") +AC_SUBST([DEV_EMAIL], "$(echo ${DEBEMAIL:-"${custom_dev_email}"})") +AC_SUBST([DEV_NAME], "$(echo ${DEBFULLNAME:-"${custom_dev_name}"})") + +AC_SUBST([HOME_PAGE], "https://php.k2hdkc.antpick.ax/") +AC_SUBST([PKGLICENSE], [$(grep License LICENSE | sed -e 's/ License//g')]) +AC_SUBST([DEBLICENSER],[$(grep Copyright LICENSE | sed -e 's/ *(c)//g')]) +AC_SUBST([DEBCOPYING], [$(sed -e 's/^$/./g' -e 's/^/ /g' LICENSE)]) + +# +# Enable for this extension +# +PHP_ARG_ENABLE([k2hdkcpx], [whether to enable k2hdkc support], [AS_HELP_STRING([--enable-k2hdkcpx], [Enable k2hdkcpx support])], [no]) + +# +# For PHP Extension +# +if test "$PHP_K2HASH" != "no"; then + PHP_EVAL_INCLINE($LIBK2HDKC_CFLAGS) + PHP_EVAL_LIBLINE($LIBK2HDKC_LIBS, K2HDKCPX_SHARED_LIBADD) + + AC_PATH_PROG(PKG_CONFIG, pkg-config, no) + AC_MSG_CHECKING(for libk2hdkcpx) + + if test -x "$PKG_CONFIG" && $PKG_CONFIG --exists libk2hdkc; then + K2HDKCPX_INCDIR=`$PKG_CONFIG libk2hdkc --variable=includedir` + K2HDKCPX_LIBDIR=`$PKG_CONFIG libk2hdkc --variable=libdir` + K2HDKCPX_VERSION=`$PKG_CONFIG libk2hdkc --modversion` + + AC_MSG_RESULT(from pkgconfig: version $K2HDKCPX_VERSION found in $K2HDKCPX_LIBDIR) + fi + + if test -z "$K2HDKCPX_LIBDIR"; then + AC_MSG_RESULT([not found]) + AC_MSG_ERROR([Please install the libk2dkc distribution]) + fi + + PHP_ADD_INCLUDE($K2HDKCPX_INCDIR/k2hdkc) + PHP_ADD_LIBRARY_WITH_PATH(k2hdkc, $K2HDKCPX_LIBDIR, K2HDKCPX_SHARED_LIBADD) + PHP_SUBST(K2HDKCPX_SHARED_LIBADD) + + AC_DEFINE(HAVE_K2HDKCPX, 1, [ Have k2hdkcpx support ]) + + # + # Source codes + # + PHP_NEW_EXTENSION(k2hdkcpx, k2hdkcpx_func.c k2hdkcpx.c, $ext_shared) +fi + +AC_CHECK_PROG(K2HDKCPX_HAVE_PHP_BINARY, [php --version], [yes], [no]) + +# +# Make PHP version variables +# +if test "${K2HDKCPX_HAVE_PHP_BINARY}" = "yes"; then + AC_SUBST([K2HDKCPX_PHP_VERSION], [$(php -r 'echo "".PHP_MAJOR_VERSION.".".PHP_MINOR_VERSION;')]) + AC_SUBST([K2HDKCPX_PHP_RAW_VERSION], [$(php -r 'echo "".PHP_MAJOR_VERSION."".PHP_MINOR_VERSION;')]) + AC_SUBST([K2HDKCPX_PHP_MAJOR_VERSION], [$(php -r 'echo "".PHP_MAJOR_VERSION."";')]) + AC_SUBST([K2HDKCPX_PHP_MINOR_VERSION], [$(php -r 'echo "".PHP_MINOR_VERSION."";')]) + AC_SUBST([K2HDKCPX_EXT_PKGNAME], [$(head -n 1 $(pwd)/ChangeLog | awk '{print $1}')]) + AC_SUBST([K2HDKCPX_EXT_VERSION], [$(head -n 1 $(pwd)/ChangeLog | sed -e 's/[(]//g' -e 's/[)]//g' | awk '{print $2}' | sed -e 's/-.*$//g')]) + + AC_DEFINE_UNQUOTED(PHP_K2HDKCPX_VERSION, ["$(head -n 1 $(pwd)/ChangeLog | sed -e 's/[(]//g' -e 's/[)]//g' | awk '{print $2}' | sed -e 's/-.*$//g')"], [ PHP Extension version ]) +else + AC_SUBST([K2HDKCPX_PHP_VERSION], "0.0") + AC_SUBST([K2HDKCPX_PHP_RAW_VERSION], "00") + AC_SUBST([K2HDKCPX_PHP_MAJOR_VERSION], "0") + AC_SUBST([K2HDKCPX_PHP_MINOR_VERSION], "0") + AC_SUBST([K2HDKCPX_EXT_PKGNAME], "php-pecl-k2hdkc") + AC_SUBST([K2HDKCPX_EXT_VERSION], "0.0.0") + + AC_DEFINE(PHP_K2HDKCPX_VERSION, "0.0.0", [ PHP Extension version ]) +fi + +# +# AC Macros for checking dependencies, etc +# +# [NOTE] +# The macros below are the macros that were output when I ran autoscan manually. +# +AC_CHECK_FUNCS([strncasecmp]) +AC_CHECK_HEADERS([fcntl.h]) +AC_CHECK_HEADER_STDBOOL +AC_C_INLINE +AC_FUNC_MALLOC +AC_PROG_CXX +AC_PROG_INSTALL +AC_PROG_MAKE_SET +AC_PROG_RANLIB +AC_TYPE_OFF_T +AC_TYPE_SIZE_T +AC_TYPE_SSIZE_T + +# +# Make changelog strings for rpm +# +if test -f $(pwd)/buildutils/make_rpm_changelog.sh; then + AC_SUBST([K2HDKCPX_RPMCHANGELOG], [$($(pwd)/buildutils/make_rpm_changelog.sh $(pwd)/ChangeLog)]) +fi + +# +# Set input files +# +if test -d buildutils; then + AC_CONFIG_FILES([ + $(pwd)/buildutils/php-pecl-k2hdkc.spec + $(pwd)/buildutils/k2hdkcpx.ini + $(pwd)/buildutils/rules + $(pwd)/buildutils/control.in + $(pwd)/buildutils/copyright + $(pwd)/buildutils/watch + $(pwd)/buildutils/upstream/metadata + $(pwd)/buildutils/APKBUILD.templ + ]) +fi + +# +# Local variables: +# tab-width: 4 +# c-basic-offset: 4 +# End: +# vim600: noexpandtab sw=4 ts=4 fdm=marker +# vim<600: noexpandtab sw=4 ts=4 +# diff --git a/k2hdkcpx.c b/k2hdkcpx.c new file mode 100644 index 0000000..643b8a2 --- /dev/null +++ b/k2hdkcpx.c @@ -0,0 +1,1071 @@ +/* +* +* K2HDKC PHP Extension library +* +* Copyright 2023 Yahoo Japan Corporation. +* +* K2HDKC is k2hash based distributed KVS cluster. +* K2HDKC uses K2HASH, CHMPX, FULLOCK libraries. K2HDKC supports +* distributed KVS cluster server program and client libraries. +* +* For the full copyright and license information, please view +* the license file that was distributed with this source code. +* +* AUTHOR: Hirotaka Wakabayashi +* CREATE: Fri, Mar 31 2023 +* REVISION: +* +*/ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "php.h" +#include "ext/standard/info.h" +#include "php_k2hdkcpx.h" + +PHP_METHOD(K2hdkc, __construct) { + // declare_variables + char* filepath = NULL; + size_t filepath_len = 0; + char* cuk = NULL; + size_t cuk_len = 0; + zend_long port = DEFAULT_PORT; + zend_bool is_rejoin = true; + zend_bool is_auto_rejoin = false; + zend_bool is_clear_backup = false; + + // assign_after_declare + // cppcheck-suppress unknownMacro + ZEND_PARSE_PARAMETERS_START(1, 6) + Z_PARAM_STRING(filepath, filepath_len) + Z_PARAM_OPTIONAL + Z_PARAM_LONG(port) + Z_PARAM_STRING(cuk, cuk_len) + Z_PARAM_BOOL(is_rejoin) + Z_PARAM_BOOL(is_auto_rejoin) + Z_PARAM_BOOL(is_clear_backup) + ZEND_PARSE_PARAMETERS_END(); + + // get_props or update_props + // k2hdkc_chmpx_handle property + // Firstly, create a k2hdkc_chmpx_handle + k2hdkc_chmpx_h* k2hdkc_chmpx_handle_ptr = emalloc(sizeof(long)); + if (k2hdkc_chmpx_handle_ptr == NULL) { + php_error(E_ERROR, "malloc error"); + return; + } + *k2hdkc_chmpx_handle_ptr = k2hdkc_open_chmpx_full(filepath, port, cuk, is_rejoin, is_auto_rejoin, is_auto_rejoin); + if (*k2hdkc_chmpx_handle_ptr == K2HDKC_INVALID_HANDLE) { + php_error(E_ERROR, "k2hdkc_open_chmpx_full error"); + return; + } + + // Secondarily, create a zend_resource with the k2hdkc handle + zend_resource* my_k2hdkc_chmpx_handle_ptr = zend_register_resource(k2hdkc_chmpx_handle_ptr, k2hdkcpx_handle_resource_number); + // Thirdly, create a zval with the zend_resource + zval zval_new_k2hdkc_chmpx_handle; + ZVAL_RES(&zval_new_k2hdkc_chmpx_handle, my_k2hdkc_chmpx_handle_ptr); + // Finally, set the zend_resource with this object + k2hdkcpx_update_property_resource(Z_OBJCE_P(ZEND_THIS), ZEND_THIS, "_handle", strlen("_handle"), &zval_new_k2hdkc_chmpx_handle); +} + +PHP_METHOD(K2hdkc, __destruct) { + // declare_variables + // NOTICE: destruct accept no parameters + + // assign_after_declare + ZEND_PARSE_PARAMETERS_NONE(); + + // get_props + zval* zval_k2hdkc_chmpx_handle_ptr = k2hdkcpx_read_property_resource(Z_OBJCE_P(ZEND_THIS), ZEND_THIS, "_handle"); + if (!zval_k2hdkc_chmpx_handle_ptr) { + php_error(E_NOTICE, "_handle property is invalid"); + return; + } + + // get_resources after get_props + k2hdkc_chmpx_h* k2hdkc_chmpx_handle_ptr; + k2hdkc_chmpx_handle_ptr = (k2hdkc_chmpx_h *)zend_fetch_resource(Z_RES_P(zval_k2hdkc_chmpx_handle_ptr), "_handle", k2hdkcpx_handle_resource_number); + + // call_some_functions after get_resources + if (K2HDKC_INVALID_HANDLE != *k2hdkc_chmpx_handle_ptr) { + // destroy handle + bool bResult = k2hdkc_close_chmpx_ex(*k2hdkc_chmpx_handle_ptr, true); + if (!bResult) { + php_error(E_NOTICE, "k2hdkc_close_chmpx_ex should return true, but returned false"); + } + } + zval_dtor(zval_k2hdkc_chmpx_handle_ptr); + + // return_result after call_some_functions + // NOTICE: destruct shoud return nothing +} + +PHP_METHOD(K2hdkc, setValue) { + // declare_variables + char* key = NULL; + size_t key_len = 0; + char* val = NULL; + size_t val_len = 0; + zend_bool clear_subkeys = false; + zval* subkeys = NULL; // NOTE: initial array of keys must be explicitly NULL to avoid SIGSEGV in Z_TYPE_P + char* password = NULL; + size_t password_len = 0; + zend_long expire = 0; + + // assign_after_declare + ZEND_PARSE_PARAMETERS_START(2, 6) + Z_PARAM_STRING(key, key_len) + Z_PARAM_STRING(val, val_len) + Z_PARAM_OPTIONAL + Z_PARAM_BOOL(clear_subkeys) + Z_PARAM_ARRAY(subkeys) + Z_PARAM_STRING(password, password_len) + Z_PARAM_LONG(expire) + ZEND_PARSE_PARAMETERS_END(); + + // validate_after_assign + time_t* ptmexpire = NULL; + if (expire > 0) { + ptmexpire = (time_t*)&expire; + } + + // get_props + zval* zval_k2hdkc_chmpx_handle_ptr = k2hdkcpx_read_property_resource(Z_OBJCE_P(ZEND_THIS), ZEND_THIS, "_handle"); + if (!zval_k2hdkc_chmpx_handle_ptr) { + php_error(E_NOTICE, "_handle property is invalid"); + RETURN_FALSE; // RETVAL_FALSE; return; + } + + // get_resources after get_props + k2hdkc_chmpx_h* k2hdkc_chmpx_handle_ptr; + k2hdkc_chmpx_handle_ptr = (k2hdkc_chmpx_h *)zend_fetch_resource(Z_RES_P(zval_k2hdkc_chmpx_handle_ptr), "_handle", k2hdkcpx_handle_resource_number); + if (K2HDKC_INVALID_HANDLE == *k2hdkc_chmpx_handle_ptr) { + php_error(E_NOTICE, "_handle property is invalid"); + RETURN_FALSE; // RETVAL_FALSE; return; + } + + // call_some_functions after get_resources + // bool k2hdkc_pm_set_str_all_wa(k2hdkc_chmpx_h handle, const char* pkey, const char* pval, const char** pskeyarray, const char* encpass, const time_t* expire) + bool bResult = false; + if (subkeys && Z_TYPE_P(subkeys) == IS_ARRAY) { + int skeypckcnt = zend_array_count(Z_ARR(*subkeys)); // returns number of elements in array. + char** pskeyarray = (char**)calloc(skeypckcnt + 1, sizeof(char*)); + zend_ulong zulong_idx = 0; + zend_string* zstring_key = NULL; + zval* zv_val = NULL; + + ZEND_HASH_FOREACH_KEY_VAL(Z_ARR(*subkeys), zulong_idx, zstring_key, zv_val) { + char* subkey = Z_STRVAL_P(zv_val); + pskeyarray[zulong_idx] = (char*)malloc(strlen(subkey) + 1); + memcpy(pskeyarray[zulong_idx], subkey, strlen(subkey)); + pskeyarray[zulong_idx][strlen(subkey)] = '\0'; + } ZEND_HASH_FOREACH_END(); + + bResult = k2hdkc_pm_set_str_all_wa(*k2hdkc_chmpx_handle_ptr, key, val, (const char**)pskeyarray, password, ptmexpire); + if (pskeyarray) { + char** ptmp = NULL; + for (ptmp = pskeyarray; *ptmp; ptmp++) { + free(*ptmp); + } + } + } else { + bResult = k2hdkc_pm_set_str_all_wa(*k2hdkc_chmpx_handle_ptr, key, val, (const char**)subkeys, password, ptmexpire); + } + // return_result after call_some_functions + if (bResult) { + RETURN_TRUE; // RETVAL_TRUE; return; + } + RETURN_FALSE; +} + +PHP_METHOD(K2hdkc, getValue) { + // declare_variables + char* key = NULL; + size_t key_len = 0; + char* password = NULL; + size_t password_len = 0; + + // assign_after_declare + ZEND_PARSE_PARAMETERS_START(1, 2) + Z_PARAM_STRING(key, key_len) + Z_PARAM_OPTIONAL + Z_PARAM_STRING(password, password_len) + ZEND_PARSE_PARAMETERS_END(); + + // get_props + zval* zval_k2hdkc_chmpx_handle_ptr = k2hdkcpx_read_property_resource(Z_OBJCE_P(ZEND_THIS), ZEND_THIS, "_handle"); + if (!zval_k2hdkc_chmpx_handle_ptr) { + php_error(E_NOTICE, "_handle property is invalid"); + RETURN_EMPTY_STRING(); // RETVAL_EMPTY_STRING(); return; + } + + // get_resources after get_props + k2hdkc_chmpx_h* k2hdkc_chmpx_handle_ptr; + k2hdkc_chmpx_handle_ptr = (k2hdkc_chmpx_h *)zend_fetch_resource(Z_RES_P(zval_k2hdkc_chmpx_handle_ptr), "_handle", k2hdkcpx_handle_resource_number); + if (K2HDKC_INVALID_HANDLE == *k2hdkc_chmpx_handle_ptr) { + php_error(E_NOTICE, "_handle property is invalid"); + RETURN_EMPTY_STRING(); // RETVAL_EMPTY_STRING(); return; + } + + // call_some_functions after get_resources + // k2hdkc_pm_get_str_value_wp(session.getHandle(), this.key, this.pass, ppval); + char* pval; + if (!k2hdkc_pm_get_str_value_wp(*k2hdkc_chmpx_handle_ptr, key, password, &pval)) { + // return_result after call_some_functions + RETURN_EMPTY_STRING(); // RETVAL_EMPTY_STRING(); return; + } + zend_string* retval = strpprintf(0, "%s", pval); + RETURN_STR(retval); + // come here ??? + free(pval); +} + +PHP_METHOD(K2hdkc, addSubkey) { + // declare_variables + char* key = NULL; + size_t key_len = 0; + char* subkey = NULL; + size_t subkey_len = 0; + char* subval = NULL; + size_t subval_len = 0; + zend_bool is_attr_checked = true; + char* password = NULL; + size_t password_len = 0; + zend_long expire = 0; + + // assign_after_declare + ZEND_PARSE_PARAMETERS_START(3, 6) + Z_PARAM_STRING(key, key_len) + Z_PARAM_STRING(subkey, subkey_len) + Z_PARAM_STRING(subval, subval_len) + Z_PARAM_OPTIONAL + Z_PARAM_BOOL(is_attr_checked) + Z_PARAM_STRING(password, password_len) + Z_PARAM_LONG(expire) + ZEND_PARSE_PARAMETERS_END(); + + // validate_after_assign + time_t* ptmexpire = NULL; + if (expire > 0) { + ptmexpire = (time_t*)&expire; + } + + // get_props + zval* zval_k2hdkc_chmpx_handle_ptr = k2hdkcpx_read_property_resource(Z_OBJCE_P(ZEND_THIS), ZEND_THIS, "_handle"); + if (!zval_k2hdkc_chmpx_handle_ptr) { + php_error(E_NOTICE, "_handle property is invalid"); + RETURN_FALSE; // RETVAL_FALSE; return; + } + + // get_resources after get_props + k2hdkc_chmpx_h* k2hdkc_chmpx_handle_ptr = (k2hdkc_chmpx_h *)zend_fetch_resource(Z_RES_P(zval_k2hdkc_chmpx_handle_ptr), "_handle", k2hdkcpx_handle_resource_number); + if (K2HDKC_INVALID_HANDLE == *k2hdkc_chmpx_handle_ptr) { + php_error(E_NOTICE, "_handle property is invalid"); + RETURN_FALSE; // RETVAL_FALSE; return; + } + + // call_some_functions after get_resources + bool bResult = k2hdkc_pm_set_str_subkey_wa(*k2hdkc_chmpx_handle_ptr, key, subkey, subval, is_attr_checked, password, ptmexpire); + // return_result after call_some_functions + if (bResult) { + RETURN_TRUE; // RETVAL_TRUE; return; + } + RETURN_FALSE; +} + +PHP_METHOD(K2hdkc, casGet) { + // declare_variables + char* key = NULL; + size_t key_len = 0; + char* password = NULL; + size_t password_len = 0; + + // assign_after_declare + ZEND_PARSE_PARAMETERS_START(1, 2) + Z_PARAM_STRING(key, key_len) + Z_PARAM_OPTIONAL + Z_PARAM_STRING(password, password_len) + ZEND_PARSE_PARAMETERS_END(); + + // get_props + zval* zval_k2hdkc_chmpx_handle_ptr = k2hdkcpx_read_property_resource(Z_OBJCE_P(ZEND_THIS), ZEND_THIS, "_handle"); + if (!zval_k2hdkc_chmpx_handle_ptr) { + php_error(E_NOTICE, "_handle property is invalid"); + RETURN_FALSE; // RETVAL_FALSE; return; + } + + // get_resources after get_props + k2hdkc_chmpx_h* k2hdkc_chmpx_handle_ptr = (k2hdkc_chmpx_h *)zend_fetch_resource(Z_RES_P(zval_k2hdkc_chmpx_handle_ptr), "_handle", k2hdkcpx_handle_resource_number); + if (K2HDKC_INVALID_HANDLE == *k2hdkc_chmpx_handle_ptr) { + php_error(E_NOTICE, "_handle property is invalid"); + RETURN_FALSE; // RETVAL_FALSE; return; + } + + // call_some_functions after get_resources + // bool bResult = k2hdkc_pm_cas64_str_get_wa(*k2hdkc_chmpx_handle_ptr, key, NULL, (uint64_t*)&pval); + int pval = 0; + bool bResult = k2hdkc_pm_cas64_str_get_wa(*k2hdkc_chmpx_handle_ptr, key, password, (uint64_t*)&pval); + if (!bResult) { + php_error(E_NOTICE, "k2hdkc_pm_cas64_str_get_wa false"); + RETURN_FALSE; + } + if (!pval) { + // return_result after call_some_functions + RETURN_LONG(0); // RETVAL_LONG(l); return + } + RETURN_LONG(pval); +} + +PHP_METHOD(K2hdkc, casDecrement) { + // declare_variables + char* key = NULL; + size_t key_len = 0; + char* password = NULL; + size_t password_len = 0; + zend_long expire = 0; + + // assign_after_declare + ZEND_PARSE_PARAMETERS_START(1, 3) + Z_PARAM_STRING(key, key_len) + Z_PARAM_OPTIONAL + Z_PARAM_STRING(password, password_len) + Z_PARAM_LONG(expire) + ZEND_PARSE_PARAMETERS_END(); + + // validate_after_assign + time_t* ptmexpire = NULL; + if (expire > 0) { + ptmexpire = (time_t*)&expire; + } + + // get_props + zval* zval_k2hdkc_chmpx_handle_ptr = k2hdkcpx_read_property_resource(Z_OBJCE_P(ZEND_THIS), ZEND_THIS, "_handle"); + if (!zval_k2hdkc_chmpx_handle_ptr) { + php_error(E_NOTICE, "_handle property is invalid"); + RETURN_FALSE; // RETVAL_FALSE; return; + } + + // get_resources after get_props + k2hdkc_chmpx_h* k2hdkc_chmpx_handle_ptr = (k2hdkc_chmpx_h *)zend_fetch_resource(Z_RES_P(zval_k2hdkc_chmpx_handle_ptr), "_handle", k2hdkcpx_handle_resource_number); + if (K2HDKC_INVALID_HANDLE == *k2hdkc_chmpx_handle_ptr) { + php_error(E_NOTICE, "_handle property is invalid"); + RETURN_FALSE; // RETVAL_FALSE; return; + } + + // call_some_functions after get_resources + // bool k2hdkc_pm_cas_str_decrement_wa(k2hdkc_chmpx_h handle, const char* pkey, const char* encpass, const time_t* expire) + bool bResult = k2hdkc_pm_cas_str_decrement_wa(*k2hdkc_chmpx_handle_ptr, key, password, ptmexpire); + if (!bResult) { + // return_result after call_some_functions + php_error(E_NOTICE, "k2hdkc_pm_cas_str_decrement_wa should return true, but false"); + RETURN_FALSE; // RETVAL_FALSE; return; + } + RETURN_TRUE; // RETVAL_TRUE; return; +} + +PHP_METHOD(K2hdkc, casIncrement) { + // declare_variables + char* key = NULL; + size_t key_len = 0; + char* password = NULL; + size_t password_len = 0; + zend_long expire = 0; + + // assign_after_declare + ZEND_PARSE_PARAMETERS_START(1, 3) + Z_PARAM_STRING(key, key_len) + Z_PARAM_OPTIONAL + Z_PARAM_STRING(password, password_len) + Z_PARAM_LONG(expire) + ZEND_PARSE_PARAMETERS_END(); + + // validate_after_assign + time_t* ptmexpire = NULL; + if (expire > 0) { + ptmexpire = (time_t*)&expire; + } + + // get_props + zval* zval_k2hdkc_chmpx_handle_ptr = k2hdkcpx_read_property_resource(Z_OBJCE_P(ZEND_THIS), ZEND_THIS, "_handle"); + if (!zval_k2hdkc_chmpx_handle_ptr) { + php_error(E_NOTICE, "_handle property is invalid"); + RETURN_FALSE; // RETVAL_FALSE; return; + } + + // get_resources after get_props + k2hdkc_chmpx_h* k2hdkc_chmpx_handle_ptr = (k2hdkc_chmpx_h *)zend_fetch_resource(Z_RES_P(zval_k2hdkc_chmpx_handle_ptr), "_handle", k2hdkcpx_handle_resource_number); + if (K2HDKC_INVALID_HANDLE == *k2hdkc_chmpx_handle_ptr) { + php_error(E_NOTICE, "_handle property is invalid"); + RETURN_FALSE; // RETVAL_FALSE; return; + } + + // call_some_functions after get_resources + // bool k2hdkc_pm_cas_str_increment_wa(k2hdkc_chmpx_h handle, const char* pkey, const char* encpass, const time_t* expire) + bool bResult = k2hdkc_pm_cas_str_increment_wa(*k2hdkc_chmpx_handle_ptr, key, password, ptmexpire); + if (!bResult) { + // return_result after call_some_functions + php_error(E_NOTICE, "k2hdkc_pm_cas_str_increment_wa should return true, but false"); + RETURN_FALSE; // RETVAL_FALSE; return; + } + RETURN_TRUE; // RETVAL_TRUE; return; +} + +PHP_METHOD(K2hdkc, casInit) { + // declare_variables + char* key = NULL; + size_t key_len = 0; + zend_long val = 0; + char* password = NULL; + size_t password_len = 0; + zend_long expire = 0; + + // assign_after_declare + ZEND_PARSE_PARAMETERS_START(2, 4) + Z_PARAM_STRING(key, key_len) + Z_PARAM_LONG(val) + Z_PARAM_OPTIONAL + Z_PARAM_STRING(password, password_len) + Z_PARAM_LONG(expire) + ZEND_PARSE_PARAMETERS_END(); + + // validate_after_assign + time_t* ptmexpire = NULL; + if (expire > 0) { + ptmexpire = (time_t*)&expire; + } + + // get_props + zval* zval_k2hdkc_chmpx_handle_ptr = k2hdkcpx_read_property_resource(Z_OBJCE_P(ZEND_THIS), ZEND_THIS, "_handle"); + if (!zval_k2hdkc_chmpx_handle_ptr) { + php_error(E_NOTICE, "_handle property is invalid"); + RETURN_FALSE; // RETVAL_FALSE; return; + } + + // get_resources after get_props + k2hdkc_chmpx_h* k2hdkc_chmpx_handle_ptr = (k2hdkc_chmpx_h *)zend_fetch_resource(Z_RES_P(zval_k2hdkc_chmpx_handle_ptr), "_handle", k2hdkcpx_handle_resource_number); + if (K2HDKC_INVALID_HANDLE == *k2hdkc_chmpx_handle_ptr) { + php_error(E_NOTICE, "_handle property is invalid"); + RETURN_FALSE; // RETVAL_FALSE; return; + } + + // call_some_functions after get_resources + // bool k2hdkc_pm_cas64_str_init_wa(k2hdkc_chmpx_h handle, const char* pkey, uint64_t val, const char* encpass, const time_t* expire) + bool bResult = k2hdkc_pm_cas64_str_init_wa(*k2hdkc_chmpx_handle_ptr, key, (uint64_t)val, password, ptmexpire); + if (!bResult) { + // return_result after call_some_functions + php_error(E_NOTICE, "k2hdkc_pm_cas64_str_init_wa should return true, but false"); + RETURN_FALSE; // RETVAL_FALSE; return; + } + RETURN_TRUE; // RETVAL_TRUE; return; +} + +PHP_METHOD(K2hdkc, casSet) { + // declare_variables + char* key = NULL; + size_t key_len = 0; + zend_long old_val = 0; + zend_long new_val = 0; + char* password = NULL; + size_t password_len = 0; + zend_long expire = 0; + + // assign_after_declare + ZEND_PARSE_PARAMETERS_START(3, 5) + Z_PARAM_STRING(key, key_len) + Z_PARAM_LONG(old_val) + Z_PARAM_LONG(new_val) + Z_PARAM_OPTIONAL + Z_PARAM_STRING(password, password_len) + Z_PARAM_LONG(expire) + ZEND_PARSE_PARAMETERS_END(); + + // validate_after_assign + time_t* ptmexpire = NULL; + if (expire > 0) { + ptmexpire = (time_t*)&expire; + } + + // get_props + zval* zval_k2hdkc_chmpx_handle_ptr = k2hdkcpx_read_property_resource(Z_OBJCE_P(ZEND_THIS), ZEND_THIS, "_handle"); + if (!zval_k2hdkc_chmpx_handle_ptr) { + php_error(E_NOTICE, "_handle property is invalid"); + RETURN_FALSE; // RETVAL_FALSE; return; + } + + // get_resources after get_props + k2hdkc_chmpx_h* k2hdkc_chmpx_handle_ptr = (k2hdkc_chmpx_h *)zend_fetch_resource(Z_RES_P(zval_k2hdkc_chmpx_handle_ptr), "_handle", k2hdkcpx_handle_resource_number); + if (K2HDKC_INVALID_HANDLE == *k2hdkc_chmpx_handle_ptr) { + php_error(E_NOTICE, "_handle property is invalid"); + RETURN_FALSE; // RETVAL_FALSE; return; + } + + // call_some_functions after get_resources + // bool k2hdkc_pm_cas64_str_set_wa(k2hdkc_chmpx_h handle, const char* pkey, uint64_t oldval, uint64_t newval, const char* encpass, const time_t* expire) + bool bResult = k2hdkc_pm_cas64_str_set_wa(*k2hdkc_chmpx_handle_ptr, key, old_val, new_val, password, ptmexpire); + if (!bResult) { + // return_result after call_some_functions + php_error(E_NOTICE, "k2hdkc_pm_cas64_str_set_wa should return true, but false"); + RETURN_FALSE; // RETVAL_FALSE; return; + } + RETURN_TRUE; // RETVAL_TRUE; return; +} + +PHP_METHOD(K2hdkc, clearSubkeys) { + // declare_variables + char* key = NULL; + size_t key_len = 0; + + // assign_after_declare + ZEND_PARSE_PARAMETERS_START(1, 1) + Z_PARAM_STRING(key, key_len) + ZEND_PARSE_PARAMETERS_END(); + + // get_props + zval* zval_k2hdkc_chmpx_handle_ptr = k2hdkcpx_read_property_resource(Z_OBJCE_P(ZEND_THIS), ZEND_THIS, "_handle"); + if (!zval_k2hdkc_chmpx_handle_ptr) { + php_error(E_NOTICE, "_handle property is invalid"); + RETURN_FALSE; // RETVAL_FALSE; return; + } + + // get_resources after get_props + k2hdkc_chmpx_h* k2hdkc_chmpx_handle_ptr = (k2hdkc_chmpx_h *)zend_fetch_resource(Z_RES_P(zval_k2hdkc_chmpx_handle_ptr), "_handle", k2hdkcpx_handle_resource_number); + if (K2HDKC_INVALID_HANDLE == *k2hdkc_chmpx_handle_ptr) { + php_error(E_NOTICE, "_handle property is invalid"); + RETURN_FALSE; // RETVAL_FALSE; return; + } + + // call_some_functions after get_resources + // bool k2hdkc_pm_clear_str_subkeys(k2hdkc_chmpx_h handle, const char* pkey) + bool bResult = k2hdkc_pm_clear_str_subkeys(*k2hdkc_chmpx_handle_ptr, key); + if (!bResult) { + // return_result after call_some_functions + php_error(E_NOTICE, "k2hdkc_pm_clear_str_subkeys should return true, but false"); + RETURN_FALSE; // RETVAL_FALSE; return; + } + RETURN_TRUE; // RETVAL_TRUE; return; +} + +PHP_METHOD(K2hdkc, close) { + // declare_variables + + // assign_after_declare + ZEND_PARSE_PARAMETERS_NONE(); + + // get_props + zval* zval_k2hdkc_chmpx_handle_ptr = k2hdkcpx_read_property_resource(Z_OBJCE_P(ZEND_THIS), ZEND_THIS, "_handle"); + if (!zval_k2hdkc_chmpx_handle_ptr) { + php_error(E_NOTICE, "_handle property is invalid"); + RETURN_FALSE; // RETVAL_FALSE; return; + } + + // get_resources after get_props + k2hdkc_chmpx_h* k2hdkc_chmpx_handle_ptr = (k2hdkc_chmpx_h *)zend_fetch_resource(Z_RES_P(zval_k2hdkc_chmpx_handle_ptr), "_handle", k2hdkcpx_handle_resource_number); + if (K2HDKC_INVALID_HANDLE == *k2hdkc_chmpx_handle_ptr) { + php_error(E_NOTICE, "_handle property is invalid"); + RETURN_FALSE; // RETVAL_FALSE; return; + } + + // call_some_functions after get_resources + if (K2HDKC_INVALID_HANDLE != *k2hdkc_chmpx_handle_ptr) { + bool bResult = k2hdkc_close_chmpx_ex(*k2hdkc_chmpx_handle_ptr, true); + if (!bResult) { + php_error(E_NOTICE, "k2hdkc_close_chmpx_ex should return true but false"); + RETURN_FALSE; // RETVAL_FALSE; return; + } + *k2hdkc_chmpx_handle_ptr = K2HDKC_INVALID_HANDLE; + } + RETURN_TRUE; // RETVAL_TRUE; return; +} + +PHP_METHOD(K2hdkc, getAttrs) { + // declare_variables + char* key = NULL; + size_t key_len = 0; + + // assign_after_declare + ZEND_PARSE_PARAMETERS_START(1, 1) + Z_PARAM_STRING(key, key_len) + ZEND_PARSE_PARAMETERS_END(); + + // get_props + zval* zval_k2hdkc_chmpx_handle_ptr = k2hdkcpx_read_property_resource(Z_OBJCE_P(ZEND_THIS), ZEND_THIS, "_handle"); + if (!zval_k2hdkc_chmpx_handle_ptr) { + php_error(E_NOTICE, "_handle property is invalid"); + RETURN_EMPTY_STRING(); // RETVAL_EMPTY_STRING(); return; + } + + // get_resources after get_props + k2hdkc_chmpx_h* k2hdkc_chmpx_handle_ptr; + k2hdkc_chmpx_handle_ptr = (k2hdkc_chmpx_h *)zend_fetch_resource(Z_RES_P(zval_k2hdkc_chmpx_handle_ptr), "_handle", k2hdkcpx_handle_resource_number); + if (K2HDKC_INVALID_HANDLE == *k2hdkc_chmpx_handle_ptr) { + php_error(E_NOTICE, "_handle property is invalid"); + RETURN_EMPTY_STRING(); // RETVAL_EMPTY_STRING(); return; + } + + // call_some_functions after get_resources + // PK2HDKCATTRPCK k2hdkc_pm_get_str_direct_attrs(k2hdkc_chmpx_h handle, const char* pkey, int* pattrspckcnt) + int attrspckcnt = 0; + PK2HDKCATTRPCK pattrs = k2hdkc_pm_get_str_direct_attrs(*k2hdkc_chmpx_handle_ptr, key, &attrspckcnt); + if (pattrs && attrspckcnt > 0) { + array_init(return_value); // zval* return_value + int cnt; + for(cnt = 0; cnt < attrspckcnt; ++cnt) { + char* pattrkey; + if(NULL != (pattrkey = (char*)emalloc(pattrs[cnt].keylength + 1))) { + memcpy(pattrkey, pattrs[cnt].pkey, pattrs[cnt].keylength); + pattrkey[pattrs[cnt].keylength] = '\0'; + add_next_index_string(return_value, pattrkey); + efree(pattrkey); + } + } + } + if(pattrs) { + k2h_free_attrpack(pattrs, attrspckcnt); + } +} + +PHP_METHOD(K2hdkc, getSubkeys) { + // declare_variables + char* key = NULL; + size_t key_len = 0; + + // assign_after_declare + ZEND_PARSE_PARAMETERS_START(1, 1) + Z_PARAM_STRING(key, key_len) + Z_PARAM_OPTIONAL + ZEND_PARSE_PARAMETERS_END(); + + // get_props + zval* zval_k2hdkc_chmpx_handle_ptr = k2hdkcpx_read_property_resource(Z_OBJCE_P(ZEND_THIS), ZEND_THIS, "_handle"); + if (!zval_k2hdkc_chmpx_handle_ptr) { + php_error(E_NOTICE, "_handle property is invalid"); + RETURN_EMPTY_STRING(); // RETVAL_EMPTY_STRING(); return; + } + + // get_resources after get_props + k2hdkc_chmpx_h* k2hdkc_chmpx_handle_ptr; + k2hdkc_chmpx_handle_ptr = (k2hdkc_chmpx_h *)zend_fetch_resource(Z_RES_P(zval_k2hdkc_chmpx_handle_ptr), "_handle", k2hdkcpx_handle_resource_number); + if (K2HDKC_INVALID_HANDLE == *k2hdkc_chmpx_handle_ptr) { + php_error(E_NOTICE, "_handle property is invalid"); + RETURN_EMPTY_STRING(); // RETVAL_EMPTY_STRING(); return; + } + + // call_some_functions after get_resources + // char** k2hdkc_pm_get_str_direct_subkeys(k2hdkc_chmpx_h handle, const char* pkey) + char** pskeyarray = k2hdkc_pm_get_str_direct_subkeys(*k2hdkc_chmpx_handle_ptr, key); + array_init(return_value); // zval* return_value + if (pskeyarray) { + char** ptmp = NULL; + for (ptmp = pskeyarray; *ptmp; ptmp++) { + add_next_index_str(return_value, strpprintf(0, "%s", *ptmp)); + free(*ptmp); + } + } +} + +PHP_METHOD(K2hdkc, queueGet) { + // declare_variables + char* prefix = NULL; + size_t prefix_len = 0; + zend_bool is_fifo = true; + char* password = NULL; + size_t password_len = 0; + + // assign_after_declare + ZEND_PARSE_PARAMETERS_START(1, 3) + Z_PARAM_STRING(prefix, prefix_len) + Z_PARAM_OPTIONAL + Z_PARAM_BOOL(is_fifo) + Z_PARAM_STRING(password, password_len) + ZEND_PARSE_PARAMETERS_END(); + + // get_props + zval* zval_k2hdkc_chmpx_handle_ptr = k2hdkcpx_read_property_resource(Z_OBJCE_P(ZEND_THIS), ZEND_THIS, "_handle"); + if (!zval_k2hdkc_chmpx_handle_ptr) { + php_error(E_NOTICE, "_handle property is invalid"); + RETURN_FALSE; // RETVAL_FALSE; return; + } + + // get_resources after get_props + k2hdkc_chmpx_h* k2hdkc_chmpx_handle_ptr = (k2hdkc_chmpx_h *)zend_fetch_resource(Z_RES_P(zval_k2hdkc_chmpx_handle_ptr), "_handle", k2hdkcpx_handle_resource_number); + if (K2HDKC_INVALID_HANDLE == *k2hdkc_chmpx_handle_ptr) { + php_error(E_NOTICE, "_handle property is invalid"); + RETURN_FALSE; // RETVAL_FALSE; return; + } + + // call_some_functions after get_resources + // bool k2hdkc_pm_q_str_pop_wp(k2hdkc_chmpx_h handle, const char* pprefix, bool is_fifo, const char* encpass, const char** ppval) + const char* pval = NULL; + bool bResult = k2hdkc_pm_q_str_pop_wp(*k2hdkc_chmpx_handle_ptr, prefix, is_fifo, password, &pval); + if (!bResult) { + php_error(E_NOTICE, "k2hdkc_pm_q_str_pop_wp should return true, but false"); + RETURN_EMPTY_STRING(); // RETVAL_EMPTY_STRING(); return; + } + zend_string* retval = strpprintf(0, "%s", pval); + RETURN_STR(retval); +} + +PHP_METHOD(K2hdkc, queuePut) { + // declare_variables + char* prefix = NULL; + size_t prefix_len = 0; + char* val = NULL; + size_t val_len = 0; + zend_bool is_fifo = true; + zend_bool is_attr_checked = true; + char* password = NULL; + size_t password_len = 0; + zend_long expire = 0; + + // assign_after_declare + ZEND_PARSE_PARAMETERS_START(2, 6) + Z_PARAM_STRING(prefix, prefix_len) + Z_PARAM_STRING(val, val_len) + Z_PARAM_OPTIONAL + Z_PARAM_BOOL(is_fifo) + Z_PARAM_BOOL(is_attr_checked) + Z_PARAM_STRING(password, password_len) + Z_PARAM_LONG(expire) + ZEND_PARSE_PARAMETERS_END(); + + // validate_after_assign + time_t* ptmexpire = NULL; + if (expire > 0) { + ptmexpire = (time_t*)&expire; + } + + // get_props + zval* zval_k2hdkc_chmpx_handle_ptr = k2hdkcpx_read_property_resource(Z_OBJCE_P(ZEND_THIS), ZEND_THIS, "_handle"); + if (!zval_k2hdkc_chmpx_handle_ptr) { + php_error(E_NOTICE, "_handle property is invalid"); + RETURN_FALSE; // RETVAL_FALSE; return; + } + + // get_resources after get_props + k2hdkc_chmpx_h* k2hdkc_chmpx_handle_ptr = (k2hdkc_chmpx_h *)zend_fetch_resource(Z_RES_P(zval_k2hdkc_chmpx_handle_ptr), "_handle", k2hdkcpx_handle_resource_number); + if (K2HDKC_INVALID_HANDLE == *k2hdkc_chmpx_handle_ptr) { + php_error(E_NOTICE, "_handle property is invalid"); + RETURN_FALSE; // RETVAL_FALSE; return; + } + + // call_some_functions after get_resources + // bool k2hdkc_pm_q_str_push_wa(k2hdkc_chmpx_h handle, const char* pprefix, const char* pval, bool is_fifo, bool checkattr, const char* encpass, const time_t* expire) + bool bResult = k2hdkc_pm_q_str_push_wa(*k2hdkc_chmpx_handle_ptr, prefix, val, is_fifo, is_attr_checked, password, ptmexpire); + if (!bResult) { + php_error(E_NOTICE, "k2hdkc_pm_q_str_push_wa should return true but false"); + RETURN_FALSE; // RETVAL_FALSE; return; + } + RETURN_TRUE; // RETVAL_TRUE; return; +} + +PHP_METHOD(K2hdkc, keyQueueGet) { + // declare_variables + char* prefix = NULL; + size_t prefix_len = 0; + zend_bool is_fifo = true; + char* password = NULL; + size_t password_len = 0; + + // assign_after_declare + ZEND_PARSE_PARAMETERS_START(1, 3) + Z_PARAM_STRING(prefix, prefix_len) + Z_PARAM_OPTIONAL + Z_PARAM_BOOL(is_fifo) + Z_PARAM_STRING(password, password_len) + ZEND_PARSE_PARAMETERS_END(); + + // get_props + zval* zval_k2hdkc_chmpx_handle_ptr = k2hdkcpx_read_property_resource(Z_OBJCE_P(ZEND_THIS), ZEND_THIS, "_handle"); + if (!zval_k2hdkc_chmpx_handle_ptr) { + php_error(E_NOTICE, "_handle property is invalid"); + RETURN_FALSE; // RETVAL_FALSE; return; + } + + // get_resources after get_props + k2hdkc_chmpx_h* k2hdkc_chmpx_handle_ptr = (k2hdkc_chmpx_h *)zend_fetch_resource(Z_RES_P(zval_k2hdkc_chmpx_handle_ptr), "_handle", k2hdkcpx_handle_resource_number); + if (K2HDKC_INVALID_HANDLE == *k2hdkc_chmpx_handle_ptr) { + php_error(E_NOTICE, "_handle property is invalid"); + RETURN_FALSE; // RETVAL_FALSE; return; + } + + // call_some_functions after get_resources + // bool k2hdkc_pm_keyq_str_pop_wp(k2hdkc_chmpx_h handle, const char* pprefix, bool is_fifo, const char* encpass, const char** ppkey, const char** ppval) + const char* pkey = NULL; + const char* pval = NULL; + bool bResult = k2hdkc_pm_keyq_str_pop_wp(*k2hdkc_chmpx_handle_ptr, prefix, is_fifo, password, &pkey, &pval); + if (!bResult) { + php_error(E_NOTICE, "k2hdkc_pm_keyq_str_pop_wp false"); + RETURN_FALSE; + } + array_init(return_value); // zval* return_value + if (pkey && pval) { + add_assoc_string(return_value, pkey, pval); + } +} + +PHP_METHOD(K2hdkc, keyQueuePut) { + // declare_variables + char* prefix = NULL; + size_t prefix_len = 0; + char* key = NULL; + size_t key_len = 0; + char* val = NULL; + size_t val_len = 0; + zend_bool is_fifo = true; + zend_bool is_attr_checked = true; + char* password = NULL; + size_t password_len = 0; + zend_long expire = 0; + + // assign_after_declare + ZEND_PARSE_PARAMETERS_START(3, 7) + Z_PARAM_STRING(prefix, prefix_len) + Z_PARAM_STRING(key, key_len) + Z_PARAM_STRING(val, val_len) + Z_PARAM_OPTIONAL + Z_PARAM_BOOL(is_fifo) + Z_PARAM_BOOL(is_attr_checked) + Z_PARAM_STRING(password, password_len) + Z_PARAM_LONG(expire) + ZEND_PARSE_PARAMETERS_END(); + + // validate_after_assign + time_t* ptmexpire = NULL; + if (expire > 0) { + ptmexpire = (time_t*)&expire; + } + + // get_props + zval* zval_k2hdkc_chmpx_handle_ptr = k2hdkcpx_read_property_resource(Z_OBJCE_P(ZEND_THIS), ZEND_THIS, "_handle"); + if (!zval_k2hdkc_chmpx_handle_ptr) { + php_error(E_NOTICE, "_handle property is invalid"); + RETURN_FALSE; // RETVAL_FALSE; return; + } + + // get_resources after get_props + k2hdkc_chmpx_h* k2hdkc_chmpx_handle_ptr = (k2hdkc_chmpx_h *)zend_fetch_resource(Z_RES_P(zval_k2hdkc_chmpx_handle_ptr), "_handle", k2hdkcpx_handle_resource_number); + if (K2HDKC_INVALID_HANDLE == *k2hdkc_chmpx_handle_ptr) { + php_error(E_NOTICE, "_handle property is invalid"); + RETURN_FALSE; // RETVAL_FALSE; return; + } + + // call_some_functions after get_resources + // bool k2hdkc_pm_keyq_str_push_wa(k2hdkc_chmpx_h handle, const char* pprefix, const char* pkey, const char* pval, bool is_fifo, bool checkattr, const char* encpass, const time_t* expire) + bool bResult = k2hdkc_pm_keyq_str_push_wa(*k2hdkc_chmpx_handle_ptr, prefix, key, val, is_fifo, is_attr_checked, password, ptmexpire); + if (!bResult) { + php_error(E_NOTICE, "k2hdkc_pm_keyq_str_push_wa should return true but false"); + RETURN_FALSE; // RETVAL_FALSE; return; + } + RETURN_TRUE; // RETVAL_TRUE; return; +} + +PHP_METHOD(K2hdkc, remove) { + // declare_variables + char* key = NULL; + size_t key_len = 0; + + // assign_after_declare + ZEND_PARSE_PARAMETERS_START(1, 1) + Z_PARAM_STRING(key, key_len) + Z_PARAM_OPTIONAL + ZEND_PARSE_PARAMETERS_END(); + + // get_props + zval* zval_k2hdkc_chmpx_handle_ptr = k2hdkcpx_read_property_resource(Z_OBJCE_P(ZEND_THIS), ZEND_THIS, "_handle"); + if (!zval_k2hdkc_chmpx_handle_ptr) { + php_error(E_NOTICE, "_handle property is invalid"); + RETURN_EMPTY_STRING(); // RETVAL_EMPTY_STRING(); return; + } + + // get_resources after get_props + k2hdkc_chmpx_h* k2hdkc_chmpx_handle_ptr; + k2hdkc_chmpx_handle_ptr = (k2hdkc_chmpx_h *)zend_fetch_resource(Z_RES_P(zval_k2hdkc_chmpx_handle_ptr), "_handle", k2hdkcpx_handle_resource_number); + if (K2HDKC_INVALID_HANDLE == *k2hdkc_chmpx_handle_ptr) { + php_error(E_NOTICE, "_handle property is invalid"); + RETURN_FALSE; // RETVAL_FALSE; return; + } + + // call_some_functions after get_resources + // bool k2hdkc_pm_remove_str(k2hdkc_chmpx_h handle, const char* pkey) + if (!k2hdkc_pm_remove_str(*k2hdkc_chmpx_handle_ptr, key)) { + php_error(E_NOTICE, "k2hdkc_pm_remove_str should return true but false"); + RETURN_FALSE; // RETVAL_FALSE; return; + } + RETURN_TRUE; // RETVAL_TRUE; return; +} + +PHP_METHOD(K2hdkc, removeSubkeys) { + // declare_variables + char* key = NULL; + size_t key_len = 0; + zval* subkeys = NULL; + zend_bool is_nested = false; + + // assign_after_declare + ZEND_PARSE_PARAMETERS_START(2, 3) + Z_PARAM_STRING(key, key_len) + Z_PARAM_ARRAY(subkeys) + Z_PARAM_OPTIONAL + Z_PARAM_BOOL(is_nested) + ZEND_PARSE_PARAMETERS_END(); + + // get_props + zval* zval_k2hdkc_chmpx_handle_ptr = k2hdkcpx_read_property_resource(Z_OBJCE_P(ZEND_THIS), ZEND_THIS, "_handle"); + if (!zval_k2hdkc_chmpx_handle_ptr) { + php_error(E_NOTICE, "_handle property is invalid"); + RETURN_FALSE; // RETVAL_FALSE; return; + } + + // get_resources after get_props + k2hdkc_chmpx_h* k2hdkc_chmpx_handle_ptr = (k2hdkc_chmpx_h *)zend_fetch_resource(Z_RES_P(zval_k2hdkc_chmpx_handle_ptr), "_handle", k2hdkcpx_handle_resource_number); + if (K2HDKC_INVALID_HANDLE == *k2hdkc_chmpx_handle_ptr) { + php_error(E_NOTICE, "_handle property is invalid"); + RETURN_FALSE; // RETVAL_FALSE; return; + } + + // call_some_functions after get_resources + // bool k2hdkc_pm_remove_str_subkey(k2hdkc_chmpx_h handle, const char* pkey, const char* psubkey, size_t subkeylength, bool is_nest) + if (subkeys && Z_TYPE_P(subkeys) == IS_ARRAY) { + zend_ulong zulong_idx = 0; + zend_string* zstring_key = NULL; + zval* zv_val = NULL; + + ZEND_HASH_FOREACH_KEY_VAL(Z_ARR(*subkeys), zulong_idx, zstring_key, zv_val) { + char* subkey = Z_STRVAL_P(zv_val); + bool bResult = k2hdkc_pm_remove_str_subkey(*k2hdkc_chmpx_handle_ptr, key, subkey, is_nested); + if (!bResult) { + // return_result after call_some_functions + php_error(E_NOTICE, "k2hdkc_pm_remove_str_subkey should return true, but false"); + RETURN_FALSE; // RETVAL_FALSE; return; + } + } ZEND_HASH_FOREACH_END(); + } + RETURN_TRUE; +} + +PHP_METHOD(K2hdkc, rename) { + // declare_variables + char* key = NULL; + size_t key_len = 0; + char* newKey = NULL; + size_t newKey_len = 0; + char* parentKey = NULL; + size_t parentKey_len = 0; + zend_bool is_attr_checked = true; + char* password = NULL; + size_t password_len = 0; + zend_long expire = 0; + + // assign_after_declare + ZEND_PARSE_PARAMETERS_START(2, 6) + Z_PARAM_STRING(key, key_len) + Z_PARAM_STRING(newKey, newKey_len) + Z_PARAM_OPTIONAL + Z_PARAM_STRING(parentKey, parentKey_len) + Z_PARAM_BOOL(is_attr_checked) + Z_PARAM_STRING(password, password_len) + Z_PARAM_LONG(expire) + ZEND_PARSE_PARAMETERS_END(); + + // validate_after_assign + time_t* ptmexpire = NULL; + if (expire > 0) { + ptmexpire = (time_t*)&expire; + } + + // get_props + zval* zval_k2hdkc_chmpx_handle_ptr = k2hdkcpx_read_property_resource(Z_OBJCE_P(ZEND_THIS), ZEND_THIS, "_handle"); + if (!zval_k2hdkc_chmpx_handle_ptr) { + php_error(E_NOTICE, "_handle property is invalid"); + RETURN_FALSE; // RETVAL_FALSE; return; + } + + // get_resources after get_props + k2hdkc_chmpx_h* k2hdkc_chmpx_handle_ptr = (k2hdkc_chmpx_h *)zend_fetch_resource(Z_RES_P(zval_k2hdkc_chmpx_handle_ptr), "_handle", k2hdkcpx_handle_resource_number); + if (K2HDKC_INVALID_HANDLE == *k2hdkc_chmpx_handle_ptr) { + php_error(E_NOTICE, "_handle property is invalid"); + RETURN_FALSE; // RETVAL_FALSE; return; + } + + // call_some_functions after get_resources + // bool k2hdkc_pm_rename_with_parent_str_wa(k2hdkc_chmpx_h handle, const char* poldkey, const char* pnewkey, const char* pparentkey, bool checkattr, const char* encpass, const time_t* expire) + bool bResult = k2hdkc_pm_rename_with_parent_str_wa(*k2hdkc_chmpx_handle_ptr, key, newKey, NULL, is_attr_checked, password, ptmexpire); + // return_result after call_some_functions + if (!bResult) { + // return_result after call_some_functions + php_error(E_NOTICE, "k2hdkc_pm_rename_with_parent_str_wa should return true, but false"); + RETURN_FALSE; // RETVAL_FALSE; return; + } + RETURN_TRUE; // RETVAL_TRUE; return; +} + +PHP_METHOD(K2hdkc, setSubkeys) { + // declare_variables + char* key = NULL; + size_t key_len = 0; + zval* subkeys = NULL; + + // assign_after_declare + ZEND_PARSE_PARAMETERS_START(2, 2) + Z_PARAM_STRING(key, key_len) + Z_PARAM_ARRAY(subkeys) + Z_PARAM_OPTIONAL + ZEND_PARSE_PARAMETERS_END(); + + // get_props + zval* zval_k2hdkc_chmpx_handle_ptr = k2hdkcpx_read_property_resource(Z_OBJCE_P(ZEND_THIS), ZEND_THIS, "_handle"); + if (!zval_k2hdkc_chmpx_handle_ptr) { + php_error(E_NOTICE, "_handle property is invalid"); + RETURN_FALSE; // RETVAL_FALSE; return; + } + + // get_resources after get_props + k2hdkc_chmpx_h* k2hdkc_chmpx_handle_ptr = (k2hdkc_chmpx_h *)zend_fetch_resource(Z_RES_P(zval_k2hdkc_chmpx_handle_ptr), "_handle", k2hdkcpx_handle_resource_number); + if (K2HDKC_INVALID_HANDLE == *k2hdkc_chmpx_handle_ptr) { + php_error(E_NOTICE, "_handle property is invalid"); + RETURN_FALSE; // RETVAL_FALSE; return; + } + + // call_some_functions after get_resources + // bool k2hdkc_pm_set_str_subkeys(k2hdkc_chmpx_h handle, const char* pkey, const char** pskeyarray) + bool bResult = false; + if (subkeys && Z_TYPE_P(subkeys) == IS_ARRAY) { + int skeypckcnt = zend_array_count(Z_ARR(*subkeys)); // returns number of elements in array. + char** pskeyarray = (char**)calloc(skeypckcnt + 1, sizeof(char*)); + zend_ulong zulong_idx = 0; + zend_string* zstring_key = NULL; + zval* zv_val = NULL; + + ZEND_HASH_FOREACH_KEY_VAL(Z_ARR(*subkeys), zulong_idx, zstring_key, zv_val) { + char* subkey = Z_STRVAL_P(zv_val); + pskeyarray[zulong_idx] = (char*)malloc(strlen(subkey) + 1); + memcpy(pskeyarray[zulong_idx], subkey, strlen(subkey)); + pskeyarray[zulong_idx][strlen(subkey)] = '\0'; + } ZEND_HASH_FOREACH_END(); + + bResult = k2hdkc_pm_set_str_subkeys(*k2hdkc_chmpx_handle_ptr, key, (const char**)pskeyarray); + if (pskeyarray) { + char** ptmp = NULL; + for (ptmp = pskeyarray; *ptmp; ptmp++) { + free(*ptmp); + } + } + } + // return_result after call_some_functions + if (bResult) { + RETURN_TRUE; // RETVAL_TRUE; return; + } + RETURN_FALSE; +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * End: + * vim600: noexpandtab sw=4 ts=4 fdm=marker + * vim<600: noexpandtab sw=4 ts=4 + */ diff --git a/k2hdkcpx.stub.php b/k2hdkcpx.stub.php new file mode 100644 index 0000000..8457af5 --- /dev/null +++ b/k2hdkcpx.stub.php @@ -0,0 +1,454 @@ +ptr); +} + +// +// PHP_FUNCTION ENTRIES START +// +PHP_FUNCTION(k2hdkcpx_open) +{ + // declare_variables + char* config_file = NULL; + size_t config_file_len = 0; + zend_long port = 8031; + char* cuk = NULL; + size_t cuk_len = 0; + zend_bool rejoin = true; + zend_bool rejoin_forever = true; + zend_bool clear_backup = true; + + // assign_after_declare + ZEND_PARSE_PARAMETERS_START(1, 6) + Z_PARAM_STRING(config_file, config_file_len) + Z_PARAM_OPTIONAL + Z_PARAM_LONG(port) + Z_PARAM_STRING(cuk, cuk_len) + Z_PARAM_BOOL(rejoin) + Z_PARAM_BOOL(rejoin_forever) + Z_PARAM_BOOL(clear_backup) + ZEND_PARSE_PARAMETERS_END(); + + // validate_after_assign + if(!config_file || 0 == config_file_len){ + php_error(E_ERROR, "k2hdkcpx_open: CHMPX configuration file path is empty."); + RETURN_FALSE; + } + + // call_some_functions after get_resources + k2hdkc_chmpx_h chmpx_handle = k2hdkc_open_chmpx_full(config_file, port, cuk, rejoin, rejoin_forever, clear_backup); + if(CHM_INVALID_CHMPXHANDLE == chmpx_handle) { + php_error(E_NOTICE, "k2hdkcpx_open: failed to open(join) CHMPX."); + RETURN_FALSE; + } + + // return_result after call_some_functions + k2hdkc_chmpx_h* chmpx_handle_ptr = emalloc(sizeof(long)); // this resource destroy by using chmpx_handle_resource_dtor + if (chmpx_handle_ptr == NULL) { + php_error(E_ERROR, "malloc error"); + RETURN_FALSE; + } + // cppcheck-suppress unmatchedSuppression + // cppcheck-suppress nullPointerRedundantCheck + *chmpx_handle_ptr = chmpx_handle; + RETURN_RES(zend_register_resource(chmpx_handle_ptr, k2hdkcpx_handle_resource_number)); // RETVAL_RES(r) and ZVAL_RES(return_value, r) +} + +PHP_FUNCTION(k2hdkcpx_set_value) +{ + // declare_variables + zval * zval_k2hdkc_chmpx_handle_ptr = NULL; + char* key = NULL; + size_t key_len = 0; + char* val = NULL; + size_t val_len = 0; + zend_bool clear_subkeys = false; + zval* subkeys = NULL; // NOTE: initial array of keys must be explicitly NULL to avoid SIGSEGV in Z_TYPE_P + char* password = NULL; + size_t password_len = 0; + zend_long expire = 0; + + // assign_after_declare + ZEND_PARSE_PARAMETERS_START(3, 7) + Z_PARAM_RESOURCE(zval_k2hdkc_chmpx_handle_ptr) + Z_PARAM_STRING(key, key_len) + Z_PARAM_STRING(val, val_len) + Z_PARAM_OPTIONAL + Z_PARAM_BOOL(clear_subkeys) + Z_PARAM_ARRAY(subkeys) + Z_PARAM_STRING(password, password_len) + Z_PARAM_LONG(expire) + ZEND_PARSE_PARAMETERS_END(); + + + // validate_after_assign + ZEND_ASSERT(Z_TYPE_P(zval_k2hdkc_chmpx_handle_ptr) == IS_RESOURCE); + if(!zval_k2hdkc_chmpx_handle_ptr) { + php_error(E_ERROR, "handle is empty."); + RETURN_FALSE; + } + time_t* ptmexpire = NULL; + if (expire > 0) { + ptmexpire = (time_t*)&expire; + } + + // get_resources + k2hdkc_chmpx_h* k2hdkc_chmpx_handle_ptr; + k2hdkc_chmpx_handle_ptr = (k2hdkc_chmpx_h *)zend_fetch_resource(Z_RES_P(zval_k2hdkc_chmpx_handle_ptr), "chmpx_handle_resource", k2hdkcpx_handle_resource_number); + if (K2HDKC_INVALID_HANDLE == *k2hdkc_chmpx_handle_ptr) { + php_error(E_NOTICE, "chmpx_handle_resource is invalid"); + RETURN_FALSE; // RETVAL_FALSE; return; + } + + // call_some_functions after get_resources + // bool k2hdkc_pm_set_str_all_wa(k2hdkc_chmpx_h handle, const char* pkey, const char* pval, const char** pskeyarray, const char* encpass, const time_t* expire) + bool bResult = false; + if (subkeys && Z_TYPE_P(subkeys) == IS_ARRAY) { + int skeypckcnt = zend_array_count(Z_ARR(*subkeys)); // returns number of elements in array. + char** pskeyarray = (char**)calloc(skeypckcnt + 1, sizeof(char*)); + zend_ulong zulong_idx = 0; + zend_string* zstring_key = NULL; + zval* zv_val = NULL; + + ZEND_HASH_FOREACH_KEY_VAL(Z_ARR(*subkeys), zulong_idx, zstring_key, zv_val) { + char* subkey = Z_STRVAL_P(zv_val); + pskeyarray[zulong_idx] = (char*)malloc(strlen(subkey) + 1); + memcpy(pskeyarray[zulong_idx], subkey, strlen(subkey)); + pskeyarray[zulong_idx][strlen(subkey)] = '\0'; + } ZEND_HASH_FOREACH_END(); + + bResult = k2hdkc_pm_set_str_all_wa(*k2hdkc_chmpx_handle_ptr, key, val, (const char**)pskeyarray, password, ptmexpire); + if (pskeyarray) { + char** ptmp = NULL; + for (ptmp = pskeyarray; *ptmp; ptmp++) { + free(*ptmp); + } + } + } else { + bResult = k2hdkc_pm_set_str_all_wa(*k2hdkc_chmpx_handle_ptr, key, val, NULL, password, ptmexpire); + } + // return_result after call_some_functions + if (bResult) { + RETURN_TRUE; // RETVAL_TRUE; return; + } + RETURN_FALSE; +} + +// get +// bool k2hdkc_pm_get_str_value_wp(k2hdkc_chmpx_h handle, const char* pkey, const char* encpass, char** ppval); +PHP_FUNCTION(k2hdkcpx_get_value) +{ + // declare_variables + zval * zval_k2hdkc_chmpx_handle_ptr = NULL; + char* key = NULL; + size_t key_len = 0; + char* password = NULL; + size_t password_len = 0; + + // assign_after_declare + ZEND_PARSE_PARAMETERS_START(2, 3) + Z_PARAM_RESOURCE(zval_k2hdkc_chmpx_handle_ptr) + Z_PARAM_STRING(key, key_len) + Z_PARAM_OPTIONAL + Z_PARAM_STRING(password, password_len) + ZEND_PARSE_PARAMETERS_END(); + + // validate_after_assign + ZEND_ASSERT(Z_TYPE_P(zval_k2hdkc_chmpx_handle_ptr) == IS_RESOURCE); + if(!zval_k2hdkc_chmpx_handle_ptr) { + php_error(E_ERROR, "handle is empty."); + RETURN_FALSE; + } + + // get_resources + k2hdkc_chmpx_h* k2hdkc_chmpx_handle_ptr; + k2hdkc_chmpx_handle_ptr = (k2hdkc_chmpx_h *)zend_fetch_resource(Z_RES_P(zval_k2hdkc_chmpx_handle_ptr), "chmpx_handle_resource", k2hdkcpx_handle_resource_number); + if (K2HDKC_INVALID_HANDLE == *k2hdkc_chmpx_handle_ptr) { + php_error(E_NOTICE, "chmpx_handle_resource is invalid"); + RETURN_FALSE; // RETVAL_FALSE; return; + } + + // call_some_functions after get_resources + //// k2hdkc_pm_get_str_value_wp(session.getHandle(), this.key, this.pass, ppval); + char* pval; + if (!k2hdkc_pm_get_str_value_wp(*k2hdkc_chmpx_handle_ptr, key, password, &pval)) { + // return_result after call_some_functions + RETURN_EMPTY_STRING(); // RETVAL_EMPTY_STRING(); return; + } + zend_string* retval = strpprintf(0, "%s", pval); + free(pval); + RETURN_STR(retval); + // come here ??? +} + +// add_subkey +// bool k2hdkc_pm_set_str_subkey_wa(k2hdkc_chmpx_h handle, const char* pkey, const char* psubkey, const char* pskeyval, bool checkattr, const char* encpass, const time_t* expire) +PHP_FUNCTION(k2hdkcpx_add_subkey) +{ + // declare_variables + zval * zval_k2hdkc_chmpx_handle_ptr = NULL; + char* key = NULL; + size_t key_len = 0; + char* subkey = NULL; + size_t subkey_len = 0; + char* subval = NULL; + size_t subval_len = 0; + zend_bool is_attr_checked = true; + char* password = NULL; + size_t password_len = 0; + zend_long expire = 0; + + // assign_after_declare + ZEND_PARSE_PARAMETERS_START(4, 7) + Z_PARAM_RESOURCE(zval_k2hdkc_chmpx_handle_ptr) + Z_PARAM_STRING(key, key_len) + Z_PARAM_STRING(subkey, subkey_len) + Z_PARAM_STRING(subval, subval_len) + Z_PARAM_OPTIONAL + Z_PARAM_BOOL(is_attr_checked) + Z_PARAM_STRING(password, password_len) + Z_PARAM_LONG(expire) + ZEND_PARSE_PARAMETERS_END(); + + // validate_after_assign + time_t* ptmexpire = NULL; + if (expire > 0) { + ptmexpire = (time_t*)&expire; + } + + // get_resources after get_props + k2hdkc_chmpx_h* k2hdkc_chmpx_handle_ptr = (k2hdkc_chmpx_h *)zend_fetch_resource(Z_RES_P(zval_k2hdkc_chmpx_handle_ptr), "chmpx_handle_resource", k2hdkcpx_handle_resource_number); + if (K2HDKC_INVALID_HANDLE == *k2hdkc_chmpx_handle_ptr) { + php_error(E_NOTICE, "_handle property is invalid"); + RETURN_FALSE; // RETVAL_FALSE; return; + } + + // call_some_functions after get_resources + bool bResult = k2hdkc_pm_set_str_subkey_wa(*k2hdkc_chmpx_handle_ptr, key, subkey, subval, is_attr_checked, password, ptmexpire); + // return_result after call_some_functions + if (bResult) { + RETURN_TRUE; // RETVAL_TRUE; return; + } + RETURN_FALSE; + +} + +// cas_get +// bool k2hdkc_pm_cas64_str_get_wa(k2hdkc_chmpx_h handle, const char* pkey, const char* encpass, uint64_t* pval) +PHP_FUNCTION(k2hdkcpx_cas_get) +{ + // declare_variables + zval * zval_k2hdkc_chmpx_handle_ptr = NULL; + char* key = NULL; + size_t key_len = 0; + char* password = NULL; + size_t password_len = 0; + + // assign_after_declare + ZEND_PARSE_PARAMETERS_START(2, 3) + Z_PARAM_RESOURCE(zval_k2hdkc_chmpx_handle_ptr) + Z_PARAM_STRING(key, key_len) + Z_PARAM_OPTIONAL + Z_PARAM_STRING(password, password_len) + ZEND_PARSE_PARAMETERS_END(); + + // get_resources after get_props + k2hdkc_chmpx_h* k2hdkc_chmpx_handle_ptr = (k2hdkc_chmpx_h *)zend_fetch_resource(Z_RES_P(zval_k2hdkc_chmpx_handle_ptr), "chmpx_handle_resource", k2hdkcpx_handle_resource_number); + if (K2HDKC_INVALID_HANDLE == *k2hdkc_chmpx_handle_ptr) { + php_error(E_NOTICE, "_handle property is invalid"); + RETURN_FALSE; // RETVAL_FALSE; return; + } + + // call_some_functions after get_resources + // bool bResult = k2hdkc_pm_cas64_str_get_wa(*k2hdkc_chmpx_handle_ptr, key, NULL, (uint64_t*)&pval); + int pval = 0; + bool bResult = k2hdkc_pm_cas64_str_get_wa(*k2hdkc_chmpx_handle_ptr, key, NULL, (uint64_t*)&pval); + if (!bResult || !pval) { + // return_result after call_some_functions + RETURN_FALSE; + } + RETURN_LONG(pval); +} + +// cas_decrement +// bool k2hdkc_pm_cas_str_decrement_wa(k2hdkc_chmpx_h handle, const char* pkey, const char* encpass, const time_t* expire) +PHP_FUNCTION(k2hdkcpx_cas_decrement) +{ + // declare_variables + zval * zval_k2hdkc_chmpx_handle_ptr = NULL; + char* key = NULL; + size_t key_len = 0; + char* password = NULL; + size_t password_len = 0; + zend_long expire = 0; + + // assign_after_declare + ZEND_PARSE_PARAMETERS_START(2, 4) + Z_PARAM_RESOURCE(zval_k2hdkc_chmpx_handle_ptr) + Z_PARAM_STRING(key, key_len) + Z_PARAM_OPTIONAL + Z_PARAM_STRING(password, password_len) + Z_PARAM_LONG(expire) + ZEND_PARSE_PARAMETERS_END(); + + // validate_after_assign + time_t* ptmexpire = NULL; + if (expire > 0) { + ptmexpire = (time_t*)&expire; + } + + // get_resources after get_props + k2hdkc_chmpx_h* k2hdkc_chmpx_handle_ptr = (k2hdkc_chmpx_h *)zend_fetch_resource(Z_RES_P(zval_k2hdkc_chmpx_handle_ptr), "chmpx_handle_resource", k2hdkcpx_handle_resource_number); + if (K2HDKC_INVALID_HANDLE == *k2hdkc_chmpx_handle_ptr) { + php_error(E_NOTICE, "_handle property is invalid"); + RETURN_FALSE; // RETVAL_FALSE; return; + } + + // call_some_functions after get_resources + // bool k2hdkc_pm_cas_str_decrement_wa(k2hdkc_chmpx_h handle, const char* pkey, const char* encpass, const time_t* expire) + bool bResult = k2hdkc_pm_cas_str_decrement_wa(*k2hdkc_chmpx_handle_ptr, key, password, ptmexpire); + if (!bResult) { + // return_result after call_some_functions + php_error(E_NOTICE, "k2hdkc_pm_cas_str_decrement_wa should return true, but false"); + RETURN_FALSE; // RETVAL_FALSE; return; + } + RETURN_TRUE; // RETVAL_TRUE; return; +} + +// cas_increment +// bool k2hdkc_pm_cas_str_increment_wa(k2hdkc_chmpx_h handle, const char* pkey, const char* encpass, const time_t* expire) +PHP_FUNCTION(k2hdkcpx_cas_increment) +{ + // declare_variables + zval * zval_k2hdkc_chmpx_handle_ptr = NULL; + char* key = NULL; + size_t key_len = 0; + char* password = NULL; + size_t password_len = 0; + zend_long expire = 0; + + // assign_after_declare + ZEND_PARSE_PARAMETERS_START(2, 4) + Z_PARAM_RESOURCE(zval_k2hdkc_chmpx_handle_ptr) + Z_PARAM_STRING(key, key_len) + Z_PARAM_OPTIONAL + Z_PARAM_STRING(password, password_len) + Z_PARAM_LONG(expire) + ZEND_PARSE_PARAMETERS_END(); + + // validate_after_assign + time_t* ptmexpire = NULL; + if (expire > 0) { + ptmexpire = (time_t*)&expire; + } + + // get_resources after get_props + k2hdkc_chmpx_h* k2hdkc_chmpx_handle_ptr = (k2hdkc_chmpx_h *)zend_fetch_resource(Z_RES_P(zval_k2hdkc_chmpx_handle_ptr), "chmpx_handle_resource", k2hdkcpx_handle_resource_number); + if (K2HDKC_INVALID_HANDLE == *k2hdkc_chmpx_handle_ptr) { + php_error(E_NOTICE, "_handle property is invalid"); + RETURN_FALSE; // RETVAL_FALSE; return; + } + + // call_some_functions after get_resources + // bool k2hdkc_pm_cas_str_increment_wa(k2hdkc_chmpx_h handle, const char* pkey, const char* encpass, const time_t* expire) + bool bResult = k2hdkc_pm_cas_str_increment_wa(*k2hdkc_chmpx_handle_ptr, key, password, ptmexpire); + if (!bResult) { + // return_result after call_some_functions + php_error(E_NOTICE, "k2hdkc_pm_cas_str_increment_wa should return true, but false"); + RETURN_FALSE; // RETVAL_FALSE; return; + } + RETURN_TRUE; // RETVAL_TRUE; return; +} + +// cas_init +// bool k2hdkc_pm_cas8_str_init_wa(k2hdkc_chmpx_h handle, const char* pkey, uint8_t val, const char* encpass, const time_t* expire) +PHP_FUNCTION(k2hdkcpx_cas_init) +{ + // declare_variables + zval * zval_k2hdkc_chmpx_handle_ptr = NULL; + char* key = NULL; + size_t key_len = 0; + zend_long val = 0; + char* password = NULL; + size_t password_len = 0; + zend_long expire = 0; + + // assign_after_declare + ZEND_PARSE_PARAMETERS_START(3, 5) + Z_PARAM_RESOURCE(zval_k2hdkc_chmpx_handle_ptr) + Z_PARAM_STRING(key, key_len) + Z_PARAM_LONG(val) + Z_PARAM_OPTIONAL + Z_PARAM_STRING(password, password_len) + Z_PARAM_LONG(expire) + ZEND_PARSE_PARAMETERS_END(); + + // validate_after_assign + time_t* ptmexpire = NULL; + if (expire > 0) { + ptmexpire = (time_t*)&expire; + } + + // get_resources after get_props + k2hdkc_chmpx_h* k2hdkc_chmpx_handle_ptr = (k2hdkc_chmpx_h *)zend_fetch_resource(Z_RES_P(zval_k2hdkc_chmpx_handle_ptr), "chmpx_handle_resource", k2hdkcpx_handle_resource_number); + if (K2HDKC_INVALID_HANDLE == *k2hdkc_chmpx_handle_ptr) { + php_error(E_NOTICE, "_handle property is invalid"); + RETURN_FALSE; // RETVAL_FALSE; return; + } + + // call_some_functions after get_resources + // bool k2hdkc_pm_cas64_str_init_wa(k2hdkc_chmpx_h handle, const char* pkey, uint64_t val, const char* encpass, const time_t* expire) + bool bResult = k2hdkc_pm_cas64_str_init_wa(*k2hdkc_chmpx_handle_ptr, key, (uint64_t)val, password, ptmexpire); + if (!bResult) { + // return_result after call_some_functions + php_error(E_NOTICE, "k2hdkc_pm_cas64_str_init_wa should return true, but false"); + RETURN_FALSE; // RETVAL_FALSE; return; + } + RETURN_TRUE; // RETVAL_TRUE; return; +} + +// cas_set +// bool k2hdkc_pm_cas8_str_set_wa(k2hdkc_chmpx_h handle, const char* pkey, uint8_t oldval, uint8_t newval, const char* encpass, const time_t* expire) +PHP_FUNCTION(k2hdkcpx_cas_set) +{ + // declare_variables + zval * zval_k2hdkc_chmpx_handle_ptr = NULL; + char* key = NULL; + size_t key_len = 0; + zend_long old_val = 0; + zend_long new_val = 0; + char* password = NULL; + size_t password_len = 0; + zend_long expire = 0; + + // assign_after_declare + ZEND_PARSE_PARAMETERS_START(4, 6) + Z_PARAM_RESOURCE(zval_k2hdkc_chmpx_handle_ptr) + Z_PARAM_STRING(key, key_len) + Z_PARAM_LONG(old_val) + Z_PARAM_LONG(new_val) + Z_PARAM_OPTIONAL + Z_PARAM_STRING(password, password_len) + Z_PARAM_LONG(expire) + ZEND_PARSE_PARAMETERS_END(); + + // validate_after_assign + time_t* ptmexpire = NULL; + if (expire > 0) { + ptmexpire = (time_t*)&expire; + } + + // get_resources after get_props + k2hdkc_chmpx_h* k2hdkc_chmpx_handle_ptr = (k2hdkc_chmpx_h *)zend_fetch_resource(Z_RES_P(zval_k2hdkc_chmpx_handle_ptr), "chmpx_handle_resource", k2hdkcpx_handle_resource_number); + if (K2HDKC_INVALID_HANDLE == *k2hdkc_chmpx_handle_ptr) { + php_error(E_NOTICE, "_handle property is invalid"); + RETURN_FALSE; // RETVAL_FALSE; return; + } + + // call_some_functions after get_resources + // bool k2hdkc_pm_cas64_str_set_wa(k2hdkc_chmpx_h handle, const char* pkey, uint64_t oldval, uint64_t newval, const char* encpass, const time_t* expire) + bool bResult = k2hdkc_pm_cas64_str_set_wa(*k2hdkc_chmpx_handle_ptr, key, old_val, new_val, password, ptmexpire); + if (!bResult) { + // return_result after call_some_functions + php_error(E_NOTICE, "k2hdkc_pm_cas64_str_set_wa should return true, but false"); + RETURN_FALSE; // RETVAL_FALSE; return; + } + RETURN_TRUE; // RETVAL_TRUE; return; +} + +// clear_subkeys +// bool k2hdkc_pm_clear_str_subkeys(k2hdkc_chmpx_h handle, const char* pkey) +PHP_FUNCTION(k2hdkcpx_clear_subkeys) +{ + // declare_variables + zval * zval_k2hdkc_chmpx_handle_ptr = NULL; + char* key = NULL; + size_t key_len = 0; + + // assign_after_declare + ZEND_PARSE_PARAMETERS_START(2, 2) + Z_PARAM_RESOURCE(zval_k2hdkc_chmpx_handle_ptr) + Z_PARAM_STRING(key, key_len) + ZEND_PARSE_PARAMETERS_END(); + + // get_resources after get_props + k2hdkc_chmpx_h* k2hdkc_chmpx_handle_ptr = (k2hdkc_chmpx_h *)zend_fetch_resource(Z_RES_P(zval_k2hdkc_chmpx_handle_ptr), "chmpx_handle_resource", k2hdkcpx_handle_resource_number); + if (K2HDKC_INVALID_HANDLE == *k2hdkc_chmpx_handle_ptr) { + php_error(E_NOTICE, "_handle property is invalid"); + RETURN_FALSE; // RETVAL_FALSE; return; + } + + // call_some_functions after get_resources + //// bool k2hdkc_pm_clear_str_subkeys(k2hdkc_chmpx_h handle, const char* pkey) + bool bResult = k2hdkc_pm_clear_str_subkeys(*k2hdkc_chmpx_handle_ptr, key); + if (!bResult) { + // return_result after call_some_functions + php_error(E_NOTICE, "k2hdkc_pm_clear_str_subkeys should return true, but false"); + RETURN_FALSE; // RETVAL_FALSE; return; + } + RETURN_TRUE; // RETVAL_TRUE; return; +} + +// bool k2hdkc_close_chmpx_ex(k2hdkc_chmpx_h handle, bool is_clean_bup) +PHP_FUNCTION(k2hdkcpx_close) +{ + // declare_variables + zval* zval_k2hdkc_chmpx_handle_ptr = NULL; + zend_bool clean_bup = true; + + // assign_after_declare + ZEND_PARSE_PARAMETERS_START(1, 2) + Z_PARAM_RESOURCE(zval_k2hdkc_chmpx_handle_ptr) + Z_PARAM_OPTIONAL + Z_PARAM_BOOL(clean_bup) + ZEND_PARSE_PARAMETERS_END(); + + // validate_after_assign + ZEND_ASSERT(Z_TYPE_P(zval_k2hdkc_chmpx_handle_ptr) == IS_RESOURCE); + if(!zval_k2hdkc_chmpx_handle_ptr) { + php_error(E_ERROR, "k2hdkcpx_close: handle is empty."); + RETURN_FALSE; + } + + // get_resources + k2hdkc_chmpx_h* chmpx_handle_ptr = (chmpx_h *)zend_fetch_resource(Z_RES_P(zval_k2hdkc_chmpx_handle_ptr), "chmpx_handle_resource", k2hdkcpx_handle_resource_number); + + // call_some_functions after get_resources + k2hdkc_close_chmpx_ex(*chmpx_handle_ptr, clean_bup); + + // return_result after call_some_functions + RETURN_TRUE; +} + + +// get_attributes +// PK2HDKCATTRPCK k2hdkc_pm_get_str_direct_attrs(k2hdkc_chmpx_h handle, const char* pkey, int* pattrspckcnt) +PHP_FUNCTION(k2hdkcpx_get_attributes) +{ + // declare_variables + zval * zval_k2hdkc_chmpx_handle_ptr = NULL; + char* key = NULL; + size_t key_len = 0; + + // assign_after_declare + ZEND_PARSE_PARAMETERS_START(2, 2) + Z_PARAM_RESOURCE(zval_k2hdkc_chmpx_handle_ptr) + Z_PARAM_STRING(key, key_len) + ZEND_PARSE_PARAMETERS_END(); + + // get_resources after get_props + k2hdkc_chmpx_h* k2hdkc_chmpx_handle_ptr; + k2hdkc_chmpx_handle_ptr = (k2hdkc_chmpx_h *)zend_fetch_resource(Z_RES_P(zval_k2hdkc_chmpx_handle_ptr), "chmpx_handle_resource", k2hdkcpx_handle_resource_number); + if (K2HDKC_INVALID_HANDLE == *k2hdkc_chmpx_handle_ptr) { + php_error(E_NOTICE, "_handle property is invalid"); + RETURN_EMPTY_STRING(); // RETVAL_EMPTY_STRING(); return; + } + + // call_some_functions after get_resources + //// PK2HDKCATTRPCK k2hdkc_pm_get_str_direct_attrs(k2hdkc_chmpx_h handle, const char* pkey, int* pattrspckcnt) + int attrspckcnt = 0; + PK2HDKCATTRPCK pattrs = k2hdkc_pm_get_str_direct_attrs(*k2hdkc_chmpx_handle_ptr, key, &attrspckcnt); + if (pattrs && attrspckcnt > 0) { + array_init(return_value); // zval* return_value + int cnt; + for(cnt = 0; cnt < attrspckcnt; ++cnt) { + char* pattrkey; + if(NULL != (pattrkey = (char*)emalloc(pattrs[cnt].keylength + 1))) { + memcpy(pattrkey, pattrs[cnt].pkey, pattrs[cnt].keylength); + pattrkey[pattrs[cnt].keylength] = '\0'; + add_next_index_string(return_value, pattrkey); + efree(pattrkey); + } + } + } + if(pattrs) { + k2h_free_attrpack(pattrs, attrspckcnt); + } +} + +// get_subkeys +// PK2HDKCKEYPCK k2hdkc_pm_get_direct_subkeys(k2hdkc_chmpx_h handle, const unsigned char* pkey, size_t keylength, int* pskeypckcnt) +PHP_FUNCTION(k2hdkcpx_get_subkeys) +{ + // declare_variables + zval * zval_k2hdkc_chmpx_handle_ptr = NULL; + char* key = NULL; + size_t key_len = 0; + + // assign_after_declare + ZEND_PARSE_PARAMETERS_START(2, 2) + Z_PARAM_RESOURCE(zval_k2hdkc_chmpx_handle_ptr) + Z_PARAM_STRING(key, key_len) + Z_PARAM_OPTIONAL + ZEND_PARSE_PARAMETERS_END(); + + // get_resources after get_props + k2hdkc_chmpx_h* k2hdkc_chmpx_handle_ptr; + k2hdkc_chmpx_handle_ptr = (k2hdkc_chmpx_h *)zend_fetch_resource(Z_RES_P(zval_k2hdkc_chmpx_handle_ptr), "chmpx_handle_resource", k2hdkcpx_handle_resource_number); + if (K2HDKC_INVALID_HANDLE == *k2hdkc_chmpx_handle_ptr) { + php_error(E_NOTICE, "_handle property is invalid"); + RETURN_EMPTY_STRING(); // RETVAL_EMPTY_STRING(); return; + } + + // call_some_functions after get_resources + //// char** k2hdkc_pm_get_str_direct_subkeys(k2hdkc_chmpx_h handle, const char* pkey) + char** pskeyarray = k2hdkc_pm_get_str_direct_subkeys(*k2hdkc_chmpx_handle_ptr, key); + array_init(return_value); // zval* return_value + if (pskeyarray) { + char** ptmp = NULL; + for (ptmp = pskeyarray; *ptmp; ptmp++) { + add_next_index_str(return_value, strpprintf(0, "%s", *ptmp)); + free(*ptmp); + } + } +} + +// queue_get +// bool k2hdkc_pm_q_str_pop_wp(k2hdkc_chmpx_h handle, const char* pprefix, bool is_fifo, const char* encpass, const char** ppval) +PHP_FUNCTION(k2hdkcpx_queue_get) +{ + // declare_variables + zval * zval_k2hdkc_chmpx_handle_ptr = NULL; + char* prefix = NULL; + size_t prefix_len = 0; + zend_bool is_fifo = true; + char* password = NULL; + size_t password_len = 0; + + // assign_after_declare + ZEND_PARSE_PARAMETERS_START(2, 4) + Z_PARAM_RESOURCE(zval_k2hdkc_chmpx_handle_ptr) + Z_PARAM_STRING(prefix, prefix_len) + Z_PARAM_OPTIONAL + Z_PARAM_BOOL(is_fifo) + Z_PARAM_STRING(password, password_len) + ZEND_PARSE_PARAMETERS_END(); + + // get_resources after get_props + k2hdkc_chmpx_h* k2hdkc_chmpx_handle_ptr = (k2hdkc_chmpx_h *)zend_fetch_resource(Z_RES_P(zval_k2hdkc_chmpx_handle_ptr), "chmpx_handle_resource", k2hdkcpx_handle_resource_number); + if (K2HDKC_INVALID_HANDLE == *k2hdkc_chmpx_handle_ptr) { + php_error(E_NOTICE, "_handle property is invalid"); + RETURN_FALSE; // RETVAL_FALSE; return; + } + + // call_some_functions after get_resources + // bool k2hdkc_pm_q_str_pop_wp(k2hdkc_chmpx_h handle, const char* pprefix, bool is_fifo, const char* encpass, const char** ppval) + const char* pval = NULL; + bool bResult = k2hdkc_pm_q_str_pop_wp(*k2hdkc_chmpx_handle_ptr, prefix, is_fifo, NULL, &pval); + if (!bResult) { + php_error(E_NOTICE, "k2hdkc_pm_q_str_pop_wp should return true, but false"); + RETURN_EMPTY_STRING(); // RETVAL_EMPTY_STRING(); return; + } + zend_string* retval = strpprintf(0, "%s", pval); + RETURN_STR(retval); +} + +// queue_put +// bool k2hdkc_pm_q_str_push_wa(k2hdkc_chmpx_h handle, const char* pprefix, const char* pval, bool is_fifo, bool checkattr, const char* encpass, const time_t* expire) +PHP_FUNCTION(k2hdkcpx_queue_put) +{ + // declare_variables + zval * zval_k2hdkc_chmpx_handle_ptr = NULL; + char* prefix = NULL; + size_t prefix_len = 0; + char* val = NULL; + size_t val_len = 0; + zend_bool is_fifo = true; + zend_bool is_attr_checked = true; + char* password = NULL; + size_t password_len = 0; + zend_long expire = 0; + + // assign_after_declare + ZEND_PARSE_PARAMETERS_START(3, 7) + Z_PARAM_RESOURCE(zval_k2hdkc_chmpx_handle_ptr) + Z_PARAM_STRING(prefix, prefix_len) + Z_PARAM_STRING(val, val_len) + Z_PARAM_OPTIONAL + Z_PARAM_BOOL(is_fifo) + Z_PARAM_BOOL(is_attr_checked) + Z_PARAM_STRING(password, password_len) + Z_PARAM_LONG(expire) + ZEND_PARSE_PARAMETERS_END(); + + // validate_after_assign + time_t* ptmexpire = NULL; + if (expire > 0) { + ptmexpire = (time_t*)&expire; + } + + // get_resources after get_props + k2hdkc_chmpx_h* k2hdkc_chmpx_handle_ptr = (k2hdkc_chmpx_h *)zend_fetch_resource(Z_RES_P(zval_k2hdkc_chmpx_handle_ptr), "chmpx_handle_resource", k2hdkcpx_handle_resource_number); + if (K2HDKC_INVALID_HANDLE == *k2hdkc_chmpx_handle_ptr) { + php_error(E_NOTICE, "_handle property is invalid"); + RETURN_FALSE; // RETVAL_FALSE; return; + } + + // call_some_functions after get_resources + // bool k2hdkc_pm_q_str_push_wa(k2hdkc_chmpx_h handle, const char* pprefix, const char* pval, bool is_fifo, bool checkattr, const char* encpass, const time_t* expire) + bool bResult = k2hdkc_pm_q_str_push_wa(*k2hdkc_chmpx_handle_ptr, prefix, val, is_fifo, is_attr_checked, password, ptmexpire); + if (!bResult) { + php_error(E_NOTICE, "k2hdkc_pm_q_str_push_wa should return true but false"); + RETURN_FALSE; // RETVAL_FALSE; return; + } + RETURN_TRUE; // RETVAL_TRUE; return; +} + +// keyqueue_get +// bool k2hdkc_pm_keyq_str_pop_wp(k2hdkc_chmpx_h handle, const char* pprefix, bool is_fifo, const char* encpass, const char** ppkey, const char** ppval) +PHP_FUNCTION(k2hdkcpx_key_queue_get) +{ + // declare_variables + zval * zval_k2hdkc_chmpx_handle_ptr = NULL; + char* prefix = NULL; + size_t prefix_len = 0; + zend_bool is_fifo = true; + char* password = NULL; + size_t password_len = 0; + + // assign_after_declare + ZEND_PARSE_PARAMETERS_START(2, 4) + Z_PARAM_RESOURCE(zval_k2hdkc_chmpx_handle_ptr) + Z_PARAM_STRING(prefix, prefix_len) + Z_PARAM_OPTIONAL + Z_PARAM_BOOL(is_fifo) + Z_PARAM_STRING(password, password_len) + ZEND_PARSE_PARAMETERS_END(); + + // get_resources after get_props + k2hdkc_chmpx_h* k2hdkc_chmpx_handle_ptr = (k2hdkc_chmpx_h *)zend_fetch_resource(Z_RES_P(zval_k2hdkc_chmpx_handle_ptr), "chmpx_handle_resource", k2hdkcpx_handle_resource_number); + if (K2HDKC_INVALID_HANDLE == *k2hdkc_chmpx_handle_ptr) { + php_error(E_NOTICE, "_handle property is invalid"); + RETURN_FALSE; // RETVAL_FALSE; return; + } + + // call_some_functions after get_resources + // bool k2hdkc_pm_keyq_str_pop_wp(k2hdkc_chmpx_h handle, const char* pprefix, bool is_fifo, const char* encpass, const char** ppkey, const char** ppval) + const char* pkey = NULL; + const char* pval = NULL; + k2hdkc_pm_keyq_str_pop_wp(*k2hdkc_chmpx_handle_ptr, prefix, is_fifo, NULL, &pkey, &pval); + array_init(return_value); // zval* return_value + if (pkey && pval) { + add_assoc_string(return_value, pkey, pval); + } +} + +// keyqueue_put +// bool k2hdkc_pm_keyq_str_push_wa(k2hdkc_chmpx_h handle, const char* pprefix, const char* pkey, const char* pval, bool is_fifo, bool checkattr, const char* encpass, const time_t* expire) +PHP_FUNCTION(k2hdkcpx_key_queue_put) +{ + // declare_variables + zval * zval_k2hdkc_chmpx_handle_ptr = NULL; + char* prefix = NULL; + size_t prefix_len = 0; + char* key = NULL; + size_t key_len = 0; + char* val = NULL; + size_t val_len = 0; + zend_bool is_fifo = true; + zend_bool is_attr_checked = true; + char* password = NULL; + size_t password_len = 0; + zend_long expire = 0; + + // assign_after_declare + ZEND_PARSE_PARAMETERS_START(4, 8) + Z_PARAM_RESOURCE(zval_k2hdkc_chmpx_handle_ptr) + Z_PARAM_STRING(prefix, prefix_len) + Z_PARAM_STRING(key, key_len) + Z_PARAM_STRING(val, val_len) + Z_PARAM_OPTIONAL + Z_PARAM_BOOL(is_fifo) + Z_PARAM_BOOL(is_attr_checked) + Z_PARAM_STRING(password, password_len) + Z_PARAM_LONG(expire) + ZEND_PARSE_PARAMETERS_END(); + + // validate_after_assign + time_t* ptmexpire = NULL; + if (expire > 0) { + ptmexpire = (time_t*)&expire; + } + + // get_resources after get_props + k2hdkc_chmpx_h* k2hdkc_chmpx_handle_ptr = (k2hdkc_chmpx_h *)zend_fetch_resource(Z_RES_P(zval_k2hdkc_chmpx_handle_ptr), "chmpx_handle_resource", k2hdkcpx_handle_resource_number); + if (K2HDKC_INVALID_HANDLE == *k2hdkc_chmpx_handle_ptr) { + php_error(E_NOTICE, "_handle property is invalid"); + RETURN_FALSE; // RETVAL_FALSE; return; + } + + // call_some_functions after get_resources + // bool k2hdkc_pm_keyq_str_push_wa(k2hdkc_chmpx_h handle, const char* pprefix, const char* pkey, const char* pval, bool is_fifo, bool checkattr, const char* encpass, const time_t* expire) + bool bResult = k2hdkc_pm_keyq_str_push_wa(*k2hdkc_chmpx_handle_ptr, prefix, key, val, is_fifo, is_attr_checked, password, ptmexpire); + if (!bResult) { + php_error(E_NOTICE, "k2hdkc_pm_keyq_str_push_wa should return true but false"); + RETURN_FALSE; // RETVAL_FALSE; return; + } + RETURN_TRUE; // RETVAL_TRUE; return; +} + + +// remove +// bool k2hdkc_pm_remove_str(k2hdkc_chmpx_h handle, const char* pkey) +PHP_FUNCTION(k2hdkcpx_remove) +{ + // declare_variables + zval * zval_k2hdkc_chmpx_handle_ptr = NULL; + char* key = NULL; + size_t key_len = 0; + + // assign_after_declare + ZEND_PARSE_PARAMETERS_START(2, 2) + Z_PARAM_RESOURCE(zval_k2hdkc_chmpx_handle_ptr) + Z_PARAM_STRING(key, key_len) + Z_PARAM_OPTIONAL + ZEND_PARSE_PARAMETERS_END(); + + // get_resources after get_props + k2hdkc_chmpx_h* k2hdkc_chmpx_handle_ptr; + k2hdkc_chmpx_handle_ptr = (k2hdkc_chmpx_h *)zend_fetch_resource(Z_RES_P(zval_k2hdkc_chmpx_handle_ptr), "chmpx_handle_resource", k2hdkcpx_handle_resource_number); + if (K2HDKC_INVALID_HANDLE == *k2hdkc_chmpx_handle_ptr) { + php_error(E_NOTICE, "_handle property is invalid"); + RETURN_FALSE; // RETVAL_FALSE; return; + } + + // call_some_functions after get_resources + //// bool k2hdkc_pm_remove_str(k2hdkc_chmpx_h handle, const char* pkey) + if (!k2hdkc_pm_remove_str(*k2hdkc_chmpx_handle_ptr, key)) { + php_error(E_NOTICE, "k2hdkc_pm_remove_str should return true but false"); + RETURN_FALSE; // RETVAL_FALSE; return; + } + RETURN_TRUE; // RETVAL_TRUE; return; +} + +// remove_subkeys +// bool k2hdkc_pm_remove_str_subkey(k2hdkc_chmpx_h handle, const char* pkey, const char* psubkey, size_t subkeylength, bool is_nest) +PHP_FUNCTION(k2hdkcpx_remove_subkeys) +{ + // declare_variables + zval * zval_k2hdkc_chmpx_handle_ptr = NULL; + char* key = NULL; + size_t key_len = 0; + zval* subkeys = NULL; + zend_bool is_nested = false; + + // assign_after_declare + ZEND_PARSE_PARAMETERS_START(3, 4) + Z_PARAM_RESOURCE(zval_k2hdkc_chmpx_handle_ptr) + Z_PARAM_STRING(key, key_len) + Z_PARAM_ARRAY(subkeys) + Z_PARAM_OPTIONAL + Z_PARAM_BOOL(is_nested) + ZEND_PARSE_PARAMETERS_END(); + + // get_resources after get_props + k2hdkc_chmpx_h* k2hdkc_chmpx_handle_ptr = (k2hdkc_chmpx_h *)zend_fetch_resource(Z_RES_P(zval_k2hdkc_chmpx_handle_ptr), "chmpx_handle_resource", k2hdkcpx_handle_resource_number); + if (K2HDKC_INVALID_HANDLE == *k2hdkc_chmpx_handle_ptr) { + php_error(E_NOTICE, "_handle property is invalid"); + RETURN_FALSE; // RETVAL_FALSE; return; + } + + // call_some_functions after get_resources + //// bool k2hdkc_pm_remove_str_subkey(k2hdkc_chmpx_h handle, const char* pkey, const char* psubkey, size_t subkeylength, bool is_nest) + if (subkeys && Z_TYPE_P(subkeys) == IS_ARRAY) { + zend_ulong zulong_idx= 0; + zend_string* zstring_key = NULL; + zval* zv_val = NULL; + + ZEND_HASH_FOREACH_KEY_VAL(Z_ARR(*subkeys), zulong_idx, zstring_key, zv_val) { + char* subkey = Z_STRVAL_P(zv_val); + bool bResult = k2hdkc_pm_remove_str_subkey(*k2hdkc_chmpx_handle_ptr, key, subkey, is_nested); + if (!bResult) { + // return_result after call_some_functions + php_error(E_NOTICE, "k2hdkc_pm_remove_str_subkey should return true, but false"); + RETURN_FALSE; // RETVAL_FALSE; return; + } + } ZEND_HASH_FOREACH_END(); + } + RETURN_TRUE; // RETVAL_TRUE; return; +} + +// rename +// bool k2hdkc_pm_rename_with_parent_str_wa(k2hdkc_chmpx_h handle, const char* poldkey, const char* pnewkey, const char* pparentkey, bool checkattr, const char* encpass, const time_t* expire) +PHP_FUNCTION(k2hdkcpx_rename) +{ + // declare_variables + zval * zval_k2hdkc_chmpx_handle_ptr = NULL; + char* key = NULL; + size_t key_len = 0; + char* newKey = NULL; + size_t newKey_len = 0; + char* parentKey = NULL; + size_t parentKey_len = 0; + zend_bool is_attr_checked = true; + char* password = NULL; + size_t password_len = 0; + zend_long expire = 0; + + // assign_after_declare + ZEND_PARSE_PARAMETERS_START(3, 7) + Z_PARAM_RESOURCE(zval_k2hdkc_chmpx_handle_ptr) + Z_PARAM_STRING(key, key_len) + Z_PARAM_STRING(newKey, newKey_len) + Z_PARAM_OPTIONAL + Z_PARAM_STRING(parentKey, parentKey_len) + Z_PARAM_BOOL(is_attr_checked) + Z_PARAM_STRING(password, password_len) + Z_PARAM_LONG(expire) + ZEND_PARSE_PARAMETERS_END(); + + // validate_after_assign + time_t* ptmexpire = NULL; + if (expire > 0) { + ptmexpire = (time_t*)&expire; + } + + // get_resources after get_props + k2hdkc_chmpx_h* k2hdkc_chmpx_handle_ptr = (k2hdkc_chmpx_h *)zend_fetch_resource(Z_RES_P(zval_k2hdkc_chmpx_handle_ptr), "chmpx_handle_resource", k2hdkcpx_handle_resource_number); + if (K2HDKC_INVALID_HANDLE == *k2hdkc_chmpx_handle_ptr) { + php_error(E_NOTICE, "_handle property is invalid"); + RETURN_FALSE; // RETVAL_FALSE; return; + } + + // call_some_functions after get_resources + //// bool k2hdkc_pm_rename_with_parent_str_wa(k2hdkc_chmpx_h handle, const char* poldkey, const char* pnewkey, const char* pparentkey, bool checkattr, const char* encpass, const time_t* expire) + bool bResult = k2hdkc_pm_rename_with_parent_str_wa(*k2hdkc_chmpx_handle_ptr, key, newKey, NULL, is_attr_checked, password, ptmexpire); + // return_result after call_some_functions + if (!bResult) { + // return_result after call_some_functions + php_error(E_NOTICE, "k2hdkc_pm_rename_with_parent_str_wa should return true, but false"); + RETURN_FALSE; // RETVAL_FALSE; return; + } + RETURN_TRUE; // RETVAL_TRUE; return; +} + +// set_subkeys +// bool k2hdkc_pm_set_subkeys(k2hdkc_chmpx_h handle, const unsigned char* pkey, size_t keylength, const PK2HDKCKEYPCK pskeypck, int skeypckcnt) +PHP_FUNCTION(k2hdkcpx_set_subkeys) +{ + // declare_variables + zval * zval_k2hdkc_chmpx_handle_ptr = NULL; + char* key = NULL; + size_t key_len = 0; + zval* subkeys = NULL; + + // assign_after_declare + ZEND_PARSE_PARAMETERS_START(3, 3) + Z_PARAM_RESOURCE(zval_k2hdkc_chmpx_handle_ptr) + Z_PARAM_STRING(key, key_len) + Z_PARAM_ARRAY(subkeys) + Z_PARAM_OPTIONAL + ZEND_PARSE_PARAMETERS_END(); + + // get_resources after get_props + k2hdkc_chmpx_h* k2hdkc_chmpx_handle_ptr = (k2hdkc_chmpx_h *)zend_fetch_resource(Z_RES_P(zval_k2hdkc_chmpx_handle_ptr), "chmpx_handle_resource", k2hdkcpx_handle_resource_number); + if (K2HDKC_INVALID_HANDLE == *k2hdkc_chmpx_handle_ptr) { + php_error(E_NOTICE, "_handle property is invalid"); + RETURN_FALSE; // RETVAL_FALSE; return; + } + + // call_some_functions after get_resources + // bool k2hdkc_pm_set_str_subkeys(k2hdkc_chmpx_h handle, const char* pkey, const char** pskeyarray) + bool bResult = false; + if (subkeys && Z_TYPE_P(subkeys) == IS_ARRAY) { + int skeypckcnt = zend_array_count(Z_ARR(*subkeys)); // returns number of elements in array. + char** pskeyarray = (char**)calloc(skeypckcnt + 1, sizeof(char*)); + zend_ulong zulong_idx = 0; + zend_string* zstring_key = NULL; + zval* zv_val = NULL; + + ZEND_HASH_FOREACH_KEY_VAL(Z_ARR(*subkeys), zulong_idx, zstring_key, zv_val) { + char* subkey = Z_STRVAL_P(zv_val); + pskeyarray[zulong_idx] = (char*)malloc(strlen(subkey) + 1); + memcpy(pskeyarray[zulong_idx], subkey, strlen(subkey)); + pskeyarray[zulong_idx][strlen(subkey)] = '\0'; + } ZEND_HASH_FOREACH_END(); + + bResult = k2hdkc_pm_set_str_subkeys(*k2hdkc_chmpx_handle_ptr, key, (const char**)pskeyarray); + if (pskeyarray) { + char** ptmp = NULL; + for (ptmp = pskeyarray; *ptmp; ptmp++) { + free(*ptmp); + } + } + } + // return_result after call_some_functions + if (bResult) { + RETURN_TRUE; // RETVAL_TRUE; return; + } + RETURN_FALSE; +} + +// void k2hdkc_bump_debug_level(void) +PHP_FUNCTION(k2hdkcpx_bump_debug_level) +{ + k2hdkc_bump_debug_level(); +} + +// void k2hdkc_set_debug_level_silent(void) +PHP_FUNCTION(k2hdkcpx_set_debug_level_silent) +{ + k2hdkc_set_debug_level_silent(); +} + +// void k2hdkc_set_debug_level_error(void) +PHP_FUNCTION(k2hdkcpx_set_debug_level_error) +{ + k2hdkc_set_debug_level_error(); +} + +// void k2hdkc_set_debug_level_warning(void) +PHP_FUNCTION(k2hdkcpx_set_debug_level_warning) +{ + k2hdkc_set_debug_level_warning(); +} + +// void k2hdkc_set_debug_level_message(void) +PHP_FUNCTION(k2hdkcpx_set_debug_level_message) +{ + k2hdkc_set_debug_level_message(); +} + +// void k2hdkc_set_debug_level_dump(void) +PHP_FUNCTION(k2hdkcpx_set_debug_level_dump) +{ + k2hdkc_set_debug_level_dump(); +} + +// bool k2hdkc_set_debug_file(const char* filepath) +PHP_FUNCTION(k2hdkcpx_set_debug_file) +{ + // declare_variables + char* filepath = NULL; + size_t filepath_len = 0; + + // assign_after_declare + ZEND_PARSE_PARAMETERS_START(1, 1) + Z_PARAM_STRING(filepath, filepath_len) + ZEND_PARSE_PARAMETERS_END(); + + // validate_after_assign + if(!filepath || 0 == filepath_len) { + php_error_docref(NULL, E_ERROR, "k2hdkcpx_set_debug_file: filepath is empty."); + RETURN_FALSE; + } + + // call_some_functions after get_resources + bool bResult = k2hdkc_set_debug_file(filepath); + + // return_result after call_some_functions + if (!bResult) { + php_error(E_NOTICE, "k2hdkcpxpx_set_debug_file: failed to set debugging file path."); + RETURN_FALSE; + } + RETURN_TRUE; +} + +// bool k2hdkc_unset_debug_file(void) +PHP_FUNCTION(k2hdkcpx_unset_debug_file) +{ + if(!k2hdkc_unset_debug_file()){ + php_error(E_NOTICE, "k2hdkcpxpx_unset_debug_file: failed to unset debugging file path."); + RETURN_FALSE; + } + RETURN_TRUE; +} + +// bool k2hdkc_load_debug_env(void) +PHP_FUNCTION(k2hdkcpx_load_debug_env) +{ + if(!k2hdkc_load_debug_env()){ + php_error(E_NOTICE, "k2hdkcpxpx_load_debug_env: failed to load environment about debugging."); + RETURN_FALSE; + } + RETURN_TRUE; +} + +// bool k2hdkc_is_enable_comlog(void) +PHP_FUNCTION(k2hdkcpx_is_enable_comlog) +{ + if(!k2hdkc_is_enable_comlog()){ + RETURN_FALSE; + } + RETURN_TRUE; +} + +// void k2hdkc_enable_comlog(void) +PHP_FUNCTION(k2hdkcpx_enable_comlog) +{ + k2hdkc_enable_comlog(); + RETURN_TRUE; +} + +// void k2hdkc_disable_comlog(void) +PHP_FUNCTION(k2hdkcpx_disable_comlog) +{ + k2hdkc_disable_comlog(); + RETURN_TRUE; +} + +// void k2hdkc_toggle_comlog(void) +PHP_FUNCTION(k2hdkcpx_toggle_comlog) +{ + k2hdkc_toggle_comlog(); + RETURN_TRUE; +} + +// +// PHP_FUNCTION ENTRIES END +// + + +// +// PHP MODULE MACROS START +// +// cppcheck-suppress unknownMacro +ZEND_DECLARE_MODULE_GLOBALS(k2hdkcpx); + + +PHP_INI_BEGIN() +STD_PHP_INI_ENTRY( + "k2hdkcpx.debug", /* configuration directive name */ + "silent", /* default value */ + PHP_INI_ALL, /* can be modified at any time */ + OnUpdateString, /* callback function to set the string value of the directive */ + k2hdkcpx_debug, /* module global variable name */ + zend_k2hdkcpx_globals, /* structure name to keep module global variables */ + k2hdkcpx_globals /* global variable to keep module global variables for a non-thread-safe build */ + ) +PHP_INI_END() + + +PHP_MINIT_FUNCTION(k2hdkcpx) +{ + // register destructors + // zend_register_list_destructors_ex must be called inside a PHP_MINIT function + // + //// k2hdkcpx_handle + k2hdkcpx_handle_resource_number = zend_register_list_destructors_ex(k2hdkcpx_handle_resource_dtor, NULL, "k2hdkcpx_handle", module_number); + + // register class entries + //// k2hdkcpx + k2hdkcpx_class_entry = register_class_K2hdkc(); // referred by arginfo.h + +#if defined(ZTS) && defined(COMPILE_DL_K2HDKCPX) + ZEND_TSRMLS_CACHE_UPDATE(); +#endif + // CONST_CS case sensitive + // CONST_PERSISTENT persistent + REGISTER_LONG_CONSTANT("K2HDKC_INVALID_HANDLE", K2HDKC_INVALID_HANDLE, CONST_CS | CONST_PERSISTENT); + + // INI + REGISTER_INI_ENTRIES(); + + return SUCCESS; +} + +PHP_MINFO_FUNCTION(k2hdkcpx) +{ + php_info_print_table_start(); + php_info_print_table_header(2, "k2hdkcpx support", "enabled"); + php_info_print_table_end(); +} + +static PHP_GINIT_FUNCTION(k2hdkcpx) +{ +#if defined(COMPILE_DL_BCMATH) && defined(ZTS) + ZEND_TSRMLS_CACHE_UPDATE(); +#endif + k2hdkcpx_globals->k2hdkcpx_debug = "silent"; +} + +PHP_RINIT_FUNCTION(k2hdkcpx) +{ +#if defined(ZTS) && defined(COMPILE_DL_K2HDKCPX) + ZEND_TSRMLS_CACHE_UPDATE(); +#endif + + char* dbgmode = K2HDKCPX_G(k2hdkcpx_debug); + if(!dbgmode || 0 == strcmp(dbgmode, "silent")) { + k2hdkc_set_debug_level_silent(); + } else if(0 == strcmp(dbgmode, "message")) { + k2hdkc_set_debug_level_message(); + } else if(0 == strcmp(dbgmode, "warning")) { + k2hdkc_set_debug_level_warning(); + } else if(0 == strcmp(dbgmode, "error")) { + k2hdkc_set_debug_level_error(); + } else { + k2hdkc_set_debug_level_silent(); + } + + return SUCCESS; +} + + +zend_module_entry k2hdkcpx_module_entry = { + STANDARD_MODULE_HEADER, + "k2hdkcpx", /* Extension name */ + ext_functions, /* zend_function_entry */ + PHP_MINIT(k2hdkcpx), /* PHP_MINIT - Module initialization */ + NULL, /* PHP_MSHUTDOWN - Module shutdown */ + PHP_RINIT(k2hdkcpx), /* PHP_RINIT - Request initialization */ + NULL, /* PHP_RSHUTDOWN - Request shutdown */ + PHP_MINFO(k2hdkcpx), /* PHP_MINFO - Module info */ + PHP_K2HDKCPX_VERSION, /* Version */ + PHP_MODULE_GLOBALS(k2hdkcpx), /* Module globals */ + PHP_GINIT(k2hdkcpx), /* PHP_GINIT – Globals initialization */ + NULL, /* PHP_GSHUTDOWN – Globals shutdown */ + NULL, + STANDARD_MODULE_PROPERTIES_EX +}; + +#ifdef COMPILE_DL_K2HDKCPX +# ifdef ZTS +ZEND_TSRMLS_CACHE_DEFINE() +# endif +ZEND_GET_MODULE(k2hdkcpx) +#endif + +// +// PHP MODULE MACROS END +// + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * End: + * vim600: noexpandtab sw=4 ts=4 fdm=marker + * vim<600: noexpandtab sw=4 ts=4 + */ diff --git a/php_k2hdkcpx.h b/php_k2hdkcpx.h new file mode 100644 index 0000000..81b5f91 --- /dev/null +++ b/php_k2hdkcpx.h @@ -0,0 +1,62 @@ +/* +* +* K2HDKC PHP Extension library +* +* Copyright 2023 Yahoo Japan Corporation. +* +* K2HDKC is k2hash based distributed KVS cluster. +* K2HDKC uses K2HASH, CHMPX, FULLOCK libraries. K2HDKC supports +* distributed KVS cluster server program and client libraries. +* +* For the full copyright and license information, please view +* the license file that was distributed with this source code. +* +* AUTHOR: Hirotaka Wakabayashi +* CREATE: Fri, Mar 31 2023 +* REVISION: +* +*/ + +#ifndef PHP_K2HDKCPX_H +# define PHP_K2HDKCPX_H + +#include "k2hdkc.h" +#include "config.h" + +# define DEFAULT_PORT 8031 + +// cppcheck-suppress unknownMacro +ZEND_BEGIN_MODULE_GLOBALS(k2hdkcpx); +char* k2hdkcpx_debug; +// cppcheck-suppress unknownMacro +ZEND_END_MODULE_GLOBALS(k2hdkcpx); + +ZEND_EXTERN_MODULE_GLOBALS(k2hdkcpx); + +#define K2HDKCPX_G(v) ZEND_MODULE_GLOBALS_ACCESSOR(k2hdkcpx, v); + +extern zend_module_entry k2hdkcpx_module_entry; +# define phpext_k2hdkcpx_ptr &k2hdkcpx_module_entry + +extern int k2hdkcpx_handle_resource_number; + +zval* k2hdkcpx_read_property_resource(zend_class_entry* scope, zval* object, const char* name); +void k2hdkcpx_update_property_resource(zend_class_entry* scope, zval* object, const char* name, size_t name_length, zval* value); + +// # define PHP_K2HDKCPX_VERSION "0.1.0" + +# if defined(ZTS) && defined(COMPILE_DL_K2HDKCPX) +// cppcheck-suppress unknownMacro +ZEND_TSRMLS_CACHE_EXTERN() +# endif + +#endif /* PHP_K2HDKCPX_H */ + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * End: + * vim600: noexpandtab sw=4 ts=4 fdm=marker + * vim<600: noexpandtab sw=4 ts=4 + */ diff --git a/tests/001.phpt b/tests/001.phpt new file mode 100644 index 0000000..2a26cdc --- /dev/null +++ b/tests/001.phpt @@ -0,0 +1,10 @@ +--TEST-- +Check if k2hdkcpx is loaded +--EXTENSIONS-- +k2hdkcpx +--FILE-- + +--EXPECT-- +The extension "k2hdkc" is available diff --git a/tests/K2hdkc__addSubkey.phpt b/tests/K2hdkc__addSubkey.phpt new file mode 100644 index 0000000..05ff11a --- /dev/null +++ b/tests/K2hdkc__addSubkey.phpt @@ -0,0 +1,109 @@ +--TEST-- +K2hdkc__addSubkey +--CREDITS-- +K2HDKC PHP Extension library + +Copyright 2023 Yahoo Japan Corporation. + +K2HDKC is k2hash based distributed KVS cluster. +K2HDKC uses K2HASH, CHMPX, FULLOCK libraries. K2HDKC supports +distributed KVS cluster server program and client libraries. + +For the full copyright and license information, please view +the license file that was distributed with this source code. +--EXTENSIONS-- +k2hdkcpx +--FILE-- + /tmp/server.log 2>&1 &"); + time_nanosleep(0, 500 * 1000 * 1000); + $procid = exec("ps ax | grep chmpx | grep tests/server.ini | grep -v grep | awk '{print $1}'"); + + // run chmpx slave + exec("chmpx -conf ./tests/slave.ini -d silent > /tmp/slave.log 2>&1 &"); + time_nanosleep(0, 500 * 1000 * 1000); + $procid_slave = exec("ps ax | grep chmpx | grep tests/slave.ini | grep -v grep | awk '{print $1}'"); + + // run k2hdkc + exec("k2hdkc -conf ./tests/server.ini -d silent > /tmp/k2hdkc.log 2>&1 &"); + time_nanosleep(0, 500 * 1000 * 1000); + $procid_k2hdkc = exec("ps ax | grep k2hdkc | grep tests/server.ini | grep -v grep | awk '{print $1}'"); + + // echo $procid_k2hdkc; + $handle = new K2hdkc("./tests/slave.ini"); + + if(false !== $handle){ + $key = "key"; + $subkey = "subkey"; + $subval = "subval"; + $handle->addSubkey($key, $subkey, $subval); + if ($subval === $handle->getValue($subkey)) { + echo "OK"; + }else{ + echo "NG"; + } + $handle->close(); + }else{ + echo "NG"; + } + // kill k2hdkc + if($procid_k2hdkc == sprintf("%d", intval($procid_k2hdkc))){ + $killcmd = "kill -HUP " . $procid_k2hdkc . " >> /tmp/test_k2hdkc.log 2>&1"; + exec($killcmd); + } + // kill chmpx slave + if($procid_slave == sprintf("%d", intval($procid_slave))){ + $killcmd = "kill -HUP " . $procid_slave . " >> /tmp/test_chmpx_slave.log 2>&1"; + exec($killcmd); + } + // kill chmpx server + if($procid == sprintf("%d", intval($procid))){ + $killcmd = "kill -HUP " . $procid . " >> /tmp/test_chmpx_server.log 2>&1"; + exec($killcmd); + } +} + +?> +--EXPECT-- +OK +--CLEAN-- + +--DESCRIPTION-- +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * End: + * vim600: noexpandtab sw=4 ts=4 fdm=marker + * vim<600: noexpandtab sw=4 ts=4 + */ diff --git a/tests/K2hdkc__casDecrement.phpt b/tests/K2hdkc__casDecrement.phpt new file mode 100644 index 0000000..41ce087 --- /dev/null +++ b/tests/K2hdkc__casDecrement.phpt @@ -0,0 +1,108 @@ +--TEST-- +K2hdkc__casDecrement +--CREDITS-- +K2HDKC PHP Extension library + +Copyright 2023 Yahoo Japan Corporation. + +K2HDKC is k2hash based distributed KVS cluster. +K2HDKC uses K2HASH, CHMPX, FULLOCK libraries. K2HDKC supports +distributed KVS cluster server program and client libraries. + +For the full copyright and license information, please view +the license file that was distributed with this source code. +--EXTENSIONS-- +k2hdkcpx +--FILE-- + /tmp/server.log 2>&1 &"); + time_nanosleep(0, 500 * 1000 * 1000); + $procid = exec("ps ax | grep chmpx | grep tests/server.ini | grep -v grep | awk '{print $1}'"); + + // run chmpx slave + exec("chmpx -conf ./tests/slave.ini -d silent > /tmp/slave.log 2>&1 &"); + time_nanosleep(0, 500 * 1000 * 1000); + $procid_slave = exec("ps ax | grep chmpx | grep tests/slave.ini | grep -v grep | awk '{print $1}'"); + + // run k2hdkc + exec("k2hdkc -conf ./tests/server.ini -d silent > /tmp/k2hdkc.log 2>&1 &"); + time_nanosleep(0, 500 * 1000 * 1000); + $procid_k2hdkc = exec("ps ax | grep k2hdkc | grep tests/server.ini | grep -v grep | awk '{print $1}'"); + + // echo $procid_k2hdkc; + $handle = new K2hdkc("./tests/slave.ini"); + + if(false !== $handle){ + $key = "key"; + $handle->casInit($key, 2); + $handle->casDecrement($key); + if (1 === $handle->casGet($key)) { + echo "OK"; + }else{ + echo "NG"; + } + $handle->close(); + }else{ + echo "NG"; + } + // kill k2hdkc + if($procid_k2hdkc == sprintf("%d", intval($procid_k2hdkc))){ + $killcmd = "kill -HUP " . $procid_k2hdkc . " >> /tmp/test_k2hdkc.log 2>&1"; + exec($killcmd); + } + // kill chmpx slave + if($procid_slave == sprintf("%d", intval($procid_slave))){ + $killcmd = "kill -HUP " . $procid_slave . " >> /tmp/test_chmpx_slave.log 2>&1"; + exec($killcmd); + } + // kill chmpx server + if($procid == sprintf("%d", intval($procid))){ + $killcmd = "kill -HUP " . $procid . " >> /tmp/test_chmpx_server.log 2>&1"; + exec($killcmd); + } +} + +?> +--EXPECT-- +OK +--CLEAN-- + +--DESCRIPTION-- +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * End: + * vim600: noexpandtab sw=4 ts=4 fdm=marker + * vim<600: noexpandtab sw=4 ts=4 + */ diff --git a/tests/K2hdkc__casGet.phpt b/tests/K2hdkc__casGet.phpt new file mode 100644 index 0000000..da0ca51 --- /dev/null +++ b/tests/K2hdkc__casGet.phpt @@ -0,0 +1,108 @@ +--TEST-- +K2hdkc__casGet +--CREDITS-- +K2HDKC PHP Extension library + +Copyright 2023 Yahoo Japan Corporation. + +K2HDKC is k2hash based distributed KVS cluster. +K2HDKC uses K2HASH, CHMPX, FULLOCK libraries. K2HDKC supports +distributed KVS cluster server program and client libraries. + +For the full copyright and license information, please view +the license file that was distributed with this source code. +--EXTENSIONS-- +k2hdkcpx +--FILE-- + /tmp/server.log 2>&1 &"); + time_nanosleep(0, 500 * 1000 * 1000); + $procid = exec("ps ax | grep chmpx | grep tests/server.ini | grep -v grep | awk '{print $1}'"); + + // run chmpx slave + exec("chmpx -conf ./tests/slave.ini -d silent > /tmp/slave.log 2>&1 &"); + time_nanosleep(0, 500 * 1000 * 1000); + $procid_slave = exec("ps ax | grep chmpx | grep tests/slave.ini | grep -v grep | awk '{print $1}'"); + + // run k2hdkc + exec("k2hdkc -conf ./tests/server.ini -d silent > /tmp/k2hdkc.log 2>&1 &"); + time_nanosleep(0, 500 * 1000 * 1000); + $procid_k2hdkc = exec("ps ax | grep k2hdkc | grep tests/server.ini | grep -v grep | awk '{print $1}'"); + + // echo $procid_k2hdkc; + $handle = new K2hdkc("./tests/slave.ini"); + + if(false !== $handle){ + $key = "key"; + $handle->casInit($key, 0); + $handle->casIncrement($key); + if (1 === $handle->casGet($key)) { + echo "OK"; + }else{ + echo "NG"; + } + $handle->close(); + }else{ + echo "NG"; + } + // kill k2hdkc + if($procid_k2hdkc == sprintf("%d", intval($procid_k2hdkc))){ + $killcmd = "kill -HUP " . $procid_k2hdkc . " >> /tmp/test_k2hdkc.log 2>&1"; + exec($killcmd); + } + // kill chmpx slave + if($procid_slave == sprintf("%d", intval($procid_slave))){ + $killcmd = "kill -HUP " . $procid_slave . " >> /tmp/test_chmpx_slave.log 2>&1"; + exec($killcmd); + } + // kill chmpx server + if($procid == sprintf("%d", intval($procid))){ + $killcmd = "kill -HUP " . $procid . " >> /tmp/test_chmpx_server.log 2>&1"; + exec($killcmd); + } +} + +?> +--EXPECT-- +OK +--CLEAN-- + +--DESCRIPTION-- +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * End: + * vim600: noexpandtab sw=4 ts=4 fdm=marker + * vim<600: noexpandtab sw=4 ts=4 + */ diff --git a/tests/K2hdkc__casIncrement.phpt b/tests/K2hdkc__casIncrement.phpt new file mode 100644 index 0000000..93444f5 --- /dev/null +++ b/tests/K2hdkc__casIncrement.phpt @@ -0,0 +1,108 @@ +--TEST-- +K2hdkc__casIncrement +--CREDITS-- +K2HDKC PHP Extension library + +Copyright 2023 Yahoo Japan Corporation. + +K2HDKC is k2hash based distributed KVS cluster. +K2HDKC uses K2HASH, CHMPX, FULLOCK libraries. K2HDKC supports +distributed KVS cluster server program and client libraries. + +For the full copyright and license information, please view +the license file that was distributed with this source code. +--EXTENSIONS-- +k2hdkcpx +--FILE-- + /tmp/server.log 2>&1 &"); + time_nanosleep(0, 500 * 1000 * 1000); + $procid = exec("ps ax | grep chmpx | grep tests/server.ini | grep -v grep | awk '{print $1}'"); + + // run chmpx slave + exec("chmpx -conf ./tests/slave.ini -d silent > /tmp/slave.log 2>&1 &"); + time_nanosleep(0, 500 * 1000 * 1000); + $procid_slave = exec("ps ax | grep chmpx | grep tests/slave.ini | grep -v grep | awk '{print $1}'"); + + // run k2hdkc + exec("k2hdkc -conf ./tests/server.ini -d silent > /tmp/k2hdkc.log 2>&1 &"); + time_nanosleep(0, 500 * 1000 * 1000); + $procid_k2hdkc = exec("ps ax | grep k2hdkc | grep tests/server.ini | grep -v grep | awk '{print $1}'"); + + // echo $procid_k2hdkc; + $handle = new K2hdkc("./tests/slave.ini"); + + if(false !== $handle){ + $key = "key"; + $handle->casInit($key, 0); + $handle->casIncrement($key); + if (1 === $handle->casGet($key)) { + echo "OK"; + }else{ + echo "NG"; + } + $handle->close(); + }else{ + echo "NG"; + } + // kill k2hdkc + if($procid_k2hdkc == sprintf("%d", intval($procid_k2hdkc))){ + $killcmd = "kill -HUP " . $procid_k2hdkc . " >> /tmp/test_k2hdkc.log 2>&1"; + exec($killcmd); + } + // kill chmpx slave + if($procid_slave == sprintf("%d", intval($procid_slave))){ + $killcmd = "kill -HUP " . $procid_slave . " >> /tmp/test_chmpx_slave.log 2>&1"; + exec($killcmd); + } + // kill chmpx server + if($procid == sprintf("%d", intval($procid))){ + $killcmd = "kill -HUP " . $procid . " >> /tmp/test_chmpx_server.log 2>&1"; + exec($killcmd); + } +} + +?> +--EXPECT-- +OK +--CLEAN-- + +--DESCRIPTION-- +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * End: + * vim600: noexpandtab sw=4 ts=4 fdm=marker + * vim<600: noexpandtab sw=4 ts=4 + */ diff --git a/tests/K2hdkc__casInit.phpt b/tests/K2hdkc__casInit.phpt new file mode 100644 index 0000000..904e377 --- /dev/null +++ b/tests/K2hdkc__casInit.phpt @@ -0,0 +1,108 @@ +--TEST-- +K2hdkc__casInit +--CREDITS-- +K2HDKC PHP Extension library + +Copyright 2023 Yahoo Japan Corporation. + +K2HDKC is k2hash based distributed KVS cluster. +K2HDKC uses K2HASH, CHMPX, FULLOCK libraries. K2HDKC supports +distributed KVS cluster server program and client libraries. + +For the full copyright and license information, please view +the license file that was distributed with this source code. +--EXTENSIONS-- +k2hdkcpx +--FILE-- + /tmp/server.log 2>&1 &"); + time_nanosleep(0, 500 * 1000 * 1000); + $procid = exec("ps ax | grep chmpx | grep tests/server.ini | grep -v grep | awk '{print $1}'"); + + // run chmpx slave + exec("chmpx -conf ./tests/slave.ini -d silent > /tmp/slave.log 2>&1 &"); + time_nanosleep(0, 500 * 1000 * 1000); + $procid_slave = exec("ps ax | grep chmpx | grep tests/slave.ini | grep -v grep | awk '{print $1}'"); + + // run k2hdkc + exec("k2hdkc -conf ./tests/server.ini -d silent > /tmp/k2hdkc.log 2>&1 &"); + time_nanosleep(0, 500 * 1000 * 1000); + $procid_k2hdkc = exec("ps ax | grep k2hdkc | grep tests/server.ini | grep -v grep | awk '{print $1}'"); + + // echo $procid_k2hdkc; + $handle = new K2hdkc("./tests/slave.ini"); + + if(false !== $handle){ + $key = "key"; + $handle->casInit($key, 0); + $handle->casIncrement($key); + if (1 === $handle->casGet($key)) { + echo "OK"; + }else{ + echo "NG"; + } + $handle->close(); + }else{ + echo "NG"; + } + // kill k2hdkc + if($procid_k2hdkc == sprintf("%d", intval($procid_k2hdkc))){ + $killcmd = "kill -HUP " . $procid_k2hdkc . " >> /tmp/test_k2hdkc.log 2>&1"; + exec($killcmd); + } + // kill chmpx slave + if($procid_slave == sprintf("%d", intval($procid_slave))){ + $killcmd = "kill -HUP " . $procid_slave . " >> /tmp/test_chmpx_slave.log 2>&1"; + exec($killcmd); + } + // kill chmpx server + if($procid == sprintf("%d", intval($procid))){ + $killcmd = "kill -HUP " . $procid . " >> /tmp/test_chmpx_server.log 2>&1"; + exec($killcmd); + } +} + +?> +--EXPECT-- +OK +--CLEAN-- + +--DESCRIPTION-- +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * End: + * vim600: noexpandtab sw=4 ts=4 fdm=marker + * vim<600: noexpandtab sw=4 ts=4 + */ diff --git a/tests/K2hdkc__casSet.phpt b/tests/K2hdkc__casSet.phpt new file mode 100644 index 0000000..530670e --- /dev/null +++ b/tests/K2hdkc__casSet.phpt @@ -0,0 +1,108 @@ +--TEST-- +K2hdkc__casSet +--CREDITS-- +K2HDKC PHP Extension library + +Copyright 2023 Yahoo Japan Corporation. + +K2HDKC is k2hash based distributed KVS cluster. +K2HDKC uses K2HASH, CHMPX, FULLOCK libraries. K2HDKC supports +distributed KVS cluster server program and client libraries. + +For the full copyright and license information, please view +the license file that was distributed with this source code. +--EXTENSIONS-- +k2hdkcpx +--FILE-- + /tmp/server.log 2>&1 &"); + time_nanosleep(0, 500 * 1000 * 1000); + $procid = exec("ps ax | grep chmpx | grep tests/server.ini | grep -v grep | awk '{print $1}'"); + + // run chmpx slave + exec("chmpx -conf ./tests/slave.ini -d silent > /tmp/slave.log 2>&1 &"); + time_nanosleep(0, 500 * 1000 * 1000); + $procid_slave = exec("ps ax | grep chmpx | grep tests/slave.ini | grep -v grep | awk '{print $1}'"); + + // run k2hdkc + exec("k2hdkc -conf ./tests/server.ini -d silent > /tmp/k2hdkc.log 2>&1 &"); + time_nanosleep(0, 500 * 1000 * 1000); + $procid_k2hdkc = exec("ps ax | grep k2hdkc | grep tests/server.ini | grep -v grep | awk '{print $1}'"); + + // echo $procid_k2hdkc; + $handle = new K2hdkc("./tests/slave.ini"); + + if(false !== $handle){ + $key = "key"; + $handle->casInit($key, 0); + $handle->casSet($key, 0, 1); + if (1 === $handle->casGet($key)) { + echo "OK"; + }else{ + echo "NG"; + } + $handle->close(); + }else{ + echo "NG"; + } + // kill k2hdkc + if($procid_k2hdkc == sprintf("%d", intval($procid_k2hdkc))){ + $killcmd = "kill -HUP " . $procid_k2hdkc . " >> /tmp/test_k2hdkc.log 2>&1"; + exec($killcmd); + } + // kill chmpx slave + if($procid_slave == sprintf("%d", intval($procid_slave))){ + $killcmd = "kill -HUP " . $procid_slave . " >> /tmp/test_chmpx_slave.log 2>&1"; + exec($killcmd); + } + // kill chmpx server + if($procid == sprintf("%d", intval($procid))){ + $killcmd = "kill -HUP " . $procid . " >> /tmp/test_chmpx_server.log 2>&1"; + exec($killcmd); + } +} + +?> +--EXPECT-- +OK +--CLEAN-- + +--DESCRIPTION-- +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * End: + * vim600: noexpandtab sw=4 ts=4 fdm=marker + * vim<600: noexpandtab sw=4 ts=4 + */ diff --git a/tests/K2hdkc__clearSubkeys.phpt b/tests/K2hdkc__clearSubkeys.phpt new file mode 100644 index 0000000..4852cfd --- /dev/null +++ b/tests/K2hdkc__clearSubkeys.phpt @@ -0,0 +1,122 @@ +--TEST-- +K2hdkc__clearSubkeys +--CREDITS-- +K2HDKC PHP Extension library + +Copyright 2023 Yahoo Japan Corporation. + +K2HDKC is k2hash based distributed KVS cluster. +K2HDKC uses K2HASH, CHMPX, FULLOCK libraries. K2HDKC supports +distributed KVS cluster server program and client libraries. + +For the full copyright and license information, please view +the license file that was distributed with this source code. +--EXTENSIONS-- +k2hdkcpx +--FILE-- + /tmp/server.log 2>&1 &"); + time_nanosleep(0, 500 * 1000 * 1000); + $procid = exec("ps ax | grep chmpx | grep tests/server.ini | grep -v grep | awk '{print $1}'"); + + // run chmpx slave + exec("chmpx -conf ./tests/slave.ini -d silent > /tmp/slave.log 2>&1 &"); + time_nanosleep(0, 500 * 1000 * 1000); + $procid_slave = exec("ps ax | grep chmpx | grep tests/slave.ini | grep -v grep | awk '{print $1}'"); + + // run k2hdkc + exec("k2hdkc -conf ./tests/server.ini -d silent > /tmp/k2hdkc.log 2>&1 &"); + time_nanosleep(0, 500 * 1000 * 1000); + $procid_k2hdkc = exec("ps ax | grep k2hdkc | grep tests/server.ini | grep -v grep | awk '{print $1}'"); + + // echo $procid_k2hdkc; + $handle = new K2hdkc("./tests/slave.ini"); + + if(false !== $handle){ + $key = "key"; + $subkey = "subkey"; + $subval = "subval"; + // 1. set + $handle->addSubkey($key, $subkey, $subval); + time_nanosleep(0, 250 * 1000 * 1000); + + if ($subval === $handle->getValue($subkey)) { + // 2. clear + $handle->clearSubkeys($key); + time_nanosleep(0, 250 * 1000 * 1000); + + // 3. check if subkey is empty + $r =$handle->getSubkeys($key); + if(!$r) { + echo "OK"; + }else{ + echo "NG"; + } + }else{ + echo "NG"; + } + $handle->close(); + }else{ + echo "NG"; + } + // kill k2hdkc + if($procid_k2hdkc == sprintf("%d", intval($procid_k2hdkc))){ + $killcmd = "kill -HUP " . $procid_k2hdkc . " >> /tmp/test_k2hdkc.log 2>&1"; + exec($killcmd); + } + // kill chmpx slave + if($procid_slave == sprintf("%d", intval($procid_slave))){ + $killcmd = "kill -HUP " . $procid_slave . " >> /tmp/test_chmpx_slave.log 2>&1"; + exec($killcmd); + } + // kill chmpx server + if($procid == sprintf("%d", intval($procid))){ + $killcmd = "kill -HUP " . $procid . " >> /tmp/test_chmpx_server.log 2>&1"; + exec($killcmd); + } +} + +?> +--EXPECT-- +OK +--CLEAN-- + +--DESCRIPTION-- +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * End: + * vim600: noexpandtab sw=4 ts=4 fdm=marker + * vim<600: noexpandtab sw=4 ts=4 + */ diff --git a/tests/K2hdkc__close.phpt b/tests/K2hdkc__close.phpt new file mode 100644 index 0000000..6d83624 --- /dev/null +++ b/tests/K2hdkc__close.phpt @@ -0,0 +1,101 @@ +--TEST-- +K2hdkc__close +--CREDITS-- +K2HDKC PHP Extension library + +Copyright 2023 Yahoo Japan Corporation. + +K2HDKC is k2hash based distributed KVS cluster. +K2HDKC uses K2HASH, CHMPX, FULLOCK libraries. K2HDKC supports +distributed KVS cluster server program and client libraries. + +For the full copyright and license information, please view +the license file that was distributed with this source code. +--EXTENSIONS-- +k2hdkcpx +--FILE-- + /tmp/server.log 2>&1 &"); + time_nanosleep(0, 500 * 1000 * 1000); + $procid = exec("ps ax | grep chmpx | grep tests/server.ini | grep -v grep | awk '{print $1}'"); + + // run chmpx slave + exec("chmpx -conf ./tests/slave.ini -d silent > /tmp/slave.log 2>&1 &"); + time_nanosleep(0, 500 * 1000 * 1000); + $procid_slave = exec("ps ax | grep chmpx | grep tests/slave.ini | grep -v grep | awk '{print $1}'"); + + // run k2hdkc + exec("k2hdkc -conf ./tests/server.ini -d silent > /tmp/k2hdkc.log 2>&1 &"); + time_nanosleep(0, 500 * 1000 * 1000); + $procid_k2hdkc = exec("ps ax | grep k2hdkc | grep tests/server.ini | grep -v grep | awk '{print $1}'"); + + // echo $procid_k2hdkc; + $handle = new K2hdkc("./tests/slave.ini"); + + if(false !== $handle){ + $handle->close(); + echo "OK"; + }else{ + echo "NG"; + } + // kill k2hdkc + if($procid_k2hdkc == sprintf("%d", intval($procid_k2hdkc))){ + $killcmd = "kill -HUP " . $procid_k2hdkc . " >> /tmp/test_k2hdkc.log 2>&1"; + exec($killcmd); + } + // kill chmpx slave + if($procid_slave == sprintf("%d", intval($procid_slave))){ + $killcmd = "kill -HUP " . $procid_slave . " >> /tmp/test_chmpx_slave.log 2>&1"; + exec($killcmd); + } + // kill chmpx server + if($procid == sprintf("%d", intval($procid))){ + $killcmd = "kill -HUP " . $procid . " >> /tmp/test_chmpx_server.log 2>&1"; + exec($killcmd); + } +} + +?> +--EXPECT-- +OK +--CLEAN-- + +--DESCRIPTION-- +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * End: + * vim600: noexpandtab sw=4 ts=4 fdm=marker + * vim<600: noexpandtab sw=4 ts=4 + */ diff --git a/tests/K2hdkc__construct.phpt b/tests/K2hdkc__construct.phpt new file mode 100644 index 0000000..9feae2f --- /dev/null +++ b/tests/K2hdkc__construct.phpt @@ -0,0 +1,101 @@ +--TEST-- +K2hdkc__construct +--CREDITS-- +K2HDKC PHP Extension library + +Copyright 2023 Yahoo Japan Corporation. + +K2HDKC is k2hash based distributed KVS cluster. +K2HDKC uses K2HASH, CHMPX, FULLOCK libraries. K2HDKC supports +distributed KVS cluster server program and client libraries. + +For the full copyright and license information, please view +the license file that was distributed with this source code. +--EXTENSIONS-- +k2hdkcpx +--FILE-- + /tmp/server.log 2>&1 &"); + time_nanosleep(0, 500 * 1000 * 1000); + $procid = exec("ps ax | grep chmpx | grep tests/server.ini | grep -v grep | awk '{print $1}'"); + + // run chmpx slave + exec("chmpx -conf ./tests/slave.ini -d silent > /tmp/slave.log 2>&1 &"); + time_nanosleep(0, 500 * 1000 * 1000); + $procid_slave = exec("ps ax | grep chmpx | grep tests/slave.ini | grep -v grep | awk '{print $1}'"); + + // run k2hdkc + exec("k2hdkc -conf ./tests/server.ini -d silent > /tmp/k2hdkc.log 2>&1 &"); + time_nanosleep(0, 500 * 1000 * 1000); + $procid_k2hdkc = exec("ps ax | grep k2hdkc | grep tests/server.ini | grep -v grep | awk '{print $1}'"); + + // echo $procid_k2hdkc; + $handle = new K2hdkc("./tests/slave.ini"); + + if(false !== $handle){ + echo "OK"; + $handle->close(); + }else{ + echo "NG"; + } + // kill k2hdkc + if($procid_k2hdkc == sprintf("%d", intval($procid_k2hdkc))){ + $killcmd = "kill -HUP " . $procid_k2hdkc . " >> /tmp/test_k2hdkc.log 2>&1"; + exec($killcmd); + } + // kill chmpx slave + if($procid_slave == sprintf("%d", intval($procid_slave))){ + $killcmd = "kill -HUP " . $procid_slave . " >> /tmp/test_chmpx_slave.log 2>&1"; + exec($killcmd); + } + // kill chmpx server + if($procid == sprintf("%d", intval($procid))){ + $killcmd = "kill -HUP " . $procid . " >> /tmp/test_chmpx_server.log 2>&1"; + exec($killcmd); + } +} + +?> +--EXPECT-- +OK +--CLEAN-- + +--DESCRIPTION-- +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * End: + * vim600: noexpandtab sw=4 ts=4 fdm=marker + * vim<600: noexpandtab sw=4 ts=4 + */ diff --git a/tests/K2hdkc__destruct.phpt b/tests/K2hdkc__destruct.phpt new file mode 100644 index 0000000..146b45e --- /dev/null +++ b/tests/K2hdkc__destruct.phpt @@ -0,0 +1,101 @@ +--TEST-- +K2hdkc__destruct +--CREDITS-- +K2HDKC PHP Extension library + +Copyright 2023 Yahoo Japan Corporation. + +K2HDKC is k2hash based distributed KVS cluster. +K2HDKC uses K2HASH, CHMPX, FULLOCK libraries. K2HDKC supports +distributed KVS cluster server program and client libraries. + +For the full copyright and license information, please view +the license file that was distributed with this source code. +--EXTENSIONS-- +k2hdkcpx +--FILE-- + /tmp/server.log 2>&1 &"); + time_nanosleep(0, 500 * 1000 * 1000); + $procid = exec("ps ax | grep chmpx | grep tests/server.ini | grep -v grep | awk '{print $1}'"); + + // run chmpx slave + exec("chmpx -conf ./tests/slave.ini -d silent > /tmp/slave.log 2>&1 &"); + time_nanosleep(0, 500 * 1000 * 1000); + $procid_slave = exec("ps ax | grep chmpx | grep tests/slave.ini | grep -v grep | awk '{print $1}'"); + + // run k2hdkc + exec("k2hdkc -conf ./tests/server.ini -d silent > /tmp/k2hdkc.log 2>&1 &"); + time_nanosleep(0, 500 * 1000 * 1000); + $procid_k2hdkc = exec("ps ax | grep k2hdkc | grep tests/server.ini | grep -v grep | awk '{print $1}'"); + + // echo $procid_k2hdkc; + $handle = new K2hdkc("./tests/slave.ini"); + + if(false !== $handle){ + unset($handle); + echo "OK"; + }else{ + echo "NG"; + } + // kill k2hdkc + if($procid_k2hdkc == sprintf("%d", intval($procid_k2hdkc))){ + $killcmd = "kill -HUP " . $procid_k2hdkc . " >> /tmp/test_k2hdkc.log 2>&1"; + exec($killcmd); + } + // kill chmpx slave + if($procid_slave == sprintf("%d", intval($procid_slave))){ + $killcmd = "kill -HUP " . $procid_slave . " >> /tmp/test_chmpx_slave.log 2>&1"; + exec($killcmd); + } + // kill chmpx server + if($procid == sprintf("%d", intval($procid))){ + $killcmd = "kill -HUP " . $procid . " >> /tmp/test_chmpx_server.log 2>&1"; + exec($killcmd); + } +} + +?> +--EXPECT-- +OK +--CLEAN-- + +--DESCRIPTION-- +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * End: + * vim600: noexpandtab sw=4 ts=4 fdm=marker + * vim<600: noexpandtab sw=4 ts=4 + */ diff --git a/tests/K2hdkc__getAttrs.phpt b/tests/K2hdkc__getAttrs.phpt new file mode 100644 index 0000000..a57f9ef --- /dev/null +++ b/tests/K2hdkc__getAttrs.phpt @@ -0,0 +1,111 @@ +--TEST-- +K2hdkc__getAttrs +--CREDITS-- +K2HDKC PHP Extension library + +Copyright 2023 Yahoo Japan Corporation. + +K2HDKC is k2hash based distributed KVS cluster. +K2HDKC uses K2HASH, CHMPX, FULLOCK libraries. K2HDKC supports +distributed KVS cluster server program and client libraries. + +For the full copyright and license information, please view +the license file that was distributed with this source code. +--EXTENSIONS-- +k2hdkcpx +--FILE-- + /tmp/server.log 2>&1 &"); + time_nanosleep(0, 500 * 1000 * 1000); + $procid = exec("ps ax | grep chmpx | grep tests/server.ini | grep -v grep | awk '{print $1}'"); + + // run chmpx slave + exec("chmpx -conf ./tests/slave.ini -d silent > /tmp/slave.log 2>&1 &"); + time_nanosleep(0, 500 * 1000 * 1000); + $procid_slave = exec("ps ax | grep chmpx | grep tests/slave.ini | grep -v grep | awk '{print $1}'"); + + // run k2hdkc + exec("k2hdkc -conf ./tests/server.ini -d silent > /tmp/k2hdkc.log 2>&1 &"); + time_nanosleep(0, 500 * 1000 * 1000); + $procid_k2hdkc = exec("ps ax | grep k2hdkc | grep tests/server.ini | grep -v grep | awk '{print $1}'"); + + // echo $procid_k2hdkc; + $handle = new K2hdkc("./tests/slave.ini"); + + if(false !== $handle){ + $key = "key"; + $val = "val"; + $handle->setValue($key, $val); + time_nanosleep(0, 250 * 1000 * 1000); + + $arr = $handle->getAttrs($key); + if ($arr[0] == 'mtime') { + echo "OK"; + }else{ + echo "NG"; + } + $handle->close(); + }else{ + echo "NG"; + } + // kill k2hdkc + if($procid_k2hdkc == sprintf("%d", intval($procid_k2hdkc))){ + $killcmd = "kill -HUP " . $procid_k2hdkc . " >> /tmp/test_k2hdkc.log 2>&1"; + exec($killcmd); + } + // kill chmpx slave + if($procid_slave == sprintf("%d", intval($procid_slave))){ + $killcmd = "kill -HUP " . $procid_slave . " >> /tmp/test_chmpx_slave.log 2>&1"; + exec($killcmd); + } + // kill chmpx server + if($procid == sprintf("%d", intval($procid))){ + $killcmd = "kill -HUP " . $procid . " >> /tmp/test_chmpx_server.log 2>&1"; + exec($killcmd); + } +} + +?> +--EXPECT-- +OK +--CLEAN-- + +--DESCRIPTION-- +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * End: + * vim600: noexpandtab sw=4 ts=4 fdm=marker + * vim<600: noexpandtab sw=4 ts=4 + */ diff --git a/tests/K2hdkc__getSubkeys.phpt b/tests/K2hdkc__getSubkeys.phpt new file mode 100644 index 0000000..9c24cf6 --- /dev/null +++ b/tests/K2hdkc__getSubkeys.phpt @@ -0,0 +1,118 @@ +--TEST-- +K2hdkc__getSugkeys +--CREDITS-- +K2HDKC PHP Extension library + +Copyright 2023 Yahoo Japan Corporation. + +K2HDKC is k2hash based distributed KVS cluster. +K2HDKC uses K2HASH, CHMPX, FULLOCK libraries. K2HDKC supports +distributed KVS cluster server program and client libraries. + +For the full copyright and license information, please view +the license file that was distributed with this source code. +--EXTENSIONS-- +k2hdkcpx +--FILE-- + /tmp/server.log 2>&1 &"); + time_nanosleep(0, 500 * 1000 * 1000); + $procid = exec("ps ax | grep chmpx | grep tests/server.ini | grep -v grep | awk '{print $1}'"); + + // run chmpx slave + exec("chmpx -conf ./tests/slave.ini -d silent > /tmp/slave.log 2>&1 &"); + time_nanosleep(0, 500 * 1000 * 1000); + $procid_slave = exec("ps ax | grep chmpx | grep tests/slave.ini | grep -v grep | awk '{print $1}'"); + + // run k2hdkc + exec("k2hdkc -conf ./tests/server.ini -d silent > /tmp/k2hdkc.log 2>&1 &"); + time_nanosleep(0, 500 * 1000 * 1000); + $procid_k2hdkc = exec("ps ax | grep k2hdkc | grep tests/server.ini | grep -v grep | awk '{print $1}'"); + + time_nanosleep(0, 500 * 1000 * 1000); + + // echo $procid_k2hdkc; + $handle = new K2hdkc("./tests/slave.ini"); + + if(false !== $handle){ + $key = "key"; + $subkey = "subkey"; + $subval = "subval"; + // 1. set + $handle->addSubkey($key, $subkey, $subval); + if ($subval === $handle->getValue($subkey)) { + // 2. check if subkey is empty + $r = $handle->getSubkeys($key); + if($r[0] === $subkey) { + echo "OK"; + }else{ + echo "NG"; + } + }else{ + echo "NG"; + } + $handle->close(); + }else{ + echo "NG"; + } + // kill k2hdkc + if($procid_k2hdkc == sprintf("%d", intval($procid_k2hdkc))){ + $killcmd = "kill -HUP " . $procid_k2hdkc . " >> /tmp/test_k2hdkc.log 2>&1"; + exec($killcmd); + } + // kill chmpx slave + if($procid_slave == sprintf("%d", intval($procid_slave))){ + $killcmd = "kill -HUP " . $procid_slave . " >> /tmp/test_chmpx_slave.log 2>&1"; + exec($killcmd); + } + // kill chmpx server + if($procid == sprintf("%d", intval($procid))){ + $killcmd = "kill -HUP " . $procid . " >> /tmp/test_chmpx_server.log 2>&1"; + exec($killcmd); + } +} + +?> +--EXPECT-- +OK +--CLEAN-- + +--DESCRIPTION-- +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * End: + * vim600: noexpandtab sw=4 ts=4 fdm=marker + * vim<600: noexpandtab sw=4 ts=4 + */ diff --git a/tests/K2hdkc__getValue.phpt b/tests/K2hdkc__getValue.phpt new file mode 100644 index 0000000..2f472c6 --- /dev/null +++ b/tests/K2hdkc__getValue.phpt @@ -0,0 +1,110 @@ +--TEST-- +K2hdkc__get +--CREDITS-- +K2HDKC PHP Extension library + +Copyright 2023 Yahoo Japan Corporation. + +K2HDKC is k2hash based distributed KVS cluster. +K2HDKC uses K2HASH, CHMPX, FULLOCK libraries. K2HDKC supports +distributed KVS cluster server program and client libraries. + +For the full copyright and license information, please view +the license file that was distributed with this source code. +--EXTENSIONS-- +k2hdkcpx +--FILE-- + /tmp/server.log 2>&1 &"); + time_nanosleep(0, 500 * 1000 * 1000); + $procid = exec("ps ax | grep chmpx | grep tests/server.ini | grep -v grep | awk '{print $1}'"); + + // run chmpx slave + exec("chmpx -conf ./tests/slave.ini -d silent > /tmp/slave.log 2>&1 &"); + time_nanosleep(0, 500 * 1000 * 1000); + $procid_slave = exec("ps ax | grep chmpx | grep tests/slave.ini | grep -v grep | awk '{print $1}'"); + + // run k2hdkc + exec("k2hdkc -conf ./tests/server.ini -d silent > /tmp/k2hdkc.log 2>&1 &"); + time_nanosleep(0, 500 * 1000 * 1000); + $procid_k2hdkc = exec("ps ax | grep k2hdkc | grep tests/server.ini | grep -v grep | awk '{print $1}'"); + + // echo $procid_k2hdkc; + $handle = new K2hdkc("./tests/slave.ini"); + + if(false !== $handle){ + $key = "key"; + $val = "val"; + $handle->setValue($key, $val); + time_nanosleep(0, 250 * 1000 * 1000); + + if ($val === $handle->getValue($key)) { + echo "OK"; + }else{ + echo "NG"; + } + $handle->close(); + }else{ + echo "NG"; + } + // kill k2hdkc + if($procid_k2hdkc == sprintf("%d", intval($procid_k2hdkc))){ + $killcmd = "kill -HUP " . $procid_k2hdkc . " >> /tmp/test_k2hdkc.log 2>&1"; + exec($killcmd); + } + // kill chmpx slave + if($procid_slave == sprintf("%d", intval($procid_slave))){ + $killcmd = "kill -HUP " . $procid_slave . " >> /tmp/test_chmpx_slave.log 2>&1"; + exec($killcmd); + } + // kill chmpx server + if($procid == sprintf("%d", intval($procid))){ + $killcmd = "kill -HUP " . $procid . " >> /tmp/test_chmpx_server.log 2>&1"; + exec($killcmd); + } +} + +?> +--EXPECT-- +OK +--CLEAN-- + +--DESCRIPTION-- +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * End: + * vim600: noexpandtab sw=4 ts=4 fdm=marker + * vim<600: noexpandtab sw=4 ts=4 + */ diff --git a/tests/K2hdkc__keyQueueGet.phpt b/tests/K2hdkc__keyQueueGet.phpt new file mode 100644 index 0000000..3981f4e --- /dev/null +++ b/tests/K2hdkc__keyQueueGet.phpt @@ -0,0 +1,112 @@ +--TEST-- +K2hdkc__keyQueueGet +--CREDITS-- +K2HDKC PHP Extension library + +Copyright 2023 Yahoo Japan Corporation. + +K2HDKC is k2hash based distributed KVS cluster. +K2HDKC uses K2HASH, CHMPX, FULLOCK libraries. K2HDKC supports +distributed KVS cluster server program and client libraries. + +For the full copyright and license information, please view +the license file that was distributed with this source code. +--EXTENSIONS-- +k2hdkcpx +--FILE-- + /tmp/server.log 2>&1 &"); + time_nanosleep(0, 500 * 1000 * 1000); + $procid = exec("ps ax | grep chmpx | grep tests/server.ini | grep -v grep | awk '{print $1}'"); + + // run chmpx slave + exec("chmpx -conf ./tests/slave.ini -d silent > /tmp/slave.log 2>&1 &"); + time_nanosleep(0, 500 * 1000 * 1000); + $procid_slave = exec("ps ax | grep chmpx | grep tests/slave.ini | grep -v grep | awk '{print $1}'"); + + // run k2hdkc + exec("k2hdkc -conf ./tests/server.ini -d silent > /tmp/k2hdkc.log 2>&1 &"); + time_nanosleep(0, 500 * 1000 * 1000); + $procid_k2hdkc = exec("ps ax | grep k2hdkc | grep tests/server.ini | grep -v grep | awk '{print $1}'"); + + // echo $procid_k2hdkc; + $handle = new K2hdkc("./tests/slave.ini"); + + if(false !== $handle){ + $prefix = "p1"; + $key = "key"; + $val = "val"; + $handle->keyQueuePut($prefix, $key, $val); + time_nanosleep(0, 250 * 1000 * 1000); + + $arr = array($key => $val); + if ($arr === $handle->keyQueueGet($prefix)) { + echo "OK"; + }else{ + echo "NG"; + } + $handle->close(); + }else{ + echo "NG"; + } + // kill k2hdkc + if($procid_k2hdkc == sprintf("%d", intval($procid_k2hdkc))){ + $killcmd = "kill -HUP " . $procid_k2hdkc . " >> /tmp/test_k2hdkc.log 2>&1"; + exec($killcmd); + } + // kill chmpx slave + if($procid_slave == sprintf("%d", intval($procid_slave))){ + $killcmd = "kill -HUP " . $procid_slave . " >> /tmp/test_chmpx_slave.log 2>&1"; + exec($killcmd); + } + // kill chmpx server + if($procid == sprintf("%d", intval($procid))){ + $killcmd = "kill -HUP " . $procid . " >> /tmp/test_chmpx_server.log 2>&1"; + exec($killcmd); + } +} + +?> +--EXPECT-- +OK +--CLEAN-- + +--DESCRIPTION-- +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * End: + * vim600: noexpandtab sw=4 ts=4 fdm=marker + * vim<600: noexpandtab sw=4 ts=4 + */ diff --git a/tests/K2hdkc__keyQueuePut.phpt b/tests/K2hdkc__keyQueuePut.phpt new file mode 100644 index 0000000..1a0f8bd --- /dev/null +++ b/tests/K2hdkc__keyQueuePut.phpt @@ -0,0 +1,112 @@ +--TEST-- +K2hdkc__keyQueuePut +--CREDITS-- +K2HDKC PHP Extension library + +Copyright 2023 Yahoo Japan Corporation. + +K2HDKC is k2hash based distributed KVS cluster. +K2HDKC uses K2HASH, CHMPX, FULLOCK libraries. K2HDKC supports +distributed KVS cluster server program and client libraries. + +For the full copyright and license information, please view +the license file that was distributed with this source code. +--EXTENSIONS-- +k2hdkcpx +--FILE-- + /tmp/server.log 2>&1 &"); + time_nanosleep(0, 500 * 1000 * 1000); + $procid = exec("ps ax | grep chmpx | grep tests/server.ini | grep -v grep | awk '{print $1}'"); + + // run chmpx slave + exec("chmpx -conf ./tests/slave.ini -d silent > /tmp/slave.log 2>&1 &"); + time_nanosleep(0, 500 * 1000 * 1000); + $procid_slave = exec("ps ax | grep chmpx | grep tests/slave.ini | grep -v grep | awk '{print $1}'"); + + // run k2hdkc + exec("k2hdkc -conf ./tests/server.ini -d silent > /tmp/k2hdkc.log 2>&1 &"); + time_nanosleep(0, 500 * 1000 * 1000); + $procid_k2hdkc = exec("ps ax | grep k2hdkc | grep tests/server.ini | grep -v grep | awk '{print $1}'"); + + // echo $procid_k2hdkc; + $handle = new K2hdkc("./tests/slave.ini"); + + if(false !== $handle){ + $prefix = "p1"; + $key = "key"; + $val = "val"; + $handle->keyQueuePut($prefix, $key, $val); + time_nanosleep(0, 250 * 1000 * 1000); + + $arr = array($key => $val); + if ($arr === $handle->keyQueueGet($prefix)) { + echo "OK"; + }else{ + echo "NG"; + } + $handle->close(); + }else{ + echo "NG"; + } + // kill k2hdkc + if($procid_k2hdkc == sprintf("%d", intval($procid_k2hdkc))){ + $killcmd = "kill -HUP " . $procid_k2hdkc . " >> /tmp/test_k2hdkc.log 2>&1"; + exec($killcmd); + } + // kill chmpx slave + if($procid_slave == sprintf("%d", intval($procid_slave))){ + $killcmd = "kill -HUP " . $procid_slave . " >> /tmp/test_chmpx_slave.log 2>&1"; + exec($killcmd); + } + // kill chmpx server + if($procid == sprintf("%d", intval($procid))){ + $killcmd = "kill -HUP " . $procid . " >> /tmp/test_chmpx_server.log 2>&1"; + exec($killcmd); + } +} + +?> +--EXPECT-- +OK +--CLEAN-- + +--DESCRIPTION-- +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * End: + * vim600: noexpandtab sw=4 ts=4 fdm=marker + * vim<600: noexpandtab sw=4 ts=4 + */ diff --git a/tests/K2hdkc__queueGet.phpt b/tests/K2hdkc__queueGet.phpt new file mode 100644 index 0000000..b0d706b --- /dev/null +++ b/tests/K2hdkc__queueGet.phpt @@ -0,0 +1,107 @@ +--TEST-- +K2hdkc__queueGet +--CREDITS-- +K2HDKC PHP Extension library + +Copyright 2023 Yahoo Japan Corporation. + +K2HDKC is k2hash based distributed KVS cluster. +K2HDKC uses K2HASH, CHMPX, FULLOCK libraries. K2HDKC supports +distributed KVS cluster server program and client libraries. + +For the full copyright and license information, please view +the license file that was distributed with this source code. +--EXTENSIONS-- +k2hdkcpx +--FILE-- + /tmp/server.log 2>&1 &"); + time_nanosleep(0, 500 * 1000 * 1000); + $procid = exec("ps ax | grep chmpx | grep tests/server.ini | grep -v grep | awk '{print $1}'"); + + // run chmpx slave + exec("chmpx -conf ./tests/slave.ini -d silent > /tmp/slave.log 2>&1 &"); + time_nanosleep(0, 500 * 1000 * 1000); + $procid_slave = exec("ps ax | grep chmpx | grep tests/slave.ini | grep -v grep | awk '{print $1}'"); + + // run k2hdkc + exec("k2hdkc -conf ./tests/server.ini -d silent > /tmp/k2hdkc.log 2>&1 &"); + time_nanosleep(0, 500 * 1000 * 1000); + $procid_k2hdkc = exec("ps ax | grep k2hdkc | grep tests/server.ini | grep -v grep | awk '{print $1}'"); + + // echo $procid_k2hdkc; + $handle = new K2hdkc("./tests/slave.ini"); + + if(false !== $handle){ + $key = "key"; + $val = "val"; + $handle->queuePut($key, $val); + if ($val === $handle->queueGet($key)) { + echo "OK"; + }else{ + echo "NG"; + } + $handle->close(); + }else{ + echo "NG"; + } + // kill k2hdkc + if($procid_k2hdkc == sprintf("%d", intval($procid_k2hdkc))){ + $killcmd = "kill -HUP " . $procid_k2hdkc . " >> /tmp/test_k2hdkc.log 2>&1"; + exec($killcmd); + } + // kill chmpx slave + if($procid_slave == sprintf("%d", intval($procid_slave))){ + $killcmd = "kill -HUP " . $procid_slave . " >> /tmp/test_chmpx_slave.log 2>&1"; + exec($killcmd); + } + // kill chmpx server + if($procid == sprintf("%d", intval($procid))){ + $killcmd = "kill -HUP " . $procid . " >> /tmp/test_chmpx_server.log 2>&1"; + exec($killcmd); + } +} + +?> +--EXPECT-- +OK +--CLEAN-- + /tmp/server.log 2>&1 &"); + time_nanosleep(0, 500 * 1000 * 1000); + $procid = exec("ps ax | grep chmpx | grep tests/server.ini | grep -v grep | awk '{print $1}'"); + + // run chmpx slave + exec("chmpx -conf ./tests/slave.ini -d silent > /tmp/slave.log 2>&1 &"); + time_nanosleep(0, 500 * 1000 * 1000); + $procid_slave = exec("ps ax | grep chmpx | grep tests/slave.ini | grep -v grep | awk '{print $1}'"); + + // run k2hdkc + exec("k2hdkc -conf ./tests/server.ini -d silent > /tmp/k2hdkc.log 2>&1 &"); + time_nanosleep(0, 500 * 1000 * 1000); + $procid_k2hdkc = exec("ps ax | grep k2hdkc | grep tests/server.ini | grep -v grep | awk '{print $1}'"); + + // echo $procid_k2hdkc; + $handle = new K2hdkc("./tests/slave.ini"); + + if(false !== $handle){ + $key = "key"; + $val = "val"; + $handle->queuePut($key, $val); + time_nanosleep(0, 250 * 1000 * 1000); + + if ($val === $handle->queueGet($key)) { + echo "OK"; + }else{ + echo "NG"; + } + $handle->close(); + }else{ + echo "NG"; + } + // kill k2hdkc + if($procid_k2hdkc == sprintf("%d", intval($procid_k2hdkc))){ + $killcmd = "kill -HUP " . $procid_k2hdkc . " >> /tmp/test_k2hdkc.log 2>&1"; + exec($killcmd); + } + // kill chmpx slave + if($procid_slave == sprintf("%d", intval($procid_slave))){ + $killcmd = "kill -HUP " . $procid_slave . " >> /tmp/test_chmpx_slave.log 2>&1"; + exec($killcmd); + } + // kill chmpx server + if($procid == sprintf("%d", intval($procid))){ + $killcmd = "kill -HUP " . $procid . " >> /tmp/test_chmpx_server.log 2>&1"; + exec($killcmd); + } +} + +?> +--EXPECT-- +OK +--CLEAN-- + +--DESCRIPTION-- +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * End: + * vim600: noexpandtab sw=4 ts=4 fdm=marker + * vim<600: noexpandtab sw=4 ts=4 + */ diff --git a/tests/K2hdkc__remove.phpt b/tests/K2hdkc__remove.phpt new file mode 100644 index 0000000..fe2ac05 --- /dev/null +++ b/tests/K2hdkc__remove.phpt @@ -0,0 +1,115 @@ +--TEST-- +K2hdkc__remove +--CREDITS-- +K2HDKC PHP Extension library + +Copyright 2023 Yahoo Japan Corporation. + +K2HDKC is k2hash based distributed KVS cluster. +K2HDKC uses K2HASH, CHMPX, FULLOCK libraries. K2HDKC supports +distributed KVS cluster server program and client libraries. + +For the full copyright and license information, please view +the license file that was distributed with this source code. +--EXTENSIONS-- +k2hdkcpx +--FILE-- + /tmp/server.log 2>&1 &"); + time_nanosleep(0, 500 * 1000 * 1000); + $procid = exec("ps ax | grep chmpx | grep tests/server.ini | grep -v grep | awk '{print $1}'"); + + // run chmpx slave + exec("chmpx -conf ./tests/slave.ini -d silent > /tmp/slave.log 2>&1 &"); + time_nanosleep(0, 500 * 1000 * 1000); + $procid_slave = exec("ps ax | grep chmpx | grep tests/slave.ini | grep -v grep | awk '{print $1}'"); + + // run k2hdkc + exec("k2hdkc -conf ./tests/server.ini -d silent > /tmp/k2hdkc.log 2>&1 &"); + time_nanosleep(0, 500 * 1000 * 1000); + $procid_k2hdkc = exec("ps ax | grep k2hdkc | grep tests/server.ini | grep -v grep | awk '{print $1}'"); + + // echo $procid_k2hdkc; + $handle = new K2hdkc("./tests/slave.ini"); + + if(false !== $handle){ + $key = "key"; + $val = "val"; + $handle->setValue($key, $val); + time_nanosleep(0, 250 * 1000 * 1000); + + if ($val === $handle->getValue($key)) { + time_nanosleep(0, 250 * 1000 * 1000); + + if ($handle->remove($key)) { + echo "OK"; + }else{ + echo "NG"; + } + }else{ + echo "NG"; + } + $handle->close(); + }else{ + echo "NG"; + } + // kill k2hdkc + if($procid_k2hdkc == sprintf("%d", intval($procid_k2hdkc))){ + $killcmd = "kill -HUP " . $procid_k2hdkc . " >> /tmp/test_k2hdkc.log 2>&1"; + exec($killcmd); + } + // kill chmpx slave + if($procid_slave == sprintf("%d", intval($procid_slave))){ + $killcmd = "kill -HUP " . $procid_slave . " >> /tmp/test_chmpx_slave.log 2>&1"; + exec($killcmd); + } + // kill chmpx server + if($procid == sprintf("%d", intval($procid))){ + $killcmd = "kill -HUP " . $procid . " >> /tmp/test_chmpx_server.log 2>&1"; + exec($killcmd); + } +} + +?> +--EXPECT-- +OK +--CLEAN-- + /tmp/server.log 2>&1 &"); + time_nanosleep(0, 500 * 1000 * 1000); + $procid = exec("ps ax | grep chmpx | grep tests/server.ini | grep -v grep | awk '{print $1}'"); + + // run chmpx slave + exec("chmpx -conf ./tests/slave.ini -d silent > /tmp/slave.log 2>&1 &"); + time_nanosleep(0, 500 * 1000 * 1000); + $procid_slave = exec("ps ax | grep chmpx | grep tests/slave.ini | grep -v grep | awk '{print $1}'"); + + // run k2hdkc + exec("k2hdkc -conf ./tests/server.ini -d silent > /tmp/k2hdkc.log 2>&1 &"); + time_nanosleep(0, 500 * 1000 * 1000); + $procid_k2hdkc = exec("ps ax | grep k2hdkc | grep tests/server.ini | grep -v grep | awk '{print $1}'"); + + // echo $procid_k2hdkc; + $handle = new K2hdkc("./tests/slave.ini"); + + if(false !== $handle){ + $key = "key"; + $subkey = "subkey"; + $subval = "subval"; + $handle->addSubkey($key, $subkey, $subval); + time_nanosleep(0, 250 * 1000 * 1000); + + if ($subval === $handle->getValue($subkey)) { + time_nanosleep(0, 250 * 1000 * 1000); + + if ($handle->removeSubkeys($key, array($subkey))) { + echo "OK"; + }else{ + echo "NG"; + } + }else{ + echo "NG"; + } + $handle->close(); + }else{ + echo "NG"; + } + // kill k2hdkc + if($procid_k2hdkc == sprintf("%d", intval($procid_k2hdkc))){ + $killcmd = "kill -HUP " . $procid_k2hdkc . " >> /tmp/test_k2hdkc.log 2>&1"; + exec($killcmd); + } + // kill chmpx slave + if($procid_slave == sprintf("%d", intval($procid_slave))){ + $killcmd = "kill -HUP " . $procid_slave . " >> /tmp/test_chmpx_slave.log 2>&1"; + exec($killcmd); + } + // kill chmpx server + if($procid == sprintf("%d", intval($procid))){ + $killcmd = "kill -HUP " . $procid . " >> /tmp/test_chmpx_server.log 2>&1"; + exec($killcmd); + } +} + +?> +--EXPECT-- +OK +--CLEAN-- + +--DESCRIPTION-- +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * End: + * vim600: noexpandtab sw=4 ts=4 fdm=marker + * vim<600: noexpandtab sw=4 ts=4 + */ diff --git a/tests/K2hdkc__rename.phpt b/tests/K2hdkc__rename.phpt new file mode 100644 index 0000000..bb6fb5d --- /dev/null +++ b/tests/K2hdkc__rename.phpt @@ -0,0 +1,117 @@ +--TEST-- +K2hdkc__rename +--CREDITS-- +K2HDKC PHP Extension library + +Copyright 2023 Yahoo Japan Corporation. + +K2HDKC is k2hash based distributed KVS cluster. +K2HDKC uses K2HASH, CHMPX, FULLOCK libraries. K2HDKC supports +distributed KVS cluster server program and client libraries. + +For the full copyright and license information, please view +the license file that was distributed with this source code. +--EXTENSIONS-- +k2hdkcpx +--FILE-- + /tmp/server.log 2>&1 &"); + time_nanosleep(0, 500 * 1000 * 1000); + $procid = exec("ps ax | grep chmpx | grep tests/server.ini | grep -v grep | awk '{print $1}'"); + + // run chmpx slave + exec("chmpx -conf ./tests/slave.ini -d silent > /tmp/slave.log 2>&1 &"); + time_nanosleep(0, 500 * 1000 * 1000); + $procid_slave = exec("ps ax | grep chmpx | grep tests/slave.ini | grep -v grep | awk '{print $1}'"); + + // run k2hdkc + exec("k2hdkc -conf ./tests/server.ini -d silent > /tmp/k2hdkc.log 2>&1 &"); + time_nanosleep(0, 500 * 1000 * 1000); + $procid_k2hdkc = exec("ps ax | grep k2hdkc | grep tests/server.ini | grep -v grep | awk '{print $1}'"); + + // echo $procid_k2hdkc; + $handle = new K2hdkc("./tests/slave.ini"); + + if(false !== $handle){ + $key = "key"; + $val = "val"; + $handle->setValue($key, $val); + time_nanosleep(0, 250 * 1000 * 1000); + + if ($val === $handle->getValue($key)) { + time_nanosleep(0, 250 * 1000 * 1000); + + $newkey = "newkey"; + if($handle->rename($key, $newkey)) { + echo "OK"; + }else{ + echo "NG"; + } + }else{ + echo "NG"; + } + $handle->close(); + }else{ + echo "NG"; + } + // kill k2hdkc + if($procid_k2hdkc == sprintf("%d", intval($procid_k2hdkc))){ + $killcmd = "kill -HUP " . $procid_k2hdkc . " >> /tmp/test_k2hdkc.log 2>&1"; + exec($killcmd); + } + // kill chmpx slave + if($procid_slave == sprintf("%d", intval($procid_slave))){ + $killcmd = "kill -HUP " . $procid_slave . " >> /tmp/test_chmpx_slave.log 2>&1"; + exec($killcmd); + } + // kill chmpx server + if($procid == sprintf("%d", intval($procid))){ + $killcmd = "kill -HUP " . $procid . " >> /tmp/test_chmpx_server.log 2>&1"; + exec($killcmd); + } +} + +?> +--EXPECT-- +OK +--CLEAN-- + +--DESCRIPTION-- +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * End: + * vim600: noexpandtab sw=4 ts=4 fdm=marker + * vim<600: noexpandtab sw=4 ts=4 + */ diff --git a/tests/K2hdkc__setSubkeys.phpt b/tests/K2hdkc__setSubkeys.phpt new file mode 100644 index 0000000..4352892 --- /dev/null +++ b/tests/K2hdkc__setSubkeys.phpt @@ -0,0 +1,118 @@ +--TEST-- +K2hdkc__setSubkeys +--CREDITS-- +K2HDKC PHP Extension library + +Copyright 2023 Yahoo Japan Corporation. + +K2HDKC is k2hash based distributed KVS cluster. +K2HDKC uses K2HASH, CHMPX, FULLOCK libraries. K2HDKC supports +distributed KVS cluster server program and client libraries. + +For the full copyright and license information, please view +the license file that was distributed with this source code. +--EXTENSIONS-- +k2hdkcpx +--FILE-- + /tmp/server.log 2>&1 &"); + time_nanosleep(0, 500 * 1000 * 1000); + $procid = exec("ps ax | grep chmpx | grep tests/server.ini | grep -v grep | awk '{print $1}'"); + + // run chmpx slave + exec("chmpx -conf ./tests/slave.ini -d silent > /tmp/slave.log 2>&1 &"); + time_nanosleep(0, 500 * 1000 * 1000); + $procid_slave = exec("ps ax | grep chmpx | grep tests/slave.ini | grep -v grep | awk '{print $1}'"); + + // run k2hdkc + exec("k2hdkc -conf ./tests/server.ini -d silent > /tmp/k2hdkc.log 2>&1 &"); + time_nanosleep(0, 500 * 1000 * 1000); + $procid_k2hdkc = exec("ps ax | grep k2hdkc | grep tests/server.ini | grep -v grep | awk '{print $1}'"); + + // echo $procid_k2hdkc; + $handle = new K2hdkc("./tests/slave.ini"); + + if(false !== $handle){ + $key = "key"; + $handle->setValue($key, "val"); + time_nanosleep(0, 250 * 1000 * 1000); + + $subkey = "subkey"; + $handle->setValue($subkey, "subval"); + time_nanosleep(0, 250 * 1000 * 1000); + + $arr = array($subkey); + $handle->setSubkeys($key, $arr); + time_nanosleep(0, 250 * 1000 * 1000); + + $arr = $handle->getSubkeys($key); + if ($arr[0] === $subkey) { + echo "OK"; + }else{ + echo "NG"; + } + $handle->close(); + }else{ + echo "NG"; + } + // kill k2hdkc + if($procid_k2hdkc == sprintf("%d", intval($procid_k2hdkc))){ + $killcmd = "kill -HUP " . $procid_k2hdkc . " >> /tmp/test_k2hdkc.log 2>&1"; + exec($killcmd); + } + // kill chmpx slave + if($procid_slave == sprintf("%d", intval($procid_slave))){ + $killcmd = "kill -HUP " . $procid_slave . " >> /tmp/test_chmpx_slave.log 2>&1"; + exec($killcmd); + } + // kill chmpx server + if($procid == sprintf("%d", intval($procid))){ + $killcmd = "kill -HUP " . $procid . " >> /tmp/test_chmpx_server.log 2>&1"; + exec($killcmd); + } +} + +?> +--EXPECT-- +OK +--CLEAN-- + +--DESCRIPTION-- +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * End: + * vim600: noexpandtab sw=4 ts=4 fdm=marker + * vim<600: noexpandtab sw=4 ts=4 + */ diff --git a/tests/K2hdkc__setValue.phpt b/tests/K2hdkc__setValue.phpt new file mode 100644 index 0000000..b272c6e --- /dev/null +++ b/tests/K2hdkc__setValue.phpt @@ -0,0 +1,110 @@ +--TEST-- +K2hdkc__set +--CREDITS-- +K2HDKC PHP Extension library + +Copyright 2023 Yahoo Japan Corporation. + +K2HDKC is k2hash based distributed KVS cluster. +K2HDKC uses K2HASH, CHMPX, FULLOCK libraries. K2HDKC supports +distributed KVS cluster server program and client libraries. + +For the full copyright and license information, please view +the license file that was distributed with this source code. +--EXTENSIONS-- +k2hdkcpx +--FILE-- + /tmp/server.log 2>&1 &"); + time_nanosleep(0, 500 * 1000 * 1000); + $procid = exec("ps ax | grep chmpx | grep tests/server.ini | grep -v grep | awk '{print $1}'"); + + // run chmpx slave + exec("chmpx -conf ./tests/slave.ini -d silent > /tmp/slave.log 2>&1 &"); + time_nanosleep(0, 500 * 1000 * 1000); + $procid_slave = exec("ps ax | grep chmpx | grep tests/slave.ini | grep -v grep | awk '{print $1}'"); + + // run k2hdkc + exec("k2hdkc -conf ./tests/server.ini -d silent > /tmp/k2hdkc.log 2>&1 &"); + time_nanosleep(0, 500 * 1000 * 1000); + $procid_k2hdkc = exec("ps ax | grep k2hdkc | grep tests/server.ini | grep -v grep | awk '{print $1}'"); + + // echo $procid_k2hdkc; + $handle = new K2hdkc("./tests/slave.ini"); + + if(false !== $handle){ + $key = "key"; + $val = "val"; + $handle->setValue($key, $val); + time_nanosleep(0, 250 * 1000 * 1000); + + if ($val === $handle->getValue($key)) { + echo "OK"; + }else{ + echo "NG"; + } + $handle->close(); + }else{ + echo "NG"; + } + // kill k2hdkc + if($procid_k2hdkc == sprintf("%d", intval($procid_k2hdkc))){ + $killcmd = "kill -HUP " . $procid_k2hdkc . " >> /tmp/test_k2hdkc.log 2>&1"; + exec($killcmd); + } + // kill chmpx slave + if($procid_slave == sprintf("%d", intval($procid_slave))){ + $killcmd = "kill -HUP " . $procid_slave . " >> /tmp/test_chmpx_slave.log 2>&1"; + exec($killcmd); + } + // kill chmpx server + if($procid == sprintf("%d", intval($procid))){ + $killcmd = "kill -HUP " . $procid . " >> /tmp/test_chmpx_server.log 2>&1"; + exec($killcmd); + } +} + +?> +--EXPECT-- +OK +--CLEAN-- + +--DESCRIPTION-- +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * End: + * vim600: noexpandtab sw=4 ts=4 fdm=marker + * vim<600: noexpandtab sw=4 ts=4 + */ diff --git a/tests/k2hdkcpx_add_subkey.phpt b/tests/k2hdkcpx_add_subkey.phpt new file mode 100644 index 0000000..b1ea8dc --- /dev/null +++ b/tests/k2hdkcpx_add_subkey.phpt @@ -0,0 +1,111 @@ +--TEST-- +k2hdkcpx_add_subkey +--CREDITS-- +K2HDKC PHP Extension library + +Copyright 2023 Yahoo Japan Corporation. + +K2HDKC is k2hash based distributed KVS cluster. +K2HDKC uses K2HASH, CHMPX, FULLOCK libraries. K2HDKC supports +distributed KVS cluster server program and client libraries. + +For the full copyright and license information, please view +the license file that was distributed with this source code. +--EXTENSIONS-- +k2hdkcpx +--FILE-- + /tmp/server.log 2>&1 &"); + time_nanosleep(0, 500 * 1000 * 1000); + $procid = exec("ps ax | grep chmpx | grep tests/server.ini | grep -v grep | awk '{print $1}'"); + + // run chmpx slave + exec("chmpx -conf ./tests/slave.ini -d silent > /tmp/slave.log 2>&1 &"); + time_nanosleep(0, 500 * 1000 * 1000); + $procid_slave = exec("ps ax | grep chmpx | grep tests/slave.ini | grep -v grep | awk '{print $1}'"); + + // run k2hdkc + exec("k2hdkc -conf ./tests/server.ini -d silent > /tmp/k2hdkc.log 2>&1 &"); + time_nanosleep(0, 500 * 1000 * 1000); + $procid_k2hdkc = exec("ps ax | grep k2hdkc | grep tests/server.ini | grep -v grep | awk '{print $1}'"); + + // echo $procid_k2hdkc; + $handle = k2hdkcpx_open("./tests/slave.ini"); + + if(false !== $handle){ + $key = "key"; + $subkey = "subkey"; + $subval = "subval"; + k2hdkcpx_add_subkey($handle, $key, $subkey, $subval); + time_nanosleep(0, 250 * 1000 * 1000); + + if ($subval === k2hdkcpx_get_value($handle, $subkey)) { + echo "OK"; + }else{ + echo "NG"; + } + k2hdkcpx_close($handle); + }else{ + echo "NG"; + } + // kill k2hdkc + if($procid_k2hdkc == sprintf("%d", intval($procid_k2hdkc))){ + $killcmd = "kill -HUP " . $procid_k2hdkc . " >> /tmp/test_k2hdkc.log 2>&1"; + exec($killcmd); + } + // kill chmpx slave + if($procid_slave == sprintf("%d", intval($procid_slave))){ + $killcmd = "kill -HUP " . $procid_slave . " >> /tmp/test_chmpx_slave.log 2>&1"; + exec($killcmd); + } + // kill chmpx server + if($procid == sprintf("%d", intval($procid))){ + $killcmd = "kill -HUP " . $procid . " >> /tmp/test_chmpx_server.log 2>&1"; + exec($killcmd); + } +} + +?> +--EXPECT-- +OK +--CLEAN-- + +--DESCRIPTION-- +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * End: + * vim600: noexpandtab sw=4 ts=4 fdm=marker + * vim<600: noexpandtab sw=4 ts=4 + */ diff --git a/tests/k2hdkcpx_bump_debug_level.phpt b/tests/k2hdkcpx_bump_debug_level.phpt new file mode 100644 index 0000000..0e503ae --- /dev/null +++ b/tests/k2hdkcpx_bump_debug_level.phpt @@ -0,0 +1,31 @@ +--TEST-- +k2hdkcpx_bump_debug_level +--CREDITS-- +K2HDKC PHP Extension library + +Copyright 2023 Yahoo Japan Corporation. + +K2HDKC is k2hash based distributed KVS cluster. +K2HDKC uses K2HASH, CHMPX, FULLOCK libraries. K2HDKC supports +distributed KVS cluster server program and client libraries. + +For the full copyright and license information, please view +the license file that was distributed with this source code. +--EXTENSIONS-- +k2hdkcpx +--FILE-- + +--EXPECT-- +OK +--DESCRIPTION-- +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * End: + * vim600: noexpandtab sw=4 ts=4 fdm=marker + * vim<600: noexpandtab sw=4 ts=4 + */ diff --git a/tests/k2hdkcpx_cas_decrement.phpt b/tests/k2hdkcpx_cas_decrement.phpt new file mode 100644 index 0000000..b6354b2 --- /dev/null +++ b/tests/k2hdkcpx_cas_decrement.phpt @@ -0,0 +1,112 @@ +--TEST-- +k2hdkcpx_cas_decrement +--CREDITS-- +K2HDKC PHP Extension library + +Copyright 2023 Yahoo Japan Corporation. + +K2HDKC is k2hash based distributed KVS cluster. +K2HDKC uses K2HASH, CHMPX, FULLOCK libraries. K2HDKC supports +distributed KVS cluster server program and client libraries. + +For the full copyright and license information, please view +the license file that was distributed with this source code. +--EXTENSIONS-- +k2hdkcpx +--FILE-- + /tmp/server.log 2>&1 &"); + time_nanosleep(0, 500 * 1000 * 1000); + $procid = exec("ps ax | grep chmpx | grep tests/server.ini | grep -v grep | awk '{print $1}'"); + + // run chmpx slave + exec("chmpx -conf ./tests/slave.ini -d silent > /tmp/slave.log 2>&1 &"); + time_nanosleep(0, 500 * 1000 * 1000); + $procid_slave = exec("ps ax | grep chmpx | grep tests/slave.ini | grep -v grep | awk '{print $1}'"); + + // run k2hdkc + exec("k2hdkc -conf ./tests/server.ini -d silent > /tmp/k2hdkc.log 2>&1 &"); + time_nanosleep(0, 500 * 1000 * 1000); + $procid_k2hdkc = exec("ps ax | grep k2hdkc | grep tests/server.ini | grep -v grep | awk '{print $1}'"); + + // echo $procid_k2hdkc; + $handle = k2hdkcpx_open("./tests/slave.ini"); + + if(false !== $handle){ + $key = "key"; + k2hdkcpx_cas_init($handle, $key, 2); + time_nanosleep(0, 250 * 1000 * 1000); + + k2hdkcpx_cas_decrement($handle, $key); + time_nanosleep(0, 250 * 1000 * 1000); + + if (1 === k2hdkcpx_cas_get($handle, $key)) { + echo "OK"; + }else{ + echo "NG"; + } + k2hdkcpx_close($handle); + }else{ + echo "NG"; + } + // kill k2hdkc + if($procid_k2hdkc == sprintf("%d", intval($procid_k2hdkc))){ + $killcmd = "kill -HUP " . $procid_k2hdkc . " >> /tmp/test_k2hdkc.log 2>&1"; + exec($killcmd); + } + // kill chmpx slave + if($procid_slave == sprintf("%d", intval($procid_slave))){ + $killcmd = "kill -HUP " . $procid_slave . " >> /tmp/test_chmpx_slave.log 2>&1"; + exec($killcmd); + } + // kill chmpx server + if($procid == sprintf("%d", intval($procid))){ + $killcmd = "kill -HUP " . $procid . " >> /tmp/test_chmpx_server.log 2>&1"; + exec($killcmd); + } +} + +?> +--EXPECT-- +OK +--CLEAN-- + +--DESCRIPTION-- +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * End: + * vim600: noexpandtab sw=4 ts=4 fdm=marker + * vim<600: noexpandtab sw=4 ts=4 + */ diff --git a/tests/k2hdkcpx_cas_get.phpt b/tests/k2hdkcpx_cas_get.phpt new file mode 100644 index 0000000..3188512 --- /dev/null +++ b/tests/k2hdkcpx_cas_get.phpt @@ -0,0 +1,112 @@ +--TEST-- +k2hdkcpx_cas_get +--CREDITS-- +K2HDKC PHP Extension library + +Copyright 2023 Yahoo Japan Corporation. + +K2HDKC is k2hash based distributed KVS cluster. +K2HDKC uses K2HASH, CHMPX, FULLOCK libraries. K2HDKC supports +distributed KVS cluster server program and client libraries. + +For the full copyright and license information, please view +the license file that was distributed with this source code. +--EXTENSIONS-- +k2hdkcpx +--FILE-- + /tmp/server.log 2>&1 &"); + time_nanosleep(0, 500 * 1000 * 1000); + $procid = exec("ps ax | grep chmpx | grep tests/server.ini | grep -v grep | awk '{print $1}'"); + + // run chmpx slave + exec("chmpx -conf ./tests/slave.ini -d silent > /tmp/slave.log 2>&1 &"); + time_nanosleep(0, 500 * 1000 * 1000); + $procid_slave = exec("ps ax | grep chmpx | grep tests/slave.ini | grep -v grep | awk '{print $1}'"); + + // run k2hdkc + exec("k2hdkc -conf ./tests/server.ini -d silent > /tmp/k2hdkc.log 2>&1 &"); + time_nanosleep(0, 500 * 1000 * 1000); + $procid_k2hdkc = exec("ps ax | grep k2hdkc | grep tests/server.ini | grep -v grep | awk '{print $1}'"); + + // echo $procid_k2hdkc; + $handle = k2hdkcpx_open("./tests/slave.ini"); + + if(false !== $handle){ + $key = "key"; + k2hdkcpx_cas_init($handle, $key, 0); + time_nanosleep(0, 250 * 1000 * 1000); + + k2hdkcpx_cas_increment($handle, $key); + time_nanosleep(0, 250 * 1000 * 1000); + + if (1 === k2hdkcpx_cas_get($handle, $key)) { + echo "OK"; + }else{ + echo "NG"; + } + k2hdkcpx_close($handle); + }else{ + echo "NG"; + } + // kill k2hdkc + if($procid_k2hdkc == sprintf("%d", intval($procid_k2hdkc))){ + $killcmd = "kill -HUP " . $procid_k2hdkc . " >> /tmp/test_k2hdkc.log 2>&1"; + exec($killcmd); + } + // kill chmpx slave + if($procid_slave == sprintf("%d", intval($procid_slave))){ + $killcmd = "kill -HUP " . $procid_slave . " >> /tmp/test_chmpx_slave.log 2>&1"; + exec($killcmd); + } + // kill chmpx server + if($procid == sprintf("%d", intval($procid))){ + $killcmd = "kill -HUP " . $procid . " >> /tmp/test_chmpx_server.log 2>&1"; + exec($killcmd); + } +} + +?> +--EXPECT-- +OK +--CLEAN-- + +--DESCRIPTION-- +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * End: + * vim600: noexpandtab sw=4 ts=4 fdm=marker + * vim<600: noexpandtab sw=4 ts=4 + */ diff --git a/tests/k2hdkcpx_cas_increment.phpt b/tests/k2hdkcpx_cas_increment.phpt new file mode 100644 index 0000000..692273b --- /dev/null +++ b/tests/k2hdkcpx_cas_increment.phpt @@ -0,0 +1,112 @@ +--TEST-- +k2hdkcpx_cas_increment +--CREDITS-- +K2HDKC PHP Extension library + +Copyright 2023 Yahoo Japan Corporation. + +K2HDKC is k2hash based distributed KVS cluster. +K2HDKC uses K2HASH, CHMPX, FULLOCK libraries. K2HDKC supports +distributed KVS cluster server program and client libraries. + +For the full copyright and license information, please view +the license file that was distributed with this source code. +--EXTENSIONS-- +k2hdkcpx +--FILE-- + /tmp/server.log 2>&1 &"); + time_nanosleep(0, 500 * 1000 * 1000); + $procid = exec("ps ax | grep chmpx | grep tests/server.ini | grep -v grep | awk '{print $1}'"); + + // run chmpx slave + exec("chmpx -conf ./tests/slave.ini -d silent > /tmp/slave.log 2>&1 &"); + time_nanosleep(0, 500 * 1000 * 1000); + $procid_slave = exec("ps ax | grep chmpx | grep tests/slave.ini | grep -v grep | awk '{print $1}'"); + + // run k2hdkc + exec("k2hdkc -conf ./tests/server.ini -d silent > /tmp/k2hdkc.log 2>&1 &"); + time_nanosleep(0, 500 * 1000 * 1000); + $procid_k2hdkc = exec("ps ax | grep k2hdkc | grep tests/server.ini | grep -v grep | awk '{print $1}'"); + + // echo $procid_k2hdkc; + $handle = k2hdkcpx_open("./tests/slave.ini"); + + if(false !== $handle){ + $key = "key"; + k2hdkcpx_cas_init($handle, $key, 0); + time_nanosleep(0, 250 * 1000 * 1000); + + k2hdkcpx_cas_increment($handle, $key); + time_nanosleep(0, 250 * 1000 * 1000); + + if (1 === k2hdkcpx_cas_get($handle, $key)) { + echo "OK"; + }else{ + echo "NG"; + } + k2hdkcpx_close($handle); + }else{ + echo "NG"; + } + // kill k2hdkc + if($procid_k2hdkc == sprintf("%d", intval($procid_k2hdkc))){ + $killcmd = "kill -HUP " . $procid_k2hdkc . " >> /tmp/test_k2hdkc.log 2>&1"; + exec($killcmd); + } + // kill chmpx slave + if($procid_slave == sprintf("%d", intval($procid_slave))){ + $killcmd = "kill -HUP " . $procid_slave . " >> /tmp/test_chmpx_slave.log 2>&1"; + exec($killcmd); + } + // kill chmpx server + if($procid == sprintf("%d", intval($procid))){ + $killcmd = "kill -HUP " . $procid . " >> /tmp/test_chmpx_server.log 2>&1"; + exec($killcmd); + } +} + +?> +--EXPECT-- +OK +--CLEAN-- + +--DESCRIPTION-- +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * End: + * vim600: noexpandtab sw=4 ts=4 fdm=marker + * vim<600: noexpandtab sw=4 ts=4 + */ diff --git a/tests/k2hdkcpx_cas_init.phpt b/tests/k2hdkcpx_cas_init.phpt new file mode 100644 index 0000000..fab9c9e --- /dev/null +++ b/tests/k2hdkcpx_cas_init.phpt @@ -0,0 +1,112 @@ +--TEST-- +k2hdkcpx_cas_init +--CREDITS-- +K2HDKC PHP Extension library + +Copyright 2023 Yahoo Japan Corporation. + +K2HDKC is k2hash based distributed KVS cluster. +K2HDKC uses K2HASH, CHMPX, FULLOCK libraries. K2HDKC supports +distributed KVS cluster server program and client libraries. + +For the full copyright and license information, please view +the license file that was distributed with this source code. +--EXTENSIONS-- +k2hdkcpx +--FILE-- + /tmp/server.log 2>&1 &"); + time_nanosleep(0, 500 * 1000 * 1000); + $procid = exec("ps ax | grep chmpx | grep tests/server.ini | grep -v grep | awk '{print $1}'"); + + // run chmpx slave + exec("chmpx -conf ./tests/slave.ini -d silent > /tmp/slave.log 2>&1 &"); + time_nanosleep(0, 500 * 1000 * 1000); + $procid_slave = exec("ps ax | grep chmpx | grep tests/slave.ini | grep -v grep | awk '{print $1}'"); + + // run k2hdkc + exec("k2hdkc -conf ./tests/server.ini -d silent > /tmp/k2hdkc.log 2>&1 &"); + time_nanosleep(0, 500 * 1000 * 1000); + $procid_k2hdkc = exec("ps ax | grep k2hdkc | grep tests/server.ini | grep -v grep | awk '{print $1}'"); + + // echo $procid_k2hdkc; + $handle = k2hdkcpx_open("./tests/slave.ini"); + + if(false !== $handle){ + $key = "key"; + k2hdkcpx_cas_init($handle, $key, 0); + time_nanosleep(0, 250 * 1000 * 1000); + + k2hdkcpx_cas_increment($handle, $key); + time_nanosleep(0, 250 * 1000 * 1000); + + if (1 === k2hdkcpx_cas_get($handle, $key)) { + echo "OK"; + }else{ + echo "NG"; + } + k2hdkcpx_close($handle); + }else{ + echo "NG"; + } + // kill k2hdkc + if($procid_k2hdkc == sprintf("%d", intval($procid_k2hdkc))){ + $killcmd = "kill -HUP " . $procid_k2hdkc . " >> /tmp/test_k2hdkc.log 2>&1"; + exec($killcmd); + } + // kill chmpx slave + if($procid_slave == sprintf("%d", intval($procid_slave))){ + $killcmd = "kill -HUP " . $procid_slave . " >> /tmp/test_chmpx_slave.log 2>&1"; + exec($killcmd); + } + // kill chmpx server + if($procid == sprintf("%d", intval($procid))){ + $killcmd = "kill -HUP " . $procid . " >> /tmp/test_chmpx_server.log 2>&1"; + exec($killcmd); + } +} + +?> +--EXPECT-- +OK +--CLEAN-- + +--DESCRIPTION-- +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * End: + * vim600: noexpandtab sw=4 ts=4 fdm=marker + * vim<600: noexpandtab sw=4 ts=4 + */ diff --git a/tests/k2hdkcpx_cas_set.phpt b/tests/k2hdkcpx_cas_set.phpt new file mode 100644 index 0000000..8749c09 --- /dev/null +++ b/tests/k2hdkcpx_cas_set.phpt @@ -0,0 +1,112 @@ +--TEST-- +k2hdkcpx_cas_set +--CREDITS-- +K2HDKC PHP Extension library + +Copyright 2023 Yahoo Japan Corporation. + +K2HDKC is k2hash based distributed KVS cluster. +K2HDKC uses K2HASH, CHMPX, FULLOCK libraries. K2HDKC supports +distributed KVS cluster server program and client libraries. + +For the full copyright and license information, please view +the license file that was distributed with this source code. +--EXTENSIONS-- +k2hdkcpx +--FILE-- + /tmp/server.log 2>&1 &"); + time_nanosleep(0, 500 * 1000 * 1000); + $procid = exec("ps ax | grep chmpx | grep tests/server.ini | grep -v grep | awk '{print $1}'"); + + // run chmpx slave + exec("chmpx -conf ./tests/slave.ini -d silent > /tmp/slave.log 2>&1 &"); + time_nanosleep(0, 500 * 1000 * 1000); + $procid_slave = exec("ps ax | grep chmpx | grep tests/slave.ini | grep -v grep | awk '{print $1}'"); + + // run k2hdkc + exec("k2hdkc -conf ./tests/server.ini -d silent > /tmp/k2hdkc.log 2>&1 &"); + time_nanosleep(0, 500 * 1000 * 1000); + $procid_k2hdkc = exec("ps ax | grep k2hdkc | grep tests/server.ini | grep -v grep | awk '{print $1}'"); + + // echo $procid_k2hdkc; + $handle = k2hdkcpx_open("./tests/slave.ini"); + + if(false !== $handle){ + $key = "key"; + k2hdkcpx_cas_init($handle, $key, 0); + time_nanosleep(0, 250 * 1000 * 1000); + + k2hdkcpx_cas_set($handle, $key, 0, 1); + time_nanosleep(0, 250 * 1000 * 1000); + + if (1 === k2hdkcpx_cas_get($handle, $key)) { + echo "OK"; + }else{ + echo "NG"; + } + k2hdkcpx_close($handle); + }else{ + echo "NG"; + } + // kill k2hdkc + if($procid_k2hdkc == sprintf("%d", intval($procid_k2hdkc))){ + $killcmd = "kill -HUP " . $procid_k2hdkc . " >> /tmp/test_k2hdkc.log 2>&1"; + exec($killcmd); + } + // kill chmpx slave + if($procid_slave == sprintf("%d", intval($procid_slave))){ + $killcmd = "kill -HUP " . $procid_slave . " >> /tmp/test_chmpx_slave.log 2>&1"; + exec($killcmd); + } + // kill chmpx server + if($procid == sprintf("%d", intval($procid))){ + $killcmd = "kill -HUP " . $procid . " >> /tmp/test_chmpx_server.log 2>&1"; + exec($killcmd); + } +} + +?> +--EXPECT-- +OK +--CLEAN-- + +--DESCRIPTION-- +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * End: + * vim600: noexpandtab sw=4 ts=4 fdm=marker + * vim<600: noexpandtab sw=4 ts=4 + */ diff --git a/tests/k2hdkcpx_clear_subkeys.phpt b/tests/k2hdkcpx_clear_subkeys.phpt new file mode 100644 index 0000000..d1f845f --- /dev/null +++ b/tests/k2hdkcpx_clear_subkeys.phpt @@ -0,0 +1,122 @@ +--TEST-- +k2hdkcpx_clear_subkey +--CREDITS-- +K2HDKC PHP Extension library + +Copyright 2023 Yahoo Japan Corporation. + +K2HDKC is k2hash based distributed KVS cluster. +K2HDKC uses K2HASH, CHMPX, FULLOCK libraries. K2HDKC supports +distributed KVS cluster server program and client libraries. + +For the full copyright and license information, please view +the license file that was distributed with this source code. +--EXTENSIONS-- +k2hdkcpx +--FILE-- + /tmp/server.log 2>&1 &"); + time_nanosleep(0, 500 * 1000 * 1000); + $procid = exec("ps ax | grep chmpx | grep tests/server.ini | grep -v grep | awk '{print $1}'"); + + // run chmpx slave + exec("chmpx -conf ./tests/slave.ini -d silent > /tmp/slave.log 2>&1 &"); + time_nanosleep(0, 500 * 1000 * 1000); + $procid_slave = exec("ps ax | grep chmpx | grep tests/slave.ini | grep -v grep | awk '{print $1}'"); + + // run k2hdkc + exec("k2hdkc -conf ./tests/server.ini -d silent > /tmp/k2hdkc.log 2>&1 &"); + time_nanosleep(0, 500 * 1000 * 1000); + $procid_k2hdkc = exec("ps ax | grep k2hdkc | grep tests/server.ini | grep -v grep | awk '{print $1}'"); + + // echo $procid_k2hdkc; + $handle = k2hdkcpx_open("./tests/slave.ini"); + + if(false !== $handle){ + $key = "key"; + $subkey = "subkey"; + $subval = "subval"; + // 1. set + k2hdkcpx_add_subkey($handle, $key, $subkey, $subval); + time_nanosleep(0, 250 * 1000 * 1000); + + if ($subval === k2hdkcpx_get_value($handle, $subkey)) { + // 2. clear + k2hdkcpx_clear_subkeys($handle, $key); + time_nanosleep(0, 250 * 1000 * 1000); + + // 3. check if subkey is empty + $r = k2hdkcpx_get_subkeys($handle, $key); + if(!$r) { + echo "OK"; + }else{ + echo "NG"; + } + }else{ + echo "NG"; + } + k2hdkcpx_close($handle); + }else{ + echo "NG"; + } + // kill k2hdkc + if($procid_k2hdkc == sprintf("%d", intval($procid_k2hdkc))){ + $killcmd = "kill -HUP " . $procid_k2hdkc . " >> /tmp/test_k2hdkc.log 2>&1"; + exec($killcmd); + } + // kill chmpx slave + if($procid_slave == sprintf("%d", intval($procid_slave))){ + $killcmd = "kill -HUP " . $procid_slave . " >> /tmp/test_chmpx_slave.log 2>&1"; + exec($killcmd); + } + // kill chmpx server + if($procid == sprintf("%d", intval($procid))){ + $killcmd = "kill -HUP " . $procid . " >> /tmp/test_chmpx_server.log 2>&1"; + exec($killcmd); + } +} + +?> +--EXPECT-- +OK +--CLEAN-- + +--DESCRIPTION-- +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * End: + * vim600: noexpandtab sw=4 ts=4 fdm=marker + * vim<600: noexpandtab sw=4 ts=4 + */ diff --git a/tests/k2hdkcpx_close.phpt b/tests/k2hdkcpx_close.phpt new file mode 100644 index 0000000..49f112e --- /dev/null +++ b/tests/k2hdkcpx_close.phpt @@ -0,0 +1,101 @@ +--TEST-- +k2hdkcpx_close +--CREDITS-- +K2HDKC PHP Extension library + +Copyright 2023 Yahoo Japan Corporation. + +K2HDKC is k2hash based distributed KVS cluster. +K2HDKC uses K2HASH, CHMPX, FULLOCK libraries. K2HDKC supports +distributed KVS cluster server program and client libraries. + +For the full copyright and license information, please view +the license file that was distributed with this source code. +--EXTENSIONS-- +k2hdkcpx +--FILE-- + /tmp/server.log 2>&1 &"); + time_nanosleep(0, 500 * 1000 * 1000); + $procid = exec("ps ax | grep chmpx | grep tests/server.ini | grep -v grep | awk '{print $1}'"); + + // run chmpx slave + exec("chmpx -conf ./tests/slave.ini -d silent > /tmp/slave.log 2>&1 &"); + time_nanosleep(0, 500 * 1000 * 1000); + $procid_slave = exec("ps ax | grep chmpx | grep tests/slave.ini | grep -v grep | awk '{print $1}'"); + + // run k2hdkc + exec("k2hdkc -conf ./tests/server.ini -d silent > /tmp/k2hdkc.log 2>&1 &"); + time_nanosleep(0, 500 * 1000 * 1000); + $procid_k2hdkc = exec("ps ax | grep k2hdkc | grep tests/server.ini | grep -v grep | awk '{print $1}'"); + + // echo $procid_k2hdkc; + $handle = k2hdkcpx_open("./tests/slave.ini"); + + if(false !== $handle){ + k2hdkcpx_close($handle); + echo "OK"; + }else{ + echo "NG"; + } + // kill k2hdkc + if($procid_k2hdkc == sprintf("%d", intval($procid_k2hdkc))){ + $killcmd = "kill -HUP " . $procid_k2hdkc . " >> /tmp/test_k2hdkc.log 2>&1"; + exec($killcmd); + } + // kill chmpx slave + if($procid_slave == sprintf("%d", intval($procid_slave))){ + $killcmd = "kill -HUP " . $procid_slave . " >> /tmp/test_chmpx_slave.log 2>&1"; + exec($killcmd); + } + // kill chmpx server + if($procid == sprintf("%d", intval($procid))){ + $killcmd = "kill -HUP " . $procid . " >> /tmp/test_chmpx_server.log 2>&1"; + exec($killcmd); + } +} + +?> +--EXPECT-- +OK +--CLEAN-- + +--DESCRIPTION-- +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * End: + * vim600: noexpandtab sw=4 ts=4 fdm=marker + * vim<600: noexpandtab sw=4 ts=4 + */ diff --git a/tests/k2hdkcpx_disable_comlog.phpt b/tests/k2hdkcpx_disable_comlog.phpt new file mode 100644 index 0000000..3152bf2 --- /dev/null +++ b/tests/k2hdkcpx_disable_comlog.phpt @@ -0,0 +1,31 @@ +--TEST-- +k2hdkcpx_disable_comlog +--CREDITS-- +K2HDKC PHP Extension library + +Copyright 2023 Yahoo Japan Corporation. + +K2HDKC is k2hash based distributed KVS cluster. +K2HDKC uses K2HASH, CHMPX, FULLOCK libraries. K2HDKC supports +distributed KVS cluster server program and client libraries. + +For the full copyright and license information, please view +the license file that was distributed with this source code. +--EXTENSIONS-- +k2hdkcpx +--FILE-- + +--EXPECT-- +OK +--DESCRIPTION-- +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * End: + * vim600: noexpandtab sw=4 ts=4 fdm=marker + * vim<600: noexpandtab sw=4 ts=4 + */ diff --git a/tests/k2hdkcpx_enable_comlog.phpt b/tests/k2hdkcpx_enable_comlog.phpt new file mode 100644 index 0000000..67f7dd7 --- /dev/null +++ b/tests/k2hdkcpx_enable_comlog.phpt @@ -0,0 +1,31 @@ +--TEST-- +k2hdkcpx_enable_comlog +--CREDITS-- +K2HDKC PHP Extension library + +Copyright 2023 Yahoo Japan Corporation. + +K2HDKC is k2hash based distributed KVS cluster. +K2HDKC uses K2HASH, CHMPX, FULLOCK libraries. K2HDKC supports +distributed KVS cluster server program and client libraries. + +For the full copyright and license information, please view +the license file that was distributed with this source code. +--EXTENSIONS-- +k2hdkcpx +--FILE-- + +--EXPECT-- +OK +--DESCRIPTION-- +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * End: + * vim600: noexpandtab sw=4 ts=4 fdm=marker + * vim<600: noexpandtab sw=4 ts=4 + */ diff --git a/tests/k2hdkcpx_get_attributes.phpt b/tests/k2hdkcpx_get_attributes.phpt new file mode 100644 index 0000000..52d1652 --- /dev/null +++ b/tests/k2hdkcpx_get_attributes.phpt @@ -0,0 +1,111 @@ +--TEST-- +k2hdkcpx_get_attributes +--CREDITS-- +K2HDKC PHP Extension library + +Copyright 2023 Yahoo Japan Corporation. + +K2HDKC is k2hash based distributed KVS cluster. +K2HDKC uses K2HASH, CHMPX, FULLOCK libraries. K2HDKC supports +distributed KVS cluster server program and client libraries. + +For the full copyright and license information, please view +the license file that was distributed with this source code. +--EXTENSIONS-- +k2hdkcpx +--FILE-- + /tmp/server.log 2>&1 &"); + time_nanosleep(0, 500 * 1000 * 1000); + $procid = exec("ps ax | grep chmpx | grep tests/server.ini | grep -v grep | awk '{print $1}'"); + + // run chmpx slave + exec("chmpx -conf ./tests/slave.ini -d silent > /tmp/slave.log 2>&1 &"); + time_nanosleep(0, 500 * 1000 * 1000); + $procid_slave = exec("ps ax | grep chmpx | grep tests/slave.ini | grep -v grep | awk '{print $1}'"); + + // run k2hdkc + exec("k2hdkc -conf ./tests/server.ini -d silent > /tmp/k2hdkc.log 2>&1 &"); + time_nanosleep(0, 500 * 1000 * 1000); + $procid_k2hdkc = exec("ps ax | grep k2hdkc | grep tests/server.ini | grep -v grep | awk '{print $1}'"); + + // echo $procid_k2hdkc; + $handle = k2hdkcpx_open("./tests/slave.ini"); + + if(false !== $handle){ + $key = "key"; + $val = "val"; + k2hdkcpx_set_value($handle, $key, $val); + time_nanosleep(0, 250 * 1000 * 1000); + + $arr = k2hdkcpx_get_attributes($handle, $key); + if ($arr[0] == 'mtime') { + echo "OK"; + }else{ + echo "NG"; + } + k2hdkcpx_close($handle); + }else{ + echo "NG"; + } + // kill k2hdkc + if($procid_k2hdkc == sprintf("%d", intval($procid_k2hdkc))){ + $killcmd = "kill -HUP " . $procid_k2hdkc . " >> /tmp/test_k2hdkc.log 2>&1"; + exec($killcmd); + } + // kill chmpx slave + if($procid_slave == sprintf("%d", intval($procid_slave))){ + $killcmd = "kill -HUP " . $procid_slave . " >> /tmp/test_chmpx_slave.log 2>&1"; + exec($killcmd); + } + // kill chmpx server + if($procid == sprintf("%d", intval($procid))){ + $killcmd = "kill -HUP " . $procid . " >> /tmp/test_chmpx_server.log 2>&1"; + exec($killcmd); + } +} + +?> +--EXPECT-- +OK +--CLEAN-- + +--DESCRIPTION-- +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * End: + * vim600: noexpandtab sw=4 ts=4 fdm=marker + * vim<600: noexpandtab sw=4 ts=4 + */ diff --git a/tests/k2hdkcpx_get_subkeys.phpt b/tests/k2hdkcpx_get_subkeys.phpt new file mode 100644 index 0000000..95c14ed --- /dev/null +++ b/tests/k2hdkcpx_get_subkeys.phpt @@ -0,0 +1,116 @@ +--TEST-- +k2hdkcpx_clear_subkey +--CREDITS-- +K2HDKC PHP Extension library + +Copyright 2023 Yahoo Japan Corporation. + +K2HDKC is k2hash based distributed KVS cluster. +K2HDKC uses K2HASH, CHMPX, FULLOCK libraries. K2HDKC supports +distributed KVS cluster server program and client libraries. + +For the full copyright and license information, please view +the license file that was distributed with this source code. +--EXTENSIONS-- +k2hdkcpx +--FILE-- + /tmp/server.log 2>&1 &"); + time_nanosleep(0, 500 * 1000 * 1000); + $procid = exec("ps ax | grep chmpx | grep tests/server.ini | grep -v grep | awk '{print $1}'"); + + // run chmpx slave + exec("chmpx -conf ./tests/slave.ini -d silent > /tmp/slave.log 2>&1 &"); + time_nanosleep(0, 500 * 1000 * 1000); + $procid_slave = exec("ps ax | grep chmpx | grep tests/slave.ini | grep -v grep | awk '{print $1}'"); + + // run k2hdkc + exec("k2hdkc -conf ./tests/server.ini -d silent > /tmp/k2hdkc.log 2>&1 &"); + time_nanosleep(0, 500 * 1000 * 1000); + $procid_k2hdkc = exec("ps ax | grep k2hdkc | grep tests/server.ini | grep -v grep | awk '{print $1}'"); + + // echo $procid_k2hdkc; + $handle = k2hdkcpx_open("./tests/slave.ini"); + + if(false !== $handle){ + $key = "key"; + $subkey = "subkey"; + $subval = "subval"; + // 1. set + k2hdkcpx_add_subkey($handle, $key, $subkey, $subval); + if ($subval === k2hdkcpx_get_value($handle, $subkey)) { + // 2. check if subkey is empty + $r = k2hdkcpx_get_subkeys($handle, $key); + if($r[0] = $subkey) { + echo "OK"; + }else{ + echo "NG"; + } + }else{ + echo "NG"; + } + k2hdkcpx_close($handle); + }else{ + echo "NG"; + } + // kill k2hdkc + if($procid_k2hdkc == sprintf("%d", intval($procid_k2hdkc))){ + $killcmd = "kill -HUP " . $procid_k2hdkc . " >> /tmp/test_k2hdkc.log 2>&1"; + exec($killcmd); + } + // kill chmpx slave + if($procid_slave == sprintf("%d", intval($procid_slave))){ + $killcmd = "kill -HUP " . $procid_slave . " >> /tmp/test_chmpx_slave.log 2>&1"; + exec($killcmd); + } + // kill chmpx server + if($procid == sprintf("%d", intval($procid))){ + $killcmd = "kill -HUP " . $procid . " >> /tmp/test_chmpx_server.log 2>&1"; + exec($killcmd); + } +} + +?> +--EXPECT-- +OK +--CLEAN-- + +--DESCRIPTION-- +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * End: + * vim600: noexpandtab sw=4 ts=4 fdm=marker + * vim<600: noexpandtab sw=4 ts=4 + */ diff --git a/tests/k2hdkcpx_get_value.phpt b/tests/k2hdkcpx_get_value.phpt new file mode 100644 index 0000000..8af26af --- /dev/null +++ b/tests/k2hdkcpx_get_value.phpt @@ -0,0 +1,110 @@ +--TEST-- +k2hdkcpx_get_value +--CREDITS-- +K2HDKC PHP Extension library + +Copyright 2023 Yahoo Japan Corporation. + +K2HDKC is k2hash based distributed KVS cluster. +K2HDKC uses K2HASH, CHMPX, FULLOCK libraries. K2HDKC supports +distributed KVS cluster server program and client libraries. + +For the full copyright and license information, please view +the license file that was distributed with this source code. +--EXTENSIONS-- +k2hdkcpx +--FILE-- + /tmp/server.log 2>&1 &"); + time_nanosleep(0, 500 * 1000 * 1000); + $procid = exec("ps ax | grep chmpx | grep tests/server.ini | grep -v grep | awk '{print $1}'"); + + // run chmpx slave + exec("chmpx -conf ./tests/slave.ini -d silent > /tmp/slave.log 2>&1 &"); + time_nanosleep(0, 500 * 1000 * 1000); + $procid_slave = exec("ps ax | grep chmpx | grep tests/slave.ini | grep -v grep | awk '{print $1}'"); + + // run k2hdkc + exec("k2hdkc -conf ./tests/server.ini -d silent > /tmp/k2hdkc.log 2>&1 &"); + time_nanosleep(0, 500 * 1000 * 1000); + $procid_k2hdkc = exec("ps ax | grep k2hdkc | grep tests/server.ini | grep -v grep | awk '{print $1}'"); + + // echo $procid_k2hdkc; + $handle = k2hdkcpx_open("./tests/slave.ini"); + + if(false !== $handle){ + $key = "key"; + $val = "val"; + k2hdkcpx_set_value($handle, $key, $val); + time_nanosleep(0, 250 * 1000 * 1000); + + if ($val === k2hdkcpx_get_value($handle, $key)) { + echo "OK"; + }else{ + echo "NG"; + } + k2hdkcpx_close($handle); + }else{ + echo "NG"; + } + // kill k2hdkc + if($procid_k2hdkc == sprintf("%d", intval($procid_k2hdkc))){ + $killcmd = "kill -HUP " . $procid_k2hdkc . " >> /tmp/test_k2hdkc.log 2>&1"; + exec($killcmd); + } + // kill chmpx slave + if($procid_slave == sprintf("%d", intval($procid_slave))){ + $killcmd = "kill -HUP " . $procid_slave . " >> /tmp/test_chmpx_slave.log 2>&1"; + exec($killcmd); + } + // kill chmpx server + if($procid == sprintf("%d", intval($procid))){ + $killcmd = "kill -HUP " . $procid . " >> /tmp/test_chmpx_server.log 2>&1"; + exec($killcmd); + } +} + +?> +--EXPECT-- +OK +--CLEAN-- + +--DESCRIPTION-- +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * End: + * vim600: noexpandtab sw=4 ts=4 fdm=marker + * vim<600: noexpandtab sw=4 ts=4 + */ diff --git a/tests/k2hdkcpx_init_get_debug.phpt b/tests/k2hdkcpx_init_get_debug.phpt new file mode 100644 index 0000000..4cd876f --- /dev/null +++ b/tests/k2hdkcpx_init_get_debug.phpt @@ -0,0 +1,32 @@ +--TEST-- +k2hdkcpx_ini_get_debug +--CREDITS-- +K2HDKC PHP Extension library + +Copyright 2023 Yahoo Japan Corporation. + +K2HDKC is k2hash based distributed KVS cluster. +K2HDKC uses K2HASH, CHMPX, FULLOCK libraries. K2HDKC supports +distributed KVS cluster server program and client libraries. + +For the full copyright and license information, please view +the license file that was distributed with this source code. +--EXTENSIONS-- +k2hdkcpx +--FILE-- + +--EXPECT-- +string(6) "silent" +OK +--DESCRIPTION-- +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * End: + * vim600: noexpandtab sw=4 ts=4 fdm=marker + * vim<600: noexpandtab sw=4 ts=4 + */ diff --git a/tests/k2hdkcpx_is_enable_comlog.phpt b/tests/k2hdkcpx_is_enable_comlog.phpt new file mode 100644 index 0000000..4df4b1e --- /dev/null +++ b/tests/k2hdkcpx_is_enable_comlog.phpt @@ -0,0 +1,31 @@ +--TEST-- +k2hdkcpx_is_enable_comlog +--CREDITS-- +K2HDKC PHP Extension library + +Copyright 2023 Yahoo Japan Corporation. + +K2HDKC is k2hash based distributed KVS cluster. +K2HDKC uses K2HASH, CHMPX, FULLOCK libraries. K2HDKC supports +distributed KVS cluster server program and client libraries. + +For the full copyright and license information, please view +the license file that was distributed with this source code. +--EXTENSIONS-- +k2hdkcpx +--FILE-- + +--EXPECT-- +OK +--DESCRIPTION-- +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * End: + * vim600: noexpandtab sw=4 ts=4 fdm=marker + * vim<600: noexpandtab sw=4 ts=4 + */ diff --git a/tests/k2hdkcpx_key_queue_get.phpt b/tests/k2hdkcpx_key_queue_get.phpt new file mode 100644 index 0000000..4830934 --- /dev/null +++ b/tests/k2hdkcpx_key_queue_get.phpt @@ -0,0 +1,113 @@ +--TEST-- +k2hdkcpx_key_queue_get +--CREDITS-- +K2HDKC PHP Extension library + +Copyright 2023 Yahoo Japan Corporation. + +K2HDKC is k2hash based distributed KVS cluster. +K2HDKC uses K2HASH, CHMPX, FULLOCK libraries. K2HDKC supports +distributed KVS cluster server program and client libraries. + +For the full copyright and license information, please view +the license file that was distributed with this source code. +--EXTENSIONS-- +k2hdkcpx +--FILE-- + /tmp/server.log 2>&1 &"); + time_nanosleep(0, 500 * 1000 * 1000); + $procid = exec("ps ax | grep chmpx | grep tests/server.ini | grep -v grep | awk '{print $1}'"); + + // run chmpx slave + exec("chmpx -conf ./tests/slave.ini -d silent > /tmp/slave.log 2>&1 &"); + time_nanosleep(0, 500 * 1000 * 1000); + $procid_slave = exec("ps ax | grep chmpx | grep tests/slave.ini | grep -v grep | awk '{print $1}'"); + + // run k2hdkc + exec("k2hdkc -conf ./tests/server.ini -d silent > /tmp/k2hdkc.log 2>&1 &"); + time_nanosleep(0, 500 * 1000 * 1000); + $procid_k2hdkc = exec("ps ax | grep k2hdkc | grep tests/server.ini | grep -v grep | awk '{print $1}'"); + + // echo $procid_k2hdkc; + $handle = k2hdkcpx_open("./tests/slave.ini"); + + if(false !== $handle){ + $prefix = "p1"; + $key = "key"; + $val = "val"; + k2hdkcpx_key_queue_put($handle, $prefix, $key, $val); + time_nanosleep(0, 250 * 1000 * 1000); + + $arr = array($key => $val); + if ($arr === k2hdkcpx_key_queue_get($handle, $prefix)) { + echo "OK"; + }else{ + echo "NG"; + } + k2hdkcpx_close($handle); + }else{ + echo "NG"; + } + // kill k2hdkc + if($procid_k2hdkc == sprintf("%d", intval($procid_k2hdkc))){ + $killcmd = "kill -HUP " . $procid_k2hdkc . " >> /tmp/test_k2hdkc.log 2>&1"; + exec($killcmd); + } + // kill chmpx slave + if($procid_slave == sprintf("%d", intval($procid_slave))){ + $killcmd = "kill -HUP " . $procid_slave . " >> /tmp/test_chmpx_slave.log 2>&1"; + exec($killcmd); + } + // kill chmpx server + if($procid == sprintf("%d", intval($procid))){ + $killcmd = "kill -HUP " . $procid . " >> /tmp/test_chmpx_server.log 2>&1"; + exec($killcmd); + } +} + +?> +--EXPECT-- +OK +--CLEAN-- + +--DESCRIPTION-- +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * End: + * vim600: noexpandtab sw=4 ts=4 fdm=marker + * vim<600: noexpandtab sw=4 ts=4 + */ diff --git a/tests/k2hdkcpx_key_queue_put.phpt b/tests/k2hdkcpx_key_queue_put.phpt new file mode 100644 index 0000000..410bbe4 --- /dev/null +++ b/tests/k2hdkcpx_key_queue_put.phpt @@ -0,0 +1,112 @@ +--TEST-- +k2hdkcpx_key_queue_put +--CREDITS-- +K2HDKC PHP Extension library + +Copyright 2023 Yahoo Japan Corporation. + +K2HDKC is k2hash based distributed KVS cluster. +K2HDKC uses K2HASH, CHMPX, FULLOCK libraries. K2HDKC supports +distributed KVS cluster server program and client libraries. + +For the full copyright and license information, please view +the license file that was distributed with this source code. +--EXTENSIONS-- +k2hdkcpx +--FILE-- + /tmp/server.log 2>&1 &"); + time_nanosleep(0, 500 * 1000 * 1000); + $procid = exec("ps ax | grep chmpx | grep tests/server.ini | grep -v grep | awk '{print $1}'"); + + // run chmpx slave + exec("chmpx -conf ./tests/slave.ini -d silent > /tmp/slave.log 2>&1 &"); + time_nanosleep(0, 500 * 1000 * 1000); + $procid_slave = exec("ps ax | grep chmpx | grep tests/slave.ini | grep -v grep | awk '{print $1}'"); + + // run k2hdkc + exec("k2hdkc -conf ./tests/server.ini -d silent > /tmp/k2hdkc.log 2>&1 &"); + time_nanosleep(0, 500 * 1000 * 1000); + $procid_k2hdkc = exec("ps ax | grep k2hdkc | grep tests/server.ini | grep -v grep | awk '{print $1}'"); + + // echo $procid_k2hdkc; + $handle = k2hdkcpx_open("./tests/slave.ini"); + + if(false !== $handle){ + $prefix = "p1"; + $key = "key"; + $val = "val"; + k2hdkcpx_key_queue_put($handle, $prefix, $key, $val); + time_nanosleep(0, 250 * 1000 * 1000); + + $arr = array($key => $val); + if ($arr === k2hdkcpx_key_queue_get($handle, $prefix)) { + echo "OK"; + }else{ + echo "NG"; + } + k2hdkcpx_close($handle); + }else{ + echo "NG"; + } + // kill k2hdkc + if($procid_k2hdkc == sprintf("%d", intval($procid_k2hdkc))){ + $killcmd = "kill -HUP " . $procid_k2hdkc . " >> /tmp/test_k2hdkc.log 2>&1"; + exec($killcmd); + } + // kill chmpx slave + if($procid_slave == sprintf("%d", intval($procid_slave))){ + $killcmd = "kill -HUP " . $procid_slave . " >> /tmp/test_chmpx_slave.log 2>&1"; + exec($killcmd); + } + // kill chmpx server + if($procid == sprintf("%d", intval($procid))){ + $killcmd = "kill -HUP " . $procid . " >> /tmp/test_chmpx_server.log 2>&1"; + exec($killcmd); + } +} + +?> +--EXPECT-- +OK +--CLEAN-- + +--DESCRIPTION-- +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * End: + * vim600: noexpandtab sw=4 ts=4 fdm=marker + * vim<600: noexpandtab sw=4 ts=4 + */ diff --git a/tests/k2hdkcpx_load_debug_env.phpt b/tests/k2hdkcpx_load_debug_env.phpt new file mode 100644 index 0000000..7bfe050 --- /dev/null +++ b/tests/k2hdkcpx_load_debug_env.phpt @@ -0,0 +1,31 @@ +--TEST-- +k2hdkcpx_load_debug_env +--CREDITS-- +K2HDKC PHP Extension library + +Copyright 2023 Yahoo Japan Corporation. + +K2HDKC is k2hash based distributed KVS cluster. +K2HDKC uses K2HASH, CHMPX, FULLOCK libraries. K2HDKC supports +distributed KVS cluster server program and client libraries. + +For the full copyright and license information, please view +the license file that was distributed with this source code. +--EXTENSIONS-- +k2hdkcpx +--FILE-- + +--EXPECT-- +OK +--DESCRIPTION-- +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * End: + * vim600: noexpandtab sw=4 ts=4 fdm=marker + * vim<600: noexpandtab sw=4 ts=4 + */ diff --git a/tests/k2hdkcpx_open.phpt b/tests/k2hdkcpx_open.phpt new file mode 100644 index 0000000..49f112e --- /dev/null +++ b/tests/k2hdkcpx_open.phpt @@ -0,0 +1,101 @@ +--TEST-- +k2hdkcpx_close +--CREDITS-- +K2HDKC PHP Extension library + +Copyright 2023 Yahoo Japan Corporation. + +K2HDKC is k2hash based distributed KVS cluster. +K2HDKC uses K2HASH, CHMPX, FULLOCK libraries. K2HDKC supports +distributed KVS cluster server program and client libraries. + +For the full copyright and license information, please view +the license file that was distributed with this source code. +--EXTENSIONS-- +k2hdkcpx +--FILE-- + /tmp/server.log 2>&1 &"); + time_nanosleep(0, 500 * 1000 * 1000); + $procid = exec("ps ax | grep chmpx | grep tests/server.ini | grep -v grep | awk '{print $1}'"); + + // run chmpx slave + exec("chmpx -conf ./tests/slave.ini -d silent > /tmp/slave.log 2>&1 &"); + time_nanosleep(0, 500 * 1000 * 1000); + $procid_slave = exec("ps ax | grep chmpx | grep tests/slave.ini | grep -v grep | awk '{print $1}'"); + + // run k2hdkc + exec("k2hdkc -conf ./tests/server.ini -d silent > /tmp/k2hdkc.log 2>&1 &"); + time_nanosleep(0, 500 * 1000 * 1000); + $procid_k2hdkc = exec("ps ax | grep k2hdkc | grep tests/server.ini | grep -v grep | awk '{print $1}'"); + + // echo $procid_k2hdkc; + $handle = k2hdkcpx_open("./tests/slave.ini"); + + if(false !== $handle){ + k2hdkcpx_close($handle); + echo "OK"; + }else{ + echo "NG"; + } + // kill k2hdkc + if($procid_k2hdkc == sprintf("%d", intval($procid_k2hdkc))){ + $killcmd = "kill -HUP " . $procid_k2hdkc . " >> /tmp/test_k2hdkc.log 2>&1"; + exec($killcmd); + } + // kill chmpx slave + if($procid_slave == sprintf("%d", intval($procid_slave))){ + $killcmd = "kill -HUP " . $procid_slave . " >> /tmp/test_chmpx_slave.log 2>&1"; + exec($killcmd); + } + // kill chmpx server + if($procid == sprintf("%d", intval($procid))){ + $killcmd = "kill -HUP " . $procid . " >> /tmp/test_chmpx_server.log 2>&1"; + exec($killcmd); + } +} + +?> +--EXPECT-- +OK +--CLEAN-- + +--DESCRIPTION-- +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * End: + * vim600: noexpandtab sw=4 ts=4 fdm=marker + * vim<600: noexpandtab sw=4 ts=4 + */ diff --git a/tests/k2hdkcpx_queue_get.phpt b/tests/k2hdkcpx_queue_get.phpt new file mode 100644 index 0000000..604f6da --- /dev/null +++ b/tests/k2hdkcpx_queue_get.phpt @@ -0,0 +1,111 @@ +--TEST-- +k2hdkcpx_queue_get +--CREDITS-- +K2HDKC PHP Extension library + +Copyright 2023 Yahoo Japan Corporation. + +K2HDKC is k2hash based distributed KVS cluster. +K2HDKC uses K2HASH, CHMPX, FULLOCK libraries. K2HDKC supports +distributed KVS cluster server program and client libraries. + +For the full copyright and license information, please view +the license file that was distributed with this source code. +--EXTENSIONS-- +k2hdkcpx +--FILE-- + /tmp/server.log 2>&1 &"); + time_nanosleep(0, 500 * 1000 * 1000); + $procid = exec("ps ax | grep chmpx | grep tests/server.ini | grep -v grep | awk '{print $1}'"); + + // run chmpx slave + exec("chmpx -conf ./tests/slave.ini -d silent > /tmp/slave.log 2>&1 &"); + time_nanosleep(0, 500 * 1000 * 1000); + $procid_slave = exec("ps ax | grep chmpx | grep tests/slave.ini | grep -v grep | awk '{print $1}'"); + + // run k2hdkc + exec("k2hdkc -conf ./tests/server.ini -d silent > /tmp/k2hdkc.log 2>&1 &"); + time_nanosleep(0, 500 * 1000 * 1000); + $procid_k2hdkc = exec("ps ax | grep k2hdkc | grep tests/server.ini | grep -v grep | awk '{print $1}'"); + + // echo $procid_k2hdkc; + $handle = k2hdkcpx_open("./tests/slave.ini"); + + if(false !== $handle){ + $key = "key"; + $val = "val"; + k2hdkcpx_queue_put($handle, $key, $val); + time_nanosleep(0, 250 * 1000 * 1000); + + if ($val === k2hdkcpx_queue_get($handle, $key)) { + echo "OK"; + }else{ + echo "NG"; + } + k2hdkcpx_close($handle); + }else{ + echo "NG"; + } + // kill k2hdkc + if($procid_k2hdkc == sprintf("%d", intval($procid_k2hdkc))){ + $killcmd = "kill -HUP " . $procid_k2hdkc . " >> /tmp/test_k2hdkc.log 2>&1"; + exec($killcmd); + } + // kill chmpx slave + if($procid_slave == sprintf("%d", intval($procid_slave))){ + $killcmd = "kill -HUP " . $procid_slave . " >> /tmp/test_chmpx_slave.log 2>&1"; + exec($killcmd); + } + // kill chmpx server + if($procid == sprintf("%d", intval($procid))){ + $killcmd = "kill -HUP " . $procid . " >> /tmp/test_chmpx_server.log 2>&1"; + exec($killcmd); + } +} + +?> +--EXPECT-- +OK +--CLEAN-- + +--DESCRIPTION-- +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * End: + * vim600: noexpandtab sw=4 ts=4 fdm=marker + * vim<600: noexpandtab sw=4 ts=4 + */ diff --git a/tests/k2hdkcpx_queue_put.phpt b/tests/k2hdkcpx_queue_put.phpt new file mode 100644 index 0000000..306a555 --- /dev/null +++ b/tests/k2hdkcpx_queue_put.phpt @@ -0,0 +1,110 @@ +--TEST-- +k2hdkcpx_queue_put +--CREDITS-- +K2HDKC PHP Extension library + +Copyright 2023 Yahoo Japan Corporation. + +K2HDKC is k2hash based distributed KVS cluster. +K2HDKC uses K2HASH, CHMPX, FULLOCK libraries. K2HDKC supports +distributed KVS cluster server program and client libraries. + +For the full copyright and license information, please view +the license file that was distributed with this source code. +--EXTENSIONS-- +k2hdkcpx +--FILE-- + /tmp/server.log 2>&1 &"); + time_nanosleep(0, 500 * 1000 * 1000); + $procid = exec("ps ax | grep chmpx | grep tests/server.ini | grep -v grep | awk '{print $1}'"); + + // run chmpx slave + exec("chmpx -conf ./tests/slave.ini -d silent > /tmp/slave.log 2>&1 &"); + time_nanosleep(0, 500 * 1000 * 1000); + $procid_slave = exec("ps ax | grep chmpx | grep tests/slave.ini | grep -v grep | awk '{print $1}'"); + + // run k2hdkc + exec("k2hdkc -conf ./tests/server.ini -d silent > /tmp/k2hdkc.log 2>&1 &"); + time_nanosleep(0, 500 * 1000 * 1000); + $procid_k2hdkc = exec("ps ax | grep k2hdkc | grep tests/server.ini | grep -v grep | awk '{print $1}'"); + + // echo $procid_k2hdkc; + $handle = k2hdkcpx_open("./tests/slave.ini"); + + if(false !== $handle){ + $key = "key"; + $val = "val"; + k2hdkcpx_queue_put($handle, $key, $val); + time_nanosleep(0, 250 * 1000 * 1000); + + if ($val === k2hdkcpx_queue_get($handle, $key)) { + echo "OK"; + }else{ + echo "NG"; + } + k2hdkcpx_close($handle); + }else{ + echo "NG"; + } + // kill k2hdkc + if($procid_k2hdkc == sprintf("%d", intval($procid_k2hdkc))){ + $killcmd = "kill -HUP " . $procid_k2hdkc . " >> /tmp/test_k2hdkc.log 2>&1"; + exec($killcmd); + } + // kill chmpx slave + if($procid_slave == sprintf("%d", intval($procid_slave))){ + $killcmd = "kill -HUP " . $procid_slave . " >> /tmp/test_chmpx_slave.log 2>&1"; + exec($killcmd); + } + // kill chmpx server + if($procid == sprintf("%d", intval($procid))){ + $killcmd = "kill -HUP " . $procid . " >> /tmp/test_chmpx_server.log 2>&1"; + exec($killcmd); + } +} + +?> +--EXPECT-- +OK +--CLEAN-- + +--DESCRIPTION-- +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * End: + * vim600: noexpandtab sw=4 ts=4 fdm=marker + * vim<600: noexpandtab sw=4 ts=4 + */ diff --git a/tests/k2hdkcpx_remove.phpt b/tests/k2hdkcpx_remove.phpt new file mode 100644 index 0000000..830c3ad --- /dev/null +++ b/tests/k2hdkcpx_remove.phpt @@ -0,0 +1,114 @@ +--TEST-- +k2hdkcpx_remove +--CREDITS-- +K2HDKC PHP Extension library + +Copyright 2023 Yahoo Japan Corporation. + +K2HDKC is k2hash based distributed KVS cluster. +K2HDKC uses K2HASH, CHMPX, FULLOCK libraries. K2HDKC supports +distributed KVS cluster server program and client libraries. + +For the full copyright and license information, please view +the license file that was distributed with this source code. +--EXTENSIONS-- +k2hdkcpx +--FILE-- + /tmp/server.log 2>&1 &"); + time_nanosleep(0, 500 * 1000 * 1000); + $procid = exec("ps ax | grep chmpx | grep tests/server.ini | grep -v grep | awk '{print $1}'"); + + // run chmpx slave + exec("chmpx -conf ./tests/slave.ini -d silent > /tmp/slave.log 2>&1 &"); + time_nanosleep(0, 500 * 1000 * 1000); + $procid_slave = exec("ps ax | grep chmpx | grep tests/slave.ini | grep -v grep | awk '{print $1}'"); + + // run k2hdkc + exec("k2hdkc -conf ./tests/server.ini -d silent > /tmp/k2hdkc.log 2>&1 &"); + time_nanosleep(0, 500 * 1000 * 1000); + $procid_k2hdkc = exec("ps ax | grep k2hdkc | grep tests/server.ini | grep -v grep | awk '{print $1}'"); + + // echo $procid_k2hdkc; + $handle = k2hdkcpx_open("./tests/slave.ini"); + + if(false !== $handle){ + $key = "key"; + $val = "val"; + k2hdkcpx_set_value($handle, $key, $val); + time_nanosleep(0, 250 * 1000 * 1000); + + if ($val === k2hdkcpx_get_value($handle, $key)) { + if (k2hdkcpx_remove($handle, $key)) { + echo "OK"; + }else{ + echo "NG"; + } + }else{ + echo "NG"; + } + k2hdkcpx_close($handle); + }else{ + echo "NG"; + } + // kill k2hdkc + if($procid_k2hdkc == sprintf("%d", intval($procid_k2hdkc))){ + $killcmd = "kill -HUP " . $procid_k2hdkc . " >> /tmp/test_k2hdkc.log 2>&1"; + exec($killcmd); + } + // kill chmpx slave + if($procid_slave == sprintf("%d", intval($procid_slave))){ + $killcmd = "kill -HUP " . $procid_slave . " >> /tmp/test_chmpx_slave.log 2>&1"; + exec($killcmd); + } + // kill chmpx server + if($procid == sprintf("%d", intval($procid))){ + $killcmd = "kill -HUP " . $procid . " >> /tmp/test_chmpx_server.log 2>&1"; + exec($killcmd); + } +} + +?> +--EXPECT-- +OK +--CLEAN-- + +--DESCRIPTION-- +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * End: + * vim600: noexpandtab sw=4 ts=4 fdm=marker + * vim<600: noexpandtab sw=4 ts=4 + */ diff --git a/tests/k2hdkcpx_remove_subkeys.phpt b/tests/k2hdkcpx_remove_subkeys.phpt new file mode 100644 index 0000000..c05741e --- /dev/null +++ b/tests/k2hdkcpx_remove_subkeys.phpt @@ -0,0 +1,115 @@ +--TEST-- +k2hdkcpx_remove_subkeys +--CREDITS-- +K2HDKC PHP Extension library + +Copyright 2023 Yahoo Japan Corporation. + +K2HDKC is k2hash based distributed KVS cluster. +K2HDKC uses K2HASH, CHMPX, FULLOCK libraries. K2HDKC supports +distributed KVS cluster server program and client libraries. + +For the full copyright and license information, please view +the license file that was distributed with this source code. +--EXTENSIONS-- +k2hdkcpx +--FILE-- + /tmp/server.log 2>&1 &"); + time_nanosleep(0, 500 * 1000 * 1000); + $procid = exec("ps ax | grep chmpx | grep tests/server.ini | grep -v grep | awk '{print $1}'"); + + // run chmpx slave + exec("chmpx -conf ./tests/slave.ini -d silent > /tmp/slave.log 2>&1 &"); + time_nanosleep(0, 500 * 1000 * 1000); + $procid_slave = exec("ps ax | grep chmpx | grep tests/slave.ini | grep -v grep | awk '{print $1}'"); + + // run k2hdkc + exec("k2hdkc -conf ./tests/server.ini -d silent > /tmp/k2hdkc.log 2>&1 &"); + time_nanosleep(0, 500 * 1000 * 1000); + $procid_k2hdkc = exec("ps ax | grep k2hdkc | grep tests/server.ini | grep -v grep | awk '{print $1}'"); + + // echo $procid_k2hdkc; + $handle = k2hdkcpx_open("./tests/slave.ini"); + + if(false !== $handle){ + $key = "key"; + $subkey = "subkey"; + $subval = "subval"; + k2hdkcpx_add_subkey($handle, $key, $subkey, $subval); + time_nanosleep(0, 250 * 1000 * 1000); + + if ($subval === k2hdkcpx_get_value($handle, $subkey)) { + if (k2hdkcpx_remove_subkeys($handle, $key, array($subkey))) { + echo "OK"; + }else{ + echo "NG"; + } + }else{ + echo "NG"; + } + k2hdkcpx_close($handle); + }else{ + echo "NG"; + } + // kill k2hdkc + if($procid_k2hdkc == sprintf("%d", intval($procid_k2hdkc))){ + $killcmd = "kill -HUP " . $procid_k2hdkc . " >> /tmp/test_k2hdkc.log 2>&1"; + exec($killcmd); + } + // kill chmpx slave + if($procid_slave == sprintf("%d", intval($procid_slave))){ + $killcmd = "kill -HUP " . $procid_slave . " >> /tmp/test_chmpx_slave.log 2>&1"; + exec($killcmd); + } + // kill chmpx server + if($procid == sprintf("%d", intval($procid))){ + $killcmd = "kill -HUP " . $procid . " >> /tmp/test_chmpx_server.log 2>&1"; + exec($killcmd); + } +} + +?> +--EXPECT-- +OK +--CLEAN-- + +--DESCRIPTION-- +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * End: + * vim600: noexpandtab sw=4 ts=4 fdm=marker + * vim<600: noexpandtab sw=4 ts=4 + */ diff --git a/tests/k2hdkcpx_rename.phpt b/tests/k2hdkcpx_rename.phpt new file mode 100644 index 0000000..588d01d --- /dev/null +++ b/tests/k2hdkcpx_rename.phpt @@ -0,0 +1,116 @@ +--TEST-- +k2hdkcpx_rename +--CREDITS-- +K2HDKC PHP Extension library + +Copyright 2023 Yahoo Japan Corporation. + +K2HDKC is k2hash based distributed KVS cluster. +K2HDKC uses K2HASH, CHMPX, FULLOCK libraries. K2HDKC supports +distributed KVS cluster server program and client libraries. + +For the full copyright and license information, please view +the license file that was distributed with this source code. +--EXTENSIONS-- +k2hdkcpx +--FILE-- + /tmp/server.log 2>&1 &"); + time_nanosleep(0, 500 * 1000 * 1000); + $procid = exec("ps ax | grep chmpx | grep tests/server.ini | grep -v grep | awk '{print $1}'"); + + // run chmpx slave + exec("chmpx -conf ./tests/slave.ini -d silent > /tmp/slave.log 2>&1 &"); + time_nanosleep(0, 500 * 1000 * 1000); + $procid_slave = exec("ps ax | grep chmpx | grep tests/slave.ini | grep -v grep | awk '{print $1}'"); + + // run k2hdkc + exec("k2hdkc -conf ./tests/server.ini -d silent > /tmp/k2hdkc.log 2>&1 &"); + time_nanosleep(0, 500 * 1000 * 1000); + $procid_k2hdkc = exec("ps ax | grep k2hdkc | grep tests/server.ini | grep -v grep | awk '{print $1}'"); + + // echo $procid_k2hdkc; + $handle = k2hdkcpx_open("./tests/slave.ini"); + + if(false !== $handle){ + $key = "key"; + $val = "val"; + k2hdkcpx_set_value($handle, $key, $val); + time_nanosleep(0, 250 * 1000 * 1000); + + if ($val === k2hdkcpx_get_value($handle, $key)) { + $newkey = "newkey"; + if(k2hdkcpx_rename($handle, $key, $newkey)) { + echo "OK"; + }else{ + echo "NG"; + } + }else{ + echo "NG"; + } + k2hdkcpx_close($handle); + }else{ + echo "NG"; + } + // kill k2hdkc + if($procid_k2hdkc == sprintf("%d", intval($procid_k2hdkc))){ + $killcmd = "kill -HUP " . $procid_k2hdkc . " >> /tmp/test_k2hdkc.log 2>&1"; + exec($killcmd); + } + // kill chmpx slave + if($procid_slave == sprintf("%d", intval($procid_slave))){ + $killcmd = "kill -HUP " . $procid_slave . " >> /tmp/test_chmpx_slave.log 2>&1"; + exec($killcmd); + } + // kill chmpx server + if($procid == sprintf("%d", intval($procid))){ + $killcmd = "kill -HUP " . $procid . " >> /tmp/test_chmpx_server.log 2>&1"; + exec($killcmd); + } +} + +?> +--EXPECT-- +OK +--CLEAN-- + +--DESCRIPTION-- +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * End: + * vim600: noexpandtab sw=4 ts=4 fdm=marker + * vim<600: noexpandtab sw=4 ts=4 + */ diff --git a/tests/k2hdkcpx_set_debug_file.phpt b/tests/k2hdkcpx_set_debug_file.phpt new file mode 100644 index 0000000..3f2d946 --- /dev/null +++ b/tests/k2hdkcpx_set_debug_file.phpt @@ -0,0 +1,34 @@ +--TEST-- +k2hdkcpx_set_debug_file +--CREDITS-- +K2HDKC PHP Extension library + +Copyright 2023 Yahoo Japan Corporation. + +K2HDKC is k2hash based distributed KVS cluster. +K2HDKC uses K2HASH, CHMPX, FULLOCK libraries. K2HDKC supports +distributed KVS cluster server program and client libraries. + +For the full copyright and license information, please view +the license file that was distributed with this source code. +--EXTENSIONS-- +k2hdkcpx +--FILE-- + +--EXPECT-- +OK +--DESCRIPTION-- +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * End: + * vim600: noexpandtab sw=4 ts=4 fdm=marker + * vim<600: noexpandtab sw=4 ts=4 + */ diff --git a/tests/k2hdkcpx_set_debug_level_dump.phpt b/tests/k2hdkcpx_set_debug_level_dump.phpt new file mode 100644 index 0000000..c00ff16 --- /dev/null +++ b/tests/k2hdkcpx_set_debug_level_dump.phpt @@ -0,0 +1,31 @@ +--TEST-- +k2hdkcpx_set_debug_level_dump +--CREDITS-- +K2HDKC PHP Extension library + +Copyright 2023 Yahoo Japan Corporation. + +K2HDKC is k2hash based distributed KVS cluster. +K2HDKC uses K2HASH, CHMPX, FULLOCK libraries. K2HDKC supports +distributed KVS cluster server program and client libraries. + +For the full copyright and license information, please view +the license file that was distributed with this source code. +--EXTENSIONS-- +k2hdkcpx +--FILE-- + +--EXPECT-- +OK +--DESCRIPTION-- +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * End: + * vim600: noexpandtab sw=4 ts=4 fdm=marker + * vim<600: noexpandtab sw=4 ts=4 + */ diff --git a/tests/k2hdkcpx_set_debug_level_error.phpt b/tests/k2hdkcpx_set_debug_level_error.phpt new file mode 100644 index 0000000..1ce34f3 --- /dev/null +++ b/tests/k2hdkcpx_set_debug_level_error.phpt @@ -0,0 +1,31 @@ +--TEST-- +k2hdkcpx_set_debug_level_error +--CREDITS-- +K2HDKC PHP Extension library + +Copyright 2023 Yahoo Japan Corporation. + +K2HDKC is k2hash based distributed KVS cluster. +K2HDKC uses K2HASH, CHMPX, FULLOCK libraries. K2HDKC supports +distributed KVS cluster server program and client libraries. + +For the full copyright and license information, please view +the license file that was distributed with this source code. +--EXTENSIONS-- +k2hdkcpx +--FILE-- + +--EXPECT-- +OK +--DESCRIPTION-- +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * End: + * vim600: noexpandtab sw=4 ts=4 fdm=marker + * vim<600: noexpandtab sw=4 ts=4 + */ diff --git a/tests/k2hdkcpx_set_debug_level_message.phpt b/tests/k2hdkcpx_set_debug_level_message.phpt new file mode 100644 index 0000000..e427c1d --- /dev/null +++ b/tests/k2hdkcpx_set_debug_level_message.phpt @@ -0,0 +1,31 @@ +--TEST-- +k2hdkcpx_set_debug_level_message +--CREDITS-- +K2HDKC PHP Extension library + +Copyright 2023 Yahoo Japan Corporation. + +K2HDKC is k2hash based distributed KVS cluster. +K2HDKC uses K2HASH, CHMPX, FULLOCK libraries. K2HDKC supports +distributed KVS cluster server program and client libraries. + +For the full copyright and license information, please view +the license file that was distributed with this source code. +--EXTENSIONS-- +k2hdkcpx +--FILE-- + +--EXPECT-- +OK +--DESCRIPTION-- +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * End: + * vim600: noexpandtab sw=4 ts=4 fdm=marker + * vim<600: noexpandtab sw=4 ts=4 + */ diff --git a/tests/k2hdkcpx_set_debug_level_silent.phpt b/tests/k2hdkcpx_set_debug_level_silent.phpt new file mode 100644 index 0000000..8fec5f2 --- /dev/null +++ b/tests/k2hdkcpx_set_debug_level_silent.phpt @@ -0,0 +1,31 @@ +--TEST-- +k2hdkcpx_set_debug_level_silent +--CREDITS-- +K2HDKC PHP Extension library + +Copyright 2023 Yahoo Japan Corporation. + +K2HDKC is k2hash based distributed KVS cluster. +K2HDKC uses K2HASH, CHMPX, FULLOCK libraries. K2HDKC supports +distributed KVS cluster server program and client libraries. + +For the full copyright and license information, please view +the license file that was distributed with this source code. +--EXTENSIONS-- +k2hdkcpx +--FILE-- + +--EXPECT-- +OK +--DESCRIPTION-- +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * End: + * vim600: noexpandtab sw=4 ts=4 fdm=marker + * vim<600: noexpandtab sw=4 ts=4 + */ diff --git a/tests/k2hdkcpx_set_debug_level_warning.phpt b/tests/k2hdkcpx_set_debug_level_warning.phpt new file mode 100644 index 0000000..bfc3233 --- /dev/null +++ b/tests/k2hdkcpx_set_debug_level_warning.phpt @@ -0,0 +1,31 @@ +--TEST-- +k2hdkcpx_set_debug_level_warning +--CREDITS-- +K2HDKC PHP Extension library + +Copyright 2023 Yahoo Japan Corporation. + +K2HDKC is k2hash based distributed KVS cluster. +K2HDKC uses K2HASH, CHMPX, FULLOCK libraries. K2HDKC supports +distributed KVS cluster server program and client libraries. + +For the full copyright and license information, please view +the license file that was distributed with this source code. +--EXTENSIONS-- +k2hdkcpx +--FILE-- + +--EXPECT-- +OK +--DESCRIPTION-- +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * End: + * vim600: noexpandtab sw=4 ts=4 fdm=marker + * vim<600: noexpandtab sw=4 ts=4 + */ diff --git a/tests/k2hdkcpx_set_subkeys.phpt b/tests/k2hdkcpx_set_subkeys.phpt new file mode 100644 index 0000000..4ec9ef2 --- /dev/null +++ b/tests/k2hdkcpx_set_subkeys.phpt @@ -0,0 +1,113 @@ +--TEST-- +k2hdkcpx_set_subkeys +--CREDITS-- +K2HDKC PHP Extension library + +Copyright 2023 Yahoo Japan Corporation. + +K2HDKC is k2hash based distributed KVS cluster. +K2HDKC uses K2HASH, CHMPX, FULLOCK libraries. K2HDKC supports +distributed KVS cluster server program and client libraries. + +For the full copyright and license information, please view +the license file that was distributed with this source code. +--EXTENSIONS-- +k2hdkcpx +--FILE-- + /tmp/server.log 2>&1 &"); + time_nanosleep(0, 500 * 1000 * 1000); + $procid = exec("ps ax | grep chmpx | grep tests/server.ini | grep -v grep | awk '{print $1}'"); + + // run chmpx slave + exec("chmpx -conf ./tests/slave.ini -d silent > /tmp/slave.log 2>&1 &"); + time_nanosleep(0, 500 * 1000 * 1000); + $procid_slave = exec("ps ax | grep chmpx | grep tests/slave.ini | grep -v grep | awk '{print $1}'"); + + // run k2hdkc + exec("k2hdkc -conf ./tests/server.ini -d silent > /tmp/k2hdkc.log 2>&1 &"); + time_nanosleep(0, 500 * 1000 * 1000); + $procid_k2hdkc = exec("ps ax | grep k2hdkc | grep tests/server.ini | grep -v grep | awk '{print $1}'"); + + // echo $procid_k2hdkc; + $handle = k2hdkcpx_open("./tests/slave.ini"); + + if(false !== $handle){ + $key = "key"; + k2hdkcpx_set_value($handle, $key, "val"); + $subkey = "subkey"; + k2hdkcpx_set_value($handle, $subkey, "subval"); + $arr = array($subkey); + k2hdkcpx_set_subkeys($handle, $key, $arr); + $arr = k2hdkcpx_get_subkeys($handle, $key); + if ($arr[0] === $subkey) { + echo "OK"; + }else{ + echo "NG"; + } + k2hdkcpx_close($handle); + }else{ + echo "NG"; + } + // kill k2hdkc + if($procid_k2hdkc == sprintf("%d", intval($procid_k2hdkc))){ + $killcmd = "kill -HUP " . $procid_k2hdkc . " >> /tmp/test_k2hdkc.log 2>&1"; + exec($killcmd); + } + // kill chmpx slave + if($procid_slave == sprintf("%d", intval($procid_slave))){ + $killcmd = "kill -HUP " . $procid_slave . " >> /tmp/test_chmpx_slave.log 2>&1"; + exec($killcmd); + } + // kill chmpx server + if($procid == sprintf("%d", intval($procid))){ + $killcmd = "kill -HUP " . $procid . " >> /tmp/test_chmpx_server.log 2>&1"; + exec($killcmd); + } +} + +?> +--EXPECT-- +OK +--CLEAN-- + +--DESCRIPTION-- +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * End: + * vim600: noexpandtab sw=4 ts=4 fdm=marker + * vim<600: noexpandtab sw=4 ts=4 + */ diff --git a/tests/k2hdkcpx_set_value.phpt b/tests/k2hdkcpx_set_value.phpt new file mode 100644 index 0000000..1ee6225 --- /dev/null +++ b/tests/k2hdkcpx_set_value.phpt @@ -0,0 +1,110 @@ +--TEST-- +k2hdkcpx_set_value +--CREDITS-- +K2HDKC PHP Extension library + +Copyright 2023 Yahoo Japan Corporation. + +K2HDKC is k2hash based distributed KVS cluster. +K2HDKC uses K2HASH, CHMPX, FULLOCK libraries. K2HDKC supports +distributed KVS cluster server program and client libraries. + +For the full copyright and license information, please view +the license file that was distributed with this source code. +--EXTENSIONS-- +k2hdkcpx +--FILE-- + /tmp/server.log 2>&1 &"); + time_nanosleep(0, 500 * 1000 * 1000); + $procid = exec("ps ax | grep chmpx | grep tests/server.ini | grep -v grep | awk '{print $1}'"); + + // run chmpx slave + exec("chmpx -conf ./tests/slave.ini -d silent > /tmp/slave.log 2>&1 &"); + time_nanosleep(0, 500 * 1000 * 1000); + $procid_slave = exec("ps ax | grep chmpx | grep tests/slave.ini | grep -v grep | awk '{print $1}'"); + + // run k2hdkc + exec("k2hdkc -conf ./tests/server.ini -d silent > /tmp/k2hdkc.log 2>&1 &"); + time_nanosleep(0, 500 * 1000 * 1000); + $procid_k2hdkc = exec("ps ax | grep k2hdkc | grep tests/server.ini | grep -v grep | awk '{print $1}'"); + + // echo $procid_k2hdkc; + $handle = k2hdkcpx_open("./tests/slave.ini"); + + if(false !== $handle){ + $key = "key"; + $val = "val"; + k2hdkcpx_set_value($handle, $key, $val); + time_nanosleep(0, 250 * 1000 * 1000); + + if ($val === k2hdkcpx_get_value($handle, $key)) { + echo "OK"; + }else{ + echo "NG"; + } + k2hdkcpx_close($handle); + }else{ + echo "NG"; + } + // kill k2hdkc + if($procid_k2hdkc == sprintf("%d", intval($procid_k2hdkc))){ + $killcmd = "kill -HUP " . $procid_k2hdkc . " >> /tmp/test_k2hdkc.log 2>&1"; + exec($killcmd); + } + // kill chmpx slave + if($procid_slave == sprintf("%d", intval($procid_slave))){ + $killcmd = "kill -HUP " . $procid_slave . " >> /tmp/test_chmpx_slave.log 2>&1"; + exec($killcmd); + } + // kill chmpx server + if($procid == sprintf("%d", intval($procid))){ + $killcmd = "kill -HUP " . $procid . " >> /tmp/test_chmpx_server.log 2>&1"; + exec($killcmd); + } +} + +?> +--EXPECT-- +OK +--CLEAN-- + +--DESCRIPTION-- +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * End: + * vim600: noexpandtab sw=4 ts=4 fdm=marker + * vim<600: noexpandtab sw=4 ts=4 + */ diff --git a/tests/k2hdkcpx_toggle_comlog.phpt b/tests/k2hdkcpx_toggle_comlog.phpt new file mode 100644 index 0000000..3f14708 --- /dev/null +++ b/tests/k2hdkcpx_toggle_comlog.phpt @@ -0,0 +1,31 @@ +--TEST-- +k2hdkcpx_toggle_comlog +--CREDITS-- +K2HDKC PHP Extension library + +Copyright 2023 Yahoo Japan Corporation. + +K2HDKC is k2hash based distributed KVS cluster. +K2HDKC uses K2HASH, CHMPX, FULLOCK libraries. K2HDKC supports +distributed KVS cluster server program and client libraries. + +For the full copyright and license information, please view +the license file that was distributed with this source code. +--EXTENSIONS-- +k2hdkcpx +--FILE-- + +--EXPECT-- +OK +--DESCRIPTION-- +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * End: + * vim600: noexpandtab sw=4 ts=4 fdm=marker + * vim<600: noexpandtab sw=4 ts=4 + */ diff --git a/tests/k2hdkcpx_unset_debug_file.phpt b/tests/k2hdkcpx_unset_debug_file.phpt new file mode 100644 index 0000000..355b0cd --- /dev/null +++ b/tests/k2hdkcpx_unset_debug_file.phpt @@ -0,0 +1,31 @@ +--TEST-- +k2hdkcpx_unset_debug_file +--CREDITS-- +K2HDKC PHP Extension library + +Copyright 2023 Yahoo Japan Corporation. + +K2HDKC is k2hash based distributed KVS cluster. +K2HDKC uses K2HASH, CHMPX, FULLOCK libraries. K2HDKC supports +distributed KVS cluster server program and client libraries. + +For the full copyright and license information, please view +the license file that was distributed with this source code. +--EXTENSIONS-- +k2hdkcpx +--FILE-- + +--EXPECT-- +OK +--DESCRIPTION-- +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * End: + * vim600: noexpandtab sw=4 ts=4 fdm=marker + * vim<600: noexpandtab sw=4 ts=4 + */ diff --git a/tests/server.ini b/tests/server.ini new file mode 100644 index 0000000..d9267ca --- /dev/null +++ b/tests/server.ini @@ -0,0 +1,120 @@ +# +# K2HDKC PHP Extension library +# +# Copyright 2023 Yahoo Japan Corporation. +# +# K2HDKC is k2hash based distributed KVS cluster. +# K2HDKC uses K2HASH, CHMPX, FULLOCK libraries. K2HDKC supports +# distributed KVS cluster server program and client libraries. +# +# For the full copyright and license information, please view +# the license file that was distributed with this source code. +# +# AUTHOR: Hirotaka Wakabayashi +# CREATE: Tue, Feb 22 2022 +# REVISION: +# + +################################################################ +# CONFIGURATION FILE FOR STANDALONE TEST +# +# NOTE: +# - k2hdkc server node must not be use MQACK +# - k2hash for k2hdkc is memory mode, because multi server node +# run on one server and we do not use configuration files for +# each process. +################################################################ + +# +# GLOBAL SECTION +# +[GLOBAL] +FILEVERSION = 2 +DATE = Wed, 07 Sep 2016 13:55:04 +0900 +GROUP = TESTDKC +MODE = SERVER +DELIVERMODE = hash +MAXCHMPX = 4 +REPLICA = 1 +MAXMQSERVER = 2 +MAXMQCLIENT = 2 +MQPERATTACH = 1 +MAXQPERSERVERMQ = 2 +MAXQPERCLIENTMQ = 1 +MAXMQPERCLIENT = 1 +MAXHISTLOG = 10000 +PORT = 8020 +CTLPORT = 8021 +SELFCTLPORT = 8021 +RWTIMEOUT = 100000 +RETRYCNT = 1000 +CONTIMEOUT = 500000 +MQRWTIMEOUT = 1000 +MQRETRYCNT = 10000 +MQACK = no +AUTOMERGE = on +DOMERGE = on +MERGETIMEOUT = 0 +SOCKTHREADCNT = 4 +MQTHREADCNT = 4 +MAXSOCKPOOL = 10 +SOCKPOOLTIMEOUT = 0 +SSL = no +K2HFULLMAP = on +K2HMASKBIT = 4 +K2HCMASKBIT = 4 +K2HMAXELE = 4 + +# +# SERVER NODES SECTION +# +[SVRNODE] +NAME = localhost +PORT = 8020 +CTLPORT = 8021 +SSL = no + +# +# SLAVE NODES SECTION +# +[SLVNODE] +NAME = [.]* +CTLPORT = 8031 + +# +# K2HDKC SECTION +# +[K2HDKC] +#RCVTIMEOUT = 1000 ### Default(1000), timeout ms for receiving command result. +#SVRNODEINI = ### Default(empty = same this file) +#REPLCLUSTERINI = ### Default(empty), for DTOR INI FILE because transaction chmpx is different from this file + ### everything about dtor setting is specified in replclusterini file. + ### If needs, you can set that dtor runs with plugin and putting file(transaction). +#DTORTHREADCNT = 1 ### Default(1), you MUST set same as the value in k2htpdtor configuration file +#DTORCTP = path.so ### Default(k2htpdtor.so.1), custom transaction plugin path +K2HTYPE = mem ### Default(file), parameter can be set M/MEM/MEMORY / F/FILE / T/TEMP/TEMPORARY +#K2HTYPE = file ### Default(file), parameter can be set M/MEM/MEMORY / F/FILE / T/TEMP/TEMPORARY +#K2HFILE = /tmp/k2hdkc.k2h ### Default(k2hash file path), when file type +K2HFULLMAP = on ### Default(on) +K2HINIT = yes ### Default(no) +K2HMASKBIT = 4 +K2HCMASKBIT = 4 +K2HMAXELE = 8 +K2HPAGESIZE = 128 +#PASSPHRASES = ### Default(empty), many entry is allowed. set either the PASSPHRASES or PASSFILE +#PASSFILE = ### Default(empty), set either the PASSPHRASES or PASSFILE +#HISTORY = on ### Default(no), MUST DO SOME WORK FOR MAKING HISTORY KEY DATA TO OTHER SERVERS +#EXPIRE = 300 ### Default(no), MUST SPECIFY THIS VALUE +#ATTRPLUGIN = ### Default(empty), many entry is allowed, and calling sequence is same keywords in this file +#MINTHREAD = 1 ### Default(1), minimum processing thread count +MAXTHREAD = 10 ### Default(100), maximum processing thread count +#REDUCETIME = 30 ### Default(30), time(second) for reducing processing thread to minimum thread count. + +# +# Local variables: +# tab-width: 4 +# c-basic-offset: 4 +# End: +# vim600: noexpandtab sw=4 ts=4 fdm=marker +# vim<600: noexpandtab sw=4 ts=4 +# diff --git a/tests/slave.ini b/tests/slave.ini new file mode 100644 index 0000000..d1dffed --- /dev/null +++ b/tests/slave.ini @@ -0,0 +1,88 @@ +# +# K2HDKC PHP Extension library +# +# Copyright 2023 Yahoo Japan Corporation. +# +# K2HDKC is k2hash based distributed KVS cluster. +# K2HDKC uses K2HASH, CHMPX, FULLOCK libraries. K2HDKC supports +# distributed KVS cluster server program and client libraries. +# +# For the full copyright and license information, please view +# the license file that was distributed with this source code. +# +# AUTHOR: Hirotaka Wakabayashi +# CREATE: Tue, Feb 22 2022 +# REVISION: +# + +################################################################ +# CONFIGURATION FILE FOR STANDALONE TEST +# +# NOTE: +# - k2hdkc server node must not be use MQACK +################################################################ + +# +# GLOBAL SECTION +# +[GLOBAL] +FILEVERSION = 2 +DATE = Wed, 07 Sep 2016 13:55:04 +0900 +GROUP = TESTDKC +MODE = SLAVE +DELIVERMODE = hash +MAXCHMPX = 4 +REPLICA = 1 +MAXMQSERVER = 2 +MAXMQCLIENT = 2 +MQPERATTACH = 1 +MAXQPERSERVERMQ = 2 +MAXQPERCLIENTMQ = 1 +MAXMQPERCLIENT = 1 +MAXHISTLOG = 10000 +#PORT = 8020 +CTLPORT = 8031 +SELFCTLPORT = 8031 +RWTIMEOUT = 100000 +RETRYCNT = 1000 +CONTIMEOUT = 500000 +MQRWTIMEOUT = 1000 +MQRETRYCNT = 10000 +MQACK = no +AUTOMERGE = on +DOMERGE = on +MERGETIMEOUT = 0 +SOCKTHREADCNT = 4 +MQTHREADCNT = 4 +MAXSOCKPOOL = 10 +SOCKPOOLTIMEOUT = 0 +SSL = no +K2HFULLMAP = on +K2HMASKBIT = 4 +K2HCMASKBIT = 4 +K2HMAXELE = 4 + +# +# SERVER NODES SECTION +# +[SVRNODE] +NAME = localhost +PORT = 8020 +CTLPORT = 8021 +SSL = no + +# +# SLAVE NODES SECTION +# +[SLVNODE] +NAME = [.]* +CTLPORT = 8031 + +# +# Local variables: +# tab-width: 4 +# c-basic-offset: 4 +# End: +# vim600: noexpandtab sw=4 ts=4 fdm=marker +# vim<600: noexpandtab sw=4 ts=4 +#