Fix caching PDO extensions on linux

This commit is contained in:
Shivam Mathur 2020-03-05 05:58:24 +05:30
parent b7d68d8225
commit 58f376b118
No known key found for this signature in database
GPG Key ID: 3E13E4C8591ACC2A
4 changed files with 50 additions and 14 deletions

View File

@ -35,15 +35,15 @@ describe('Extension tests', () => {
it('checking addExtensionOnLinux', async () => { it('checking addExtensionOnLinux', async () => {
let linux: string = await extensions.addExtension( let linux: string = await extensions.addExtension(
'xdebug, pcov, ast-beta, xdebug-alpha, grpc-1.2.3', 'xdebug, pcov, ast-beta, pdo_mysql, pdo-odbc, xdebug-alpha, grpc-1.2.3',
'7.4', '7.4',
'linux' 'linux'
); );
expect(linux).toContain('update_extension xdebug 2.9.1'); expect(linux).toContain('update_extension xdebug 2.9.1');
expect(linux).toContain( expect(linux).toContain('sudo $debconf_fix apt-get install -y php7.4-pcov');
'sudo DEBIAN_FRONTEND=noninteractive apt-get install -y php7.4-pcov'
);
expect(linux).toContain('add_unstable_extension ast beta extension'); expect(linux).toContain('add_unstable_extension ast beta extension');
expect(linux).toContain('add_pdo_extension mysql');
expect(linux).toContain('add_pdo_extension odbc');
expect(linux).toContain('add_pecl_extension grpc 1.2.3 extension'); expect(linux).toContain('add_pecl_extension grpc 1.2.3 extension');
expect(linux).toContain( expect(linux).toContain(
'add_unstable_extension xdebug alpha zend_extension' 'add_unstable_extension xdebug alpha zend_extension'

10
dist/index.js vendored
View File

@ -2917,12 +2917,18 @@ function addExtensionLinux(extension_csv, version, pipe) {
'\n' + '\n' +
(yield utils.addLog('$tick', 'xdebug', 'Enabled', 'linux')); (yield utils.addLog('$tick', 'xdebug', 'Enabled', 'linux'));
return; return;
// match pdo extensions
case /.*pdo[_-].*/.test(version_extension):
script +=
'\nadd_pdo_extension ' +
extension.replace('pdo_', '').replace('pdo-', '');
return;
default: default:
install_command = install_command =
'sudo DEBIAN_FRONTEND=noninteractive apt-get install -y php' + 'sudo $debconf_fix apt-get install -y php' +
version + version +
'-' + '-' +
extension.replace('pdo_', '').replace('pdo-', '') + extension +
pipe; pipe;
break; break;
} }

View File

@ -241,12 +241,18 @@ export async function addExtensionLinux(
'\n' + '\n' +
(await utils.addLog('$tick', 'xdebug', 'Enabled', 'linux')); (await utils.addLog('$tick', 'xdebug', 'Enabled', 'linux'));
return; return;
// match pdo extensions
case /.*pdo[_-].*/.test(version_extension):
script +=
'\nadd_pdo_extension ' +
extension.replace('pdo_', '').replace('pdo-', '');
return;
default: default:
install_command = install_command =
'sudo DEBIAN_FRONTEND=noninteractive apt-get install -y php' + 'sudo $debconf_fix apt-get install -y php' +
version + version +
'-' + '-' +
extension.replace('pdo_', '').replace('pdo-', '') + extension +
pipe; pipe;
break; break;
} }

View File

@ -56,8 +56,7 @@ get_pecl_version() {
# Function to test if extension is loaded # Function to test if extension is loaded
check_extension() { check_extension() {
extension=$1 php -m | grep -i -q -w "$1"
php -m | grep -i -q -w "$extension"
} }
# Function to delete extensions # Function to delete extensions
@ -77,6 +76,32 @@ remove_extension() {
delete_extension "$extension" delete_extension "$extension"
} }
# Function to enable existing extension
enable_extension() {
if ! check_extension "$1" && [ -e "$ext_dir/$1.so" ]; then
echo "$2=$1.so" >>"$ini_file"
fi
}
# Funcion to add PDO extension
add_pdo_extension() {
pdo_ext="pdo_$1"
if check_extension "$pdo_ext"; then
add_log "$tick" "$pdo_ext" "Enabled"
else
read -r ext ext_name <<< "$1 $1"
sudo rm -rf "$scan_dir"/*pdo.ini >/dev/null 2>&1 && enable_extension "pdo" "extension" >/dev/null 2>&1
if [ "$ext" = "mysql" ]; then
enable_extension "mysqlnd" "extension"
ext_name="mysqli"
fi
add_extension "$ext_name" "$apt_install php$version-$ext" "extension" >/dev/null 2>&1
enable_extension "$pdo_ext" "extension"
(check_extension "$pdo_ext" && add_log "$tick" "$pdo_ext" "Enabled") ||
add_log "$cross" "$pdo_ext" "Could not install $pdo_ext on PHP $semver"
fi
}
# Function to setup extensions # Function to setup extensions
add_extension() { add_extension() {
extension=$1 extension=$1
@ -85,11 +110,10 @@ add_extension() {
if [[ "$version" =~ $old_versions ]]; then if [[ "$version" =~ $old_versions ]]; then
install_command="update_ppa && ${install_command/5\.[4-5]-$extension/5-$extension=$release_version}" install_command="update_ppa && ${install_command/5\.[4-5]-$extension/5-$extension=$release_version}"
fi fi
if ! check_extension "$extension" && [ -e "$ext_dir/$extension.so" ]; then enable_extension "$extension" "$prefix"
echo "$prefix=$extension.so" >>"$ini_file" && add_log "$tick" "$extension" "Enabled" if check_extension "$extension"; then
elif check_extension "$extension"; then
add_log "$tick" "$extension" "Enabled" add_log "$tick" "$extension" "Enabled"
elif ! check_extension "$extension"; then else
eval "$install_command" >/dev/null 2>&1 || eval "$install_command" >/dev/null 2>&1 ||
(update_ppa && eval "$install_command" >/dev/null 2>&1) || (update_ppa && eval "$install_command" >/dev/null 2>&1) ||
sudo pecl install -f "$extension" >/dev/null 2>&1 sudo pecl install -f "$extension" >/dev/null 2>&1