setup-php/src/extensions.ts

446 lines
14 KiB
TypeScript
Raw Normal View History

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