Merge pull request #86 from mlocati/improve-win32

Simplify win32 script
This commit is contained in:
Shivam Mathur 2019-11-25 21:35:52 +05:30 committed by GitHub
commit 159a09794e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 73 additions and 119 deletions

View File

@ -7,17 +7,10 @@ describe('Extension tests', () => {
'7.2', '7.2',
'win32' 'win32'
); );
expect(win32).toContain('Install-PhpExtension xdebug'); expect(win32).toContain('Add-Extension xdebug');
expect(win32).toContain('Install-PhpExtension pcov'); expect(win32).toContain('Add-Extension pcov');
win32 = await extensions.addExtension('xdebug, pcov', '7.4', 'win32'); win32 = await extensions.addExtension('xdebug, pcov', '7.4', 'win32');
const extension_url = expect(win32).toContain('Add-Extension xdebug');
'https://xdebug.org/files/php_xdebug-2.8.0-7.4-vc15.dll';
expect(win32).toContain(
'Invoke-WebRequest -Uri ' +
extension_url +
' -OutFile C:\\tools\\php\\ext\\php_xdebug.dll'
);
expect(win32).toContain('Install-PhpExtension pcov');
win32 = await extensions.addExtension( win32 = await extensions.addExtension(
'does_not_exist', 'does_not_exist',
@ -25,9 +18,7 @@ describe('Extension tests', () => {
'win32', 'win32',
true true
); );
expect(win32).toContain( expect(win32).toContain('Add-Extension does_not_exist');
'Add-Extension does_not_exist "Install-PhpExtension does_not_exist" extension'
);
win32 = await extensions.addExtension('xdebug', '7.2', 'fedora'); win32 = await extensions.addExtension('xdebug', '7.2', 'fedora');
expect(win32).toContain('Platform fedora is not supported'); expect(win32).toContain('Platform fedora is not supported');

25
dist/index.js vendored
View File

@ -1648,31 +1648,8 @@ function addExtensionWindows(extension_csv, version) {
let script = '\n'; let script = '\n';
yield utils.asyncForEach(extensions, function (extension) { yield utils.asyncForEach(extensions, function (extension) {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
extension = extension.toLowerCase();
// add script to enable extension is already installed along with php // add script to enable extension is already installed along with php
let install_command = ''; script += '\nAdd-Extension ' + extension;
switch (version + extension) {
case '7.4xdebug': {
const extension_url = 'https://xdebug.org/files/php_xdebug-2.8.0-7.4-vc15.dll';
install_command =
'Invoke-WebRequest -Uri ' +
extension_url +
' -OutFile C:\\tools\\php\\ext\\php_xdebug.dll\n';
install_command += 'Enable-PhpExtension xdebug';
break;
}
case '7.2xdebug':
default:
install_command = 'Install-PhpExtension ' + extension;
break;
}
script +=
'\nAdd-Extension ' +
extension +
' "' +
install_command +
'" ' +
(yield utils.getExtensionPrefix(extension));
}); });
}); });
return script; return script;

View File

@ -49,33 +49,8 @@ export async function addExtensionWindows(
const extensions: Array<string> = await utils.extensionArray(extension_csv); const extensions: Array<string> = await utils.extensionArray(extension_csv);
let script = '\n'; let script = '\n';
await utils.asyncForEach(extensions, async function(extension: string) { await utils.asyncForEach(extensions, async function(extension: string) {
extension = extension.toLowerCase();
// add script to enable extension is already installed along with php // add script to enable extension is already installed along with php
script += '\nAdd-Extension ' + extension;
let install_command = '';
switch (version + extension) {
case '7.4xdebug': {
const extension_url =
'https://xdebug.org/files/php_xdebug-2.8.0-7.4-vc15.dll';
install_command =
'Invoke-WebRequest -Uri ' +
extension_url +
' -OutFile C:\\tools\\php\\ext\\php_xdebug.dll\n';
install_command += 'Enable-PhpExtension xdebug';
break;
}
case '7.2xdebug':
default:
install_command = 'Install-PhpExtension ' + extension;
break;
}
script +=
'\nAdd-Extension ' +
extension +
' "' +
install_command +
'" ' +
(await utils.getExtensionPrefix(extension));
}); });
return script; return script;
} }

View File

