1@setlocal 2@echo off 3 4rem This script is intended for building official releases of Python. 5rem To use it to build alternative releases, you should clone this file 6rem and modify the following three URIs. 7 8rem These two will ensure that your release can be installed 9rem alongside an official Python release, by modifying the GUIDs used 10rem for all components. 11rem 12rem The following substitutions will be applied to the release URI: 13rem Variable Description Example 14rem {arch} architecture amd64, win32 15set RELEASE_URI=https://www.python.org/{arch} 16 17rem This is the URL that will be used to download installation files. 18rem The files available from the default URL *will* conflict with your 19rem installer. Trust me, you don't want them, even if it seems like a 20rem good idea. 21rem 22rem The following substitutions will be applied to the download URL: 23rem Variable Description Example 24rem {version} version number 3.5.0 25rem {arch} architecture amd64, win32 26rem {releasename} release name a1, b2, rc3 (or blank for final) 27rem {msi} MSI filename core.msi 28set DOWNLOAD_URL=https://www.python.org/ftp/python/{version}/{arch}{releasename}/{msi} 29 30set D=%~dp0 31set PCBUILD=%D%..\..\PCbuild\ 32if NOT DEFINED Py_OutDir set Py_OutDir=%PCBUILD% 33set EXTERNALS=%D%..\..\externals\windows-installer\ 34 35set BUILDX86= 36set BUILDX64= 37set TARGET=Rebuild 38set TESTTARGETDIR= 39set PGO=-m test -q --pgo 40set BUILDMSI=1 41set BUILDNUGET=1 42set BUILDZIP=1 43 44 45:CheckOpts 46if "%1" EQU "-h" goto Help 47if "%1" EQU "-c" (set CERTNAME=%~2) && shift && shift && goto CheckOpts 48if "%1" EQU "--certificate" (set CERTNAME=%~2) && shift && shift && goto CheckOpts 49if "%1" EQU "-o" (set OUTDIR=%~2) && shift && shift && goto CheckOpts 50if "%1" EQU "--out" (set OUTDIR=%~2) && shift && shift && goto CheckOpts 51if "%1" EQU "-D" (set SKIPDOC=1) && shift && goto CheckOpts 52if "%1" EQU "--skip-doc" (set SKIPDOC=1) && shift && goto CheckOpts 53if "%1" EQU "-B" (set SKIPBUILD=1) && shift && goto CheckOpts 54if "%1" EQU "--skip-build" (set SKIPBUILD=1) && shift && goto CheckOpts 55if "%1" EQU "--download" (set DOWNLOAD_URL=%~2) && shift && shift && goto CheckOpts 56if "%1" EQU "--test" (set TESTTARGETDIR=%~2) && shift && shift && goto CheckOpts 57if "%1" EQU "-b" (set TARGET=Build) && shift && goto CheckOpts 58if "%1" EQU "--build" (set TARGET=Build) && shift && goto CheckOpts 59if "%1" EQU "-x86" (set BUILDX86=1) && shift && goto CheckOpts 60if "%1" EQU "-x64" (set BUILDX64=1) && shift && goto CheckOpts 61if "%1" EQU "--pgo" (set PGO=%~2) && shift && shift && goto CheckOpts 62if "%1" EQU "--skip-pgo" (set PGO=) && shift && goto CheckOpts 63if "%1" EQU "--skip-nuget" (set BUILDNUGET=) && shift && goto CheckOpts 64if "%1" EQU "--skip-zip" (set BUILDZIP=) && shift && goto CheckOpts 65if "%1" EQU "--skip-msi" (set BUILDMSI=) && shift && goto CheckOpts 66 67if "%1" NEQ "" echo Invalid option: "%1" && exit /B 1 68 69if not defined BUILDX86 if not defined BUILDX64 (set BUILDX86=1) && (set BUILDX64=1) 70 71if not exist "%GIT%" where git > "%TEMP%\git.loc" 2> nul && set /P GIT= < "%TEMP%\git.loc" & del "%TEMP%\git.loc" 72if not exist "%GIT%" echo Cannot find Git on PATH && exit /B 1 73 74call "%D%get_externals.bat" 75call "%PCBUILD%find_msbuild.bat" %MSBUILD% 76if ERRORLEVEL 1 (echo Cannot locate MSBuild.exe on PATH or as MSBUILD variable & exit /b 2) 77 78:builddoc 79if "%SKIPBUILD%" EQU "1" goto skipdoc 80if "%SKIPDOC%" EQU "1" goto skipdoc 81 82call "%D%..\..\doc\make.bat" htmlhelp 83if errorlevel 1 exit /B %ERRORLEVEL% 84:skipdoc 85 86where dlltool /q && goto skipdlltoolsearch 87set _DLLTOOL_PATH= 88where /R "%EXTERNALS%\" dlltool > "%TEMP%\dlltool.loc" 2> nul && set /P _DLLTOOL_PATH= < "%TEMP%\dlltool.loc" & del "%TEMP%\dlltool.loc" 89if not exist "%_DLLTOOL_PATH%" echo Cannot find binutils on PATH or in external && exit /B 1 90for %%f in (%_DLLTOOL_PATH%) do set PATH=%PATH%;%%~dpf 91set _DLLTOOL_PATH= 92:skipdlltoolsearch 93 94if defined BUILDX86 ( 95 call :build x86 96 if errorlevel 1 exit /B %ERRORLEVEL% 97) 98 99if defined BUILDX64 ( 100 call :build x64 "%PGO%" 101 if errorlevel 1 exit /B %ERRORLEVEL% 102) 103 104if defined TESTTARGETDIR ( 105 call "%D%testrelease.bat" -t "%TESTTARGETDIR%" 106 if errorlevel 1 exit /B %ERRORLEVEL% 107) 108 109exit /B 0 110 111:build 112@setlocal 113@echo off 114 115if "%1" EQU "x86" ( 116 set PGO= 117 set BUILD=%Py_OutDir%win32\ 118 set BUILD_PLAT=Win32 119 set OUTDIR_PLAT=win32 120 set OBJDIR_PLAT=x86 121) else ( 122 set BUILD=%Py_OutDir%amd64\ 123 set PGO=%~2 124 set BUILD_PLAT=x64 125 set OUTDIR_PLAT=amd64 126 set OBJDIR_PLAT=x64 127) 128 129if exist "%BUILD%en-us" ( 130 echo Deleting %BUILD%en-us 131 rmdir /q/s "%BUILD%en-us" 132 if errorlevel 1 exit /B %ERRORLEVEL% 133) 134 135if exist "%D%obj\Debug_%OBJDIR_PLAT%" ( 136 echo Deleting "%D%obj\Debug_%OBJDIR_PLAT%" 137 rmdir /q/s "%D%obj\Debug_%OBJDIR_PLAT%" 138 if errorlevel 1 exit /B %ERRORLEVEL% 139) 140 141if exist "%D%obj\Release_%OBJDIR_PLAT%" ( 142 echo Deleting "%D%obj\Release_%OBJDIR_PLAT%" 143 rmdir /q/s "%D%obj\Release_%OBJDIR_PLAT%" 144 if errorlevel 1 exit /B %ERRORLEVEL% 145) 146 147if not "%CERTNAME%" EQU "" ( 148 set CERTOPTS="/p:SigningCertificate=%CERTNAME%" 149) else ( 150 set CERTOPTS= 151) 152if not "%PGO%" EQU "" ( 153 set PGOOPTS=--pgo-job "%PGO%" 154) else ( 155 set PGOOPTS= 156) 157if not "%SKIPBUILD%" EQU "1" ( 158 @echo call "%PCBUILD%build.bat" -e -p %BUILD_PLAT% -t %TARGET% %PGOOPTS% %CERTOPTS% 159 @call "%PCBUILD%build.bat" -e -p %BUILD_PLAT% -t %TARGET% %PGOOPTS% %CERTOPTS% 160 @if errorlevel 1 exit /B %ERRORLEVEL% 161 @rem build.bat turns echo back on, so we disable it again 162 @echo off 163 164 @echo call "%PCBUILD%build.bat" -d -e -p %BUILD_PLAT% -t %TARGET% 165 @call "%PCBUILD%build.bat" -d -e -p %BUILD_PLAT% -t %TARGET% 166 @if errorlevel 1 exit /B %ERRORLEVEL% 167 @rem build.bat turns echo back on, so we disable it again 168 @echo off 169) 170 171if "%OUTDIR_PLAT%" EQU "win32" ( 172 %MSBUILD% "%D%launcher\launcher.wixproj" /p:Platform=x86 %CERTOPTS% /p:ReleaseUri=%RELEASE_URI% 173 if errorlevel 1 exit /B %ERRORLEVEL% 174) else if not exist "%Py_OutDir%win32\en-us\launcher.msi" ( 175 %MSBUILD% "%D%launcher\launcher.wixproj" /p:Platform=x86 %CERTOPTS% /p:ReleaseUri=%RELEASE_URI% 176 if errorlevel 1 exit /B %ERRORLEVEL% 177) 178 179set BUILDOPTS=/p:Platform=%1 /p:BuildForRelease=true /p:DownloadUrl=%DOWNLOAD_URL% /p:DownloadUrlBase=%DOWNLOAD_URL_BASE% /p:ReleaseUri=%RELEASE_URI% 180if defined BUILDMSI ( 181 %MSBUILD% "%D%bundle\releaselocal.wixproj" /t:Rebuild %BUILDOPTS% %CERTOPTS% /p:RebuildAll=true 182 if errorlevel 1 exit /B %ERRORLEVEL% 183 %MSBUILD% "%D%bundle\releaseweb.wixproj" /t:Rebuild %BUILDOPTS% %CERTOPTS% /p:RebuildAll=false 184 if errorlevel 1 exit /B %ERRORLEVEL% 185) 186 187if defined BUILDZIP ( 188 %MSBUILD% "%D%make_zip.proj" /t:Build %BUILDOPTS% %CERTOPTS% /p:OutputPath="%BUILD%en-us" 189 if errorlevel 1 exit /B %ERRORLEVEL% 190) 191 192if defined BUILDNUGET ( 193 %MSBUILD% "%D%..\nuget\make_pkg.proj" /t:Build /p:Configuration=Release /p:Platform=%1 /p:OutputPath="%BUILD%en-us" 194 if errorlevel 1 exit /B %ERRORLEVEL% 195) 196 197if not "%OUTDIR%" EQU "" ( 198 mkdir "%OUTDIR%\%OUTDIR_PLAT%" 199 mkdir "%OUTDIR%\%OUTDIR_PLAT%\binaries" 200 mkdir "%OUTDIR%\%OUTDIR_PLAT%\symbols" 201 robocopy "%BUILD%en-us" "%OUTDIR%\%OUTDIR_PLAT%" /XF "*.wixpdb" 202 robocopy "%BUILD%\" "%OUTDIR%\%OUTDIR_PLAT%\binaries" *.exe *.dll *.pyd /XF "_test*" /XF "*_d.*" /XF "_freeze*" /XF "tcl*" /XF "tk*" /XF "*_test.*" 203 robocopy "%BUILD%\" "%OUTDIR%\%OUTDIR_PLAT%\symbols" *.pdb /XF "_test*" /XF "*_d.*" /XF "_freeze*" /XF "tcl*" /XF "tk*" /XF "*_test.*" 204) 205 206exit /B 0 207 208:Help 209echo buildrelease.bat [--out DIR] [-x86] [-x64] [--certificate CERTNAME] [--build] [--pgo COMMAND] 210echo [--skip-build] [--skip-doc] [--skip-nuget] [--skip-zip] [--skip-pgo] 211echo [--download DOWNLOAD URL] [--test TARGETDIR] 212echo [-h] 213echo. 214echo --out (-o) Specify an additional output directory for installers 215echo -x86 Build x86 installers 216echo -x64 Build x64 installers 217echo --build (-b) Incrementally build Python rather than rebuilding 218echo --skip-build (-B) Do not build Python (just do the installers) 219echo --skip-doc (-D) Do not build documentation 220echo --pgo Specify PGO command for x64 installers 221echo --skip-pgo Build x64 installers without using PGO 222echo --skip-msi Do not build executable/MSI packages 223echo --skip-nuget Do not build Nuget packages 224echo --skip-zip Do not build embeddable package 225echo --download Specify the full download URL for MSIs 226echo --test Specify the test directory to run the installer tests 227echo -h Display this help information 228echo. 229echo If no architecture is specified, all architectures will be built. 230echo If --test is not specified, the installer tests are not run. 231echo. 232echo For the --pgo option, any Python command line can be used, or 'default' to 233echo use the default task (-m test --pgo). 234echo. 235echo The following substitutions will be applied to the download URL: 236echo Variable Description Example 237echo {version} version number 3.5.0 238echo {arch} architecture amd64, win32 239echo {releasename} release name a1, b2, rc3 (or blank for final) 240echo {msi} MSI filename core.msi 241