diff --git a/README.md b/README.md index 61845fc..49ad46e 100644 --- a/README.md +++ b/README.md @@ -72,13 +72,14 @@ Additional options available in `ext_skel.php` are also supported. We provide a convenient testing environment using the `pskel` command: ```bash -$ pskel test # Test with standard PHP -$ pskel test debug # Test with debug build PHP -$ pskel test gcov # Generate code coverage using GCC Gcov -$ pskel test valgrind # Memory check using Valgrind -$ pskel test msan # Check using LLVM MemorySanitizer -$ pskel test asan # Check using LLVM AddressSanitizer -$ pskel test ubsan # Check using LLVM UndefinedBehaviorSanitizer +$ pskel test # Test with standard PHP +$ pskel test debug # Test with debug build PHP +$ pskel test gcov # Generate code coverage using GCC Gcov +$ pskel test valgrind # Memory check using Valgrind +$ pskel test msan # Check using LLVM MemorySanitizer +$ pskel test asan # Check using LLVM AddressSanitizer +$ pskel test ubsan # Check using LLVM UndefinedBehaviorSanitizer +$ pskel clean-build-cache # Remove built PHP runtimes and cache ``` ### Testing Integration with External Services diff --git a/README_ja.md b/README_ja.md index 31f1896..4ed8663 100644 --- a/README_ja.md +++ b/README_ja.md @@ -72,13 +72,14 @@ $ pskel init "" `pskel` コマンドを使用した便利なテスト環境を提供しています: ```bash -$ pskel test # 通常のPHPによるテスト -$ pskel test debug # デバッグビルドPHPでのテスト -$ pskel test gcov # GCC Gcovによるコードカバレッジ生成 -$ pskel test valgrind # Valgrindによるメモリチェック -$ pskel test msan # LLVM MemorySanitizerによるチェック -$ pskel test asan # LLVM AddressSanitizerによるチェック -$ pskel test ubsan # LLVM UndefinedBehaviorSanitizerによるチェック +$ pskel test # 通常のPHPによるテスト +$ pskel test debug # デバッグビルドPHPでのテスト +$ pskel test gcov # GCC Gcovによるコードカバレッジ生成 +$ pskel test valgrind # Valgrindによるメモリチェック +$ pskel test msan # LLVM MemorySanitizerによるチェック +$ pskel test asan # LLVM AddressSanitizerによるチェック +$ pskel test ubsan # LLVM UndefinedBehaviorSanitizerによるチェック +$ pskel clean-build-cache # ビルド済みPHPランタイムとキャッシュを削除 ``` ### 外部サービスとの連携テスト diff --git a/pskel.sh b/pskel.sh index 17ee7a7..b80d134 100755 --- a/pskel.sh +++ b/pskel.sh @@ -170,10 +170,11 @@ cmd_usage() { Usage: ${0} [task] ... Available commands: - init create new extension - test test extension - build build PHP runtime - coverage generate code coverage + init create new extension + test test extension + build build PHP runtime + clean-build-cache remove built PHP runtimes and cache + coverage generate code coverage EOF } @@ -261,6 +262,8 @@ COMPOSER_EOF } cmd_test() { + PSKEL_TRACK_ARENA_ALLOC=0 + case "${1}" in -h|--help) cat << EOF @@ -272,6 +275,7 @@ EOF return 0 ;; debug|gcov|valgrind) + PSKEL_TRACK_ARENA_ALLOC=1 CC="$(command -v "gcc")" CXX="$(command -v "g++")" case "${1}" in @@ -290,6 +294,7 @@ EOF CMD="$(basename "${CC}")-${1}-php" ;; msan|asan|ubsan) + PSKEL_TRACK_ARENA_ALLOC=1 CC="$(command -v "clang")" CXX="$(command -v "clang++")" case "${1}" in @@ -331,6 +336,11 @@ EOF PSKEL_EXT_DIR="$(get_ext_dir)" + if test "${PSKEL_TRACK_ARENA_ALLOC}" = "1"; then + CFLAGS="${CFLAGS} -DZEND_TRACK_ARENA_ALLOC" + CPPFLAGS="${CPPFLAGS} -DZEND_TRACK_ARENA_ALLOC" + fi + cd "${PSKEL_EXT_DIR}" "${CMD}ize" if test "$("${CMD}" -r "echo PHP_VERSION_ID;")" -lt "80400"; then @@ -380,11 +390,13 @@ check_and_restore_cached_php() { if test -f "${CACHE_DIR}/.build_complete"; then for BIN in php phpize php-config; do if test -f "${CACHE_DIR}/usr/local/bin/${PREFIX}-${BIN}"; then + remove_path_if_exists "/usr/local/bin/${PREFIX}-${BIN}" ln -sf "${CACHE_DIR}/usr/local/bin/${PREFIX}-${BIN}" "/usr/local/bin/${PREFIX}-${BIN}" fi done if test -d "${CACHE_DIR}/usr/local/include/${PREFIX}-php"; then + remove_path_if_exists "/usr/local/include/${PREFIX}-php" ln -sf "${CACHE_DIR}/usr/local/include/${PREFIX}-php" "/usr/local/include/${PREFIX}-php" fi @@ -441,6 +453,71 @@ cache_php_build() { echo "[Pskel > Cache] Cached PHP header and binary: ${PREFIX}-php" >&2 } +remove_path_if_exists() { + if test -e "${1}" || test -L "${1}"; then + rm -rf "${1}" + echo "[Pskel > Clean] Removed: ${1}" >&2 + fi +} + +remove_built_php_runtime() { + PREFIX="${1}" + + for BIN in php phpize php-config; do + remove_path_if_exists "/usr/local/bin/${PREFIX}-${BIN}" + done + + remove_path_if_exists "/usr/local/include/${PREFIX}-php" +} + +cmd_clean_build_cache() { + case "${1}" in + -h|--help) + cat << EOF +Usage: ${0} clean-build-cache +Environment variables: + PHP_CACHE_DIR: PHP runtime cache directory +EOF + return 0 + ;; + ?*) + echo "Error: clean-build-cache does not accept arguments." >&2 + return 1 + ;; + esac + + for PREFIX in \ + gcc-debug gcc-gcov gcc-valgrind \ + clang-msan clang-asan clang-ubsan + do + remove_built_php_runtime "${PREFIX}" + done + + if test -n "${PHP_CACHE_DIR}" && test -d "${PHP_CACHE_DIR}"; then + for CACHE_ENTRY in "${PHP_CACHE_DIR}"/*; do + if test -f "${CACHE_ENTRY}/.build_complete"; then + if test -d "${CACHE_ENTRY}/usr/local/bin"; then + for BIN in "${CACHE_ENTRY}/usr/local/bin/"*; do + if test -f "${BIN}"; then + remove_path_if_exists "/usr/local/bin/$(basename "${BIN}")" + fi + done + fi + + if test -d "${CACHE_ENTRY}/usr/local/include"; then + for INCLUDE_DIR in "${CACHE_ENTRY}/usr/local/include/"*; do + if test -d "${INCLUDE_DIR}"; then + remove_path_if_exists "/usr/local/include/$(basename "${INCLUDE_DIR}")" + fi + done + fi + + remove_path_if_exists "${CACHE_ENTRY}" + fi + done + fi +} + cmd_build() { case "${1}" in -h|--help) @@ -534,6 +611,7 @@ case "${1}" in init) shift; cmd_init "${@}";; test) shift; cmd_test "${@}";; build) shift; cmd_build "${@}";; + clean-build-cache) shift; cmd_clean_build_cache "${@}";; coverage) shift; cmd_coverage "${@}";; *) echo "${0} error: invalid command: '${1}'" >&2