From 4c045616f458dcd672298c0b9bc526cca7dfb8ff Mon Sep 17 00:00:00 2001 From: Shivam Mathur Date: Mon, 23 Dec 2019 23:19:38 +0530 Subject: [PATCH] Improve support for ext-phalcon and refactor extensions.ts --- __tests__/extensions.test.ts | 28 +++++++++-------- dist/index.js | 59 +++++++++++++++--------------------- src/extensions.ts | 59 +++++++++++++++--------------------- src/scripts/darwin.sh | 16 ++++++++++ src/scripts/phalcon.sh | 12 +++----- src/scripts/win32.ps1 | 28 ++++++++++++++++- 6 files changed, 112 insertions(+), 90 deletions(-) diff --git a/__tests__/extensions.test.ts b/__tests__/extensions.test.ts index 5aa82106..02ae61c0 100644 --- a/__tests__/extensions.test.ts +++ b/__tests__/extensions.test.ts @@ -3,20 +3,21 @@ import * as extensions from '../src/extensions'; describe('Extension tests', () => { it('checking addExtensionOnWindows', async () => { let win32: string = await extensions.addExtension( - 'xdebug, pcov, redis', + 'xdebug, pcov, phalcon4', '7.4', 'win32' ); expect(win32).toContain('Add-Extension xdebug'); expect(win32).toContain('Add-Extension pcov'); - expect(win32).toContain('Add-Extension redis beta'); + expect(win32).toContain('Add-Phalcon phalcon4'); win32 = await extensions.addExtension( - 'does_not_exist', + 'phalcon3, does_not_exist', '7.2', 'win32', true ); + expect(win32).toContain('Add-Phalcon phalcon3'); expect(win32).toContain('Add-Extension does_not_exist'); win32 = await extensions.addExtension('xdebug', '7.2', 'fedora'); @@ -25,7 +26,7 @@ describe('Extension tests', () => { it('checking addExtensionOnLinux', async () => { let linux: string = await extensions.addExtension( - 'xdebug, pcov, redis', + 'xdebug, pcov', '7.4', 'linux' ); @@ -37,9 +38,6 @@ describe('Extension tests', () => { 'sudo DEBIAN_FRONTEND=noninteractive apt-get install -y php7.4-pcov' ); expect(linux).toContain('pecl install pcov'); - expect(linux).toContain( - 'sudo DEBIAN_FRONTEND=noninteractive apt-get install -y php7.4-igbinary php7.4-redis' - ); linux = await extensions.addExtension('gearman', '7.0', 'linux'); expect(linux).toContain('gearman.sh 7.0'); @@ -51,8 +49,8 @@ describe('Extension tests', () => { '7.2', 'linux' ); - expect(linux).toContain('phalcon.sh 3.4.x 7.2'); - expect(linux).toContain('phalcon.sh master 7.2'); + expect(linux).toContain('phalcon.sh phalcon3 7.2'); + expect(linux).toContain('phalcon.sh phalcon4 7.2'); expect(linux).toContain('gearman.sh 7.2'); linux = await extensions.addExtension( @@ -60,12 +58,12 @@ describe('Extension tests', () => { '7.3', 'linux' ); - expect(linux).toContain('phalcon.sh 3.4.x 7.3'); - expect(linux).toContain('phalcon.sh master 7.3'); + expect(linux).toContain('phalcon.sh phalcon3 7.3'); + expect(linux).toContain('phalcon.sh phalcon4 7.3'); expect(linux).toContain('gearman.sh 7.3'); linux = await extensions.addExtension('phalcon4, gearman', '7.4', 'linux'); - expect(linux).toContain('phalcon.sh master 7.4'); + expect(linux).toContain('phalcon.sh phalcon4 7.4'); expect(linux).toContain('gearman.sh 7.4'); linux = await extensions.addExtension('xdebug', '7.2', 'fedora'); @@ -81,6 +79,12 @@ describe('Extension tests', () => { expect(darwin).toContain('sudo pecl install xdebug'); expect(darwin).toContain('sudo pecl install pcov'); + darwin = await extensions.addExtension('phalcon3', '7.0', 'darwin'); + expect(darwin).toContain('add_phalcon phalcon3'); + + darwin = await extensions.addExtension('phalcon4', '7.3', 'darwin'); + expect(darwin).toContain('add_phalcon phalcon4'); + darwin = await extensions.addExtension('pcov', '5.6', 'darwin'); expect(darwin).toContain('sudo pecl install pcov'); diff --git a/dist/index.js b/dist/index.js index accea60c..1e140d0a 100644 --- a/dist/index.js +++ b/dist/index.js @@ -2194,13 +2194,16 @@ function addExtensionDarwin(extension_csv, version) { extension = extension.toLowerCase(); // add script to enable extension is already installed along with php let install_command = ''; - switch (version + extension) { - case '5.6xdebug': + switch (true) { + case /5\.6xdebug/.test(version + extension): install_command = 'sudo pecl install xdebug-2.5.5 >/dev/null 2>&1'; break; - case '5.6redis': + case /5\.6redis/.test(version + extension): install_command = 'sudo pecl install redis-2.2.8 >/dev/null 2>&1'; break; + case /^7\.[0-3]phalcon3$|^7\.[2-4]phalcon4$/.test(version + extension): + script += '\nadd_phalcon ' + extension; + return; default: install_command = 'sudo pecl install ' + extension + ' >/dev/null 2>&1'; break; @@ -2231,9 +2234,10 @@ function addExtensionWindows(extension_csv, version) { yield utils.asyncForEach(extensions, function (extension) { return __awaiter(this, void 0, void 0, function* () { // add script to enable extension is already installed along with php - switch (version + extension) { - case '7.4redis': - script += '\nAdd-Extension ' + extension + ' beta'; + switch (true) { + // match 7.0phalcon3...7.3phalcon3 and 7.2phalcon4...7.4phalcon4 + case /^7\.[0-3]phalcon3$|^7\.[2-4]phalcon4$/.test(version + extension): + script += '\nAdd-Phalcon ' + extension; break; default: script += '\nAdd-Extension ' + extension; @@ -2260,35 +2264,9 @@ function addExtensionLinux(extension_csv, version) { extension = extension.toLowerCase(); // add script to enable extension is already installed along with php let install_command = ''; - switch (version + extension) { - case '7.4redis': - install_command = - 'sudo DEBIAN_FRONTEND=noninteractive apt-get install -y php7.4-igbinary php7.4-redis >/dev/null 2>&1'; - break; - case '7.2phalcon3': - case '7.3phalcon3': - install_command = - 'sh ' + - path.join(__dirname, '../src/scripts/phalcon.sh') + - ' 3.4.x ' + - version + - ' >/dev/null 2>&1'; - break; - case '7.2phalcon4': - case '7.3phalcon4': - case '7.4phalcon4': - install_command = - 'sh ' + - path.join(__dirname, '../src/scripts/phalcon.sh') + - ' master ' + - version + - ' >/dev/null 2>&1'; - break; - case '7.0gearman': - case '7.1gearman': - case '7.2gearman': - case '7.3gearman': - case '7.4gearman': + switch (true) { + // match 5.6gearman..7.4gearman + case /^((5\.6)|(7\.[0-4]))gearman$/.test(version + extension): install_command = 'sh ' + path.join(__dirname, '../src/scripts/gearman.sh') + @@ -2296,6 +2274,17 @@ function addExtensionLinux(extension_csv, version) { version + ' >/dev/null 2>&1'; break; + // match 7.0phalcon3..7.3phalcon3 and 7.2phalcon4...7.4phalcon4 + case /^7\.[0-3]phalcon3$|^7\.[2-4]phalcon4$/.test(version + extension): + install_command = + 'sh ' + + path.join(__dirname, '../src/scripts/phalcon.sh') + + ' ' + + extension + + ' ' + + version + + ' >/dev/null 2>&1'; + break; default: install_command = 'sudo DEBIAN_FRONTEND=noninteractive apt-get install -y php' + diff --git a/src/extensions.ts b/src/extensions.ts index b10fd33e..3f76d86a 100644 --- a/src/extensions.ts +++ b/src/extensions.ts @@ -17,13 +17,16 @@ export async function addExtensionDarwin( extension = extension.toLowerCase(); // add script to enable extension is already installed along with php let install_command = ''; - switch (version + extension) { - case '5.6xdebug': + switch (true) { + case /5\.6xdebug/.test(version + extension): install_command = 'sudo pecl install xdebug-2.5.5 >/dev/null 2>&1'; break; - case '5.6redis': + case /5\.6redis/.test(version + extension): install_command = 'sudo pecl install redis-2.2.8 >/dev/null 2>&1'; break; + case /^7\.[0-3]phalcon3$|^7\.[2-4]phalcon4$/.test(version + extension): + script += '\nadd_phalcon ' + extension; + return; default: install_command = 'sudo pecl install ' + extension + ' >/dev/null 2>&1'; break; @@ -53,9 +56,10 @@ export async function addExtensionWindows( let script = '\n'; await utils.asyncForEach(extensions, async function(extension: string) { // add script to enable extension is already installed along with php - switch (version + extension) { - case '7.4redis': - script += '\nAdd-Extension ' + extension + ' beta'; + switch (true) { + // match 7.0phalcon3...7.3phalcon3 and 7.2phalcon4...7.4phalcon4 + case /^7\.[0-3]phalcon3$|^7\.[2-4]phalcon4$/.test(version + extension): + script += '\nAdd-Phalcon ' + extension; break; default: script += '\nAdd-Extension ' + extension; @@ -82,35 +86,9 @@ export async function addExtensionLinux( // add script to enable extension is already installed along with php let install_command = ''; - switch (version + extension) { - case '7.4redis': - install_command = - 'sudo DEBIAN_FRONTEND=noninteractive apt-get install -y php7.4-igbinary php7.4-redis >/dev/null 2>&1'; - break; - case '7.2phalcon3': - case '7.3phalcon3': - install_command = - 'sh ' + - path.join(__dirname, '../src/scripts/phalcon.sh') + - ' 3.4.x ' + - version + - ' >/dev/null 2>&1'; - break; - case '7.2phalcon4': - case '7.3phalcon4': - case '7.4phalcon4': - install_command = - 'sh ' + - path.join(__dirname, '../src/scripts/phalcon.sh') + - ' master ' + - version + - ' >/dev/null 2>&1'; - break; - case '7.0gearman': - case '7.1gearman': - case '7.2gearman': - case '7.3gearman': - case '7.4gearman': + switch (true) { + // match 5.6gearman..7.4gearman + case /^((5\.6)|(7\.[0-4]))gearman$/.test(version + extension): install_command = 'sh ' + path.join(__dirname, '../src/scripts/gearman.sh') + @@ -118,6 +96,17 @@ export async function addExtensionLinux( version + ' >/dev/null 2>&1'; break; + // match 7.0phalcon3..7.3phalcon3 and 7.2phalcon4...7.4phalcon4 + case /^7\.[0-3]phalcon3$|^7\.[2-4]phalcon4$/.test(version + extension): + install_command = + 'sh ' + + path.join(__dirname, '../src/scripts/phalcon.sh') + + ' ' + + extension + + ' ' + + version + + ' >/dev/null 2>&1'; + break; default: install_command = 'sudo DEBIAN_FRONTEND=noninteractive apt-get install -y php' + diff --git a/src/scripts/darwin.sh b/src/scripts/darwin.sh index 068e2141..e4d68bba 100644 --- a/src/scripts/darwin.sh +++ b/src/scripts/darwin.sh @@ -40,6 +40,22 @@ add_extension() { fi } +add_phalcon() { + extension=$1 + sudo pecl install psr >/dev/null 2>&1 + brew install autoconf automake libtool >/dev/null 2>&1 + git clone https://github.com/phalcon/cphalcon.git >/dev/null 2>&1 + cd cphalcon || echo "could not cd" + git checkout "$(git branch -r | grep -E "origin/${extension: -1}\.\d\.x" | sort -r | head -n 1 | sed "s/ //g")" >/dev/null 2>&1 + sed -i '' 's/zend_ulong/ulong/' build/php7/64bits/phalcon.zep.c + sed -i '' 's/ulong/zend_ulong/' build/php7/64bits/phalcon.zep.c + cd build/php7/64bits && sudo phpize >/dev/null 2>&1 + sudo ./configure --with-php-config=/usr/local/bin/php-config --enable-phalcon >/dev/null 2>&1 + sudo glibtoolize --force >/dev/null 2>&1 && sudo autoreconf >/dev/null 2>&1 + sudo make -i -j2 >/dev/null 2>&1 && sudo make install >/dev/null 2>&1 + echo "extension=phalcon.so" >>"$ini_file" && add_log "$tick" "$extension" "Installed and enabled" +} + # Function to setup PHP and composer setup_php_and_composer() { export HOMEBREW_NO_INSTALL_CLEANUP=TRUE diff --git a/src/scripts/phalcon.sh b/src/scripts/phalcon.sh index 382f7314..516f3c03 100644 --- a/src/scripts/phalcon.sh +++ b/src/scripts/phalcon.sh @@ -1,8 +1,6 @@ ini_file=$(php --ini | grep "Loaded Configuration" | sed -e "s|.*:s*||" | sed "s/ //g") -ini_dir=$(php --ini | grep in: | sed -e "s|.*:s*||" | sed "s/ //g") -if [ ! "$(apt-cache search php"$2"-psr)" ]; then - sudo DEBIAN_FRONTEND=noninteractive add-apt-repository ppa:ondrej/php -y >/dev/null 2>&1 -fi +find /etc/apt/sources.list.d -type f -name 'ondrej-ubuntu-php*.list' -exec sudo DEBIAN_FRONTEND=noninteractive apt-fast update -o Dir::Etc::sourcelist="{}" ';' >/dev/null 2>&1 +curl -s https://packagecloud.io/install/repositories/phalcon/stable/script.deb.sh | sudo bash sudo DEBIAN_FRONTEND=noninteractive apt-fast install -y php"$2"-dev sudo DEBIAN_FRONTEND=noninteractive apt-fast install -y php"$2"-psr for tool in php-config phpize; do @@ -19,6 +17,6 @@ if [ ! "$(apt-cache search php"$2"-psr)" ]; then echo "extension=psr.so" >> "$ini_file" fi -cd ~ && git clone --depth=1 -v https://github.com/phalcon/cphalcon.git -b "$1" -cd cphalcon/build && sudo ./install --phpize /usr/bin/phpize"$2" --php-config /usr/bin/php-config"$2" -echo "extension=phalcon.so" | sudo tee "$ini_dir/50-phalcon.ini" \ No newline at end of file +extension_major_version=$(echo "$1" | grep -i -Po '\d') +extension_version=$(apt-cache policy -- *phalcon | grep -i -Po "$extension_major_version\.\d\.\d.*php$2" | head -n 1) +sudo DEBIAN_FRONTEND=noninteractive apt-fast -o Dpkg::Options::="--force-overwrite" install -y php"$2"-phalcon="$extension_version" \ No newline at end of file diff --git a/src/scripts/win32.ps1 b/src/scripts/win32.ps1 index 7193d900..5d67c86d 100644 --- a/src/scripts/win32.ps1 +++ b/src/scripts/win32.ps1 @@ -9,6 +9,7 @@ $php_dir = 'C:\tools\php' $ext_dir = $php_dir + '\ext' $ProgressPreference = 'SilentlyContinue' $master_version = '8.0' +$arch='x64' Function Step-Log($message) { printf "\n\033[90;1m==> \033[0m\033[37;1m%s \033[0m\n" $message @@ -33,7 +34,6 @@ if (Test-Path -LiteralPath $php_dir -PathType Container) { } Step-Log "Setup PHP and Composer" if ($null -eq $installed -or -not("$($installed.Version).".StartsWith(($version -replace '^(\d+(\.\d+)*).*', '$1.')))) { - $arch='x64' if ($version -lt '7.0') { Install-Module -Name VcRedist -Force $arch='x86' @@ -101,3 +101,29 @@ Function Add-Extension { Add-Log $cross $extension "Could not install $extension on PHP $($installed.FullVersion)" } } + +Function Add-Phalcon { + Param ( + [Parameter(Position = 0, Mandatory = $true)] + [ValidateNotNull()] + [ValidateSet('phalcon3', 'phalcon4')] + [string] + $extension + ) + $extension_version = $extension.substring($extension.Length - 1) + $nts = if(! $installed.ThreadSafe ) { "_nts" } else { "" } + $domain = "https://github.com" + Install-Phpextension psr + try + { + $match = Invoke-WebRequest -UseBasicParsing -Uri $domain/phalcon/cphalcon/releases | Select-String -Pattern "href=`"(.*phalcon_${arch}_.*_php${version}_${extension_version}.*[0-9]${nts}.zip)`"" + $zip_file = $match.Matches[0].Groups[1].Value + Invoke-WebRequest -UseBasicParsing -Uri $domain/$zip_file -OutFile $PSScriptRoot\phalcon.zip + Expand-Archive -Path $PSScriptRoot\phalcon.zip -DestinationPath $PSScriptRoot\phalcon -Force > $null 2>&1 + New-Item -ItemType SymbolicLink -Path $ext_dir\php_phalcon.dll -Target $PSScriptRoot\phalcon\php_phalcon.dll > $null 2>&1 + Enable-PhpExtension -Extension phalcon -Path $php_dir + Add-Log $tick $extension "Installed and enabled" + } catch { + Add-Log $cross $extension "Could not install $extension on PHP $($installed.FullVersion)" + } +}