From 2fd5a36ee6f86f799a4470fb9ab01966c43edede Mon Sep 17 00:00:00 2001 From: Christian Fritsch Date: Thu, 25 Jul 2024 10:56:22 +0200 Subject: [PATCH] Add pcov extension (#78) * Add pcov extension * Add command * Better --------- Co-authored-by: Christian Fritsch --- .ddev/commands/web/pcov | 55 +++++++++++++++++++++++++++++++++ .ddev/web-build/Dockerfile.pcov | 7 +++++ 2 files changed, 62 insertions(+) create mode 100755 .ddev/commands/web/pcov create mode 100644 .ddev/web-build/Dockerfile.pcov diff --git a/.ddev/commands/web/pcov b/.ddev/commands/web/pcov new file mode 100755 index 0000000..f237595 --- /dev/null +++ b/.ddev/commands/web/pcov @@ -0,0 +1,55 @@ +#!/bin/bash + +## #ddev-generated +## Description: Enable or disable pcov +## Usage: pcov on|off|enable|disable|true|false|toggle|status +## Example: "ddev pcov" (default is "on"), "ddev pcov off", "ddev pcov on", "ddev pcov toggle", "ddev pcov status" +## ExecRaw: false +## Flags: [] +## AutocompleteTerms: ["on","off","enable","disable","toggle","status"] + +get_pcov_status() { + php -r 'echo extension_loaded("pcov") ? "1" : "0";' +} + +enable_pcov() { + phpenmod -v "${DDEV_PHP_VERSION}" pcov +} + +disable_pcov() { + phpdismod -v "${DDEV_PHP_VERSION}" pcov +} + +if [ $# -eq 0 ] ; then + enable_pcov + exit +fi + +case $1 in + on|true|enable) + enable_pcov + ;; + off|false|disable) + disable_pcov + ;; + toggle) + status=$(get_pcov_status) + if [ "${status}" = "1" ]; then + disable_pcov + else + enable_pcov + fi + ;; + status) + status=$(get_pcov_status) + if [ "${status}" = "1" ]; then + result="pcov enabled" + else + result="pcov disabled" + fi + echo $result + ;; + *) + echo "Invalid argument: $1" + ;; +esac diff --git a/.ddev/web-build/Dockerfile.pcov b/.ddev/web-build/Dockerfile.pcov new file mode 100644 index 0000000..5548e0f --- /dev/null +++ b/.ddev/web-build/Dockerfile.pcov @@ -0,0 +1,7 @@ +ENV extension=pcov +SHELL ["/bin/bash", "-c"] +# Install the needed development packages +RUN (apt-get update || true) && DEBIAN_FRONTEND=noninteractive apt-get install -y -o Dpkg::Options::="--force-confnew" --no-install-recommends --no-install-suggests build-essential php-pear php${DDEV_PHP_VERSION}-dev +# Install the extension +RUN pecl install ${extension} +RUN echo "extension=${extension}.so" > /etc/php/${DDEV_PHP_VERSION}/mods-available/${extension}.ini && chmod 666 /etc/php/${DDEV_PHP_VERSION}/mods-available/${extension}.ini