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