@ -1,89 +1,100 @@
param ( param (
[Parameter(Mandatory=$true)][string]$version = "7.3", [Parameter(Mandatory = $true)][string]$version = "7.3",
[Parameter(Mandatory=$true)][string]$dir [Parameter(Mandatory = $true)][string]$dir
) )
$tick = ([char]8730) $tick = ([char]8730)
$cross = ([char]10007) $cross = ([char]10007)
$php_dir = 'C:\tools\php'
Function Step-Log($message) { Function Step-Log($message) {
printf "\n\033[90;1m==> \033[0m\033[37;1m%s \033[0m\n" $message printf "\n\033[90;1m==> \033[0m\033[37;1m%s \033[0m\n" $message
} }
Function Add-Log($mark, $subject, $message) { Function Add-Log($mark, $subject, $message) {
$code = if($mark -eq $cross) {"31"} else {"32"} $code = if ($mark -eq $cross) { "31" } else { "32" }
printf "\033[%s;1m%s \033[0m\033[34;1m%s \033[0m\033[90;1m%s \033[0m\n" $code $mark $subject $message printf "\033[%s;1m%s \033[0m\033[34;1m%s \033[0m\033[90;1m%s \033[0m\n" $code $mark $subject $message
} }
if($version -eq '7.4') {
$version = '7.4RC'
}
Step-Log "Setup PhpManager" Step-Log "Setup PhpManager"
Install-Module -Name PhpManager -Force -Scope CurrentUser Install-Module -Name PhpManager -Force -Scope CurrentUser
Add-Log $tick "PhpManager" "Installed" Add-Log $tick "PhpManager" "Installed"
$installed = $($(php -v)[0] -join '')[4..6] -join '' $installed = $null
if (Test-Path -LiteralPath $php_dir -PathType Container) {
try {
$installed = Get-Php -Path $php_dir
}
catch {
}
}
Step-Log "Setup PHP and Composer" Step-Log "Setup PHP and Composer"
$status = "Switched to PHP$version" if ($null -eq $installed -or -not("$($installed.Version).".StartsWith(($version -replace '^(\d+(\.\d+)*).*', '$1.')))) {
if($installed -ne $version) { if ($version -lt '7.0') {
if($version -lt '7.0') {
Install-Module -Name VcRedist -Force Install-Module -Name VcRedist -Force
} }
Install-Php -Version $version -Architecture x86 -ThreadSafe $true -InstallVC -Path C:\tools\php -TimeZone UTC -InitialPhpIni Production -Force >$null 2>&1 if ($version -eq '7.4') {
$status = "Installed PHP$version" $version = '7.4RC'
}
Install-Php -Version $version -Architecture x86 -ThreadSafe $true -InstallVC -Path $php_dir -TimeZone UTC -InitialPhpIni Production -Force >$null 2>&1
$installed = Get-Php -Path $php_dir
$status = "Installed PHP $($installed.FullVersion)"
}
else {
$status = "Switched to PHP $($installed.FullVersion)"
} }
$ext_dir = "C:\tools\php\ext" Set-PhpIniKey -Key 'date.timezone' -Value 'UTC' -Path $php_dir
Add-Content C:\tools\php\php.ini "date.timezone = 'UTC'" Enable-PhpExtension -Extension openssl, curl -Path $php_dir
Set-PhpIniKey extension_dir $ext_dir try {
if($version -lt '7.4') { Update-PhpCAInfo -Path $php_dir -Source CurrentUser
Enable-PhpExtension openssl }
Enable-PhpExtension curl catch {
} else { Update-PhpCAInfo -Path $php_dir -Source Curl
Add-Content C:\tools\php\php.ini "extension=php_openssl.dll`nextension=php_curl.dll" }
Copy-Item $dir"\..\src\ext\php_pcov.dll" -Destination $ext_dir"\php_pcov.dll" if ([Version]$installed.Version -ge '7.4') {
Copy-Item "$dir\..\src\ext\php_pcov.dll" -Destination "$($installed.ExtensionsPath)\php_pcov.dll"
} }
Add-Log $tick "PHP" $status Add-Log $tick "PHP" $status
Install-Composer -Scope System -Path C:\tools\php Install-Composer -Scope System -Path $php_dir -PhpPath $php_dir
Add-Log $tick "Composer" "Installed" Add-Log $tick "Composer" "Installed"
Function Add-Extension($extension, $install_command, $prefix) Function Add-Extension {
{ Param (
[Parameter(Position = 0, Mandatory = $true)]
[ValidateNotNull()]
[ValidateLength(1, [int]::MaxValue)]
[string]
$extension,
[Parameter(Position = 1, Mandatory = $false)]
[ValidateNotNull()]
[ValidateSet('stable', 'beta', 'alpha', 'devel', 'snapshot')]
[string]
$mininum_stability = 'stable'
)
try { try {
$existing_extensions = Get-PhpExtension -Path C:\tools\php $extension_info = Get-PhpExtension -Path $php_dir | Where-Object { $_.Name -eq $extension -or $_.Handle -eq $extension }
$match = @($existing_extensions | Where-Object { $_.Name -like $extension }) if ($null -ne $extension_info) {
if(!(php -m | findstr -i ${extension}) -and $match) { switch ($extension_info.State) {
$filename = $match."Filename".split('\')[-1] 'Builtin' {
Add-Content C:\tools\php\php.ini "`n$prefix=$filename"
Add-Log $tick $extension "Enabled"
} elseif(php -m | findstr -i $extension) {
Add-Log $tick $extension "Enabled" Add-Log $tick $extension "Enabled"
} }
} catch [Exception] { 'Enabled' {
Add-Log $tick $extension "Enabled"
}
default {
Enable-PhpExtension -Extension $extension_info.Handle -Path $php_dir
Add-Log $tick $extension "Enabled"
}
}
}
else {
Install-PhpExtension -Extension $extension -MinimumStability $mininum_stability -Path $php_dir
Add-Log $tick $extension "Downloaded and enabled"
}
}
catch {
Add-Log $cross $extension "Could not enable" Add-Log $cross $extension "Could not enable"
} }
$status = 404
try {
$status = (Invoke-WebRequest -Uri "https://pecl.php.net/json.php?package=$extension" -UseBasicParsing -DisableKeepAlive).StatusCode
} catch [Exception] {
$status = 500
}
if($status -eq 200) {
if(!(php -m | findstr -i $extension)) {
try {
Invoke-Expression $install_command
Add-Log $tick $extension "Installed and enabled"
} catch [Exception] {
Add-Log $cross $extension "Could not install on PHP$version"
}
}
} else {
if(!(php -m | findstr -i $extension)) {
Add-Log $cross $extension "Could not find $extension for PHP$version on PECL"
}
}
} }