Compare commits

..

4 Commits

Author SHA1 Message Date
gowridurgad
42cf8bab67 Update win-python-builder.psm1 2024-06-24 14:29:58 +05:30
gowridurgad
d3b7d73238 Update build-python-packages.yml 2024-06-24 14:29:29 +05:30
github-actions[bot]
1d2e861434 Update versions-manifest (#289)
Co-authored-by: Service account <no-reply@microsoft.com>
2024-06-23 23:48:32 -05:00
Matthieu Darbois
d55f04f8e6 build ubuntu-22.04_arm64 on setup-actions-ubuntu-arm64-2-core (#280) 2024-06-20 08:10:34 -05:00
4 changed files with 174 additions and 7 deletions

View File

@@ -1,3 +1,4 @@
name: Build Python package
run-name: Generate Python ${{ inputs.VERSION || '3.12.3' }}
on:
@@ -15,7 +16,7 @@ on:
PLATFORMS:
description: 'Platforms for execution in "os" or "os_arch" format (arch is "x64" by default)'
required: true
default: 'ubuntu-20.04,ubuntu-22.04,ubuntu-22.04_arm64,ubuntu-24.04,macos-11_x64,macos-14_arm64,windows-2019_x64,windows-2019_x86,windows-2019_arm64'
default: 'ubuntu-20.04,ubuntu-20.04_arm64,ubuntu-22.04,ubuntu-22.04_arm64,ubuntu-24.04,ubuntu-24.04_arm64,macos-11_x64,macos-14_arm64,windows-2019_x64,windows-2019_x86,windows-2019_arm64'
pull_request:
paths-ignore:
- 'versions-manifest.json'
@@ -39,7 +40,7 @@ jobs:
- name: Generate execution matrix
id: generate-matrix
run: |
[String[]]$configurations = "${{ inputs.platforms || 'ubuntu-20.04,ubuntu-22.04,ubuntu-22.04_arm64,ubuntu-24.04,macos-11,macos-14_arm64,windows-2019_x64,windows-2019_x86,windows-2019_arm64' }}".Split(",").Trim()
[String[]]$configurations = "${{ inputs.platforms || 'ubuntu-20.04,ubuntu-20.04_arm64,ubuntu-22.04,ubuntu-22.04_arm64,ubuntu-24.04,ubuntu-24.04_arm64,macos-11,macos-14_arm64,windows-2019_x64,windows-2019_x86,windows-2019_arm64' }}".Split(",").Trim()
$matrix = @()
foreach ($configuration in $configurations) {
@@ -53,9 +54,7 @@ jobs:
"*windows*" { $platform = 'win32' }
}
if ($configuration -eq "ubuntu-22.04_arm64") {
$os = "setup-actions-ubuntu-arm64-2-core"
}elseif ($configuration -eq "windows-2019_arm64") {
if ($configuration -eq "windows-2019_arm64") {
$os = "setup-actions-windows-arm64-4-core"
}
$matrix += @{

View File

@@ -0,0 +1,169 @@
using module "./python-builder.psm1"
class NixPythonBuilder : PythonBuilder {
<#
.SYNOPSIS
Base Python builder class for *Nix systems.
.DESCRIPTION
Contains methods that required to build Python artifact for *nix systems. Inherited from base PythonBuilder class.
.PARAMETER version
The version of Python that should be built.
.PARAMETER Platform
The type of platform for which Python should be built.
.PARAMETER PlatformVersion
The version of platform for which Python should be built.
.PARAMETER InstallationTemplateName
The name of template that will be used to create installation script for generated Python artifact.
.PARAMETER InstallationScriptName
The name of installation script that will be generated for Python artifact.
.PARAMETER OutputArtifactName
The name of archive with Python binaries that will be generated as part of Python artifact.
#>
[string] $InstallationTemplateName
[string] $InstallationScriptName
[string] $OutputArtifactName
NixPythonBuilder(
[semver] $version,
[string] $architecture,
[string] $platform
) : Base($version, $architecture, $platform) {
$this.InstallationTemplateName = "nix-setup-template.sh"
$this.InstallationScriptName = "setup.sh"
$this.OutputArtifactName = "python-$Version-$Platform-$Architecture.tar.gz"
}
[uri] GetSourceUri() {
<#
.SYNOPSIS
Get base Python URI and return complete URI for Python sources.
#>
$base = $this.GetBaseUri()
$versionName = $this.GetBaseVersion()
$nativeVersion = Convert-Version -version $this.Version
return "${base}/${versionName}/Python-${nativeVersion}.tgz"
}
[string] GetPythonBinary() {
<#
.SYNOPSIS
Return name of Python binary.
#>
if ($this.Version.Major -eq 2) { $pythonBinary = "python" } else { $pythonBinary = "python3" }
return $pythonBinary
}
[string] Download() {
<#
.SYNOPSIS
Download Python sources and extract them at temporary work folder. Returns expanded archive location path.
#>
$sourceUri = $this.GetSourceUri()
Write-Host "Sources URI: $sourceUri"
$archiveFilepath = Download-File -Uri $sourceUri -OutputFolder $this.WorkFolderLocation
$expandedSourceLocation = Join-Path -Path $this.TempFolderLocation -ChildPath "SourceCode"
New-Item -Path $expandedSourceLocation -ItemType Directory
Extract-TarArchive -ArchivePath $archiveFilepath -OutputDirectory $expandedSourceLocation
Write-Debug "Done; Sources location: $expandedSourceLocation"
return $expandedSourceLocation
}
[void] CreateInstallationScript() {
<#
.SYNOPSIS
Create Python artifact installation script based on template specified in InstallationTemplateName property.
#>
$installationScriptLocation = New-Item -Path $this.WorkFolderLocation -Name $this.InstallationScriptName -ItemType File
$installationTemplateLocation = Join-Path -Path $this.InstallationTemplatesLocation -ChildPath $this.InstallationTemplateName
$installationTemplateContent = Get-Content -Path $installationTemplateLocation -Raw
$variablesToReplace = @{
"{{__VERSION_FULL__}}" = $this.Version;
"{{__ARCH__}}" = $this.Architecture;
}
$variablesToReplace.keys | ForEach-Object { $installationTemplateContent = $installationTemplateContent.Replace($_, $variablesToReplace[$_]) }
$installationTemplateContent | Out-File -FilePath $installationScriptLocation
Write-Debug "Done; Installation script location: $installationScriptLocation)"
}
[void] Make() {
<#
.SYNOPSIS
Executes "make" and "make install" commands for configured build sources. Make output will be writen in build_output.txt located in artifact location folder.
#>
Write-Debug "make Python $($this.Version)-$($this.Architecture) $($this.Platform)"
$buildOutputLocation = New-Item -Path $this.WorkFolderLocation -Name "build_output.txt" -ItemType File
Execute-Command -Command "make 2>&1 | tee $buildOutputLocation" -ErrorAction Continue
Execute-Command -Command "make install" -ErrorAction Continue
Write-Debug "Done; Make log location: $buildOutputLocation"
}
[void] CopyBuildResults() {
$buildFolder = $this.GetFullPythonToolcacheLocation()
Move-Item -Path "$buildFolder/*" -Destination $this.WorkFolderLocation
}
[void] ArchiveArtifact() {
$OutputPath = Join-Path $this.ArtifactFolderLocation $this.OutputArtifactName
Create-TarArchive -SourceFolder $this.WorkFolderLocation -ArchivePath $OutputPath
}
[void] Build() {
<#
.SYNOPSIS
Build Python artifact from sources.
#>
Write-Host "Prepare Python Hostedtoolcache location..."
$this.PreparePythonToolcacheLocation()
Write-Host "Prepare system environment..."
$this.PrepareEnvironment()
Write-Host "Download Python $($this.Version)[$($this.Architecture)] sources..."
$sourcesLocation = $this.Download()
Push-Location -Path $sourcesLocation
Write-Host "Configure for $($this.Platform)..."
$this.Configure()
Write-Host "Make for $($this.Platform)..."
$this.Make()
Pop-Location
Write-Host "Generate structure dump"
New-ToolStructureDump -ToolPath $this.GetFullPythonToolcacheLocation() -OutputFolder $this.WorkFolderLocation
Write-Host "Copying build results to destination location"
$this.CopyBuildResults()
Write-Host "Create installation script..."
$this.CreateInstallationScript()
Write-Host "Archive artifact..."
$this.ArchiveArtifact()
}
}

View File

@@ -55,4 +55,4 @@ export PIP_ROOT_USER_ACTION=ignore
./python -m pip install --upgrade --force-reinstall pip --disable-pip-version-check --no-warn-script-location
echo "Create complete file"
touch $PYTHON_TOOLCACHE_VERSION_PATH/$ARCH.complete
touch $PYTHON_TOOLCACHE_VERSION_PATH/$ARCH.complete

View File

@@ -1,4 +1,3 @@
[
{
"version": "3.13.0-beta.2",