Simplify win32 script

- Always specify the PHP install dir
- Use default PhpManager functions
- Fix CA Authorities (so that HTTPS calls work)
- Don't handle the special xdebug case (it's bundled in PhpManager)
This commit is contained in:
Michele Locati 2019-11-25 11:53:13 +01:00
parent 1db0b0651d
commit fec9df11d6
No known key found for this signature in database
GPG Key ID: 98B7CE2E7234E28B
4 changed files with 56 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 pcov');
'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,83 @@
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 Update-PhpCAInfo -Path $php_dir -Source CurrentUser
if($version -lt '7.4') { if ([Version]$installed.Version -ge '7.4') {
Enable-PhpExtension openssl Copy-Item "$dir\..\src\ext\php_pcov.dll" -Destination "$($installed.ExtensionsPath)\php_pcov.dll"
Enable-PhpExtension curl
} else {
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"
} }
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($extension) {
{
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"
Add-Log $tick $extension "Enabled" }
} elseif(php -m | findstr -i $extension) { 'Enabled' {
Add-Log $tick $extension "Enabled" Add-Log $tick $extension "Enabled"
} }
} catch [Exception] { default {
Add-Log $cross $extension "Could not enable" Enable-PhpExtension -Extension $extension_info.Handle -Path $php_dir
} Add-Log $tick $extension "Enabled"
}
$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 { else {
if(!(php -m | findstr -i $extension)) { Install-PhpExtension -Extension $extension -Path $php_dir
Add-Log $cross $extension "Could not find $extension for PHP$version on PECL" Add-Log $tick $extension "Downloaded and enabled"
} }
} }
} catch {
Add-Log $cross $extension "Could not enable"
}
}