Skip to content

Commit a8dbd93

Browse files
committed
Issue python#25348: Add --pgo and --pgo-job flags to PCbuild\build.bat
1 parent b45bed1 commit a8dbd93

4 files changed

Lines changed: 67 additions & 49 deletions

File tree

‎Misc/NEWS‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,11 @@ Tests
8585
Build
8686
-----
8787

88+
- Issue #25348: Added ``--pgo`` and ``--pgo-job`` arguments to
89+
``PCbuild\build.bat`` for building with Profile-Guided Optimization. The
90+
old ``PCbuild\build_pgo.bat`` script is now deprecated, and simply calls
91+
``PCbuild\build.bat --pgo %*``.
92+
8893
- Issue #25827: Add support for building with ICC to ``configure``, including
8994
a new ``--with-icc`` flag.
9095

‎PCbuild/build.bat‎

Lines changed: 52 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ echo. -M Disable parallel build (disabled by default)
2424
echo. -v Increased output messages
2525
echo. -k Attempt to kill any running Pythons before building (usually done
2626
echo. automatically by the pythoncore project)
27+
echo. --pgo Build with Profile-Guided Optimization. This flag
28+
echo. overrides -c and -d
2729
echo.
2830
echo.Available flags to avoid building certain modules.
2931
echo.These flags have no effect if '-e' is not given:
@@ -38,6 +40,8 @@ echo. -p x64 ^| Win32
3840
echo. Set the platform (default: Win32)
3941
echo. -t Build ^| Rebuild ^| Clean ^| CleanAll
4042
echo. Set the target manually
43+
echo. --pgo-job The job to use for PGO training; implies --pgo
44+
echo. (default: "-m test.regrtest --pgo")
4145
exit /b 127
4246

4347
:Run
@@ -50,6 +54,12 @@ set dir=%~dp0
5054
set parallel=
5155
set verbose=/nologo /v:m
5256
set kill=
57+
set do_pgo=
58+
set pgo_job=-m test.regrtest --pgo
59+
set on_64_bit=true
60+
61+
rem This may not be 100% accurate, but close enough.
62+
if "%ProgramFiles(x86)%"=="" (set on_64_bit=false)
5363

5464
:CheckOpts
5565
if "%~1"=="-h" goto Usage
@@ -62,6 +72,8 @@ if "%~1"=="-m" (set parallel=/m) & shift & goto CheckOpts
6272
if "%~1"=="-M" (set parallel=) & shift & goto CheckOpts
6373
if "%~1"=="-v" (set verbose=/v:n) & shift & goto CheckOpts
6474
if "%~1"=="-k" (set kill=true) & shift & goto CheckOpts
75+
if "%~1"=="--pgo" (set do_pgo=true) & shift & goto CheckOpts
76+
if "%~1"=="--pgo-job" (set do_pgo=true) & (set pgo_job=%~2) & shift & shift & goto CheckOpts
6577
rem These use the actual property names used by MSBuild. We could just let
6678
rem them in through the environment, but we specify them on the command line
6779
rem anyway for visibility so set defaults after this
@@ -77,15 +89,49 @@ if "%IncludeBsddb%"=="" set IncludeBsddb=true
7789

7890
if "%IncludeExternals%"=="true" call "%dir%get_externals.bat"
7991

80-
if "%platf%"=="x64" (set vs_platf=x86_amd64)
92+
if "%platf%"=="x64" (
93+
if "%on_64_bit%"=="true" (
94+
rem This ought to always be correct these days...
95+
set vs_platf=amd64
96+
) else (
97+
if "%do_pgo%"=="true" (
98+
echo.ERROR: Cannot cross-compile with PGO
99+
echo. 32bit operating system detected, if this is incorrect,
100+
echo. make sure the ProgramFiles(x86^) environment variable is set
101+
exit /b 1
102+
)
103+
set vs_platf=x86_amd64
104+
)
105+
)
81106

82107
rem Setup the environment
83108
call "%dir%env.bat" %vs_platf% >nul
84109

