From 5106db21e6a35781bff937be3c9e1e56d7b17789 Mon Sep 17 00:00:00 2001 From: Shivam Mathur Date: Thu, 22 Aug 2024 10:34:13 +0530 Subject: [PATCH] Install python when config.w32 uses PYTHONHOME --- .../private/Add-BuildTools.ps1 | 20 ++++++++++++++++++- .../private/Get-ExtensionConfig.ps1 | 3 +++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/extension/BuildPhpExtension/private/Add-BuildTools.ps1 b/extension/BuildPhpExtension/private/Add-BuildTools.ps1 index ec342a2..5563880 100644 --- a/extension/BuildPhpExtension/private/Add-BuildTools.ps1 +++ b/extension/BuildPhpExtension/private/Add-BuildTools.ps1 @@ -32,12 +32,30 @@ Function Add-BuildTools { choco install git.install --params "'/GitAndUnixToolsOnPath /WindowsTerminal /NoAutoCrlf'" -y --force } Default { + $program = $_ $resultLines = (choco search $_ --limit-output) -split "\`r?\`n" - if($resultLines | Where-Object { $_ -match "^$_\|" }) { + if($resultLines | Where-Object { $_ -match "^$program\|" }) { choco install $_ -y --force } } } + } else { + switch ($_) + { + # Check if python is actually installed. + python { + $pythonVersion = python --version 2>&1 + if($pythonVersion -match "not found") { + choco install python -y --force + } + $pythonPath = (Get-Command python).Source + $pythonHome = Split-Path $pythonPath + [Environment]::SetEnvironmentVariable("PYTHONPATH", $pythonPATH, [System.EnvironmentVariableTarget]::User) + $env:PYTHONPATH = $pythonPath + [Environment]::SetEnvironmentVariable("PYTHONHOME", $pythonHome, [System.EnvironmentVariableTarget]::User) + $env:PYTHONHOME = $pythonHome + } + } } } } diff --git a/extension/BuildPhpExtension/private/Get-ExtensionConfig.ps1 b/extension/BuildPhpExtension/private/Get-ExtensionConfig.ps1 index 0fa7cb3..fa6cd03 100644 --- a/extension/BuildPhpExtension/private/Get-ExtensionConfig.ps1 +++ b/extension/BuildPhpExtension/private/Get-ExtensionConfig.ps1 @@ -176,6 +176,9 @@ Function Get-ExtensionConfig { $config.build_tools += $_.Groups[2].Value } } + if($configW32Content.contains('PYTHONHOME')) { + $config.build_tools += "python" + } $config.build_directory = if ($Arch -eq "x64") { "x64\" } else { "" } $config.build_directory += "Release"