setup-php/src/extensions.ts

350 lines
12 KiB
TypeScript
Raw Normal View History

2019-09-20 09:41:20 +07:00
import * as utils from './utils';
/**
* Install and enable extensions for darwin
*
* @param extension_csv
* @param version
2019-09-20 09:41:20 +07:00
*/
export async function addExtensionDarwin(
extension_csv: string,
2020-11-08 14:36:21 +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) {
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);
switch (true) {
2020-05-07 04:57:00 +07:00
// match :extension
case /^:/.test(ext_name):
remove_script += '\ndisable_extension ' + ext_name.slice(1);
2020-05-07 04:57:00 +07:00
return;
// match extensions for compiling from source
case /.+-.+\/.+@.+/.test(extension):
add_script += await utils.parseExtensionSource(extension, ext_prefix);
return;
2020-12-14 15:44:49 +07:00
// match 5.3blackfire...8.0blackfire
// match 5.3blackfire-(semver)...8.0blackfire-(semver)
// match couchbase, geos, pdo_oci, oci8, http, pecl_http
// match 5.3ioncube...7.4ioncube
2020-08-06 17:03:58 +07:00
// match 7.0phalcon3...7.3phalcon3 and 7.2phalcon4...7.4phalcon4
2020-12-14 15:43:45 +07:00
case /^(5\.[3-6]|7\.[0-4]|8\.0)blackfire(-\d+\.\d+\.\d+)?$/.test(
2020-02-27 18:55:54 +07:00
version_extension
):
case /^couchbase$|^geos$|^pdo_oci$|^oci8$|^(pecl_)?http|^pdo_firebird$/.test(
extension
):
case /^(5\.[3-6]|7\.[0-4])ioncube$/.test(version_extension):
2020-08-06 17:03:58 +07:00
add_script += await utils.customPackage(
ext_name,
'ext',
extension,
'darwin'
2020-07-26 17:18:19 +07:00
);
return;
2020-03-12 06:17:52 +07:00
// match pre-release versions. For example - xdebug-beta
2021-02-09 01:36:18 +07:00
case /.+-(stable|beta|alpha|devel|snapshot|rc|preview)/.test(extension):
2020-07-24 11:58:48 +07:00
add_script += await utils.joins(
'\nadd_unstable_extension',
ext_name,
ext_version,
ext_prefix
);
2020-01-30 13:33:30 +07:00
return;
2020-03-12 06:17:52 +07:00
// match semver
2021-02-09 01:36:18 +07:00
case /.+-\d+\.\d+\.\d+.*/.test(extension):
2020-07-24 11:58:48 +07:00
add_script += await utils.joins(
'\nadd_pecl_extension',
ext_name,
ext_version,
ext_prefix
);
2020-02-23 20:30:40 +07:00
return;
// match 5.3pcov to 7.0pcov
case /(5\.[3-6]|7\.0)pcov/.test(version_extension):
2020-07-24 11:58:48 +07:00
add_script += await utils.getUnsupportedLog('pcov', version, 'darwin');
return;
// match 5.6 and newer - amqp, apcu, grpc, igbinary, imagick, imap, memcache, memcached, mongodb, msgpack, protobuf, raphf, rdkafka, redis, swoole, xdebug, xdebug2, yaml, zmq
// match 7.1 and newer - pcov
// match 5.6 to 7.4 - propro
case /(?<!5\.[3-5])(amqp|apcu|grpc|igbinary|imagick|imap|memcache|memcached|mongodb|msgpack|protobuf|psr|raphf|rdkafka|redis|swoole|xdebug|xdebug2|yaml|zmq)/.test(
version_extension
):
case /(5\.6|7\.[0-4])propro/.test(version_extension):
case /(?<!5\.[3-6]|7\.0)pcov/.test(version_extension):
case /(5\.6|7\.[0-3])phalcon3|7\.[2-4]phalcon4/.test(version_extension):
2020-11-08 14:36:21 +07:00
add_script += await utils.joins(
'\nadd_brew_extension',
ext_name,
ext_prefix
);
return;
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';
break;
default:
break;
2019-09-20 09:41:20 +07:00
}
2020-11-08 14:36:21 +07:00
add_script += await utils.joins('\nadd_extension', extension, 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 += '\nDisable-Extension ' + ext_name.slice(1);
2020-07-26 17:18:19 +07:00
break;
2020-12-14 15:44:49 +07:00
// match 5.3blackfire...8.0blackfire
// match 5.3blackfire-(semver)...8.0blackfire-(semver)
2020-08-06 17:03:58 +07:00
// match pdo_oci and oci8
2020-12-14 15:44:49 +07:00
// match 5.3ioncube...7.4ioncube
2020-08-06 17:03:58 +07:00
// match 7.0phalcon3...7.3phalcon3 and 7.2phalcon4...7.4phalcon4
// match 7.1pecl_http...8.0pecl_http and 7.1http...8.0http
2020-12-14 15:43:45 +07:00
case /^(5\.[3-6]|7\.[0-4]|8\.0)blackfire(-\d+\.\d+\.\d+)?$/.test(
2020-02-27 18:55:54 +07:00
version_extension
):
case /^pdo_oci$|^oci8$|^pdo_firebird$/.test(extension):
case /^(5\.[3-6]|7\.[0-4])ioncube$/.test(version_extension):
2020-07-26 17:18:19 +07:00
case /^7\.[0-3]phalcon3$|^7\.[2-4]phalcon4$/.test(version_extension):
case /^(7\.[1-4]|8\.0)(pecl_)?http/.test(version_extension):
2020-08-06 17:03:58 +07:00
add_script += await utils.customPackage(
ext_name,
'ext',
extension,
'win32'
2020-07-26 17:18:19 +07:00
);
2020-08-06 17:03:58 +07:00
return;
2020-03-12 06:17:52 +07:00
// match pre-release versions. For example - xdebug-beta
2021-02-09 01:36:18 +07:00
case /.+-(stable|beta|alpha|devel|snapshot)/.test(extension):
2020-07-24 11:58:48 +07:00
add_script += await utils.joins(
'\nAdd-Extension',
ext_name,
2020-11-27 16:25:30 +07:00
ext_version.replace('stable', '')
2020-07-24 11:58:48 +07:00
);
break;
// match extensions for compiling from source
2021-02-09 01:36:18 +07:00
case /.+-.+\/.+@.+/.test(extension):
add_script += await utils.getUnsupportedLog(
extension,
version,
'win32'
);
break;
2020-03-12 06:17:52 +07:00
// match semver without state
2021-02-09 01:36:18 +07:00
case /.+-\d+\.\d+\.\d+$/.test(extension):
2020-07-24 11:58:48 +07:00
add_script += await utils.joins(
'\nAdd-Extension',
ext_name,
'stable',
ext_version
);
2020-07-26 17:18:19 +07:00
break;
2020-03-12 06:17:52 +07:00
// match semver with state
2021-02-09 01:36:18 +07:00
case /.+-\d+\.\d+\.\d+[a-zA-Z]+\d*/.test(extension):
matches = /.+-(\d+\.\d+\.\d+)([a-zA-Z]+)\d*/.exec(
2020-02-16 01:55:50 +07:00
version_extension
) as RegExpExecArray;
2020-07-24 11:58:48 +07:00
add_script += await utils.joins(
'\nAdd-Extension',
ext_name,
matches[2].replace('preview', 'devel'),
2020-07-24 11:58:48 +07:00
matches[1]
);
2020-07-26 17:18:19 +07:00
break;
2020-12-24 19:50:42 +07:00
// match 7.2xdebug2 to 7.4xdebug2
case /7\.[2-4]xdebug2/.test(version_extension):
add_script += '\nAdd-Extension xdebug stable 2.9.8';
break;
2020-12-24 19:50:42 +07:00
// match 5.3pcov to 7.0pcov
case /(5\.[3-6]|7\.0)pcov/.test(version_extension):
2020-07-24 11:58:48 +07:00
add_script += await utils.getUnsupportedLog('pcov', version, 'win32');
break;
// match 5.3 to 5.6 - mysql, mysqli, mysqlnd
case /^5\.[3-6](?<!pdo_)(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.0 and newer mysql, mysqli and mysqlnd
case /(?<!5\.[3-6])(?<!pdo_)(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-07-24 11:58:48 +07:00
add_script += await utils.joins('\nAdd-Extension', extension);
2020-03-12 06:17:52 +07:00
break;
2019-12-02 22:13:45 +07:00
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
*/
export async function addExtensionLinux(
extension_csv: string,
2020-11-08 14:36:21 +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) {
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);
switch (true) {
2020-05-07 04:57:00 +07:00
// Match :extension
case /^:/.test(ext_name):
remove_script += '\ndisable_extension ' + ext_name.slice(1);
2020-05-07 04:57:00 +07:00
return;
// match extensions for compiling from source
case /.+-.+\/.+@.+/.test(extension):
add_script += await utils.parseExtensionSource(extension, ext_prefix);
return;
2020-12-14 15:44:49 +07:00
// match 5.3blackfire...8.0blackfire
// match 5.3blackfire-(semver)...8.0blackfire-(semver)
// match 5.3pdo_cubrid...7.2php_cubrid, 5.3cubrid...7.4cubrid
// match couchbase, geos, pdo_oci, oci8, http, pecl_http
// match 5.3ioncube...7.4ioncube
2020-08-06 17:03:58 +07:00
// match 7.0phalcon3...7.3phalcon3 and 7.2phalcon4...7.4phalcon4
2020-12-14 15:43:45 +07:00
case /^(5\.[3-6]|7\.[0-4]|8\.0)blackfire(-\d+\.\d+\.\d+)?$/.test(
2020-02-27 18:55:54 +07:00
version_extension
):
case /^((5\.[3-6])|(7\.[0-2]))pdo_cubrid$|^((5\.[3-6])|(7\.[0-4]))cubrid$/.test(
version_extension
):
case /^couchbase$|^gearman$|^geos$|^pdo_oci$|^oci8$|^(pecl_)?http|^pdo_firebird$/.test(
extension
):
2021-04-13 01:33:56 +07:00
case /(?<!5\.[3-5])intl-[\d]+\.[\d]+$/.test(version_extension):
case /^(5\.[3-6]|7\.[0-4])ioncube$/.test(version_extension):
2020-07-26 17:18:19 +07:00
case /^7\.[0-3]phalcon3$|^7\.[2-4]phalcon4$/.test(version_extension):
2020-08-06 17:03:58 +07:00
add_script += await utils.customPackage(
ext_name,
'ext',
extension,
'linux'
);
2020-07-26 17:18:19 +07:00
return;
2020-03-12 06:17:52 +07:00
// match pre-release versions. For example - xdebug-beta
2021-02-09 01:36:18 +07:00
case /.+-(stable|beta|alpha|devel|snapshot|rc|preview)/.test(extension):
2020-07-24 11:58:48 +07:00
add_script += await utils.joins(
'\nadd_unstable_extension',
ext_name,
ext_version,
ext_prefix
);
2020-01-30 13:33:30 +07:00
return;
2020-03-12 06:17:52 +07:00
// match semver versions
2021-02-09 01:36:18 +07:00
case /.+-\d+\.\d+\.\d+.*/.test(extension):
2020-07-24 11:58:48 +07:00
add_script += await utils.joins(
'\nadd_pecl_extension',
ext_name,
ext_version,
ext_prefix
);
return;
// match 5.3pcov to 7.0pcov
case /(5\.[3-6]|7\.0)pcov/.test(version_extension):
2020-07-24 11:58:48 +07:00
add_script += await utils.getUnsupportedLog('pcov', version, 'linux');
return;
2020-12-24 19:50:42 +07:00
// match 7.2xdebug2...7.4xdebug2
case /^7\.[2-4]xdebug2$/.test(version_extension):
add_script += await utils.joins(
'\nadd_pecl_extension',
2020-12-24 19:50:42 +07:00
'xdebug',
'2.9.8',
ext_prefix
);
2020-12-24 19:50:42 +07:00
return;
2020-03-05 07:28:24 +07:00
// match pdo extensions
2021-02-09 01:36:18 +07:00
case /^pdo[_-].+/.test(extension):
2020-07-26 17:18:19 +07:00
extension = extension.replace(/pdo[_-]|3/, '');
2020-05-07 04:57:00 +07:00
add_script += '\nadd_pdo_extension ' + extension;
2020-03-05 07:28:24 +07:00
return;
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';
break;
default:
break;
}
2020-11-08 14:36:21 +07:00
add_script += await utils.joins('\nadd_extension', extension, 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> {
2020-11-08 14:36:21 +07:00
const log: string = await utils.stepLog('Setup Extensions', os_version);
2019-11-24 03:34:12 +07:00
let script = '\n';
switch (no_step) {
case true:
2020-11-08 14:36:21 +07:00
script += log + (await utils.suppressOutput(os_version));
2019-11-24 03:34:12 +07:00
break;
case false:
default:
2020-11-08 14:36:21 +07:00
script += log;
2019-11-24 03:34:12 +07:00
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':
2020-11-08 14:36:21 +07:00
return script + (await addExtensionDarwin(extension_csv, version));
2019-11-24 03:34:12 +07:00
case 'linux':
2020-11-08 14:36:21 +07:00
return script + (await addExtensionLinux(extension_csv, version));
2019-11-24 03:34:12 +07:00
default:
return await utils.log(
'Platform ' + os_version + ' is not supported',
os_version,
'error'
);
}
}