blob: 6f0c85e4a45a03fa2b5680ff8292dedf5f87ba8b [file] [log] [blame]
Zachary Ware6b6e6872017-06-10 14:58:42 -05001@echo off
2goto Run
3:Usage
4echo.%~nx0 [flags and arguments] [quoted MSBuild options]
5echo.
6echo.Build CPython from the command line. Requires the appropriate
7echo.version(s) of Microsoft Visual Studio to be installed (see readme.txt).
Zachary Ware6b6e6872017-06-10 14:58:42 -05008echo.
9echo.After the flags recognized by this script, up to 9 arguments to be passed
10echo.directly to MSBuild may be passed. If the argument contains an '=', the
11echo.entire argument must be quoted (e.g. `%~nx0 "/p:PlatformToolset=v100"`).
12echo.Alternatively you can put extra flags for MSBuild in a file named
13echo.`msbuild.rsp` in the `PCbuild` directory, one flag per line. This file
14echo.will be picked automatically by MSBuild. Flags put in this file does not
15echo.need to be quoted. You can still use environment variables inside the
16echo.response file.
17echo.
18echo.Available flags:
19echo. -h Display this help message
20echo. -V Display version information for the current build
21echo. -r Target Rebuild instead of Build
22echo. -d Set the configuration to Debug
Zachary Wared01db1c2017-09-06 17:29:37 -070023echo. -E Don't fetch or build external libraries. Extension modules that
24echo. depend on external libraries will not attempt to build if this flag
25echo. is present; -e is also accepted to explicitly enable fetching and
26echo. building externals.
Zachary Ware6b6e6872017-06-10 14:58:42 -050027echo. -m Enable parallel build (enabled by default)
28echo. -M Disable parallel build
29echo. -v Increased output messages
30echo. -k Attempt to kill any running Pythons before building (usually done
31echo. automatically by the pythoncore project)
32echo. --pgo Build with Profile-Guided Optimization. This flag
33echo. overrides -c and -d
34echo. --test-marker Enable the test marker within the build.
35echo.
36echo.Available flags to avoid building certain modules.
37echo.These flags have no effect if '-e' is not given:
Paul Monsonf96e7fd2019-05-17 10:07:24 -070038echo. --no-ctypes Do not attempt to build _ctypes
Zachary Ware6b6e6872017-06-10 14:58:42 -050039echo. --no-ssl Do not attempt to build _ssl
40echo. --no-tkinter Do not attempt to build Tkinter
41echo.
42echo.Available arguments:
43echo. -c Release ^| Debug ^| PGInstrument ^| PGUpdate
44echo. Set the configuration (default: Release)
Paul Monsonf96e7fd2019-05-17 10:07:24 -070045echo. -p x64 ^| Win32 ^| ARM ^| ARM64
Zachary Ware6b6e6872017-06-10 14:58:42 -050046echo. Set the platform (default: Win32)
47echo. -t Build ^| Rebuild ^| Clean ^| CleanAll
48echo. Set the target manually
49echo. --pgo-job The job to use for PGO training; implies --pgo
50echo. (default: "-m test --pgo")
51exit /b 127
52
53:Run
54setlocal
55set platf=Win32
Zachary Ware6b6e6872017-06-10 14:58:42 -050056set conf=Release
57set target=Build
58set dir=%~dp0
59set parallel=/m
60set verbose=/nologo /v:m
61set kill=
62set do_pgo=
63set pgo_job=-m test --pgo
Zachary Ware6b6e6872017-06-10 14:58:42 -050064
65:CheckOpts
66if "%~1"=="-h" goto Usage
67if "%~1"=="-c" (set conf=%2) & shift & shift & goto CheckOpts
68if "%~1"=="-p" (set platf=%2) & shift & shift & goto CheckOpts
69if "%~1"=="-r" (set target=Rebuild) & shift & goto CheckOpts
70if "%~1"=="-t" (set target=%2) & shift & shift & goto CheckOpts
71if "%~1"=="-d" (set conf=Debug) & shift & goto CheckOpts
72if "%~1"=="-m" (set parallel=/m) & shift & goto CheckOpts
73if "%~1"=="-M" (set parallel=) & shift & goto CheckOpts
74if "%~1"=="-v" (set verbose=/v:n) & shift & goto CheckOpts
75if "%~1"=="-k" (set kill=true) & shift & goto CheckOpts
76if "%~1"=="--pgo" (set do_pgo=true) & shift & goto CheckOpts
77if "%~1"=="--pgo-job" (set do_pgo=true) & (set pgo_job=%~2) & shift & shift & goto CheckOpts
78if "%~1"=="--test-marker" (set UseTestMarker=true) & shift & goto CheckOpts
79if "%~1"=="-V" shift & goto Version
80rem These use the actual property names used by MSBuild. We could just let
81rem them in through the environment, but we specify them on the command line
82rem anyway for visibility so set defaults after this
83if "%~1"=="-e" (set IncludeExternals=true) & shift & goto CheckOpts
Zachary Wared01db1c2017-09-06 17:29:37 -070084if "%~1"=="-E" (set IncludeExternals=false) & shift & goto CheckOpts
Paul Monsonf96e7fd2019-05-17 10:07:24 -070085if "%~1"=="--no-ctypes" (set IncludeCTypes=false) & shift & goto CheckOpts
Zachary Ware6b6e6872017-06-10 14:58:42 -050086if "%~1"=="--no-ssl" (set IncludeSSL=false) & shift & goto CheckOpts
87if "%~1"=="--no-tkinter" (set IncludeTkinter=false) & shift & goto CheckOpts
88
Steve Dower05f01d82017-09-07 11:49:23 -070089if "%IncludeExternals%"=="" set IncludeExternals=true
Paul Monsonf96e7fd2019-05-17 10:07:24 -070090if "%IncludeCTypes%"=="" set IncludeCTypes=true
Zachary Ware6b6e6872017-06-10 14:58:42 -050091if "%IncludeSSL%"=="" set IncludeSSL=true
92if "%IncludeTkinter%"=="" set IncludeTkinter=true
93
94if "%IncludeExternals%"=="true" call "%dir%get_externals.bat"
95
Steve Dower40a23e82017-06-19 10:34:25 -070096if "%do_pgo%" EQU "true" if "%platf%" EQU "x64" (
97 if "%PROCESSOR_ARCHITEW6432%" NEQ "AMD64" if "%PROCESSOR_ARCHITECTURE%" NEQ "AMD64" (
98 echo.ERROR: Cannot cross-compile with PGO
99 echo. 32bit operating system detected. Ensure your PROCESSOR_ARCHITECTURE
100 echo. and PROCESSOR_ARCHITEW6432 environment variables are correct.
101 exit /b 1
Zachary Ware6b6e6872017-06-10 14:58:42 -0500102 )
103)
104
105if not exist "%GIT%" where git > "%TEMP%\git.loc" 2> nul && set /P GIT= < "%TEMP%\git.loc" & del "%TEMP%\git.loc"
106if exist "%GIT%" set GITProperty=/p:GIT="%GIT%"
107if not exist "%GIT%" echo Cannot find Git on PATH & set GITProperty=
108
109rem Setup the environment
Steve Dower40a23e82017-06-19 10:34:25 -0700110call "%dir%find_msbuild.bat" %MSBUILD%
111if ERRORLEVEL 1 (echo Cannot locate MSBuild.exe on PATH or as MSBUILD variable & exit /b 2)
Zachary Ware6b6e6872017-06-10 14:58:42 -0500112
113if "%kill%"=="true" call :Kill
114
115if "%do_pgo%"=="true" (
116 set conf=PGInstrument
117 call :Build %1 %2 %3 %4 %5 %6 %7 %8 %9
118 del /s "%dir%\*.pgc"
119 del /s "%dir%\..\Lib\*.pyc"
120 echo on
121 call "%dir%\..\python.bat" %pgo_job%
122 @echo off
123 call :Kill
124 set conf=PGUpdate
125 set target=Build
126)
127goto Build
128:Kill
129echo on
Steve Dower40a23e82017-06-19 10:34:25 -0700130%MSBUILD% "%dir%\pythoncore.vcxproj" /t:KillPython %verbose%^
Zachary Ware6b6e6872017-06-10 14:58:42 -0500131 /p:Configuration=%conf% /p:Platform=%platf%^
132 /p:KillPython=true
133
134@echo off
135goto :eof
136
137:Build
138rem Call on MSBuild to do the work, echo the command.
139rem Passing %1-9 is not the preferred option, but argument parsing in
140rem batch is, shall we say, "lackluster"
141echo on
Steve Dower40a23e82017-06-19 10:34:25 -0700142%MSBUILD% "%dir%pcbuild.proj" /t:%target% %parallel% %verbose%^
Zachary Ware6b6e6872017-06-10 14:58:42 -0500143 /p:Configuration=%conf% /p:Platform=%platf%^
144 /p:IncludeExternals=%IncludeExternals%^
Paul Monsonf96e7fd2019-05-17 10:07:24 -0700145 /p:IncludeCTypes=%IncludeCTypes%^
Zachary Ware6b6e6872017-06-10 14:58:42 -0500146 /p:IncludeSSL=%IncludeSSL% /p:IncludeTkinter=%IncludeTkinter%^
147 /p:UseTestMarker=%UseTestMarker% %GITProperty%^
148 %1 %2 %3 %4 %5 %6 %7 %8 %9
149
150@echo off
151goto :eof
152
153:Version
154rem Display the current build version information
Jeremy Klothf46eccd2018-12-09 20:59:32 -0700155call "%dir%find_msbuild.bat" %MSBUILD%
156if not ERRORLEVEL 1 %MSBUILD% "%dir%pythoncore.vcxproj" /t:ShowVersionInfo /v:m /nologo %1 %2 %3 %4 %5 %6 %7 %8 %9