blob: 5dc1b57b668a11dd993963a1fba59fc2630bb7e8 [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\
Steve Dowerf0851912017-07-26 09:09:01 -070032if "%Py_OutDir%"=="" set Py_OutDir=%PCBUILD%
Zachary Ware6b6e6872017-06-10 14:58:42 -050033set EXTERNALS=%D%..\..\externals\windows-installer\
34
35set BUILDX86=
36set BUILDX64=
37set TARGET=Rebuild
38set TESTTARGETDIR=
39set PGO=-m test -q --pgo
40set BUILDNUGET=1
41set BUILDZIP=1
42
43
44:CheckOpts
45if "%1" EQU "-h" goto Help
46if "%1" EQU "-c" (set CERTNAME=%~2) && shift && shift && goto CheckOpts
47if "%1" EQU "--certificate" (set CERTNAME=%~2) && shift && shift && goto CheckOpts
48if "%1" EQU "-o" (set OUTDIR=%~2) && shift && shift && goto CheckOpts
49if "%1" EQU "--out" (set OUTDIR=%~2) && shift && shift && goto CheckOpts
50if "%1" EQU "-D" (set SKIPDOC=1) && shift && goto CheckOpts
51if "%1" EQU "--skip-doc" (set SKIPDOC=1) && shift && goto CheckOpts
52if "%1" EQU "-B" (set SKIPBUILD=1) && shift && goto CheckOpts
53if "%1" EQU "--skip-build" (set SKIPBUILD=1) && shift && goto CheckOpts
54if "%1" EQU "--download" (set DOWNLOAD_URL=%~2) && shift && shift && goto CheckOpts
55if "%1" EQU "--test" (set TESTTARGETDIR=%~2) && shift && shift && goto CheckOpts
56if "%1" EQU "-b" (set TARGET=Build) && shift && goto CheckOpts
57if "%1" EQU "--build" (set TARGET=Build) && shift && goto CheckOpts
58if "%1" EQU "-x86" (set BUILDX86=1) && shift && goto CheckOpts
59if "%1" EQU "-x64" (set BUILDX64=1) && shift && goto CheckOpts
60if "%1" EQU "--pgo" (set PGO=%~2) && shift && shift && goto CheckOpts
61if "%1" EQU "--skip-pgo" (set PGO=) && shift && goto CheckOpts
62if "%1" EQU "--skip-nuget" (set BUILDNUGET=) && shift && goto CheckOpts
63if "%1" EQU "--skip-zip" (set BUILDZIP=) && shift && goto CheckOpts
64
65if "%1" NEQ "" echo Invalid option: "%1" && exit /B 1
66
67if not defined BUILDX86 if not defined BUILDX64 (set BUILDX86=1) && (set BUILDX64=1)
68
69if not exist "%GIT%" where git > "%TEMP%\git.loc" 2> nul && set /P GIT= < "%TEMP%\git.loc" & del "%TEMP%\git.loc"
70if not exist "%GIT%" echo Cannot find Git on PATH && exit /B 1
71
72call "%D%get_externals.bat"
Steve Dower40a23e82017-06-19 10:34:25 -070073call "%PCBUILD%find_msbuild.bat" %MSBUILD%
74if ERRORLEVEL 1 (echo Cannot locate MSBuild.exe on PATH or as MSBUILD variable & exit /b 2)
Zachary Ware6b6e6872017-06-10 14:58:42 -050075
76:builddoc
77if "%SKIPBUILD%" EQU "1" goto skipdoc
78if "%SKIPDOC%" EQU "1" goto skipdoc
79
Zachary Ware6b6e6872017-06-10 14:58:42 -050080call "%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=
Steve Dowerf0851912017-07-26 09:09:01 -0700114 set BUILD=%Py_OutDir%win32\
Zachary Ware6b6e6872017-06-10 14:58:42 -0500115 set BUILD_PLAT=Win32
116 set OUTDIR_PLAT=win32
117 set OBJDIR_PLAT=x86
118) else (
Steve Dowerf0851912017-07-26 09:09:01 -0700119 set BUILD=%Py_OutDir%amd64\
Zachary Ware6b6e6872017-06-10 14:58:42 -0500120 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
Zachary Ware6b6e6872017-06-10 14:58:42 -0500168if "%OUTDIR_PLAT%" EQU "win32" (
Steve Dower40a23e82017-06-19 10:34:25 -0700169 %MSBUILD% "%D%launcher\launcher.wixproj" /p:Platform=x86 %CERTOPTS% /p:ReleaseUri=%RELEASE_URI%
Zachary Ware6b6e6872017-06-10 14:58:42 -0500170 if errorlevel 1 exit /B
Steve Dowerf0851912017-07-26 09:09:01 -0700171) else if not exist "%Py_OutDir%win32\en-us\launcher.msi" (
Steve Dower40a23e82017-06-19 10:34:25 -0700172 %MSBUILD% "%D%launcher\launcher.wixproj" /p:Platform=x86 %CERTOPTS% /p:ReleaseUri=%RELEASE_URI%
Zachary Ware6b6e6872017-06-10 14:58:42 -0500173 if errorlevel 1 exit /B
174)
175
176set BUILDOPTS=/p:Platform=%1 /p:BuildForRelease=true /p:DownloadUrl=%DOWNLOAD_URL% /p:DownloadUrlBase=%DOWNLOAD_URL_BASE% /p:ReleaseUri=%RELEASE_URI%
Steve Dower40a23e82017-06-19 10:34:25 -0700177%MSBUILD% "%D%bundle\releaselocal.wixproj" /t:Rebuild %BUILDOPTS% %CERTOPTS% /p:RebuildAll=true
Zachary Ware6b6e6872017-06-10 14:58:42 -0500178if errorlevel 1 exit /B
Steve Dower40a23e82017-06-19 10:34:25 -0700179%MSBUILD% "%D%bundle\releaseweb.wixproj" /t:Rebuild %BUILDOPTS% %CERTOPTS% /p:RebuildAll=false
Zachary Ware6b6e6872017-06-10 14:58:42 -0500180if errorlevel 1 exit /B
181
182if defined BUILDZIP (
Steve Dower40a23e82017-06-19 10:34:25 -0700183 %MSBUILD% "%D%make_zip.proj" /t:Build %BUILDOPTS% %CERTOPTS% /p:OutputPath="%BUILD%en-us"
Zachary Ware6b6e6872017-06-10 14:58:42 -0500184 if errorlevel 1 exit /B
185)
186
187if defined BUILDNUGET (
Steve Dower40a23e82017-06-19 10:34:25 -0700188 %MSBUILD% "%D%..\nuget\make_pkg.proj" /t:Build /p:Configuration=Release /p:Platform=%1 /p:OutputPath="%BUILD%en-us"
Zachary Ware6b6e6872017-06-10 14:58:42 -0500189 if errorlevel 1 exit /B
190)
191
192if not "%OUTDIR%" EQU "" (
193 mkdir "%OUTDIR%\%OUTDIR_PLAT%"
194 mkdir "%OUTDIR%\%OUTDIR_PLAT%\binaries"
195 mkdir "%OUTDIR%\%OUTDIR_PLAT%\symbols"
196 robocopy "%BUILD%en-us" "%OUTDIR%\%OUTDIR_PLAT%" /XF "*.wixpdb"
197 robocopy "%BUILD%\" "%OUTDIR%\%OUTDIR_PLAT%\binaries" *.exe *.dll *.pyd /XF "_test*" /XF "*_d.*" /XF "_freeze*" /XF "tcl*" /XF "tk*" /XF "*_test.*"
198 robocopy "%BUILD%\" "%OUTDIR%\%OUTDIR_PLAT%\symbols" *.pdb /XF "_test*" /XF "*_d.*" /XF "_freeze*" /XF "tcl*" /XF "tk*" /XF "*_test.*"
199)
200
201exit /B 0
202
203:Help
204echo buildrelease.bat [--out DIR] [-x86] [-x64] [--certificate CERTNAME] [--build] [--pgo COMMAND]
205echo [--skip-build] [--skip-doc] [--skip-nuget] [--skip-zip] [--skip-pgo]
206echo [--download DOWNLOAD URL] [--test TARGETDIR]
207echo [-h]
208echo.
209echo --out (-o) Specify an additional output directory for installers
210echo -x86 Build x86 installers
211echo -x64 Build x64 installers
212echo --build (-b) Incrementally build Python rather than rebuilding
213echo --skip-build (-B) Do not build Python (just do the installers)
214echo --skip-doc (-D) Do not build documentation
215echo --pgo Specify PGO command for x64 installers
216echo --skip-pgo Build x64 installers without using PGO
217echo --skip-nuget Do not build Nuget packages
218echo --skip-zip Do not build embeddable package
219echo --download Specify the full download URL for MSIs
220echo --test Specify the test directory to run the installer tests
221echo -h Display this help information
222echo.
223echo If no architecture is specified, all architectures will be built.
224echo If --test is not specified, the installer tests are not run.
225echo.
226echo For the --pgo option, any Python command line can be used, or 'default' to
227echo use the default task (-m test --pgo).
228echo.
229echo The following substitutions will be applied to the download URL:
230echo Variable Description Example
231echo {version} version number 3.5.0
232echo {arch} architecture amd64, win32
233echo {releasename} release name a1, b2, rc3 (or blank for final)
234echo {msi} MSI filename core.msi