Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Python debug build support #295

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
9 changes: 6 additions & 3 deletions builders/macos-python-builder.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ class macOSPythonBuilder : NixPythonBuilder {
.SYNOPSIS
Prepare system environment by installing dependencies and required packages.
#>

if ($this.Version -eq "3.7.17") {
# We have preinstalled ncurses and readLine on the hoster runners. But we need to install bzip2 for
# setting up an environemnt
# We have preinstalled ncurses and readLine on the hoster runners. But we need to install bzip2 for
# setting up an environemnt
# If we get any issues realted to ncurses or readline we can try to run this command
# brew install ncurses readline
Execute-Command -Command "brew install bzip2"
Expand All @@ -53,6 +53,9 @@ class macOSPythonBuilder : NixPythonBuilder {
$configureString += " --enable-optimizations"
$configureString += " --enable-shared"
$configureString += " --with-lto"
if ($this.WithPyDebug) {
$configureString += " --with-pydebug"
}

### For Python versions which support it, compile a universal2 (arm64 + x86_64 hybrid) build. The arm64 slice
### will never be used itself by a Github Actions runner but using a universal2 Python is the only way to build
Expand Down
9 changes: 6 additions & 3 deletions builders/python-builder.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ class PythonBuilder {
.PARAMETER Architecture
The architecture with which Python should be built.

.PARAMETER WithPyDebug
The flag that indicates whether Python should be a debug build with the --with-pydebug configure option.

.PARAMETER HostedToolcacheLocation
The location of hostedtoolcache artifacts. Using system AGENT_TOOLSDIRECTORY variable value.

Expand Down Expand Up @@ -97,17 +100,17 @@ class PythonBuilder {
[void] PreparePythonToolcacheLocation() {
<#
.SYNOPSIS
Prepare system hostedtoolcache folder for new Python version.
Prepare system hostedtoolcache folder for new Python version.
#>

$pythonBinariesLocation = $this.GetFullPythonToolcacheLocation()

if (Test-Path $pythonBinariesLocation) {
Write-Host "Purge $pythonBinariesLocation folder..."
Remove-Item $pythonBinariesLocation -Recurse -Force
} else {
Write-Host "Create $pythonBinariesLocation folder..."
New-Item -ItemType Directory -Path $pythonBinariesLocation
New-Item -ItemType Directory -Path $pythonBinariesLocation
}
}
}
3 changes: 3 additions & 0 deletions builders/ubuntu-python-builder.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ class UbuntuPythonBuilder : NixPythonBuilder {
$configureString += " --prefix=$pythonBinariesLocation"
$configureString += " --enable-shared"
$configureString += " --enable-optimizations"
if ($this.WithPyDebug) {
$configureString += " --with-pydebug"
}

### Compile with support of loadable sqlite extensions.
### Link to documentation (https://docs.python.org/3/library/sqlite3.html#sqlite3.Connection.enable_load_extension)
Expand Down
15 changes: 11 additions & 4 deletions builders/win-python-builder.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ class WinPythonBuilder : PythonBuilder {
.PARAMETER architecture
The architecture with which Python should be built.

.PARAMETER WithPyDebug
The flag that indicates whether Python should be installed with debug symbols.

.PARAMETER InstallationTemplateName
The name of installation script template that will be used in generated artifact.

Expand All @@ -39,7 +42,7 @@ class WinPythonBuilder : PythonBuilder {
[string] GetPythonExtension() {
<#
.SYNOPSIS
Return extension for required version of Python executable.
Return extension for required version of Python executable.
#>

$extension = if ($this.Version -lt "3.5" -and $this.Version -ge "2.5") { ".msi" } else { ".exe" }
Expand All @@ -50,7 +53,7 @@ class WinPythonBuilder : PythonBuilder {
[string] GetArchitectureExtension() {
<#
.SYNOPSIS
Return architecture suffix for Python executable.
Return architecture suffix for Python executable.
#>

$ArchitectureExtension = ""
Expand All @@ -60,7 +63,7 @@ class WinPythonBuilder : PythonBuilder {
} else {
$ArchitectureExtension = ".amd64"
}
}elseif ($this.Architecture -eq "arm64") {
} elseif ($this.Architecture -eq "arm64") {
$ArchitectureExtension = "-arm64"
}

Expand Down Expand Up @@ -114,7 +117,11 @@ class WinPythonBuilder : PythonBuilder {
$variablesToReplace = @{
"{{__ARCHITECTURE__}}" = $this.Architecture;
"{{__VERSION__}}" = $this.Version;
"{{__PYTHON_EXEC_NAME__}}" = $pythonExecName
"{{__PYTHON_EXEC_NAME__}}" = $pythonExecName;
"{{__PYTHON_EXTRA_PARAMS__}}" = "";
}
if ($this.WithPyDebug) {
$variablesToReplace["{{__PYTHON_EXTRA_PARAMS__}}"] " Include_debug=1 Include_symbols=1"
}

$variablesToReplace.keys | ForEach-Object { $installationTemplateContent = $installationTemplateContent.Replace($_, $variablesToReplace[$_]) }
Expand Down
3 changes: 2 additions & 1 deletion installers/win-setup-template.ps1
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[String] $Architecture = "{{__ARCHITECTURE__}}"
[String] $Version = "{{__VERSION__}}"
[String] $PythonExecName = "{{__PYTHON_EXEC_NAME__}}"
[String] $PythonExtraParams = "{{__PYTHON_EXTRA_PARAMS__}}"

function Get-RegistryVersionFilter {
param(
Expand Down Expand Up @@ -122,7 +123,7 @@ Copy-Item -Path ./$PythonExecName -Destination $PythonArchPath | Out-Null
Write-Host "Install Python $Version in $PythonToolcachePath..."
$ExecParams = Get-ExecParams -IsMSI $IsMSI -PythonArchPath $PythonArchPath

cmd.exe /c "cd $PythonArchPath && call $PythonExecName $ExecParams /quiet"
cmd.exe /c "cd $PythonArchPath && call $PythonExecName $ExecParams $PythonExtraParams /quiet"
if ($LASTEXITCODE -ne 0) {
Throw "Error happened during Python installation"
}
Expand Down