From da729085ef6e82caa5d7ef97fd6c254d304beb7d Mon Sep 17 00:00:00 2001 From: Shivam Mathur Date: Mon, 23 Dec 2024 16:04:30 +0530 Subject: [PATCH] Add support for pre-installed PHP --- README.md | 1 + src/scripts/darwin.sh | 1 + src/scripts/linux.sh | 1 + src/scripts/unix.sh | 13 +++++++++++++ src/scripts/win32.ps1 | 9 +++++++++ 5 files changed, 25 insertions(+) diff --git a/README.md b/README.md index 5b71b5b5..1bc511ad 100644 --- a/README.md +++ b/README.md @@ -410,6 +410,7 @@ Disable coverage for these reasons: - Accepts `lowest` to set up the lowest supported PHP version. - Accepts `highest` or `latest` to set up the latest stable PHP version. - Accepts `nightly` to set up a nightly build from the master branch of PHP. +- Accepts `pre-installed` to set up the highest pre-installed PHP version. You can combine this with `update: true` to update the pre-installed PHP version. - Accepts the format `d.x`, where `d` is the major version. For example `5.x`, `7.x` and `8.x`. - See [PHP support](#tada-php-support) for the supported PHP versions. - If not specified, it looks for the following in order: diff --git a/src/scripts/darwin.sh b/src/scripts/darwin.sh index c6fa5233..f34bddf5 100644 --- a/src/scripts/darwin.sh +++ b/src/scripts/darwin.sh @@ -213,6 +213,7 @@ get_scan_dir() { setup_php() { step_log "Setup PHP" php_config="$(command -v php-config 2>/dev/null)" + check_pre_installed existing_version=$(get_brewed_php) if [[ "$version" =~ ${old_versions:?} ]]; then run_script "php5-darwin" "${version/./}" >/dev/null 2>&1 diff --git a/src/scripts/linux.sh b/src/scripts/linux.sh index af4e23db..0d7de121 100644 --- a/src/scripts/linux.sh +++ b/src/scripts/linux.sh @@ -246,6 +246,7 @@ setup_php() { step_log "Setup PHP" sudo mkdir -m 777 -p /var/run /run/php php_config="$(command -v php-config)" + check_pre_installed if [[ -z "$php_config" ]] || [ "$(php_semver | cut -c 1-3)" != "$version" ]; then if [ ! -e "/usr/bin/php$version" ] || [ ! -e "/usr/bin/php-config$version" ]; then add_php >/dev/null 2>&1 diff --git a/src/scripts/unix.sh b/src/scripts/unix.sh index 69a0cfe3..f1902f8b 100644 --- a/src/scripts/unix.sh +++ b/src/scripts/unix.sh @@ -184,6 +184,19 @@ self_hosted_setup() { fi } +# Function to check pre-installed PHP +check_pre_installed() { + if [ "$version" = "pre" ]; then + if [ -n "$php_config" ]; then + version="$(php_semver | cut -c 1-3)" + update=false + else + fail_fast=true + add_log "$cross" "PHP" "No pre-installed PHP version found" + fi + fi +} + # Function to configure PHP configure_php() { add_php_config diff --git a/src/scripts/win32.ps1 b/src/scripts/win32.ps1 index 3b830fb9..cdd10ed2 100644 --- a/src/scripts/win32.ps1 +++ b/src/scripts/win32.ps1 @@ -401,6 +401,15 @@ if (Test-Path -LiteralPath $php_dir -PathType Container) { } $status = "Installed" $extra_version = "" +if($version -eq 'pre') { + if($null -ne $installed) { + $version = $installed.MajorMinorVersion + $env:update = 'false' + } else { + Add-Log $cross "PHP" "No pre-installed PHP version found" + Write-Error "No pre-installed PHP version found" -ErrorAction Stop + } +} if ($null -eq $installed -or -not("$($installed.Version).".StartsWith(($version -replace '^(\d+(\.\d+)*).*', '$1.'))) -or $ts -ne $installed.ThreadSafe) { if ($version -lt '7.0' -and ($null -eq (Get-Module -ListAvailable -Name VcRedist))) { Install-PSPackage VcRedist VcRedist-main\VcRedist\VcRedist "$github/aaronparker/VcRedist/archive/main.zip" Get-VcList >$null 2>&1