blob: 81a3f86cab36b039d7964d6ea2dc89416db05718 [file] [log] [blame]
Zachary Ware774ac372015-04-13 12:11:40 -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.
Zachary Ware774ac372015-04-13 12:11:40 -05007
Steve Dowerc4b76002015-10-01 15:18:53 -07008rem 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}
Zachary Ware774ac372015-04-13 12:11:40 -050029
30set D=%~dp0
31set PCBUILD=%D%..\..\PCBuild\
Steve Dowerd28a8a92015-10-23 09:50:49 -070032set EXTERNALS=%D%..\..\externals\windows-installer\
Zachary Ware774ac372015-04-13 12:11:40 -050033
34set BUILDX86=
35set BUILDX64=
36set TARGET=Rebuild
37set TESTTARGETDIR=
Steve Dower4468bed2016-11-14 16:13:56 -080038set PGO=-m test -q --pgo
Steve Dowerfcf622e2016-10-27 12:08:45 -070039set BUILDNUGET=1
40set BUILDZIP=1
Zachary Ware774ac372015-04-13 12:11:40 -050041
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
Steve Dower148827c2015-10-14 10:40:09 -070059if "%1" EQU "--pgo" (set PGO=%~2) && shift && shift && goto CheckOpts
Steve Dower22d06982016-09-06 19:38:15 -070060if "%1" EQU "--skip-pgo" (set PGO=) && shift && goto CheckOpts
Steve Dowerfcf622e2016-10-27 12:08:45 -070061if "%1" EQU "--skip-nuget" (set BUILDNUGET=) && shift && goto CheckOpts
62if "%1" EQU "--skip-zip" (set BUILDZIP=) && shift && goto CheckOpts
Steve Dower148827c2015-10-14 10:40:09 -070063
64if "%1" NEQ "" echo Invalid option: "%1" && exit /B 1
Zachary Ware774ac372015-04-13 12:11:40 -050065
66if not defined BUILDX86 if not defined BUILDX64 (set BUILDX86=1) && (set BUILDX64=1)
67
Steve Dowerd3e1e9d2017-03-03 21:32:17 -080068if 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
Steve Dower190dbd92016-12-03 11:18:53 -080070
Steve Dowerd28a8a92015-10-23 09:50:49 -070071call "%D%get_externals.bat"
72
Zachary Ware774ac372015-04-13 12:11:40 -050073: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
Steve Dowerd28a8a92015-10-23 09:50:49 -070079
Zachary Ware774ac372015-04-13 12:11:40 -050080call "%D%..\..\doc\make.bat" htmlhelp
81if errorlevel 1 goto :eof
82:skipdoc
83
Zachary Ware774ac372015-04-13 12:11:40 -050084where dlltool /q && goto skipdlltoolsearch
85set _DLLTOOL_PATH=
Steve Dowerd28a8a92015-10-23 09:50:49 -070086where /R "%EXTERNALS%\" dlltool > "%TEMP%\dlltool.loc" 2> nul && set /P _DLLTOOL_PATH= < "%TEMP%\dlltool.loc" & del "%TEMP%\dlltool.loc"
Zachary Ware774ac372015-04-13 12:11:40 -050087if 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 (
Steve Dower148827c2015-10-14 10:40:09 -070098 call :build x64 "%PGO%"
Zachary Ware774ac372015-04-13 12:11:40 -050099 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" (
Steve Dower2a1f30f2016-09-09 14:21:24 -0700113 set PGO=
Zachary Ware774ac372015-04-13 12:11:40 -0500114 set BUILD=%PCBUILD%win32\
115 set BUILD_PLAT=Win32
116 set OUTDIR_PLAT=win32
117 set OBJDIR_PLAT=x86
Steve Dower148827c2015-10-14 10:40:09 -0700118) else (
Zachary Ware774ac372015-04-13 12:11:40 -0500119 set BUILD=%PCBUILD%amd64\
Steve Dowere7da2f82016-09-11 20:19:35 -0700120 set PGO=%~2
Zachary Ware774ac372015-04-13 12:11:40 -0500121 set BUILD_PLAT=x64
122 set OUTDIR_PLAT=amd64
123 set OBJDIR_PLAT=x64
Zachary Ware774ac372015-04-13 12:11:40 -0500124)
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
Steve Dower02a40182016-11-22 11:48:52 -0800132if 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
Zachary Ware774ac372015-04-13 12:11:40 -0500138if 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)
Steve Dowerde40e122016-11-14 17:51:42 -0800149if not "%PGO%" EQU "" (
150 set PGOOPTS=--pgo-job "%PGO%"
151) else (
152 set PGOOPTS=
153)
Zachary Ware774ac372015-04-13 12:11:40 -0500154if not "%SKIPBUILD%" EQU "1" (
Steve Dower02a40182016-11-22 11:48:52 -0800155 @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%
Steve Dower148827c2015-10-14 10:40:09 -0700163 @if errorlevel 1 exit /B
Zachary Ware774ac372015-04-13 12:11:40 -0500164 @rem build.bat turns echo back on, so we disable it again
165 @echo off
166)
167
Steve Dower4468bed2016-11-14 16:13:56 -0800168call "%PCBUILD%env.bat"
Steve Dowerec1f28a2016-10-10 16:19:06 -0700169if "%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
Zachary Ware774ac372015-04-13 12:11:40 -0500177set 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
Steve Dowerfcf622e2016-10-27 12:08:45 -0700183if defined BUILDZIP (
Steve Dower190dbd92016-12-03 11:18:53 -0800184 msbuild "%D%make_zip.proj" /t:Build %BUILDOPTS% %CERTOPTS% /p:OutputPath="%BUILD%en-us"
Steve Dowerfcf622e2016-10-27 12:08:45 -0700185 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)
Steve Dowerf70fdd22015-04-14 18:34:04 -0400192
Zachary Ware774ac372015-04-13 12:11:40 -0500193if not "%OUTDIR%" EQU "" (
194 mkdir "%OUTDIR%\%OUTDIR_PLAT%"
Steve Dowerfcf622e2016-10-27 12:08:45 -0700195 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.*"
Zachary Ware774ac372015-04-13 12:11:40 -0500200)
201
202exit /B 0
203
204:Help
Steve Dowerfcf622e2016-10-27 12:08:45 -0700205echo buildrelease.bat [--out DIR] [-x86] [-x64] [--certificate CERTNAME] [--build] [--pgo COMMAND]
Steve Dower43d2b262016-10-27 12:12:24 -0700206echo [--skip-build] [--skip-doc] [--skip-nuget] [--skip-zip] [--skip-pgo]
Steve Dowerfcf622e2016-10-27 12:08:45 -0700207echo [--download DOWNLOAD URL] [--test TARGETDIR]
Steve Dower148827c2015-10-14 10:40:09 -0700208echo [-h]
Zachary Ware774ac372015-04-13 12:11:40 -0500209echo.
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
Steve Dower22d06982016-09-06 19:38:15 -0700216echo --pgo Specify PGO command for x64 installers
Steve Dower4468bed2016-11-14 16:13:56 -0800217echo --skip-pgo Build x64 installers without using PGO
Steve Dowerfcf622e2016-10-27 12:08:45 -0700218echo --skip-nuget Do not build Nuget packages
219echo --skip-zip Do not build embeddable package
Steve Dowerc4b76002015-10-01 15:18:53 -0700220echo --download Specify the full download URL for MSIs
Zachary Ware774ac372015-04-13 12:11:40 -0500221echo --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.
Steve Dowerc4b76002015-10-01 15:18:53 -0700226echo.
Steve Dower4468bed2016-11-14 16:13:56 -0800227echo For the --pgo option, any Python command line can be used, or 'default' to
228echo use the default task (-m test --pgo).
Steve Dower148827c2015-10-14 10:40:09 -0700229echo.
Steve Dowerc4b76002015-10-01 15:18:53 -0700230echo 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