setup-php/src/extensions.ts

421 lines
13 KiB
TypeScript
Raw Normal View History

2019-10-27 07:12:49 +07:00
import * as path from 'path';
2019-09-20 09:41:20 +07:00
import * as utils from './utils';
2020-06-19 05:39:13 +07:00
/**
* Function to get Xdebug version compatible with php versions
*
* @param version
*/
export async function getXdebugVersion(version: string): Promise<string> {
switch (version) {
case '5.3':
return '2.2.7';
case '5.4':
return '2.4.1';
case '5.5':
case '5.6':
2020-06-19 05:39:13 +07:00
return '2.5.5';
case '7.0':
return '2.7.2';
2020-06-19 05:39:13 +07:00
default:
return '2.9.6';
}
}
2019-09-20 09:41:20 +07:00
/**
* Install and enable extensions for darwin
*
* @param extension_csv
* @param version
2019-12-26 20:01:18 +07:00
* @param pipe
2019-09-20 09:41:20 +07:00
*/
export async function addExtensionDarwin(
extension_csv: string,
2019-12-26 20:01:18 +07:00
version: string,
pipe: string
2019-09-20 09:41:20 +07:00
): Promise<string> {
2019-11-24 03:34:12 +07:00
const extensions: Array<string> = await utils.extensionArray(extension_csv);
2020-05-07 04:57:00 +07:00
let add_script = '\n';
2020-05-22 01:01:12 +07:00
let remove_script = '';
2020-05-08 07:11:00 +07:00
await utils.asyncForEach(extensions, async function (extension: string) {
2019-12-26 20:01:18 +07:00
const version_extension: string = version + extension;
2020-02-16 01:55:50 +07:00
const [ext_name, ext_version]: string[] = extension.split('-');
2020-03-12 06:17:52 +07:00
const ext_prefix = await utils.getExtensionPrefix(ext_name);
const command_prefix = 'sudo pecl install -f ';
let command = '';
switch (true) {
2020-05-07 04:57:00 +07:00
// match :extension
case /^:/.test(ext_name):
remove_script += '\nremove_extension ' + ext_name.slice(1);
return;
// match 5.3blackfire...5.6blackfire, 7.0blackfire...7.4blackfire
// match 5.3blackfire-1.31.0...5.6blackfire-1.31.0, 7.0blackfire-1.31.0...7.4blackfire-1.31.0
2020-02-27 18:55:54 +07:00
case /^(5\.[3-6]|7\.[0-4])blackfire(-\d+\.\d+\.\d+)?$/.test(
version_extension
):
2020-03-12 06:17:52 +07:00
command =
2020-02-27 18:55:54 +07:00
'bash ' +
2020-02-27 15:19:30 +07:00
path.join(__dirname, '../src/scripts/ext/blackfire_darwin.sh') +
' ' +
version +
' ' +
2020-05-07 18:44:15 +07:00
extension;
2020-02-27 18:55:54 +07:00
break;
2020-03-12 06:17:52 +07:00
// match pre-release versions. For example - xdebug-beta
case /.*-(beta|alpha|devel|snapshot)/.test(version_extension):
2020-05-07 04:57:00 +07:00
add_script +=
2020-01-30 13:33:30 +07:00
'\nadd_unstable_extension ' +
2020-02-16 01:55:50 +07:00
ext_name +
2020-01-30 13:33:30 +07:00
' ' +
2020-02-16 01:55:50 +07:00
ext_version +
2020-01-30 13:33:30 +07:00
' ' +
2020-03-12 06:17:52 +07:00
ext_prefix;
2020-01-30 13:33:30 +07:00
return;
2020-03-12 06:17:52 +07:00
// match semver
2020-02-23 20:30:40 +07:00
case /.*-\d+\.\d+\.\d+.*/.test(version_extension):
2020-05-07 04:57:00 +07:00
add_script +=
2020-03-12 06:17:52 +07:00
'\nadd_pecl_extension ' +
ext_name +
' ' +
ext_version +
' ' +
ext_prefix;
2020-02-23 20:30:40 +07:00
return;
2020-06-19 05:39:13 +07:00
// match 5.3xdebug...5.5xdebug
case /5\.[3-5]xdebug/.test(version_extension):
command =
command_prefix + 'xdebug-' + (await getXdebugVersion(version));
break;
// match 5.6xdebug to 8.0xdebug, 5.6swoole to 8.0swoole
// match 5.6grpc to 7.4grpc, 5.6protobuf to 7.4protobuf
// match 7.1pcov to 8.0pcov
case /(5\.6|7\.[0-4]|8\.[0-9])(xdebug|swoole)/.test(version_extension):
case /(5\.6|7\.[0-4])(grpc|protobuf)/.test(version_extension):
2020-06-19 05:39:13 +07:00
case /(7\.[1-4]|8\.[0-9])pcov/.test(version_extension):
command = 'add_brew_extension ' + ext_name;
2020-01-17 07:21:46 +07:00
break;
2020-03-12 06:17:52 +07:00
// match 5.6redis
2019-12-26 20:01:18 +07:00
case /5\.6redis/.test(version_extension):
2020-06-19 05:39:13 +07:00
command = command_prefix + 'redis-2.2.8';
2019-12-26 20:01:18 +07:00
break;
2020-03-12 06:17:52 +07:00
// match imagick
2020-03-16 08:23:58 +07:00
case /^imagick$/.test(extension):
2020-03-12 06:17:52 +07:00
command =
2020-01-21 02:36:31 +07:00
'brew install pkg-config imagemagick' +
pipe +
2020-03-12 06:17:52 +07:00
' && ' +
command_prefix +
'imagick' +
2020-01-21 02:36:31 +07:00
pipe;
break;
2020-03-12 06:17:52 +07:00
// match sqlite
2020-03-16 08:23:58 +07:00
case /^sqlite$/.test(extension):
2020-03-12 06:17:52 +07:00
extension = 'sqlite3';
2020-06-19 05:39:13 +07:00
command = command_prefix + extension;
2020-03-12 06:17:52 +07:00
break;
2020-07-15 11:15:40 +07:00
// match pdo_oci and oci8
case /^pdo_oci$|^oci8$/.test(extension):
add_script +=
'\nbash ' +
path.join(__dirname, '../src/scripts/ext/oci.sh') +
' ' +
extension +
' ' +
version;
return;
2020-03-12 06:17:52 +07:00
// match 7.0phalcon3...7.3phalcon3 and 7.2phalcon4...7.4phalcon4
2019-12-26 20:01:18 +07:00
case /^7\.[0-3]phalcon3$|^7\.[2-4]phalcon4$/.test(version_extension):
2020-05-07 04:57:00 +07:00
add_script +=
2020-05-09 08:50:08 +07:00
'\nbash ' +
2019-12-26 20:01:18 +07:00
path.join(__dirname, '../src/scripts/ext/phalcon_darwin.sh') +
' ' +
extension +
' ' +
2020-02-16 00:21:02 +07:00
version;
return;
default:
2020-06-19 05:39:13 +07:00
command = command_prefix + extension;
break;
2019-09-20 09:41:20 +07:00
}
2020-05-07 04:57:00 +07:00
add_script +=
2020-05-17 12:49:52 +07:00
'\nadd_extension ' + extension + ' "' + command + '" ' + ext_prefix;
2019-09-20 09:41:20 +07:00
});
2020-05-07 04:57:00 +07:00
return add_script + remove_script;
2019-09-20 09:41:20 +07:00
}
/**
* Install and enable extensions for windows
*
* @param extension_csv
* @param version
*/
export async function addExtensionWindows(
extension_csv: string,
2020-03-12 09:27:40 +07:00
version: string
2019-09-20 09:41:20 +07:00
): Promise<string> {
2019-11-24 03:34:12 +07:00
const extensions: Array<string> = await utils.extensionArray(extension_csv);
2020-05-07 04:57:00 +07:00
let add_script = '\n';
2020-05-22 01:01:12 +07:00
let remove_script = '';
2020-05-08 07:11:00 +07:00
await utils.asyncForEach(extensions, async function (extension: string) {
2020-02-16 01:55:50 +07:00
const [ext_name, ext_version]: string[] = extension.split('-');
2019-12-26 20:01:18 +07:00
const version_extension: string = version + extension;
2020-02-16 01:55:50 +07:00
let matches: RegExpExecArray;
switch (true) {
2020-05-07 04:57:00 +07:00
// Match :extension
case /^:/.test(ext_name):
remove_script += '\nRemove-Extension ' + ext_name.slice(1);
return;
// match 5.4blackfire...5.6blackfire, 7.0blackfire...7.4blackfire
// match 5.4blackfire-1.31.0...5.6blackfire-1.31.0, 7.0blackfire-1.31.0...7.4blackfire-1.31.0
2020-02-27 18:55:54 +07:00
case /^(5\.[4-6]|7\.[0-4])blackfire(-\d+\.\d+\.\d+)?$/.test(
version_extension
):
2020-05-07 04:57:00 +07:00
add_script +=
2020-02-27 15:19:30 +07:00
'\n& ' +
2020-02-27 05:59:45 +07:00
path.join(__dirname, '../src/scripts/ext/blackfire.ps1') +
' ' +
2020-02-27 18:55:54 +07:00
version +
' ' +
2020-05-07 18:44:15 +07:00
extension;
2020-02-27 05:59:45 +07:00
return;
2020-03-12 06:17:52 +07:00
// match pre-release versions. For example - xdebug-beta
case /.*-(beta|alpha|devel|snapshot)/.test(version_extension):
2020-05-07 04:57:00 +07:00
add_script += '\nAdd-Extension ' + ext_name + ' ' + ext_version;
break;
2020-03-12 06:17:52 +07:00
// match semver without state
2020-02-16 01:55:50 +07:00
case /.*-\d+\.\d+\.\d+$/.test(version_extension):
2020-05-07 04:57:00 +07:00
add_script += '\nAdd-Extension ' + ext_name + ' stable ' + ext_version;
2020-02-16 01:55:50 +07:00
return;
2020-03-12 06:17:52 +07:00
// match semver with state
case /.*-(\d+\.\d+\.\d)(beta|alpha|devel|snapshot)\d*/.test(
2020-02-16 01:55:50 +07:00
version_extension
):
2020-03-12 06:17:52 +07:00
matches = /.*-(\d+\.\d+\.\d)(beta|alpha|devel|snapshot)\d*/.exec(
2020-02-16 01:55:50 +07:00
version_extension
) as RegExpExecArray;
2020-05-07 04:57:00 +07:00
add_script +=
2020-02-16 01:55:50 +07:00
'\nAdd-Extension ' + ext_name + ' ' + matches[2] + ' ' + matches[1];
return;
2020-03-16 08:23:58 +07:00
// match 5.3mysql..5.6mysql
// match 5.3mysqli..5.6mysqli
// match 5.3mysqlnd..5.6mysqlnd
case /^5\.\d(mysql|mysqli|mysqlnd)$/.test(version_extension):
2020-05-07 04:57:00 +07:00
add_script +=
2020-03-16 08:23:58 +07:00
'\nAdd-Extension mysql\nAdd-Extension mysqli\nAdd-Extension mysqlnd';
break;
// match 7.0mysql..8.0mysql
// match 7.0mysqli..8.0mysqli
// match 7.0mysqlnd..8.0mysqlnd
case /[7-8]\.\d(mysql|mysqli|mysqlnd)$/.test(version_extension):
2020-05-07 04:57:00 +07:00
add_script += '\nAdd-Extension mysqli\nAdd-Extension mysqlnd';
2020-03-16 08:23:58 +07:00
break;
2020-03-12 06:17:52 +07:00
// match sqlite
2020-03-16 08:23:58 +07:00
case /^sqlite$/.test(extension):
2020-03-12 06:17:52 +07:00
extension = 'sqlite3';
2020-05-07 04:57:00 +07:00
add_script += '\nAdd-Extension ' + extension;
2020-03-12 06:17:52 +07:00
break;
2020-07-15 11:15:40 +07:00
// match pdo_oci and oci8
case /^pdo_oci$|^oci8$/.test(extension):
add_script +=
'\n& ' +
path.join(__dirname, '../src/scripts/ext/oci.ps1') +
' ' +
extension +
' ' +
version +
'\n';
break;
// match 7.0phalcon3...7.3phalcon3 and 7.2phalcon4...7.4phalcon4
2019-12-26 20:01:18 +07:00
case /^7\.[0-3]phalcon3$|^7\.[2-4]phalcon4$/.test(version_extension):
2020-05-07 04:57:00 +07:00
add_script +=
2019-12-26 20:01:18 +07:00
'\n& ' +
path.join(__dirname, '../src/scripts/ext/phalcon.ps1') +
' ' +
extension +
' ' +
version +
'\n';
2019-12-02 22:13:45 +07:00
break;
default:
2020-05-17 12:49:52 +07:00
add_script += '\nAdd-Extension ' + extension;
2019-12-02 22:13:45 +07:00
break;
}
2019-09-20 09:41:20 +07:00
});
2020-05-07 04:57:00 +07:00
return add_script + remove_script;
2019-09-20 09:41:20 +07:00
}
/**
* Install and enable extensions for linux
*
* @param extension_csv
* @param version
2019-12-26 20:01:18 +07:00
* @param pipe
2019-09-20 09:41:20 +07:00
*/
export async function addExtensionLinux(
extension_csv: string,
2019-12-26 20:01:18 +07:00
version: string,
pipe: string
2019-09-20 09:41:20 +07:00
): Promise<string> {
2019-11-24 03:34:12 +07:00
const extensions: Array<string> = await utils.extensionArray(extension_csv);
2020-05-07 04:57:00 +07:00
let add_script = '\n';
2020-05-22 01:01:12 +07:00
let remove_script = '';
2020-05-08 07:11:00 +07:00
await utils.asyncForEach(extensions, async function (extension: string) {
2019-12-26 20:01:18 +07:00
const version_extension: string = version + extension;
2020-02-16 01:55:50 +07:00
const [ext_name, ext_version]: string[] = extension.split('-');
2020-03-12 06:17:52 +07:00
const ext_prefix = await utils.getExtensionPrefix(ext_name);
const command_prefix = 'sudo $debconf_fix apt-get install -y php';
let command = '';
switch (true) {
2020-05-07 04:57:00 +07:00
// Match :extension
case /^:/.test(ext_name):
remove_script += '\nremove_extension ' + ext_name.slice(1);
return;
// match 5.3blackfire...5.6blackfire, 7.0blackfire...7.4blackfire
2020-05-07 18:44:15 +07:00
// match 5.3blackfire-{semver}...5.6blackfire-{semver}, 7.0blackfire-{semver}...7.4blackfire-{semver}
2020-02-27 18:55:54 +07:00
case /^(5\.[3-6]|7\.[0-4])blackfire(-\d+\.\d+\.\d+)?$/.test(
version_extension
):
2020-03-12 06:17:52 +07:00
command =
2020-02-27 18:55:54 +07:00
'bash ' +
path.join(__dirname, '../src/scripts/ext/blackfire.sh') +
' ' +
version +
' ' +
2020-05-07 18:44:15 +07:00
extension;
2020-02-27 18:55:54 +07:00
break;
2020-03-12 06:17:52 +07:00
// match pre-release versions. For example - xdebug-beta
case /.*-(beta|alpha|devel|snapshot)/.test(version_extension):
2020-05-07 04:57:00 +07:00
add_script +=
2020-01-30 13:33:30 +07:00
'\nadd_unstable_extension ' +
2020-02-16 01:55:50 +07:00
ext_name +
2020-01-30 13:33:30 +07:00
' ' +
2020-02-16 01:55:50 +07:00
ext_version +
2020-01-30 13:33:30 +07:00
' ' +
2020-03-12 06:17:52 +07:00
ext_prefix;
2020-01-30 13:33:30 +07:00
return;
2020-03-12 06:17:52 +07:00
// match semver versions
2020-02-16 01:55:50 +07:00
case /.*-\d+\.\d+\.\d+.*/.test(version_extension):
2020-05-07 04:57:00 +07:00
add_script +=
2020-03-12 06:17:52 +07:00
'\nadd_pecl_extension ' +
ext_name +
' ' +
ext_version +
' ' +
ext_prefix;
return;
// match 5.6gearman..7.4gearman
2019-12-26 20:01:18 +07:00
case /^((5\.6)|(7\.[0-4]))gearman$/.test(version_extension):
2020-03-12 06:17:52 +07:00
command =
2020-05-09 08:50:08 +07:00
'\nbash ' +
2019-12-26 20:01:18 +07:00
path.join(__dirname, '../src/scripts/ext/gearman.sh') +
' ' +
2019-10-27 07:12:49 +07:00
version +
2019-12-26 20:01:18 +07:00
pipe;
2019-10-13 11:18:29 +07:00
break;
2020-07-15 11:15:40 +07:00
// match pdo_oci and oci8
case /^pdo_oci$|^oci8$/.test(extension):
add_script +=
'\nbash ' +
path.join(__dirname, '../src/scripts/ext/oci.sh') +
' ' +
extension +
' ' +
version;
return;
2020-01-22 02:30:13 +07:00
// match 7.0phalcon3...7.3phalcon3 or 7.2phalcon4...7.4phalcon4
case /^7\.[0-3]phalcon3$|^7\.[2-4]phalcon4$/.test(version_extension):
2020-05-07 04:57:00 +07:00
add_script +=
2020-05-09 08:50:08 +07:00
'\nbash ' +
path.join(__dirname, '../src/scripts/ext/phalcon.sh') +
' ' +
extension +
' ' +
version;
return;
2020-06-20 07:55:19 +07:00
// match 7.2xdebug3..7.4xdebug3
case /^7\.[2-4]xdebug3$/.test(version_extension):
add_script +=
'\nadd_extension_from_source xdebug xdebug/xdebug master --enable-xdebug zend_extension';
return;
// match 8.0xdebug3
case /^8\.[0-9]xdebug3$/.test(version_extension):
extension = 'xdebug';
command = command_prefix + version + '-' + extension + pipe;
break;
2020-03-28 10:52:27 +07:00
// match 7.1xdebug..7.4xdebug
case /^7\.[1-4]xdebug$/.test(version_extension):
2020-05-07 04:57:00 +07:00
add_script +=
2020-06-20 07:55:19 +07:00
'\nupdate_extension xdebug 2.9.6' +
2020-01-17 17:48:00 +07:00
pipe +
'\n' +
(await utils.addLog('$tick', 'xdebug', 'Enabled', 'linux'));
return;
2020-03-05 07:28:24 +07:00
// match pdo extensions
case /.*pdo[_-].*/.test(version_extension):
2020-05-17 12:49:52 +07:00
extension = extension
.replace('pdo_', '')
.replace('pdo-', '')
.replace('sqlite3', 'sqlite');
2020-05-07 04:57:00 +07:00
add_script += '\nadd_pdo_extension ' + extension;
2020-03-05 07:28:24 +07:00
return;
// match ast and uopz
case /^(ast|uopz)$/.test(extension):
command = command_prefix + '-' + extension + pipe;
break;
2020-03-12 06:17:52 +07:00
// match sqlite
2020-03-16 08:23:58 +07:00
case /^sqlite$/.test(extension):
2020-03-12 06:17:52 +07:00
extension = 'sqlite3';
command = command_prefix + version + '-' + extension + pipe;
break;
default:
2020-03-12 06:17:52 +07:00
command = command_prefix + version + '-' + extension + pipe;
break;
}
2020-05-07 04:57:00 +07:00
add_script +=
2020-05-17 12:49:52 +07:00
'\nadd_extension ' + extension + ' "' + command + '" ' + ext_prefix;
2019-09-20 09:41:20 +07:00
});
2020-05-07 04:57:00 +07:00
return add_script + remove_script;
2019-09-20 09:41:20 +07:00
}
2019-11-24 03:34:12 +07:00
/**
* Install and enable extensions
*
* @param extension_csv
* @param version
* @param os_version
2020-03-12 06:17:52 +07:00
* @param no_step
2019-11-24 03:34:12 +07:00
*/
export async function addExtension(
extension_csv: string,
version: string,
os_version: string,
no_step = false
): Promise<string> {
2019-12-26 20:01:18 +07:00
const pipe: string = await utils.suppressOutput(os_version);
2019-11-24 03:34:12 +07:00
let script = '\n';
switch (no_step) {
case true:
2019-12-26 20:01:18 +07:00
script += (await utils.stepLog('Setup Extensions', os_version)) + pipe;
2019-11-24 03:34:12 +07:00
break;
case false:
default:
script += await utils.stepLog('Setup Extensions', os_version);
break;
}
switch (os_version) {
case 'win32':
2020-03-12 09:27:40 +07:00
return script + (await addExtensionWindows(extension_csv, version));
2019-11-24 03:34:12 +07:00
case 'darwin':
2019-12-26 20:01:18 +07:00
return script + (await addExtensionDarwin(extension_csv, version, pipe));
2019-11-24 03:34:12 +07:00
case 'linux':
2019-12-26 20:01:18 +07:00
return script + (await addExtensionLinux(extension_csv, version, pipe));
2019-11-24 03:34:12 +07:00
default:
return await utils.log(
'Platform ' + os_version + ' is not supported',
os_version,
'error'
);
}
}