Merge branch 'master' into v-malob/switch-nix-to-tar

This commit is contained in:
Maxim Lobanov 2020-04-24 00:31:59 +03:00
commit 4afb552bdd
2 changed files with 89 additions and 85 deletions

View File

@ -1,26 +1,10 @@
jobs:
- job:
- job: Test_Python
pool:
name: Azure Pipelines
vmImage: $(VmImage)
strategy:
matrix:
Validate_Python_Clean_Machine:
NeedCleanToolcacheDir: true
TestRunTitle: "Python $(VERSION) $(Platform) $(Architecture) (clean-machine)"
Validate_Python:
NeedCleanToolcacheDir: false
TestRunTitle: "Python $(VERSION) $(Platform) $(Architecture)"
steps:
- checkout: self
submodules: true
- task: PowerShell@2
displayName: Fully cleanup the toolcache directory
inputs:
TargetType: filePath
filePath: tests/clean-toolcache.ps1
condition: eq(variables['NeedCleanToolcacheDir'], true)
- template: test-steps.yml

View File

@ -1,71 +1,78 @@
$ErrorActionPreference = "Stop"
[String]$Architecture = "{{__ARCHITECTURE__}}"
[Version]$Version = "{{__VERSION__}}"
[String]$PythonExecName = "{{__PYTHON_EXEC_NAME__}}"
[String] $Architecture = "{{__ARCHITECTURE__}}"
[Version] $Version = "{{__VERSION__}}"
[String] $PythonExecName = "{{__PYTHON_EXEC_NAME__}}"
function Get-ArchitectureFilter {
param(
[Parameter (Mandatory = $true)]
[String]$Architecture
function Get-ArchitectureFilter
{
param
(
[Parameter (Mandatory)]
[String] $Architecture
)
if ($Architecture -eq 'x86') {
if ($Architecture -eq 'x86')
{
"32-bit"
} else {
}
else
{
"64-bit"
}
}
function Get-PythonFilter {
param(
[Parameter (Mandatory = $true)]
[String]$ArchFilter,
[Parameter (Mandatory = $true)]
[String]$Architecture,
[Parameter (Mandatory = $true)]
[Boolean]$IsMSI,
[Parameter (Mandatory = $true)]
[Int32]$MajorVersion,
[Parameter (Mandatory = $true)]
[Int32]$MinorVersion
function Uninstall-Python
{
param
(
[Parameter (Mandatory)]
[String] $Architecture,
[Parameter (Mandatory)]
[Int32] $MajorVersion,
[Parameter (Mandatory)]
[Int32] $MinorVersion
)
### Python 2.7 have no architecture postfix
if ($IsMSI -and $Architecture -eq "x86") {
"(Name like '%Python%%$MajorVersion.$MinorVersion%') and (not (Name like '%64-bit%'))"
} else {
"Name like '%Python%%$MajorVersion.$MinorVersion%%$ArchFilter%'"
$archFilter = Get-ArchitectureFilter -Architecture $Architecture
### Python 2.7 x86 have no architecture postfix
$versionFilter = if (($Architecture -eq "x86") -and ($MajorVersion -eq 2))
{
"Python $MajorVersion.$MinorVersion.\d+$"
}
else
{
"Python $MajorVersion.$MinorVersion.*($archFilter)"
}
$regPath = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Products"
$regKeys = Get-ChildItem -Path Registry::$regPath -Recurse | Where-Object Property -Ccontains DisplayName
foreach ($key in $regKeys)
{
if ($key.getValue("DisplayName") -match $versionFilter)
{
Remove-Item -Path $key.PSParentPath -Recurse -Force -Verbose
}
}
$regPath = "HKEY_CLASSES_ROOT\Installer\Products"
Get-ChildItem -Path Registry::$regPath | Where-Object {
$productName = $_.GetValue("ProductName")
return $productName -and $productName -match $versionFilter
} | ForEach-Object {
Remove-Item Registry::$_ -Recurse -Force -Verbose
}
}
function Uninstall-Python {
param(
[Parameter (Mandatory = $true)]
[String]$Architecture,
[Parameter (Mandatory = $true)]
[Boolean]$IsMSI,
[Parameter (Mandatory = $true)]
[Int32]$MajorVersion,
[Parameter (Mandatory = $true)]
[Int32]$MinorVersion
)
$ArchFilter = Get-ArchitectureFilter -Architecture $Architecture
Write-Host "Check for installed Python$MajorVersion.$MinorVersion $ArchFilter WMI..."
$PythonFilter = Get-PythonFilter -ArchFilter $ArchFilter -Architecture $Architecture -IsMSI $IsMSI -MajorVersion $MajorVersion -MinorVersion $MinorVersion
Get-WmiObject Win32_Product -Filter $PythonFilter | Foreach-Object {
Write-Host "Uninstalling $($_.Name) ..."
$_.Uninstall() | Out-Null
}
}
function Delete-PythonVersion {
param(
[Parameter (Mandatory = $true)]
[System.IO.FileSystemInfo]$InstalledVersion,
[Parameter (Mandatory = $true)]
[String]$Architecture
function Delete-PythonVersion
{
param
(
[Parameter (Mandatory)]
[System.IO.FileSystemInfo] $InstalledVersion,
[Parameter (Mandatory)]
[String] $Architecture
)
Remove-Item -Path "$($InstalledVersion.FullName)/$Architecture" -Recurse -Force
@ -73,22 +80,27 @@ function Delete-PythonVersion {
}
function Get-ExecParams {
param(
[Parameter (Mandatory = $true)]
[Boolean]$IsMSI,
[Parameter (Mandatory = $true)]
[String]$PythonArchPath
param
(
[Parameter (Mandatory)]
[Boolean] $IsMSI,
[Parameter (Mandatory)]
[String] $PythonArchPath
)
if ($IsMSI) {
if ($IsMSI)
{
"TARGETDIR=$PythonArchPath ALLUSERS=1"
} else {
}
else
{
"DefaultAllUsersTargetDir=$PythonArchPath InstallAllUsers=1"
}
}
$ToolcacheRoot = $env:AGENT_TOOLSDIRECTORY
if ([string]::IsNullOrEmpty($ToolcacheRoot)) {
if ([string]::IsNullOrEmpty($ToolcacheRoot))
{
# GitHub images don't have `AGENT_TOOLSDIRECTORY` variable
$ToolcacheRoot = $env:RUNNER_TOOL_CACHE
}
@ -102,22 +114,29 @@ $MajorVersion = $Version.Major
$MinorVersion = $Version.Minor
Write-Host "Check if Python hostedtoolcache folder exist..."
if (-Not (Test-Path $PythonToolcachePath)) {
if (-Not (Test-Path $PythonToolcachePath))
{
Write-Host "Create Python toolcache folder"
New-Item -ItemType Directory -Path $PythonToolcachePath | Out-Null
} else {
}
else
{
Write-Host "Check if current Python version is installed..."
$InstalledVersion = Get-ChildItem -Path $PythonToolcachePath -Filter "$MajorVersion.$MinorVersion.*"
if ($InstalledVersion -ne $null) {
Uninstall-Python -Architecture $Architecture -IsMSI $IsMSI -MajorVersion $MajorVersion -MinorVersion $MinorVersion
if ($InstalledVersion -ne $null)
{
Uninstall-Python -Architecture $Architecture -MajorVersion $MajorVersion -MinorVersion $MinorVersion
if (Test-Path -Path "$($InstalledVersion.FullName)/$Architecture") {
if (Test-Path -Path "$($InstalledVersion.FullName)/$Architecture")
{
Write-Host "Python$MajorVersion.$MinorVersion/$Architecture was found in $PythonToolcachePath"
Write-Host "Delete Python$MajorVersion.$MinorVersion $Architecture"
Delete-PythonVersion -InstalledVersion $InstalledVersion -Architecture $Architecture
}
} else {
}
else
{
Write-Host "No Python$MajorVersion.$MinorVersion.* found"
}
}
@ -132,7 +151,8 @@ Write-Host "Install Python $Version in $PythonToolcachePath..."
$ExecParams = Get-ExecParams -IsMSI $IsMSI -PythonArchPath $PythonArchPath
cmd.exe /c "cd $PythonArchPath && call $PythonExecName $ExecParams /quiet"
if ($LASTEXITCODE -ne 0) {
if ($LASTEXITCODE -ne 0)
{
Throw "Error happened during Python installation"
}