85-
if "%kill%"=="true" (
86-
msbuild /v:m /nologo /target:KillPython "%dir%\pythoncore.vcxproj" /p:Configuration=%conf% /p:Platform=%platf% /p:KillPython=true
110+
if "%kill%"=="true" call :Kill
111+
112+
if "%do_pgo%"=="true" (
113+
set conf=PGInstrument
114+
call :Build
115+
del /s "%dir%\*.pgc"
116+
del /s "%dir%\..\Lib\*.pyc"
117+
echo on
118+
call "%dir%\..\python.bat" %pgo_job%
119+
@echo off
120+
call :Kill
121+
set conf=PGUpdate
87122
)
123+
goto Build
124+
125+
:Kill
126+
echo on
127+
msbuild "%dir%\pythoncore.vcxproj" /t:KillPython %verbose%^
128+
/p:Configuration=%conf% /p:Platform=%platf%^
129+
/p:KillPython=true
130+
131+
@echo off
132+
goto :eof
88133

134+
:Build
89135
rem Call on MSBuild to do the work, echo the command.
90136
rem Passing %1-9 is not the preferred option, but argument parsing in
91137
rem batch is, shall we say, "lackluster"
@@ -96,3 +142,6 @@ msbuild "%dir%pcbuild.proj" /t:%target% %parallel% %verbose%^
96142
/p:IncludeSSL=%IncludeSSL% /p:IncludeTkinter=%IncludeTkinter%^
97143
/p:IncludeBsddb=%IncludeBsddb%^
98144
%1 %2 %3 %4 %5 %6 %7 %8 %9
145+
146+
@echo off
147+
goto :eof

‎PCbuild/build_pgo.bat‎

Lines changed: 4 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,6 @@
11
@echo off
2-
rem A batch program to build PGO (Profile guided optimization) by first
3-
rem building instrumented binaries, then running the testsuite, and
4-
rem finally building the optimized code.
5-
rem Note, after the first instrumented run, one can just keep on
6-
rem building the PGUpdate configuration while developing.
2+
echo.DeprecationWarning:
3+
echo. This script is deprecated, use `build.bat --pgo` instead.
4+
echo.
75

8-
setlocal
9-
set platf=Win32
10-
set parallel=/m
11-
set dir=%~dp0
12-
13-
rem use the performance testsuite. This is quick and simple
14-
set job1="%dir%..\tools\pybench\pybench.py" -n 1 -C 1 --with-gc
15-
set path1="%dir%..\tools\pybench"
16-
17-
rem or the whole testsuite for more thorough testing
18-
set job2="%dir%..\lib\test\regrtest.py"
19-
set path2="%dir%..\lib"
20-
21-
set job=%job1%
22-
set clrpath=%path1%
23-
24-
:CheckOpts
25-
if "%1"=="-p" (set platf=%2) & shift & shift & goto CheckOpts
26-
if "%1"=="-2" (set job=%job2%) & (set clrpath=%path2%) & shift & goto CheckOpts
27-
if "%1"=="-M" (set parallel=) & shift & goto CheckOpts
28-
29-
30-
rem We cannot cross compile PGO builds, as the optimization needs to be run natively
31-
set vs_platf=x86
32-
set PGO=%dir%win32-pgo
33-
34-
if "%platf%"=="x64" (set vs_platf=amd64) & (set PGO=%dir%amd64-pgo)
35-
rem Setup the environment
36-
call "%dir%env.bat" %vs_platf%
37-
38-
39-
rem build the instrumented version
40-
msbuild "%dir%pcbuild.proj" %parallel% /t:Build /p:Configuration=PGInstrument /p:Platform=%platf% %1 %2 %3 %4 %5 %6 %7 %8 %9
41-
42-
rem remove .pyc files, .pgc files and execute the job
43-
"%PGO%\python.exe" "%dir%rmpyc.py" %clrpath%
44-
del "%PGO%\*.pgc"
45-
"%PGO%\python.exe" %job%
46-
47-
rem build optimized version
48-
msbuild "%dir%pcbuild.proj" %parallel% /t:Build /p:Configuration=PGUpdate /p:Platform=%platf% %1 %2 %3 %4 %5 %6 %7 %8 %9
6+
call "%~dp0build.bat" --pgo %*

‎PCbuild/env.bat‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ rem other than 'v90' is supported!
1010

1111
echo Build environments: x86, amd64, x86_amd64
1212
echo.
13+
14+
rem Set up the v90 tools first. This is mostly needed to allow PGInstrument
15+
rem builds to find the PGO DLL. Do it first so the newer MSBuild is found
16+
rem before the one from v90 (vcvarsall.bat prepends to PATH).
17+
call "%VS90COMNTOOLS%..\..\VC\vcvarsall.bat" %*
18+
1319
set VSTOOLS=%VS140COMNTOOLS%
1420
if "%VSTOOLS%"=="" set VSTOOLS=%VS120COMNTOOLS%
1521
if "%VSTOOLS%"=="" set VSTOOLS=%VS110COMNTOOLS%

0 commit comments

Comments
 (0)