Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion BuildAutomation/BuildCloudbaseInitSetup.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ Param(
[switch]$ClonePullInstallerRepo = $true,
[string]$InstallerDir = $null,
[string]$VSRedistDir = "${ENV:ProgramFiles(x86)}\Common Files\Merge Modules",
[string]$SignTimestampUrl = "http://timestamp.digicert.com?alg=sha256"
[string]$SignTimestampUrl = "http://timestamp.digicert.com?alg=sha256",
[string]$PythonMsiChecksum = $null
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it is worth adding a boolean flag?

)

$ErrorActionPreference = "Stop"
Expand Down Expand Up @@ -76,6 +77,10 @@ try

$python_template_dir = join-path $cloudbaseInitInstallerDir "Python$($pythonversion.replace('.', ''))_${platform}_Template"

if ($PythonMsiChecksum) {
DownloadInstall-PythonMsi $platform $python_template_dir $pythonversion $PythonMsiChecksum
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After the MSI build is done, the python_template_dir can be cleaned up as well.

CheckCopyDir $python_template_dir $python_dir

# Make sure that we don't have temp files from a previous build
Expand Down
68 changes: 65 additions & 3 deletions BuildAutomation/BuildUtils.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -387,8 +387,70 @@ function ImportCertificateUser($pfxPath, $pfxPassword) {
}

function ChechFileHash($path, $hash, $algorithm="SHA1") {
$h = Get-Filehash -Algorithm $algorithm $path
if ($h.Hash.ToUpper() -ne $hash.ToUpper()) {
throw "Hash comparison failed for file: $path"
$actualHash = (Get-Filehash -Algorithm $algorithm $path).Hash.ToUpper()
if ($actualHash -ne $hash.ToUpper()) {
throw "Hash comparison failed for file: $path. Expected hash: ${hash}. Actual hash: ${actualHash}"
}
}


function DownloadInstall-PythonMsi($platform, $python_template_dir, $pythonVersion, $PythonMsiChecksum, $algorithm="SHA1") {
$platformSuffix = ""
if ($platform -eq "x64") {
$platformSuffix = "-amd64"
}

if (Test-Path $python_template_dir) {
throw "$python_template_dir folder already exists"
}

$pythonInstallerPath = Join-Path (Resolve-Path "${python_template_dir}/..").Path "/python-${pythonVersion}${platformSuffix}.exe"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use parent path instead of ..

$pythonVersionEscaped = $pythonVersion.replace("_",".")
$PythonMsiUrl = "https://www.python.org/ftp/python/${pythonVersionEscaped}/python-${pythonVersionEscaped}${platformSuffix}.exe"

if ($python_template_dir -and (Test-Path $python_template_dir)) {
throw "Python template directory already exists"
}

$tmp_python_template_dir = "${python_template_dir}_tmp"
if ($tmp_python_template_dir -and (Test-Path $tmp_python_template_dir)) {
throw "Python temp template directory already exists"
}

try {
ExecRetry { DownloadFile $PythonMsiUrl $pythonInstallerPath }
ChechFileHash $pythonInstallerPath $PythonMsiChecksum $algorithm

Write-Host "Trying to uninstall Python using $pythonInstallerPath"
Start-Process -FilePath "${pythonInstallerPath}" -NoNewWindow -Wait `
-ArgumentList @("/quiet", "/uninstall")

$package = Get-Package -Name "Python ${pythonVersionEscaped}*" -ErrorAction SilentlyContinue
if ($package) {
throw "Python package was already installed"
}

Write-Host "Installing Python using $pythonInstallerPath"
Start-Process -FilePath "${pythonInstallerPath}" -NoNewWindow -Wait `
-ArgumentList @("/quiet", "TargetDir=${tmp_python_template_dir}","Include_test=0","Include_tcltk=0","Include_launcher=0","Include_doc=0")

Copy-Item -Recurse $tmp_python_template_dir $python_template_dir

} finally {

Start-Process -FilePath "${pythonInstallerPath}" -NoNewWindow -Wait `
-ArgumentList @("/quiet", "/uninstall")

if (Test-Path $pythonInstallerPath) {
Remove-Item $pythonInstallerPath
}

if (Test-Path $tmp_python_template_dir) {
Remove-Item $tmp_python_template_dir -Recurse -Force
}
}
if (!(Test-Path $python_template_dir)) {
throw "$python_template_dir has not been created"
}

}