Improve examples and logging, and fix PCOV setup on linux

This commit is contained in:
Shivam Mathur
2019-10-04 19:34:05 +05:30
parent ba5306eea9
commit 17d90ace86
10 changed files with 289 additions and 103 deletions

View File

@ -18,17 +18,17 @@ var __importStar = (this && this.__importStar) || function (mod) {
Object.defineProperty(exports, "__esModule", { value: true });
const utils = __importStar(require("./utils"));
const pecl = __importStar(require("./pecl"));
function addExtension(extension_csv, version, os_version) {
function addExtension(extension_csv, version, os_version, log_prefix = 'Add Extension') {
return __awaiter(this, void 0, void 0, function* () {
switch (os_version) {
case 'win32':
return yield addExtensionWindows(extension_csv, version);
return yield addExtensionWindows(extension_csv, version, log_prefix);
case 'darwin':
return yield addExtensionDarwin(extension_csv, version);
return yield addExtensionDarwin(extension_csv, version, log_prefix);
case 'linux':
return yield addExtensionLinux(extension_csv, version);
return yield addExtensionLinux(extension_csv, version, log_prefix);
default:
return yield utils.log('Platform ' + os_version + ' is not supported', os_version, 'error');
return yield utils.log('Platform ' + os_version + ' is not supported', os_version, 'error', log_prefix);
}
});
}
@ -42,7 +42,7 @@ function addINIValues(ini_values_csv, os_version) {
case 'linux':
return yield addINIValuesUnix(ini_values_csv);
default:
return yield utils.log('Platform ' + os_version + ' is not supported', os_version, 'error');
return yield utils.log('Platform ' + os_version + ' is not supported', os_version, 'error', 'Add Config');
}
});
}
@ -52,18 +52,18 @@ exports.addINIValues = addINIValues;
*
* @param extension
*/
function enableExtensionWindows(extension) {
function enableExtensionWindows(extension, log_prefix) {
return __awaiter(this, void 0, void 0, function* () {
return (`try {
$exist = Test-Path -Path $ext_dir\\php_${extension}.dll
if(!(php -m | findstr -i ${extension}) -and $exist) {
Add-Content C:\\tools\\php\\php.ini "${yield utils.getExtensionPrefix(extension)}=php_${extension}.dll"\n` +
(yield utils.log('Enabled ' + extension, 'win32', 'success')) +
(yield utils.log('Enabled ' + extension, 'win32', 'success', log_prefix)) +
` } elseif(php -m | findstr -i ${extension}) {\n` +
(yield utils.log('Extension ' + extension + ' was already enabled', 'win32', 'success')) +
(yield utils.log(extension + ' was already enabled', 'win32', 'success', log_prefix)) +
` }
} catch [Exception] {\n` +
(yield utils.log(extension + ' could not be enabled', 'win32', 'error')) +
(yield utils.log(extension + ' could not be enabled', 'win32', 'error', log_prefix)) +
` }\n`);
});
}
@ -74,13 +74,13 @@ exports.enableExtensionWindows = enableExtensionWindows;
* @param extension
* @param os_version
*/
function enableExtensionUnix(extension, os_version) {
function enableExtensionUnix(extension, os_version, log_prefix) {
return __awaiter(this, void 0, void 0, function* () {
return (`if [ ! "$(php -m | grep -i ${extension})" ] && [ -e "$ext_dir/${extension}.so" ]; then
echo "${yield utils.getExtensionPrefix(extension)}=${extension}" >> 'php -i | grep "Loaded Configuration" | sed -e "s|.*=>\s*||"'\n` +
(yield utils.log('Enabled ' + extension, os_version, 'success')) +
(yield utils.log('Enabled ' + extension, os_version, 'success', log_prefix)) +
`;\n elif [ "$(php -m | grep -i ${extension})" ]; then \n` +
(yield utils.log('Extension ' + extension + ' was already enabled', os_version, 'success')) +
(yield utils.log(extension + ' was already enabled', os_version, 'success', log_prefix)) +
`; fi\n`);
});
}
@ -91,7 +91,7 @@ exports.enableExtensionUnix = enableExtensionUnix;
* @param extension_csv
* @param version
*/
function addExtensionDarwin(extension_csv, version) {
function addExtensionDarwin(extension_csv, version, log_prefix) {
return __awaiter(this, void 0, void 0, function* () {
let extensions = yield utils.extensionArray(extension_csv);
let script = '\n';
@ -99,7 +99,7 @@ function addExtensionDarwin(extension_csv, version) {
return __awaiter(this, void 0, void 0, function* () {
extension = extension.toLowerCase();
// add script to enable extension is already installed along with php
script += yield enableExtensionUnix(extension, 'darwin');
script += yield enableExtensionUnix(extension, 'darwin', log_prefix);
switch (yield pecl.checkPECLExtension(extension)) {
case true:
let install_command = '';
@ -126,9 +126,9 @@ function addExtensionDarwin(extension_csv, version) {
')" ]; then ' +
install_command +
' && ' +
(yield utils.log('Installed and enabled ' + extension, 'darwin', 'success')) +
(yield utils.log('Installed and enabled ' + extension, 'darwin', 'success', log_prefix)) +
' || ' +
(yield utils.log('Could not install ' + extension + ' on PHP' + version, 'darwin', 'error')) +
(yield utils.log('Could not install ' + extension + ' on PHP' + version, 'darwin', 'error', log_prefix)) +
'; fi\n';
break;
case false:
@ -137,7 +137,7 @@ function addExtensionDarwin(extension_csv, version) {
'if [ ! "$(php -m | grep -i ' +
extension +
')" ]; then \n' +
(yield utils.log('Could not find ' + extension + ' for PHP' + version + ' on PECL', 'darwin', 'error')) +
(yield utils.log('Could not find ' + extension + ' for PHP' + version + ' on PECL', 'darwin', 'error', log_prefix)) +
'; fi\n';
break;
}
@ -153,7 +153,7 @@ exports.addExtensionDarwin = addExtensionDarwin;
* @param extension_csv
* @param version
*/
function addExtensionWindows(extension_csv, version) {
function addExtensionWindows(extension_csv, version, log_prefix) {
return __awaiter(this, void 0, void 0, function* () {
let extensions = yield utils.extensionArray(extension_csv);
let script = '\n';
@ -161,7 +161,7 @@ function addExtensionWindows(extension_csv, version) {
return __awaiter(this, void 0, void 0, function* () {
extension = extension.toLowerCase();
// add script to enable extension is already installed along with php
script += yield enableExtensionWindows(extension);
script += yield enableExtensionWindows(extension, log_prefix);
switch (yield pecl.checkPECLExtension(extension)) {
case true:
let install_command = '';
@ -186,9 +186,9 @@ function addExtensionWindows(extension_csv, version) {
'try { ' +
install_command +
'\n' +
(yield utils.log('Installed and enabled ' + extension, 'win32', 'success')) +
(yield utils.log('Installed and enabled ' + extension, 'win32', 'success', log_prefix)) +
' } catch [Exception] { ' +
(yield utils.log('Could not install ' + extension + ' on PHP' + version, 'win32', 'error')) +
(yield utils.log('Could not install ' + extension + ' on PHP' + version, 'win32', 'error', log_prefix)) +
' } }\n';
break;
case false:
@ -197,7 +197,7 @@ function addExtensionWindows(extension_csv, version) {
'if(!(php -m | findstr -i ' +
extension +
')) { ' +
(yield utils.log('Could not find ' + extension + ' for PHP' + version + ' on PECL', 'win32', 'error')) +
(yield utils.log('Could not find ' + extension + ' for PHP' + version + ' on PECL', 'win32', 'error', log_prefix)) +
' } \n';
break;
}
@ -213,7 +213,7 @@ exports.addExtensionWindows = addExtensionWindows;
* @param extension_csv
* @param version
*/
function addExtensionLinux(extension_csv, version) {
function addExtensionLinux(extension_csv, version, log_prefix) {
return __awaiter(this, void 0, void 0, function* () {
let extensions = yield utils.extensionArray(extension_csv);
let script = '\n';
@ -221,7 +221,7 @@ function addExtensionLinux(extension_csv, version) {
return __awaiter(this, void 0, void 0, function* () {
extension = extension.toLowerCase();
// add script to enable extension is already installed along with php
script += yield enableExtensionUnix(extension, 'linux');
script += yield enableExtensionUnix(extension, 'linux', log_prefix);
let install_command = '';
switch (version + extension) {
case '7.4xdebug':
@ -247,9 +247,9 @@ function addExtensionLinux(extension_csv, version) {
')" ]; then ' +
install_command +
' && ' +
(yield utils.log('Installed and enabled ' + extension, 'linux', 'success')) +
(yield utils.log('Installed and enabled ' + extension, 'linux', 'success', log_prefix)) +
' || ' +
(yield utils.log('Could not find php' + version + '-' + extension + ' on APT repository', 'linux', 'error')) +
(yield utils.log('Could not find php' + version + '-' + extension + ' on APT repository', 'linux', 'error', log_prefix)) +
'; fi\n';
});
});
@ -306,11 +306,15 @@ function addCoverage(coverage, version, os_version) {
// if version is 7.1 or newer
switch (version) {
default:
script += yield addExtension('pcov', version, os_version);
script += yield addExtension('pcov', version, os_version, 'Set Coverage Driver');
script += yield addINIValues('pcov.enabled=1', os_version);
// add command to disable xdebug and enable pcov
switch (os_version) {
case 'linux':
script +=
'if [ -e /etc/php/' +
version +
'/mods-available/xdebug.ini ]; then sudo phpdismod xdebug; fi\n';
script += 'sudo sed -i "/xdebug/d" $ini_file\n';
break;
case 'darwin':
@ -322,19 +326,19 @@ function addCoverage(coverage, version, os_version) {
break;
}
// success
script += yield utils.log('pcov enabled as coverage driver', os_version, 'success');
script += yield utils.log('PCOV enabled as coverage driver', os_version, 'success', 'Set Coverage Driver');
// version is not supported
break;
case '5.6':
case '7.0':
script += yield utils.log('pcov requires php 7.1 or newer', os_version, 'warning');
script += yield utils.log('PCOV requires PHP 7.1 or newer', os_version, 'warning', 'Set Coverage Driver');
break;
}
break;
//xdebug
case 'xdebug':
script += yield addExtension('xdebug', version, os_version);
script += yield utils.log('Xdebug enabled as coverage driver', os_version, 'success');
script += yield addExtension('xdebug', version, os_version, 'Set Coverage Driver');
script += yield utils.log('Xdebug enabled as coverage driver', os_version, 'success', 'Set Coverage Driver');
break;
// unknown coverage driver
default:

View File

@ -156,13 +156,21 @@ function INIArray(ini_values_csv) {
});
}
exports.INIArray = INIArray;
function log(message, os_version, log_type) {
function log(message, os_version, log_type, prefix = '') {
return __awaiter(this, void 0, void 0, function* () {
const unix_color = {
error: '31',
success: '32',
warning: '33'
};
switch (prefix) {
case '':
prefix = prefix;
break;
default:
prefix = prefix + ': ';
break;
}
switch (os_version) {
case 'win32':
const color = {
@ -170,11 +178,20 @@ function log(message, os_version, log_type) {
success: 'green',
warning: 'yellow'
};
return "Write-Host '" + message + "' -ForegroundColor " + color[log_type];
return ("Write-Host '" +
prefix +
message +
"' -ForegroundColor " +
color[log_type]);
case 'linux':
case 'darwin':
default:
return ('echo "\\033[' + unix_color[log_type] + ';1m' + message + '\\033[0m"');
return ('echo "\\033[' +
unix_color[log_type] +
';1m' +
prefix +
message +
'\\033[0m"');
}
});
}