@@ -137,6 +137,7 @@ param
137137 [string ] $PinnedVersion = " " ,
138138 [ValidateSet (" Asserts" , " NoAsserts" )]
139139 [string ] $PinnedToolchainVariant = " Asserts" ,
140+ [ValidatePattern (' ^\d+(\.\d+)*$' )]
140141 [string ] $PythonVersion = " 3.9.10" ,
141142 [ValidatePattern (" ^r(?:[1-9]|[1-9][0-9])(?:[a-z])?$" )]
142143 [string ] $AndroidNDKVersion = " r27c" ,
@@ -329,6 +330,42 @@ $BuildArch = switch ($BuildArchName) {
329330 default { throw " Unsupported processor architecture" }
330331}
331332
333+ $KnownPythons = @ {
334+ " 3.9.10" = @ {
335+ AMD64 = @ {
336+ URL = " https://www.nuget.org/api/v2/package/python/3.9.10" ;
337+ SHA256 = " ac43b491e9488ac926ed31c5594f0c9409a21ecbaf99dc7a93f8c7b24cf85867" ;
338+ };
339+ ARM64 = @ {
340+ URL = " https://www.nuget.org/api/v2/package/pythonarm64/3.9.10" ;
341+ SHA256 = " 429ada77e7f30e4bd8ff22953a1f35f98b2728e84c9b1d006712561785641f69" ;
342+ };
343+ }
344+ }
345+
346+ $PythonWheels = @ {
347+ " packaging" = @ {
348+ File = " packaging-24.1-py3-none-any.whl" ;
349+ URL = " https://files.pythonhosted.org/packages/08/aa/cc0199a5f0ad350994d660967a8efb233fe0416e4639146c089643407ce6/packaging-24.1-py3-none-any.whl" ;
350+ SHA256 = " 5b8f2217dbdbd2f7f384c41c628544e6d52f2d0f53c6d0c3ea61aa5d1d7ff124" ;
351+ };
352+ " distutils" = @ {
353+ File = " setuptools-75.1.0-py3-none-any.whl" ;
354+ URL = " https://files.pythonhosted.org/packages/ff/ae/f19306b5a221f6a436d8f2238d5b80925004093fa3edea59835b514d9057/setuptools-75.1.0-py3-none-any.whl" ;
355+ SHA256 = " 35ab7fd3bcd95e6b7fd704e4a1539513edad446c097797f2985e0e4b960772f2" ;
356+ };
357+ " psutil" = @ {
358+ File = " psutil-6.1.0-cp37-abi3-win_amd64.whl" ;
359+ URL = " https://files.pythonhosted.org/packages/11/91/87fa6f060e649b1e1a7b19a4f5869709fbf750b7c8c262ee776ec32f3028/psutil-6.1.0-cp37-abi3-win_amd64.whl" ;
360+ SHA256 = " a8fb3752b491d246034fa4d279ff076501588ce8cbcdbb62c32fd7a377d996be" ;
361+ };
362+ " unittest2" = @ {
363+ File = " unittest2-1.1.0-py2.py3-none-any.whl" ;
364+ URL = " https://files.pythonhosted.org/packages/72/20/7f0f433060a962200b7272b8c12ba90ef5b903e218174301d0abfd523813/unittest2-1.1.0-py2.py3-none-any.whl" ;
365+ SHA256 = " 13f77d0875db6d9b435e1d4f41e74ad4cc2eb6e1d5c824996092b3430f088bb8" ;
366+ };
367+ }
368+
332369$KnownNDKs = @ {
333370 r26b = @ {
334371 URL = " https://dl.google.com/android/repository/android-ndk-r26b-windows.zip"
@@ -808,63 +845,52 @@ function Fetch-Dependencies {
808845 New-Item - ItemType Directory - ErrorAction Ignore $BinaryCache \toolchains | Out-Null
809846 Extract- Toolchain " $PinnedToolchain .exe" $BinaryCache $PinnedToolchain
810847
811- function Install-Python ([string ] $ArchName ) {
812- $Python = @ {
813- AMD64 = @ {
814- URL = " https://www.nuget.org/api/v2/package/python/$PythonVersion " ;
815- SHA256 = " ac43b491e9488ac926ed31c5594f0c9409a21ecbaf99dc7a93f8c7b24cf85867" ;
816- };
817- ARM64 = @ {
818- URL = " https://www.nuget.org/api/v2/package/pythonarm64/$PythonVersion " ;
819- SHA256 = " 429ada77e7f30e4bd8ff22953a1f35f98b2728e84c9b1d006712561785641f69" ;
820- }
848+ function Get-KnownPython ([string ] $ArchName ) {
849+ if (-not $KnownPythons.ContainsKey ($PythonVersion )) {
850+ throw " Unknown python version: $PythonVersion "
821851 }
852+ return $KnownPythons [$PythonVersion ].$ArchName
853+ }
822854
823- DownloadAndVerify $Python [$ArchName ].URL " $BinaryCache \Python$ArchName -$PythonVersion .zip" $Python [$ArchName ].SHA256
855+ function Install-Python ([string ] $ArchName ) {
856+ $Python = Get-KnownPython $ArchName
857+ DownloadAndVerify $Python.URL " $BinaryCache \Python$ArchName -$PythonVersion .zip" $Python.SHA256
824858 if (-not $ToBatch ) {
825859 Extract- ZipFile Python$ArchName - $PythonVersion.zip " $BinaryCache " Python$ArchName - $PythonVersion
826860 }
827861 }
828862
829- function Install-PythonWheel ([ string ] $ModuleName , [ string ] $WheelFile , [ string ] $WheelURL , [ string ] $WheelHash ) {
863+ function Install-PIPIfNeeded ( ) {
830864 try {
831- Invoke-Program - Silent " $ ( Get-PythonExecutable ) " - c " import $ModuleName "
865+ Invoke-Program - Silent " $ ( Get-PythonExecutable ) " - m pip
832866 } catch {
833- DownloadAndVerify $WheelURL " $BinaryCache \python\$WheelFile " $WheelHash
834- Write-Output " Installing '$WheelFile ' ..."
835- Invoke-Program - OutNull " $ ( Get-PythonExecutable ) " ' -I' - m pip install " $BinaryCache \python\$WheelFile " -- disable-pip - version- check
867+ Write-Output " Installing pip ..."
868+ Invoke-Program - OutNull " $ ( Get-PythonExecutable ) " ' -I' - m ensurepip - U -- default- pip
869+ } finally {
870+ Write-Output " pip installed."
836871 }
837872 }
838873
839- function Install-PythonModules () {
840- # First ensure pip is installed, else bootstrap it
874+ function Install-PythonWheel ([string ] $ModuleName ) {
841875 try {
842- Invoke-Program - Silent " $ ( Get-PythonExecutable ) " - m pip
876+ Invoke-Program - Silent " $ ( Get-PythonExecutable ) " - c " import $ModuleName "
843877 } catch {
844- Write-Output " Installing pip ..."
845- Invoke-Program - OutNull " $ ( Get-PythonExecutable ) " ' -I' - m ensurepip - U -- default- pip
878+ $Wheel = $PythonWheels [$ModuleName ]
879+ DownloadAndVerify $Wheel.URL " $BinaryCache \python\$ ( $Wheel.File ) " $Wheel.SHA256
880+ Write-Output " Installing '$ ( $Wheel.File ) ' ..."
881+ Invoke-Program - OutNull " $ ( Get-PythonExecutable ) " ' -I' - m pip install " $BinaryCache \python\$ ( $Wheel.File ) " -- disable-pip - version- check
882+ } finally {
883+ Write-Output " $ModuleName installed."
846884 }
885+ }
847886
848- # 'packaging' is required for building LLVM 18+
849- Install-PythonWheel ' packaging' ' packaging-24.1-py3-none-any.whl' `
850- ' https://files.pythonhosted.org/packages/08/aa/cc0199a5f0ad350994d660967a8efb233fe0416e4639146c089643407ce6/packaging-24.1-py3-none-any.whl' `
851- ' 5b8f2217dbdbd2f7f384c41c628544e6d52f2d0f53c6d0c3ea61aa5d1d7ff124'
852-
853- # 'setuptools' provides 'distutils' module for Python 3.12+, required for SWIG support
854- Install-PythonWheel ' distutils' ' setuptools-75.1.0-py3-none-any.whl' `
855- ' https://files.pythonhosted.org/packages/ff/ae/f19306b5a221f6a436d8f2238d5b80925004093fa3edea59835b514d9057/setuptools-75.1.0-py3-none-any.whl' `
856- ' 35ab7fd3bcd95e6b7fd704e4a1539513edad446c097797f2985e0e4b960772f2'
857-
887+ function Install-PythonModules () {
888+ Install-PIPIfNeeded
889+ Install-PythonWheel " packaging" # For building LLVM 18+
890+ Install-PythonWheel " distutils" # Required for SWIG support
858891 if ($Test -contains " lldb" ) {
859- # 'psutil' is required for testing LLDB
860- Install-PythonWheel ' psutil' ' psutil-6.1.0-cp37-abi3-win_amd64.whl' `
861- ' https://files.pythonhosted.org/packages/11/91/87fa6f060e649b1e1a7b19a4f5869709fbf750b7c8c262ee776ec32f3028/psutil-6.1.0-cp37-abi3-win_amd64.whl' `
862- ' a8fb3752b491d246034fa4d279ff076501588ce8cbcdbb62c32fd7a377d996be'
863-
864- # 'unittest2' is required for testing LLDB
865- Install-PythonWheel ' unittest2' ' unittest2-1.1.0-py2.py3-none-any.whl' `
866- ' https://files.pythonhosted.org/packages/72/20/7f0f433060a962200b7272b8c12ba90ef5b903e218174301d0abfd523813/unittest2-1.1.0-py2.py3-none-any.whl' `
867- ' 13f77d0875db6d9b435e1d4f41e74ad4cc2eb6e1d5c824996092b3430f088bb8'
892+ Install-PythonWheel " psutil" # Required for testing LLDB
893+ Install-PythonWheel " unittest2" # Required for testing LLDB
868894 }
869895 }
870896
0 commit comments