Skip to content

Commit 6c39e46

Browse files
committed
Make packaging scripts robust for Python versions
Add resilience and version-awareness to Android and Windows packaging scripts. The Android script now creates a downloads directory. The Windows script derives a pythonTag from the short version to generalize DLL/import-lib names, searches multiple candidate locations for pyconfig.h with a clearer error message, and updates file selection to use the tagged names. Also use the chosen Python executable (& $pythonFromPath -I) when running compileall to ensure the correct interpreter is used.
1 parent 4be7726 commit 6c39e46

File tree

2 files changed

+28
-13
lines changed

2 files changed

+28
-13
lines changed

android/package-for-dart.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ python_version=${2:?}
66
abi=${3:?}
77

88
script_dir=$(dirname $(realpath $0))
9+
downloads=$script_dir/downloads
10+
mkdir -p $downloads
911

1012
. abi-to-host.sh
1113
. android-env.sh

windows/package-for-dart.ps1

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,12 @@ $srcRoot = Join-Path $workspace "windows\build"
1818
$srcArchive = Join-Path $srcRoot "Python-$PythonVersion.tgz"
1919
$srcDir = Join-Path $srcRoot "Python-$PythonVersion"
2020
$pcbuildDir = Join-Path $srcDir "PCbuild\amd64"
21+
$pythonTag = $PythonVersionShort -replace '\.', ''
2122

2223
$packageRoot = Join-Path $workspace "windows\python-windows-for-dart-$PythonVersionShort"
2324
$zipPath = Join-Path $workspace "windows\python-windows-for-dart-$PythonVersionShort.zip"
2425
$excludeListPath = Join-Path $workspace "windows\python-windows-dart.exclude"
25-
$keepImportLibs = @("python3.lib", "python3_d.lib", "python312.lib", "python312_d.lib")
26+
$keepImportLibs = @("python3.lib", "python3_d.lib", "python$pythonTag.lib", "python${pythonTag}_d.lib")
2627

2728
New-Item -ItemType Directory -Force -Path $srcRoot | Out-Null
2829

@@ -49,10 +50,22 @@ New-Item -ItemType Directory -Force -Path "$packageRoot\DLLs", "$packageRoot\inc
4950
Copy-Item -Path "$srcDir\Include\*" -Destination "$packageRoot\include" -Recurse -Force
5051
Copy-Item -Path "$srcDir\Lib\*" -Destination "$packageRoot\Lib" -Recurse -Force
5152

52-
# pyconfig.h is generated/platform-specific and lives under PC on Windows builds.
53-
$pyconfigHeader = Join-Path $srcDir "PC\pyconfig.h"
54-
if (-not (Test-Path $pyconfigHeader)) {
55-
throw "Missing required header: $pyconfigHeader"
53+
# pyconfig.h location varies by CPython version/build layout.
54+
$pyconfigCandidates = @(
55+
(Join-Path $srcDir "PC\pyconfig.h"),
56+
(Join-Path $srcDir "Include\pyconfig.h"),
57+
(Join-Path $pcbuildDir "pyconfig.h")
58+
)
59+
$pyconfigHeader = $null
60+
foreach ($candidate in $pyconfigCandidates) {
61+
if (Test-Path $candidate) {
62+
$pyconfigHeader = $candidate
63+
break
64+
}
65+
}
66+
if (-not $pyconfigHeader) {
67+
$candidateList = $pyconfigCandidates -join ", "
68+
throw "Missing required header. Checked: $candidateList"
5669
}
5770
Copy-Item -Path $pyconfigHeader -Destination "$packageRoot\include\pyconfig.h" -Force
5871

@@ -67,9 +80,9 @@ foreach ($name in @("LICENSE.txt", "NEWS.txt")) {
6780
$rootFiles = @(
6881
"python3.dll",
6982
"python3_d.dll",
70-
"python312.dll",
71-
"python312_d.dll",
72-
"python312_d.pdb",
83+
"python$pythonTag.dll",
84+
"python${pythonTag}_d.dll",
85+
"python${pythonTag}_d.pdb",
7386
"python_d.pdb",
7487
"pythonw_d.pdb"
7588
)
@@ -93,7 +106,7 @@ foreach ($name in @("vcruntime140.dll", "vcruntime140_1.dll")) {
93106
# Extension modules and supporting DLLs.
94107
Get-ChildItem -Path $pcbuildDir -Filter "*.pyd" -File | Copy-Item -Destination "$packageRoot\DLLs" -Force
95108
Get-ChildItem -Path $pcbuildDir -Filter "*.dll" -File |
96-
Where-Object { $_.Name -notin @("python3.dll", "python3_d.dll", "python312.dll", "python312_d.dll", "vcruntime140.dll", "vcruntime140_1.dll") } |
109+
Where-Object { $_.Name -notin @("python3.dll", "python3_d.dll", "python$pythonTag.dll", "python${pythonTag}_d.dll", "vcruntime140.dll", "vcruntime140_1.dll") } |
97110
Copy-Item -Destination "$packageRoot\DLLs" -Force
98111
foreach ($name in $keepImportLibs) {
99112
$src = Join-Path $pcbuildDir $name
@@ -118,7 +131,7 @@ foreach ($pattern in $excludePatterns) {
118131
}
119132

120133
# Match existing packaging behavior: bytecode-only stdlib.
121-
python -m compileall -b "$packageRoot\Lib"
134+
& $pythonFromPath -I -m compileall -b "$packageRoot\Lib"
122135
Get-ChildItem -Path "$packageRoot\Lib" -Recurse -File -Include *.py,*.typed | Remove-Item -Force
123136
Get-ChildItem -Path "$packageRoot\Lib" -Recurse -Directory -Filter __pycache__ | Remove-Item -Recurse -Force
124137

@@ -136,9 +149,9 @@ $requiredEntries = @(
136149
"$packageRoot\libs",
137150
"$packageRoot\python3.dll",
138151
"$packageRoot\python3_d.dll",
139-
"$packageRoot\python312.dll",
140-
"$packageRoot\python312_d.dll",
141-
"$packageRoot\python312_d.pdb",
152+
"$packageRoot\python$pythonTag.dll",
153+
"$packageRoot\python${pythonTag}_d.dll",
154+
"$packageRoot\python${pythonTag}_d.pdb",
142155
"$packageRoot\python_d.pdb",
143156
"$packageRoot\pythonw_d.pdb"
144157
)

0 commit comments

Comments
 (0)