skiasharp/scripts/install-python.ps1
Matthew Leibowitz 2f218deb78
Use Python 3.x and Clang 12.x (#1959)
* Update to Python 3.x to generate the build scripts and other related things
* Update to Clang 12.x to work with Visual Studio 2022
* Update all Windows builds to use Visual Studio 2022
* Update the required .net tools
* Streamline the pipeline a bit more
* Extracted all the tool install yaml into scripts so they can be better edited and tracked
2022-03-02 09:24:47 +02:00

67 lines
1.8 KiB
PowerShell

Param(
[string] $Version = '3.10.2',
[string] $Arch = 'x64'
)
$ErrorActionPreference = 'Stop'
Add-Type -AssemblyName System.IO.Compression.FileSystem
$HOME_DIR = if ($env:HOME) { $env:HOME } else { $env:USERPROFILE }
$destDir = Join-Path "$env:AGENT_TOOLSDIRECTORY" "Python" "$Version" "$Arch"
$completeFile = "$destDir.complete"
if (Test-Path $completeFile) {
Write-Host "Python $Version ($Arch) already installed."
exit 0;
} else {
Write-Host "No matching Python found."
}
Write-Host "Downloading manifest..."
$pythonManifestUri = "https://raw.githubusercontent.com/actions/python-versions/main/versions-manifest.json"
$pythonManifest = Invoke-WebRequest -Uri $pythonManifestUri | ConvertFrom-Json
if ($IsMacOS) {
$platform = "darwin"
} elseif ($IsLinux) {
$platform = "linux"
} else {
$platform = "win32"
}
$downloadUrl = (($pythonManifest
| Where-Object { $_.version -eq $Version }
| Select-Object -First 1).files
| Where-Object { $_.platform -eq $platform -and $_.arch -eq $Arch }
| Select-Object -First 1).download_url
# download
$tempDir = Join-Path "$HOME_DIR" "python-temp"
$archive = Join-Path "$tempDir" (Split-Path $downloadUrl -Leaf)
New-Item -ItemType Directory -Force -Path "$tempDir" | Out-Null
Write-Host "Downloading Python package '$downloadUrl' to '$archive'..."
(New-Object System.Net.WebClient).DownloadFile("$downloadUrl", "$archive")
# extract
Write-Host "Extracting Python to '$tempDir'..."
if ($IsMacOS -or $IsLinux) {
tar -vxzf "$archive" -C "$tempDir"
} else {
[System.IO.Compression.ZipFile]::ExtractToDirectory("$archive", "$tempDir")
}
Write-Host "Extraction complete."
# install
Write-Host "Installing Python..."
try {
Push-Location "$tempDir"
.\setup.ps1
} finally {
Pop-Location
}
exit $LASTEXITCODE