2019-10-08 19:42:54 +07:00
|
|
|
import * as utils from './utils';
|
|
|
|
import * as extensions from './extensions';
|
|
|
|
import * as config from './config';
|
|
|
|
|
2021-11-26 01:37:28 +07:00
|
|
|
export async function checkXdebugError(
|
|
|
|
extension: string,
|
|
|
|
version: string
|
|
|
|
): Promise<string> {
|
|
|
|
if (
|
|
|
|
(/^5\.[3-6]$|^7\.[0-1]$/.test(version) && extension == 'xdebug3') ||
|
|
|
|
(/^8\.[0-9]$/.test(version) && extension == 'xdebug2')
|
|
|
|
) {
|
|
|
|
return extension + ' is not supported on PHP ' + version;
|
|
|
|
}
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
2019-10-12 00:39:05 +07:00
|
|
|
/**
|
2023-01-18 10:30:28 +07:00
|
|
|
* Function to set up Xdebug
|
2019-10-12 00:39:05 +07:00
|
|
|
*
|
2020-06-20 07:55:19 +07:00
|
|
|
* @param extension
|
2019-10-12 00:39:05 +07:00
|
|
|
* @param version
|
2022-01-29 06:59:58 +07:00
|
|
|
* @param os
|
2019-12-26 20:01:18 +07:00
|
|
|
* @param pipe
|
2019-10-12 00:39:05 +07:00
|
|
|
*/
|
2019-11-24 03:34:12 +07:00
|
|
|
export async function addCoverageXdebug(
|
2020-06-20 07:55:19 +07:00
|
|
|
extension: string,
|
2019-10-08 19:42:54 +07:00
|
|
|
version: string,
|
2022-01-29 06:59:58 +07:00
|
|
|
os: string,
|
2019-12-26 20:01:18 +07:00
|
|
|
pipe: string
|
2019-10-08 19:42:54 +07:00
|
|
|
): Promise<string> {
|
2021-03-23 08:20:05 +07:00
|
|
|
let script = '\n';
|
2023-01-18 10:30:28 +07:00
|
|
|
const error: string = await checkXdebugError(extension, version);
|
|
|
|
if (!error) {
|
2021-11-26 01:37:28 +07:00
|
|
|
script +=
|
2022-01-29 06:59:58 +07:00
|
|
|
(await extensions.addExtension(':pcov:false', version, os, true)) + pipe;
|
2021-11-26 01:37:28 +07:00
|
|
|
extension = extension == 'xdebug3' ? 'xdebug' : extension;
|
|
|
|
script +=
|
2022-01-29 06:59:58 +07:00
|
|
|
(await extensions.addExtension(extension, version, os, true)) + pipe;
|
2022-06-30 19:06:40 +07:00
|
|
|
script += await utils.setVariable(
|
|
|
|
'xdebug_version',
|
|
|
|
'php -r "echo phpversion(\'xdebug\');"',
|
|
|
|
os
|
|
|
|
);
|
2023-01-18 10:30:28 +07:00
|
|
|
script +=
|
|
|
|
(await utils.getCommand(os, 'extension_log')) +
|
|
|
|
'xdebug "Xdebug $xdebug_version enabled as coverage driver"';
|
|
|
|
} else {
|
|
|
|
script += await utils.addLog('$cross', extension, error, os);
|
2021-11-26 01:37:28 +07:00
|
|
|
}
|
2021-03-23 08:20:05 +07:00
|
|
|
return script;
|
2019-10-08 19:42:54 +07:00
|
|
|
}
|
|
|
|
|
2019-10-12 00:39:05 +07:00
|
|
|
/**
|
2023-01-18 10:30:28 +07:00
|
|
|
* Function to set up PCOV
|
2019-10-12 00:39:05 +07:00
|
|
|
*
|
|
|
|
* @param version
|
2022-01-29 06:59:58 +07:00
|
|
|
* @param os
|
2019-12-26 20:01:18 +07:00
|
|
|
* @param pipe
|
2019-10-12 00:39:05 +07:00
|
|
|
*/
|
2019-11-24 03:34:12 +07:00
|
|
|
export async function addCoveragePCOV(
|
|
|
|
version: string,
|
2022-01-29 06:59:58 +07:00
|
|
|
os: string,
|
2019-12-26 20:01:18 +07:00
|
|
|
pipe: string
|
2019-11-24 03:34:12 +07:00
|
|
|
): Promise<string> {
|
|
|
|
let script = '\n';
|
2020-02-09 05:38:48 +07:00
|
|
|
switch (true) {
|
2019-10-08 19:42:54 +07:00
|
|
|
default:
|
2021-03-23 08:20:05 +07:00
|
|
|
script +=
|
2022-01-29 06:59:58 +07:00
|
|
|
(await extensions.addExtension(':xdebug:false', version, os, true)) +
|
2021-03-23 08:20:05 +07:00
|
|
|
pipe;
|
2019-10-17 03:11:13 +07:00
|
|
|
script +=
|
2022-01-29 06:59:58 +07:00
|
|
|
(await extensions.addExtension('pcov', version, os, true)) + pipe;
|
|
|
|
script += (await config.addINIValues('pcov.enabled=1', os, true)) + '\n';
|
2022-06-30 19:06:40 +07:00
|
|
|
script += await utils.setVariable(
|
|
|
|
'pcov_version',
|
|
|
|
'php -r "echo phpversion(\'pcov\');"',
|
|
|
|
os
|
|
|
|
);
|
2023-01-18 10:30:28 +07:00
|
|
|
script +=
|
|
|
|
(await utils.getCommand(os, 'extension_log')) +
|
|
|
|
'pcov "PCOV $pcov_version enabled as coverage driver"';
|
2019-10-08 19:42:54 +07:00
|
|
|
break;
|
2020-02-09 05:38:48 +07:00
|
|
|
|
|
|
|
case /5\.[3-6]|7\.0/.test(version):
|
2019-10-17 03:11:13 +07:00
|
|
|
script += await utils.addLog(
|
|
|
|
'$cross',
|
|
|
|
'pcov',
|
|
|
|
'PHP 7.1 or newer is required',
|
2022-01-29 06:59:58 +07:00
|
|
|
os
|
2019-10-08 19:42:54 +07:00
|
|
|
);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return script;
|
|
|
|
}
|
|
|
|
|
2019-10-12 00:39:05 +07:00
|
|
|
/**
|
|
|
|
* Function to disable Xdebug and PCOV
|
|
|
|
*
|
|
|
|
* @param version
|
2022-01-29 06:59:58 +07:00
|
|
|
* @param os
|
2019-12-26 20:01:18 +07:00
|
|
|
* @param pipe
|
2019-10-12 00:39:05 +07:00
|
|
|
*/
|
2019-11-24 03:34:12 +07:00
|
|
|
export async function disableCoverage(
|
|
|
|
version: string,
|
2022-01-29 06:59:58 +07:00
|
|
|
os: string,
|
2019-12-26 20:01:18 +07:00
|
|
|
pipe: string
|
2019-11-24 03:34:12 +07:00
|
|
|
): Promise<string> {
|
|
|
|
let script = '\n';
|
2021-03-23 08:20:05 +07:00
|
|
|
script +=
|
2022-01-29 06:59:58 +07:00
|
|
|
(await extensions.addExtension(':pcov:false', version, os, true)) + pipe;
|
2021-08-25 21:06:40 +07:00
|
|
|
script +=
|
2022-01-29 06:59:58 +07:00
|
|
|
(await extensions.addExtension(':xdebug:false', version, os, true)) + pipe;
|
|
|
|
script += await utils.addLog('$tick', 'none', 'Disabled Xdebug and PCOV', os);
|
2019-10-08 19:42:54 +07:00
|
|
|
|
|
|
|
return script;
|
|
|
|
}
|
2019-11-24 03:34:12 +07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Function to set coverage driver
|
|
|
|
*
|
|
|
|
* @param coverage_driver
|
|
|
|
* @param version
|
2022-01-29 06:59:58 +07:00
|
|
|
* @param os
|
2019-11-24 03:34:12 +07:00
|
|
|
*/
|
|
|
|
export async function addCoverage(
|
|
|
|
coverage_driver: string,
|
|
|
|
version: string,
|
2022-01-29 06:59:58 +07:00
|
|
|
os: string
|
2019-11-24 03:34:12 +07:00
|
|
|
): Promise<string> {
|
2020-01-26 17:45:39 +07:00
|
|
|
coverage_driver = coverage_driver.toLowerCase();
|
2022-01-29 06:59:58 +07:00
|
|
|
const script: string = '\n' + (await utils.stepLog('Setup Coverage', os));
|
|
|
|
const pipe: string = (await utils.suppressOutput(os)) + '\n';
|
2019-11-24 03:34:12 +07:00
|
|
|
switch (coverage_driver) {
|
|
|
|
case 'pcov':
|
2022-01-29 06:59:58 +07:00
|
|
|
return script + (await addCoveragePCOV(version, os, pipe));
|
2019-11-24 03:34:12 +07:00
|
|
|
case 'xdebug':
|
2020-12-24 19:50:42 +07:00
|
|
|
case 'xdebug2':
|
2021-11-26 01:37:28 +07:00
|
|
|
case 'xdebug3':
|
2020-12-24 19:50:42 +07:00
|
|
|
return (
|
2022-01-29 06:59:58 +07:00
|
|
|
script + (await addCoverageXdebug(coverage_driver, version, os, pipe))
|
2020-06-20 07:55:19 +07:00
|
|
|
);
|
2019-11-24 03:34:12 +07:00
|
|
|
case 'none':
|
2022-01-29 06:59:58 +07:00
|
|
|
return script + (await disableCoverage(version, os, pipe));
|
2019-11-24 03:34:12 +07:00
|
|
|
default:
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
}
|