blob: c432c39d443c13714dad684db88e6cb1889004ce [file] [log] [blame]
Zachary Ware6b6e6872017-06-10 14:58:42 -05001@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=-m test -q --pgo
39set BUILDNUGET=1
40set BUILDZIP=1
41
42
43:CheckOpts
44if "%1" EQU "-h" goto Help
45if "%1" EQU "-c" (set CERTNAME=%~2) && shift && shift && goto CheckOpts
46if "%1" EQU "--certificate" (set CERTNAME=%~2) && shift && shift && goto CheckOpts
47if "%1" EQU "-o" (set OUTDIR=%~2) && shift && shift && goto CheckOpts
48if "%1" EQU "--out" (set OUTDIR=%~2) && shift && shift && goto CheckOpts
49if "%1" EQU "-D" (set SKIPDOC=1) && shift && goto CheckOpts
50if "%1" EQU "--skip-doc" (set SKIPDOC=1) && shift && goto CheckOpts
51if "%1" EQU "-B" (set SKIPBUILD=1) && shift && goto CheckOpts
52if "%1" EQU "--skip-build" (set SKIPBUILD=1) && shift && goto CheckOpts
53if "%1" EQU "--download" (set DOWNLOAD_URL=%~2) && shift && shift && goto CheckOpts
54if "%1" EQU "--test" (set TESTTARGETDIR=%~2) && shift && shift && goto CheckOpts
55if "%1" EQU "-b" (set TARGET=Build) && shift && goto CheckOpts
56if "%1" EQU "--build" (set TARGET=Build) && shift && goto CheckOpts
57if "%1" EQU "-x86" (set BUILDX86=1) && shift && goto CheckOpts
58if "%1" EQU "-x64" (set BUILDX64=1) && shift && goto CheckOpts
59if "%1" EQU "--pgo" (set PGO=%~2) && shift && shift && goto CheckOpts
60if "%1" EQU "--skip-pgo" (set PGO=) && shift && goto CheckOpts
61if "%1" EQU "--skip-nuget" (set BUILDNUGET=) && shift && goto CheckOpts
62if "%1" EQU "--skip-zip" (set BUILDZIP=) && shift && goto CheckOpts
63
64if "%1" NEQ "" echo Invalid option: "%1" && exit /B 1
65
66if not defined BUILDX86 if not defined BUILDX64 (set BUILDX86=1) && (set BUILDX64=1)
67
68if not exist "%GIT%" where git > "%TEMP%\git.loc" 2> nul && set /P GIT= < "%TEMP%\git.loc" & del "%TEMP%\git.loc"
69if not exist "%GIT%" echo Cannot find Git on PATH && exit /B 1
70
71call "%D%get_externals.bat"
72
73:builddoc
74if "%SKIPBUILD%" EQU "1" goto skipdoc
75if "%SKIPDOC%" EQU "1" goto skipdoc
76
77if not defined PYTHON where py -q || echo Cannot find py on path and PYTHON is not set. && exit /B 1
78if not defined SPHINXBUILD where sphinx-build -q || echo Cannot find sphinx-build on path and SPHINXBUILD is not set. && exit /B 1
79
80call "%D%..\..\doc\make.bat" htmlhelp
81if errorlevel 1 goto :eof
82:skipdoc
83
84where dlltool /q && goto skipdlltoolsearch
85set _DLLTOOL_PATH=
86where /R "%EXTERNALS%\" dlltool > "%TEMP%\dlltool.loc" 2> nul && set /P _DLLTOOL_PATH= < "%TEMP%\dlltool.loc" & del "%TEMP%\dlltool.loc"
87if not exist "%_DLLTOOL_PATH%" echo Cannot find binutils on PATH or in external && exit /B 1
88for %%f in (%_DLLTOOL_PATH%) do set PATH=%PATH%;%%~dpf
89set _DLLTOOL_PATH=
90:skipdlltoolsearch
91
92if defined BUILDX86 (
93 call :build x86
94 if errorlevel 1 exit /B
95)
96
97if defined BUILDX64 (
98 call :build x64 "%PGO%"
99 if errorlevel 1 exit /B
100)
101
102if defined TESTTARGETDIR (
103 call "%D%testrelease.bat" -t "%TESTTARGETDIR%"
104)
105
106exit /B 0
107
108:build
109@setlocal
110@echo off
111
112if "%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
126if 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
132if 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
138if 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
144if not "%CERTNAME%" EQU "" (
145 set CERTOPTS="/p:SigningCertificate=%CERTNAME%"
146) else (
147 set CERTOPTS=
148)
149if not "%PGO%" EQU "" (
150 set PGOOPTS=--pgo-job "%PGO%"
151) else (
152 set PGOOPTS=
153)
154if 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
168call "%PCBUILD%env.bat"
169if "%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
177set BUILDOPTS=/p:Platform=%1 /p:BuildForRelease=true /p:DownloadUrl=%DOWNLOAD_URL% /p:DownloadUrlBase=%DOWNLOAD_URL_BASE% /p:ReleaseUri=%RELEASE_URI%
178msbuild "%D%bundle\releaselocal.wixproj" /t:Rebuild %BUILDOPTS% %CERTOPTS% /p:RebuildAll=true
179if errorlevel 1 exit /B
180msbuild "%D%bundle\releaseweb.wixproj" /t:Rebuild %BUILDOPTS% %CERTOPTS% /p:RebuildAll=false
181if errorlevel 1 exit /B
182
183if 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
188if 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
193if 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
202exit /B 0
203
204:Help
205echo buildrelease.bat [--out DIR] [-x86] [-x64] [--certificate CERTNAME] [--build] [--pgo COMMAND]
206echo [--skip-build] [--skip-doc] [--skip-nuget] [--skip-zip] [--skip-pgo]
207echo [--download DOWNLOAD URL] [--test TARGETDIR]
208echo [-h]
209echo.
210echo --out (-o) Specify an additional output directory for installers
211echo -x86 Build x86 installers
212echo -x64 Build x64 installers
213echo --build (-b) Incrementally build Python rather than rebuilding
214echo --skip-build (-B) Do not build Python (just do the installers)
215echo --skip-doc (-D) Do not build documentation
216echo --pgo Specify PGO command for x64 installers
217echo --skip-pgo Build x64 installers without using PGO
218echo --skip-nuget Do not build Nuget packages
219echo --skip-zip Do not build embeddable package
220echo --download Specify the full download URL for MSIs
221echo --test Specify the test directory to run the installer tests
222echo -h Display this help information
223echo.
224echo If no architecture is specified, all architectures will be built.
225echo If --test is not specified, the installer tests are not run.
226echo.
227echo For the --pgo option, any Python command line can be used, or 'default' to
228echo use the default task (-m test --pgo).
229echo.
230echo The following substitutions will be applied to the download URL:
231echo Variable Description Example
232echo {version} version number 3.5.0
233echo {arch} architecture amd64, win32
234echo {releasename} release name a1, b2, rc3 (or blank for final)
235echo {msi} MSI filename core.msi