build_base.bat 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. setlocal EnableDelayedExpansion
  2. echo on
  3. :: brand Python with conda-forge startup message
  4. if "%CONDA_FORGE%"=="yes" (
  5. %SYS_PYTHON% %RECIPE_DIR%\brand_python.py
  6. if errorlevel 1 exit 1
  7. )
  8. :: Compile python, extensions and external libraries
  9. if "%ARCH%"=="64" (
  10. set PLATFORM=x64
  11. set VC_PATH=x64
  12. set BUILD_PATH=amd64
  13. ) else (
  14. set PLATFORM=Win32
  15. set VC_PATH=x86
  16. set BUILD_PATH=win32
  17. )
  18. for /F "tokens=1,2 delims=." %%i in ("%PKG_VERSION%") do (
  19. set "VERNODOTS=%%i%%j"
  20. )
  21. :: Make sure the "python" value in conda_build_config.yaml is up to date.
  22. for /F "tokens=1,2 delims=." %%i in ("%PKG_VERSION%") do (
  23. if NOT "%PY_VER%"=="%%i.%%j" exit 1
  24. )
  25. set "OPENSSL_DIR=%LIBRARY_PREFIX%"
  26. set "SQLITE3_DIR=%LIBRARY_PREFIX%"
  27. for /f "usebackq delims=" %%i in (`conda list -p %PREFIX% sqlite --no-show-channel-urls --json ^| findstr "version"`) do set SQLITE3_VERSION_LINE=%%i
  28. for /f "tokens=2 delims==/ " %%i IN ('echo %SQLITE3_VERSION_LINE%') do (set SQLITE3_VERSION=%%~i)
  29. echo SQLITE3_VERSION detected as %SQLITE3_VERSION%
  30. if "%PY_INTERP_DEBUG%"=="yes" (
  31. set CONFIG=-d
  32. set _D=_d
  33. ) else (
  34. set CONFIG=
  35. set _D=
  36. )
  37. if "%DEBUG_C%"=="yes" (
  38. set PGO=
  39. ) else (
  40. set PGO=--pgo
  41. )
  42. :: AP doesn't support PGO atm?
  43. if "%CONDA_FORGE%"=="yes" (
  44. set PGO=
  45. )
  46. :: PGO is not yet working for Python 3.9:
  47. :: (CopyPGCFiles target) ->
  48. :: C:\opt\conda\conda-bld\python-split-3.9.0_7\work\PCbuild\pyproject.props(165,5): error : PGO run did not succeed (no python39!*.pgc files) and there is no data to merge [C:\opt\conda\conda-bld\python-split-3.9.0_7\work\PCbuild\pythoncore.vcxproj]
  49. :: set PGO=
  50. cd PCbuild
  51. :: Twice because:
  52. :: error : importlib_zipimport.h updated. You will need to rebuild pythoncore to see the changes.
  53. call build.bat %PGO% %CONFIG% -m -e -v -p %PLATFORM%
  54. call build.bat %PGO% %CONFIG% -m -e -v -p %PLATFORM%
  55. if errorlevel 1 exit 1
  56. cd ..
  57. :: Populate the root package directory
  58. for %%x in (python%VERNODOTS%%_D%.dll python3%_D%.dll python%_D%.exe pythonw%_D%.exe venvlauncher%_D%.exe venvwlauncher%_D%.exe) do (
  59. if exist %SRC_DIR%\PCbuild\%BUILD_PATH%\%%x (
  60. copy /Y %SRC_DIR%\PCbuild\%BUILD_PATH%\%%x %PREFIX%
  61. ) else (
  62. echo "WARNING :: %SRC_DIR%\PCbuild\%BUILD_PATH%\%%x does not exist"
  63. )
  64. )
  65. for %%x in (python%_D%.pdb python%VERNODOTS%%_D%.pdb pythonw%_D%.pdb) do (
  66. if exist %SRC_DIR%\PCbuild\%BUILD_PATH%\%%x (
  67. copy /Y %SRC_DIR%\PCbuild\%BUILD_PATH%\%%x %PREFIX%
  68. ) else (
  69. echo "WARNING :: %SRC_DIR%\PCbuild\%BUILD_PATH%\%%x does not exist"
  70. )
  71. )
  72. copy %SRC_DIR%\LICENSE %PREFIX%\LICENSE_PYTHON.txt
  73. if errorlevel 1 exit 1
  74. :: Populate the DLLs directory
  75. mkdir %PREFIX%\DLLs
  76. xcopy /s /y %SRC_DIR%\PCBuild\%BUILD_PATH%\*.pyd %PREFIX%\DLLs\
  77. if errorlevel 1 exit 1
  78. copy /Y %SRC_DIR%\PCbuild\%BUILD_PATH%\tcl86t.dll %PREFIX%\DLLs\
  79. if errorlevel 1 exit 1
  80. copy /Y %SRC_DIR%\PCbuild\%BUILD_PATH%\tk86t.dll %PREFIX%\DLLs\
  81. if errorlevel 1 exit 1
  82. copy /Y %SRC_DIR%\externals\libffi-3.3.0\%BUILD_PATH%\libffi-7.dll %PREFIX%\DLLs\
  83. if errorlevel 1 exit 1
  84. copy /Y %SRC_DIR%\PC\icons\py.ico %PREFIX%\DLLs\
  85. if errorlevel 1 exit 1
  86. copy /Y %SRC_DIR%\PC\icons\pyc.ico %PREFIX%\DLLs\
  87. if errorlevel 1 exit 1
  88. :: Populate the Tools directory
  89. mkdir %PREFIX%\Tools
  90. xcopy /s /y /i %SRC_DIR%\Tools\demo %PREFIX%\Tools\demo
  91. if errorlevel 1 exit 1
  92. xcopy /s /y /i %SRC_DIR%\Tools\i18n %PREFIX%\Tools\i18n
  93. if errorlevel 1 exit 1
  94. xcopy /s /y /i %SRC_DIR%\Tools\pynche %PREFIX%\Tools\pynche
  95. if errorlevel 1 exit 1
  96. xcopy /s /y /i %SRC_DIR%\Tools\scripts %PREFIX%\Tools\scripts
  97. if errorlevel 1 exit 1
  98. del %PREFIX%\Tools\demo\README
  99. if errorlevel 1 exit 1
  100. del %PREFIX%\Tools\pynche\README
  101. if errorlevel 1 exit 1
  102. del %PREFIX%\Tools\pynche\pynche
  103. if errorlevel 1 exit 1
  104. del %PREFIX%\Tools\scripts\README
  105. if errorlevel 1 exit 1
  106. del %PREFIX%\Tools\scripts\dutree.doc
  107. if errorlevel 1 exit 1
  108. del %PREFIX%\Tools\scripts\idle3
  109. if errorlevel 1 exit 1
  110. move /y %PREFIX%\Tools\scripts\2to3 %PREFIX%\Tools\scripts\2to3.py
  111. if errorlevel 1 exit 1
  112. move /y %PREFIX%\Tools\scripts\pydoc3 %PREFIX%\Tools\scripts\pydoc3.py
  113. if errorlevel 1 exit 1
  114. :: Populate the tcl directory
  115. xcopy /s /y /i %SRC_DIR%\externals\tcltk-8.6.12.0\%BUILD_PATH%\lib %PREFIX%\tcl
  116. if errorlevel 1 exit 1
  117. :: Populate the include directory
  118. xcopy /s /y %SRC_DIR%\Include %PREFIX%\include\
  119. if errorlevel 1 exit 1
  120. copy /Y %SRC_DIR%\PC\pyconfig.h %PREFIX%\include\
  121. if errorlevel 1 exit 1
  122. :: Populate the Scripts directory
  123. if not exist %SCRIPTS% (mkdir %SCRIPTS%)
  124. if errorlevel 1 exit 1
  125. for %%x in (idle pydoc) do (
  126. copy /Y %SRC_DIR%\Tools\scripts\%%x3 %SCRIPTS%\%%x
  127. if errorlevel 1 exit 1
  128. )
  129. copy /Y %SRC_DIR%\Tools\scripts\2to3 %SCRIPTS%
  130. if errorlevel 1 exit 1
  131. :: Populate the libs directory
  132. if not exist %PREFIX%\libs mkdir %PREFIX%\libs
  133. if exist %SRC_DIR%\PCbuild\%BUILD_PATH%\python%VERNODOTS%%_D%.lib copy /Y %SRC_DIR%\PCbuild\%BUILD_PATH%\python%VERNODOTS%%_D%.lib %PREFIX%\libs\
  134. if errorlevel 1 exit 1
  135. if exist %SRC_DIR%\PCbuild\%BUILD_PATH%\python3%_D%.lib copy /Y %SRC_DIR%\PCbuild\%BUILD_PATH%\python3%_D%.lib %PREFIX%\libs\
  136. if errorlevel 1 exit 1
  137. if exist %SRC_DIR%\PCbuild\%BUILD_PATH%\_tkinter%_D%.lib copy /Y %SRC_DIR%\PCbuild\%BUILD_PATH%\_tkinter%_D%.lib %PREFIX%\libs\
  138. if errorlevel 1 exit 1
  139. :: Populate the Lib directory
  140. del %PREFIX%\libs\libpython*.a
  141. xcopy /s /y %SRC_DIR%\Lib %PREFIX%\Lib\
  142. if errorlevel 1 exit 1
  143. :: Remove test data to save space.
  144. :: Though keep `support` as some things use that.
  145. mkdir %PREFIX%\Lib\test_keep
  146. if errorlevel 1 exit 1
  147. move %PREFIX%\Lib\test\__init__.py %PREFIX%\Lib\test_keep\
  148. if errorlevel 1 exit 1
  149. move %PREFIX%\Lib\test\support %PREFIX%\Lib\test_keep\
  150. if errorlevel 1 exit 1
  151. rd /s /q %PREFIX%\Lib\test
  152. if errorlevel 1 exit 1
  153. move %PREFIX%\Lib\test_keep %PREFIX%\Lib\test
  154. if errorlevel 1 exit 1
  155. :: Remove some tests (unfortunate, a split package would be nice)
  156. rd /s /q %PREFIX%\Lib\lib2to3\tests\
  157. if errorlevel 1 exit 1
  158. :: Remove PGO DLLs
  159. if exist %PREFIX%\DLLs\instrumented (
  160. rd /s /q %PREFIX%\DLLs\instrumented\
  161. if errorlevel 1 exit 1
  162. )
  163. :: bytecode compile the standard library
  164. rd /s /q %PREFIX%\Lib\lib2to3\tests\
  165. if errorlevel 1 exit 1
  166. :: We need our Python to be found!
  167. if "%_D%" neq "" copy %PREFIX%\python%_D%.exe %PREFIX%\python.exe
  168. %PREFIX%\python.exe -Wi %PREFIX%\Lib\compileall.py -f -q -x "bad_coding|badsyntax|py2_" %PREFIX%\Lib
  169. if errorlevel 1 exit 1
  170. :: Pickle lib2to3 Grammar
  171. %PREFIX%\python.exe -m lib2to3 --help
  172. :: Ensure that scripts are generated
  173. :: https://github.com/conda-forge/python-feedstock/issues/384
  174. %SYS_PREFIX%\python.exe %RECIPE_DIR%\fix_staged_scripts.py %ARCH%
  175. if errorlevel 1 exit 1
  176. :: Some quick tests for common failures
  177. echo "Testing print() does not print: Hello"
  178. %CONDA_EXE% run -p %PREFIX% cd %PREFIX% & %PREFIX%\python.exe -c "print()" 2>&1 | findstr /r /c:"Hello"
  179. if %errorlevel% neq 1 exit /b 1
  180. echo "Testing print('Hello') prints: Hello"
  181. %CONDA_EXE% run -p %PREFIX% cd %PREFIX% & %PREFIX%\python.exe "print('Hello')" 2>&1 | findstr /r /c:"Hello"
  182. if %errorlevel% neq 0 exit /b 1
  183. echo "Testing import of os (no DLL needed) does not print: The specified module could not be found"
  184. %CONDA_EXE% run -p %PREFIX% cd %PREFIX% & %PREFIX%\python.exe -v -c "import os" 2>&1
  185. %CONDA_EXE% run -p %PREFIX% cd %PREFIX% & %PREFIX%\python.exe -v -c "import os" 2>&1 | findstr /r /c:"The specified module could not be found"
  186. if %errorlevel% neq 1 exit /b 1
  187. echo "Testing import of _sqlite3 (DLL located via PATH needed) does not print: The specified module could not be found"
  188. %CONDA_EXE% run -p %PREFIX% cd %PREFIX% & %PREFIX%\python.exe -v -c "import _sqlite3" 2>&1
  189. %CONDA_EXE% run -p %PREFIX% cd %PREFIX% & %PREFIX%\python.exe -v -c "import _sqlite3" 2>&1 | findstr /r /c:"The specified module could not be found"
  190. if %errorlevel% neq 1 exit /b 1