Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6460677

Browse files
committed
Issue #25348: Add --pgo and --pgo-job flags to PCbuild\build.bat
1 parent 3e00303 commit 6460677

File tree

3 files changed

+61
-51
lines changed

3 files changed

+61
-51
lines changed

Misc/NEWS

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,11 @@ Tests
151151
Build
152152
-----
153153

154+
- Issue #25348: Added ``--pgo`` and ``--pgo-job`` arguments to
155+
``PCbuild\build.bat`` for building with Profile-Guided Optimization. The
156+
old ``PCbuild\build_pgo.bat`` script is now deprecated, and simply calls
157+
``PCbuild\build.bat --pgo %*``.
158+
154159
- Issue #25827: Add support for building with ICC to ``configure``, including
155160
a new ``--with-icc`` flag.
156161

PCbuild/build.bat

Lines changed: 52 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ echo. -M Disable parallel build
2525
echo. -v Increased output messages
2626
echo. -k Attempt to kill any running Pythons before building (usually done
2727
echo. automatically by the pythoncore project)
28+
echo. --pgo Build with Profile-Guided Optimization. This flag
29+
echo. overrides -c and -d
30+
echo. --test-marker Enable the test marker within the build.
2831
echo.
2932
echo.Available flags to avoid building certain modules.
3033
echo.These flags have no effect if '-e' is not given:
@@ -38,7 +41,8 @@ echo. -p x64 ^| Win32
3841
echo. Set the platform (default: Win32)
3942
echo. -t Build ^| Rebuild ^| Clean ^| CleanAll
4043
echo. Set the target manually
41-
echo. --test-marker Enable the test marker within the build.
44+
echo. --pgo-job The job to use for PGO training; implies --pgo
45+
echo. (default: "-m test --pgo")
4246
exit /b 127
4347

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

5565
:CheckOpts
5666
if "%~1"=="-h" goto Usage
@@ -63,6 +73,8 @@ if "%~1"=="-m" (set parallel=/m) & shift & goto CheckOpts
6373
if "%~1"=="-M" (set parallel=) & shift & goto CheckOpts
6474
if "%~1"=="-v" (set verbose=/v:n) & shift & goto CheckOpts
6575
if "%~1"=="-k" (set kill=true) & shift & goto CheckOpts
76+
if "%~1"=="--pgo" (set do_pgo=true) & shift & goto CheckOpts
77+
if "%~1"=="--pgo-job" (set do_pgo=true) & (set pgo_job=%~2) & shift & shift & goto CheckOpts
6678
if "%~1"=="--test-marker" (set UseTestMarker=true) & shift & goto CheckOpts
6779
if "%~1"=="-V" shift & goto Version
6880
rem These use the actual property names used by MSBuild. We could just let
@@ -78,15 +90,49 @@ if "%IncludeTkinter%"=="" set IncludeTkinter=true
7890

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

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

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

86-
if "%kill%"=="true" (
87-
msbuild /v:m /nologo /target:KillPython "%dir%\pythoncore.vcxproj" /p:Configuration=%conf% /p:Platform=%platf% /p:KillPython=true
111+
if "%kill%"=="true" call :Kill
112+
113+
if "%do_pgo%"=="true" (
114+
set conf=PGInstrument
115+
call :Build
116+
del /s "%dir%\*.pgc"
117+
del /s "%dir%\..\Lib\*.pyc"
118+
echo on
119+
call "%dir%\..\python.bat" %pgo_job%
120+
@echo off
121+
call :Kill
122+
set conf=PGUpdate
88123
)
124+
goto Build
89125

126+
:Kill
127+
echo on
128+
msbuild "%dir%\pythoncore.vcxproj" /t:KillPython %verbose%^
129+
/p:Configuration=%conf% /p:Platform=%platf%^
130+
/p:KillPython=true
131+
132+
@echo off
133+
goto :eof
134+
135+
:Build
90136
rem Call on MSBuild to do the work, echo the command.
91137
rem Passing %1-9 is not the preferred option, but argument parsing in
92138
rem batch is, shall we say, "lackluster"
@@ -98,7 +144,8 @@ msbuild "%dir%pcbuild.proj" /t:%target% %parallel% %verbose%^
98144
/p:UseTestMarker=%UseTestMarker%^
99145
%1 %2 %3 %4 %5 %6 %7 %8 %9
100146

101-
@goto :eof
147+
@echo off
148+
goto :eof
102149

103150
:Version
104151
rem Display the current build version information

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 %*

0 commit comments

Comments
 (0)