build_python.bat 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. @setlocal enabledelayedexpansion
  2. @echo off
  3. REM
  4. REM Copyright (c) Contributors to the Open 3D Engine Project.
  5. REM For complete copyright and license terms please see the LICENSE at the root of this distribution.
  6. REM
  7. REM SPDX-License-Identifier: Apache-2.0 OR MIT
  8. REM
  9. REM
  10. set ScriptDir=%~dp0
  11. set outputdir=%ScriptDir%package
  12. set tempdir=%ScriptDir%temp
  13. set python_src=%tempdir%\cpython
  14. rem dont allow python to read pip packages from user's local folder
  15. set PYTHONNOUSERSITE=1
  16. echo Building python from source - Basic requirements:
  17. echo - Visual studio vc141 build tools installed (VS2017). This can be installed into vs2019 or above.
  18. echo - git installed
  19. echo.
  20. echo ... This will take about 10 minutes ...
  21. echo.
  22. set vswhere_location=%ProgramFiles(x86)%\Microsoft Visual Studio\Installer
  23. echo adding %vswhere_location% to PATH
  24. set PATH=%vswhere_location%;%PATH%
  25. for /f "tokens=*" %%i in ('vswhere -property installationPath') do set VS2017_LOCATION=%%i
  26. echo Using Visual Studio: %VS2017_LOCATION%
  27. if NOT exist "%VS2017_LOCATION%\Common7\Tools\vsdevcmd.bat" (
  28. echo Could not find visual studio 2017 installed
  29. exit /B 1
  30. )
  31. call "%VS2017_LOCATION%\Common7\Tools\vsdevcmd.bat"
  32. echo Clearing %tempdir% if present...
  33. rmdir /s /q %tempdir% > NUL
  34. echo Clearing %outputdir% if present...
  35. rmdir /s /q %outputdir% > NUL
  36. mkdir %outputdir%
  37. mkdir %tempdir%
  38. cd /d %tempdir%
  39. echo Cloning python from git using v3.7.10...
  40. git clone https://github.com/python/cpython.git --branch "v3.7.10" --depth 1
  41. if %ERRORLEVEL% NEQ 0 (
  42. echo "Git clone failed"
  43. exit /B 1
  44. )
  45. cd /d %python_src%
  46. call .\PCBuild\get_externals.bat
  47. msbuild.exe "%python_src%\PCbuild\pcbuild.proj" /t:Build /m /nologo /v:m /p:Configuration=Debug /p:Platform=x64 /p:IncludeExternals=true /p:IncludeSSL=true /p:IncludeTkinter=true /p:PlatformToolset=v141
  48. if %ERRORLEVEL% NEQ 0 (
  49. echo Failed to build debug python
  50. exit /B 1
  51. )
  52. echo building release...
  53. msbuild.exe "%python_src%\PCbuild\pcbuild.proj" /t:Build /m /nologo /v:m /p:Configuration=Release /p:Platform=x64 /p:IncludeExternals=true /p:IncludeSSL=true /p:IncludeTkinter=true /p:PlatformToolset=v141
  54. if %ERRORLEVEL% NEQ 0 (
  55. echo Failed to build release python
  56. exit /B 1
  57. )
  58. cd /d %python_src%
  59. echo installing PIP...
  60. .\PCBuild\amd64\Python.exe -m ensurepip --upgrade
  61. if %ERRORLEVEL% NEQ 0 (
  62. echo Failed to ensure pip is present.
  63. exit /B 1
  64. )
  65. .\PCBuild\amd64\Python.exe -m pip install --upgrade pip
  66. echo creating the installation image...
  67. rem We'll actually use the real python dist builder to do this:
  68. cd /d %python_src%
  69. .\PCBuild\amd64\python.exe .\PC\layout\main.py --copy %outputdir%\python -v -d --include-stable --include-pip --include-distutils --include-tcltk --include-idle --include-tools --include-venv --include-dev --include-launchers
  70. if %ERRORLEVEL% NEQ 0 (
  71. echo "Failed to call python's layout script (debug)"
  72. exit /B 1
  73. )
  74. .\PCBuild\amd64\python.exe .\PC\layout\main.py --copy %outputdir%\python -v --include-stable --include-pip --include-distutils --include-tcltk --include-idle --include-tools --include-venv --include-dev --include-launchers
  75. if %ERRORLEVEL% NEQ 0 (
  76. echo "Failed to call python's layout script (release)"
  77. exit /B 1
  78. )
  79. echo copying package metadata and cmake files...
  80. rem But we do add our own few things...
  81. set ROBOCOPY_OPTIONS=/NJH /NJS /NP /NDL
  82. robocopy %ScriptDir% %outputdir% *.cmake PackageInfo.json %ROBOCOPY_OPTIONS%
  83. robocopy %python_src%\PCbuild\amd64 %outputdir%\python Python*.pdb %ROBOCOPY_OPTIONS%
  84. cd /d %ScriptDir%
  85. echo clearing temp dir...
  86. rmdir /s /q %tempdir%
  87. rem we leave only the output folder which is the actual output for packaging.
  88. echo this folder is ready for packaging: %outputdir%
  89. exit /B 0