buildrelease.bat revision 22d0698d3b034f4f4314aa793da7225a5da640ba
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=http://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\
32set EXTERNALS=%D%..\..\externals\windows-installer\
33
34set BUILDX86=
35set BUILDX64=
36set TARGET=Rebuild
37set TESTTARGETDIR=
38set PGO=default
39
40
41:CheckOpts
42if "%1" EQU "-h" goto Help
43if "%1" EQU "-c" (set CERTNAME=%~2) && shift && shift && goto CheckOpts
44if "%1" EQU "--certificate" (set CERTNAME=%~2) && shift && shift && goto CheckOpts
45if "%1" EQU "-o" (set OUTDIR=%~2) && shift && shift && goto CheckOpts
46if "%1" EQU "--out" (set OUTDIR=%~2) && shift && shift && goto CheckOpts
47if "%1" EQU "-D" (set SKIPDOC=1) && shift && goto CheckOpts
48if "%1" EQU "--skip-doc" (set SKIPDOC=1) && shift && goto CheckOpts
49if "%1" EQU "-B" (set SKIPBUILD=1) && shift && goto CheckOpts
50if "%1" EQU "--skip-build" (set SKIPBUILD=1) && shift && goto CheckOpts
51if "%1" EQU "--download" (set DOWNLOAD_URL=%~2) && shift && shift && goto CheckOpts
52if "%1" EQU "--test" (set TESTTARGETDIR=%~2) && shift && shift && goto CheckOpts
53if "%1" EQU "-b" (set TARGET=Build) && shift && goto CheckOpts
54if "%1" EQU "--build" (set TARGET=Build) && shift && goto CheckOpts
55if "%1" EQU "-x86" (set BUILDX86=1) && shift && goto CheckOpts
56if "%1" EQU "-x64" (set BUILDX64=1) && shift && goto CheckOpts
57if "%1" EQU "--pgo" (set PGO=%~2) && shift && shift && goto CheckOpts
58if "%1" EQU "--skip-pgo" (set PGO=) && shift && goto CheckOpts
59
60if "%1" NEQ "" echo Invalid option: "%1" && exit /B 1
61
62if not defined BUILDX86 if not defined BUILDX64 (set BUILDX86=1) && (set BUILDX64=1)
63
64call "%D%get_externals.bat"
65
66:builddoc
67if "%SKIPBUILD%" EQU "1" goto skipdoc
68if "%SKIPDOC%" EQU "1" goto skipdoc
69
70if not defined PYTHON where py -q || echo Cannot find py on path and PYTHON is not set. && exit /B 1
71if not defined SPHINXBUILD where sphinx-build -q || echo Cannot find sphinx-build on path and SPHINXBUILD is not set. && exit /B 1
72
73call "%D%..\..\doc\make.bat" htmlhelp
74if errorlevel 1 goto :eof
75:skipdoc
76
77where hg /q || echo Cannot find Mercurial on PATH && exit /B 1
78
79where dlltool /q && goto skipdlltoolsearch
80set _DLLTOOL_PATH=
81where /R "%EXTERNALS%\" dlltool > "%TEMP%\dlltool.loc" 2> nul && set /P _DLLTOOL_PATH= < "%TEMP%\dlltool.loc" & del "%TEMP%\dlltool.loc" 
82if not exist "%_DLLTOOL_PATH%" echo Cannot find binutils on PATH or in external && exit /B 1
83for %%f in (%_DLLTOOL_PATH%) do set PATH=%PATH%;%%~dpf
84set _DLLTOOL_PATH=
85:skipdlltoolsearch
86
87if defined BUILDX86 (
88    call :build x86
89    if errorlevel 1 exit /B
90)
91
92if defined BUILDX64 (
93    call :build x64 "%PGO%"
94    if errorlevel 1 exit /B
95)
96
97if defined TESTTARGETDIR (
98    call "%D%testrelease.bat" -t "%TESTTARGETDIR%"
99)
100
101exit /B 0
102
103:build
104@setlocal
105@echo off
106
107if "%1" EQU "x86" (
108    call "%PCBUILD%env.bat" x86
109    set BUILD=%PCBUILD%win32\
110    set BUILD_PLAT=Win32
111    set OUTDIR_PLAT=win32
112    set OBJDIR_PLAT=x86
113) else if "%~2" NEQ "" (
114    call "%PCBUILD%env.bat" amd64
115    set PGO=%~2
116    set BUILD=%PCBUILD%amd64-pgo\
117    set BUILD_PLAT=x64
118    set OUTDIR_PLAT=amd64
119    set OBJDIR_PLAT=x64
120) else (
121    call "%PCBUILD%env.bat" amd64
122    set BUILD=%PCBUILD%amd64\
123    set BUILD_PLAT=x64
124    set OUTDIR_PLAT=amd64
125    set OBJDIR_PLAT=x64
126)
127
128if exist "%BUILD%en-us" (
129    echo Deleting %BUILD%en-us
130    rmdir /q/s "%BUILD%en-us"
131    if errorlevel 1 exit /B
132)
133
134if exist "%D%obj\Release_%OBJDIR_PLAT%" (
135    echo Deleting "%D%obj\Release_%OBJDIR_PLAT%"
136    rmdir /q/s "%D%obj\Release_%OBJDIR_PLAT%"
137    if errorlevel 1 exit /B
138)
139
140if not "%CERTNAME%" EQU "" (
141    set CERTOPTS="/p:SigningCertificate=%CERTNAME%"
142) else (
143    set CERTOPTS=
144)
145
146if not "%SKIPBUILD%" EQU "1" (
147    @call "%PCBUILD%build.bat" -e -p %BUILD_PLAT% -d -t %TARGET% %CERTOPTS%
148    @if errorlevel 1 exit /B
149    @rem build.bat turns echo back on, so we disable it again
150    @echo off
151    
152    if "%PGO%" EQU "" (
153        @call "%PCBUILD%build.bat" -e -p %BUILD_PLAT% -t %TARGET% %CERTOPTS%
154    ) else (
155        @call "%PCBUILD%build.bat" -e -p %BUILD_PLAT% -c PGInstrument -t %TARGET% %CERTOPTS%
156        @if errorlevel 1 exit /B
157        
158        @del "%BUILD%*.pgc"
159        if "%PGO%" EQU "default" (
160            "%BUILD%python.exe" -m test -q --pgo
161        ) else if "%PGO%" EQU "default2" (
162            "%BUILD%python.exe" -m test -r -q --pgo
163            "%BUILD%python.exe" -m test -r -q --pgo
164        ) else if "%PGO%" EQU "default10" (
165            for /L %%i in (0, 1, 9) do "%BUILD%python.exe" -m test -q -r --pgo
166        ) else if "%PGO%" EQU "pybench" (
167            "%BUILD%python.exe" "%PCBUILD%..\Tools\pybench\pybench.py"
168        ) else (
169            "%BUILD%python.exe" %PGO%
170        )
171        
172        @call "%PCBUILD%build.bat" -e -p %BUILD_PLAT% -c PGUpdate -t Build %CERTOPTS%
173    )
174    @if errorlevel 1 exit /B
175    @echo off
176)
177
178set BUILDOPTS=/p:Platform=%1 /p:BuildForRelease=true /p:DownloadUrl=%DOWNLOAD_URL% /p:DownloadUrlBase=%DOWNLOAD_URL_BASE% /p:ReleaseUri=%RELEASE_URI%
179if "%PGO%" NEQ "" set BUILDOPTS=%BUILDOPTS% /p:PGOBuildPath=%BUILD%
180msbuild "%D%bundle\releaselocal.wixproj" /t:Rebuild %BUILDOPTS% %CERTOPTS% /p:RebuildAll=true
181if errorlevel 1 exit /B
182msbuild "%D%bundle\releaseweb.wixproj" /t:Rebuild %BUILDOPTS% %CERTOPTS% /p:RebuildAll=false
183if errorlevel 1 exit /B
184
185msbuild "%D%make_zip.proj" /t:Build %BUILDOPTS% %CERTOPTS%
186
187if not "%OUTDIR%" EQU "" (
188    mkdir "%OUTDIR%\%OUTDIR_PLAT%"
189    copy /Y "%BUILD%en-us\*.cab" "%OUTDIR%\%OUTDIR_PLAT%"
190    copy /Y "%BUILD%en-us\*.exe" "%OUTDIR%\%OUTDIR_PLAT%"
191    copy /Y "%BUILD%en-us\*.msi" "%OUTDIR%\%OUTDIR_PLAT%"
192    copy /Y "%BUILD%en-us\*.msu" "%OUTDIR%\%OUTDIR_PLAT%"
193)
194
195exit /B 0
196
197:Help
198echo buildrelease.bat [--out DIR] [-x86] [-x64] [--certificate CERTNAME] [--build] [--skip-build]
199echo                  [--pgo COMMAND] [--skip-pgo] [--skip-doc] [--download DOWNLOAD URL] [--test TARGETDIR]
200echo                  [-h]
201echo.
202echo    --out (-o)          Specify an additional output directory for installers
203echo    -x86                Build x86 installers
204echo    -x64                Build x64 installers
205echo    --build (-b)        Incrementally build Python rather than rebuilding
206echo    --skip-build (-B)   Do not build Python (just do the installers)
207echo    --skip-doc (-D)     Do not build documentation
208echo    --pgo               Specify PGO command for x64 installers
209echo    --skip-pgo          Build x64 installers using PGO
210echo    --download          Specify the full download URL for MSIs
211echo    --test              Specify the test directory to run the installer tests
212echo    -h                  Display this help information
213echo.
214echo If no architecture is specified, all architectures will be built.
215echo If --test is not specified, the installer tests are not run.
216echo.
217echo For the --pgo option, any Python command line can be used as well as the
218echo following shortcuts:
219echo     Shortcut        Description
220echo     default         Test suite with --pgo
221echo     default2        2x test suite with --pgo and randomized test order
222echo     default10       10x test suite with --pgo and randomized test order
223echo     pybench         pybench script
224echo.
225echo The following substitutions will be applied to the download URL:
226echo     Variable        Description         Example
227echo     {version}       version number      3.5.0
228echo     {arch}          architecture        amd64, win32
229echo     {releasename}   release name        a1, b2, rc3 (or blank for final)
230echo     {msi}           MSI filename        core.msi
231