Skip to content

Commit 6250df8

Browse files
committed
Clean up/refactor the batch scripts used for building on Windows.
This is mostly a backport of issue #21907, but also includes a few extras necessary to make the bulidbot scripts as thin as possible.
1 parent 17d5f47 commit 6250df8

14 files changed

+262
-200
lines changed

PCbuild/build.bat

+98-10
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,107 @@
11
@echo off
2-
rem A batch program to build or rebuild a particular configuration.
2+
rem A batch program to build or rebuild a particular configuration,
33
rem just for convenience.
44

5+
rem Arguments:
6+
rem -c Set the configuration (default: Release)
7+
rem -p Set the platform (x64 or Win32, default: Win32)
8+
rem -r Target Rebuild instead of Build
9+
rem -t Set the target manually (Build, Rebuild, or Clean)
10+
rem -d Set the configuration to Debug
11+
rem -e Pull in external libraries using get_externals.bat
12+
rem -m Enable parallel build
13+
rem -M Disable parallel build (disabled by default)
14+
rem -v Increased output messages
15+
rem -k Attempt to kill any running Pythons before building
16+
517
setlocal
618
set platf=Win32
19+
set vs_platf=x86
720
set conf=Release
8-
set target=build
21+
set target=Build
922
set dir=%~dp0
23+
set parallel=
24+
set verbose=/nologo /v:m
25+
set kill=
26+
set build_tkinter=
1027

1128
:CheckOpts
12-
if "%1"=="-c" (set conf=%2) & shift & shift & goto CheckOpts
13-
if "%1"=="-p" (set platf=%2) & shift & shift & goto CheckOpts
14-
if "%1"=="-r" (set target=rebuild) & shift & goto CheckOpts
15-
if "%1"=="-d" (set conf=Debug) & shift & goto CheckOpts
16-
17-
set cmd=msbuild /p:useenv=true %dir%pcbuild.sln /t:%target% /p:Configuration=%conf% /p:Platform=%platf%
18-
echo %cmd%
19-
%cmd%
29+
if '%1'=='-c' (set conf=%2) & shift & shift & goto CheckOpts
30+
if '%1'=='-p' (set platf=%2) & shift & shift & goto CheckOpts
31+
if '%1'=='-r' (set target=Rebuild) & shift & goto CheckOpts
32+
if '%1'=='-t' (set target=%2) & shift & shift & goto CheckOpts
33+
if '%1'=='-d' (set conf=Debug) & shift & goto CheckOpts
34+
if '%1'=='-e' call "%dir%get_externals.bat" & (set build_tkinter=true) & shift & goto CheckOpts
35+
if '%1'=='-m' (set parallel=/m) & shift & goto CheckOpts
36+
if '%1'=='-M' (set parallel=) & shift & goto CheckOpts
37+
if '%1'=='-v' (set verbose=/v:n) & shift & goto CheckOpts
38+
if '%1'=='-k' (set kill=true) & shift & goto CheckOpts
39+
40+
if '%conf%'=='Debug' (set dbg_ext=_d) else (set dbg_ext=)
41+
if '%platf%'=='x64' (
42+
set vs_platf=x86_amd64
43+
set builddir=%dir%amd64\
44+
) else (
45+
set builddir=%dir%
46+
)
47+
48+
rem Setup the environment
49+
call "%dir%env.bat" %vs_platf%
50+
51+
if '%kill%'=='true' (
52+
msbuild "%dir%kill_python.vcxproj" %verbose% /p:Configuration=%conf% /p:Platform=%platf% && "%builddir%kill_python%dbg_ext%.exe"
53+
)
54+
55+
set externals_dir=%dir%..\externals
56+
if '%build_tkinter%'=='true' (
57+
if '%platf%'=='x64' (
58+
set tcltkdir=%externals_dir%\tcltk64
59+
set machine=AMD64
60+
) else (
61+
set tcltkdir=%externals_dir%\tcltk
62+
set machine=IX86
63+
)
64+
if '%conf%'=='Debug' (
65+
set tcl_dbg_ext=g
66+
set debug_flag=1
67+
set options=symbols
68+
) else (
69+
set tcl_dbg_ext=
70+
set debug_flag=0
71+
set options=
72+
)
73+
set tcldir=%externals_dir%\tcl-8.6.1.0
74+
set tkdir=%externals_dir%\tk-8.6.1.0
75+
set tixdir=%externals_dir%\tix-8.4.3.4
76+
)
77+
if '%build_tkinter%'=='true' (
78+
if not exist "%tcltkdir%\bin\tcl86t%tcl_dbg_ext%.dll" (
79+
@rem all and install need to be separate invocations, otherwise nmakehlp is not found on install
80+
pushd "%tcldir%\win"
81+
nmake -f makefile.vc MACHINE=%machine% OPTS=%options% INSTALLDIR="%tcltkdir%" clean all
82+
nmake -f makefile.vc MACHINE=%machine% OPTS=%options% INSTALLDIR="%tcltkdir%" install-binaries install-libraries
83+
popd
84+
)
85+
86+
if not exist "%tcltkdir%\bin\tk86t%tcl_dbg_ext%.dll" (
87+
pushd "%tkdir%\win"
88+
nmake -f makefile.vc MACHINE=%machine% OPTS=%options% INSTALLDIR="%tcltkdir%" TCLDIR="%tcldir%" clean
89+
nmake -f makefile.vc MACHINE=%machine% OPTS=%options% INSTALLDIR="%tcltkdir%" TCLDIR="%tcldir%" all
90+
nmake -f makefile.vc MACHINE=%machine% OPTS=%options% INSTALLDIR="%tcltkdir%" TCLDIR="%tcldir%" install-binaries install-libraries
91+
popd
92+
)
93+
94+
if not exist "%tcltkdir%\lib\tix8.4.3\tix84%tcl_dbg_ext%.dll" (
95+
pushd "%tixdir%\win"
96+
nmake -f python.mak DEBUG=%debug_flag% MACHINE=%machine% TCL_DIR="%tcldir%" TK_DIR="%tkdir%" INSTALL_DIR="%tcltkdir%" clean
97+
nmake -f python.mak DEBUG=%debug_flag% MACHINE=%machine% TCL_DIR="%tcldir%" TK_DIR="%tkdir%" INSTALL_DIR="%tcltkdir%" all
98+
nmake -f python.mak DEBUG=%debug_flag% MACHINE=%machine% TCL_DIR="%tcldir%" TK_DIR="%tkdir%" INSTALL_DIR="%tcltkdir%" install
99+
popd
100+
)
101+
)
102+
103+
rem Call on MSBuild to do the work, echo the command.
104+
rem Passing %1-9 is not the preferred option, but argument parsing in
105+
rem batch is, shall we say, "lackluster"
106+
echo on
107+
msbuild "%dir%pcbuild.sln" /t:%target% %parallel% %verbose% /p:Configuration=%conf% /p:Platform=%platf% %1 %2 %3 %4 %5 %6 %7 %8 %9

PCbuild/env.bat

+1-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
11
@echo off
2-
set VS10=%ProgramFiles(x86)%\Microsoft Visual Studio 10.0
3-
IF EXIST "%VS10%" GOTO ok
4-
set VS10=%ProgramFiles%\Microsoft Visual Studio 10.0
5-
:ok
6-
72
echo Build environments: x86, ia64, amd64, x86_amd64, x86_ia64
83
echo.
9-
call "%VS10%\VC\vcvarsall.bat" %1
4+
call "%VS100COMNTOOLS%..\..\VC\vcvarsall.bat" %*

PCbuild/get_externals.bat

+103
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
@echo off
2+
setlocal
3+
rem Simple script to fetch source for external libraries
4+
5+
if not exist "%~dp0..\externals" mkdir "%~dp0..\externals"
6+
pushd "%~dp0..\externals"
7+
8+
if "%SVNROOT%"=="" set SVNROOT=http://svn.python.org/projects/external/
9+
10+
rem Optionally clean up first. Be warned that this can be very destructive!
11+
if not "%1"=="" (
12+
for %%c in (-c --clean --clean-only) do (
13+
if "%1"=="%%c" goto clean
14+
)
15+
goto usage
16+
)
17+
goto fetch
18+
19+
:clean
20+
echo.Cleaning up external libraries.
21+
for /D %%d in (
22+
bzip2-*
23+
db-*
24+
nasm-*
25+
openssl-*
26+
tcl-*
27+
tcltk*
28+
tk-*
29+
tix-*
30+
sqlite-*
31+
xz-*
32+
) do (
33+
echo.Removing %%d
34+
rmdir /s /q %%d
35+
)
36+
if "%1"=="--clean-only" (
37+
goto end
38+
)
39+
40+
:fetch
41+
rem Fetch current versions
42+
43+
svn --version > nul 2>&1
44+
if ERRORLEVEL 9009 (
45+
echo.svn.exe must be on your PATH.
46+
echo.Try TortoiseSVN (http://tortoisesvn.net/^) and be sure to check the
47+
echo.command line tools option.
48+
popd
49+
exit /b 1
50+
)
51+
52+
echo.Fetching external libraries...
53+
54+
for %%e in (
55+
bzip2-1.0.6
56+
nasm-2.11.06
57+
openssl-1.0.2a
58+
tcl-8.6.1.0
59+
tk-8.6.1.0
60+
tix-8.4.3.4
61+
sqlite-3.8.3.1
62+
xz-5.0.5
63+
) do (
64+
if exist %%e (
65+
echo.%%e already exists, skipping.
66+
) else (
67+
echo.Fetching %%e...
68+
svn export %SVNROOT%%%e
69+
)
70+
)
71+
72+
goto end
73+
74+
:usage
75+
echo.invalid argument: %1
76+
echo.usage: %~n0 [[ -c ^| --clean ] ^| --clean-only ]
77+
echo.
78+
echo.Pull all sources necessary for compiling optional extension modules
79+
echo.that rely on external libraries. Requires svn.exe to be on your PATH
80+
echo.and pulls sources from %SVNROOT%.
81+
echo.
82+
echo.Use the -c or --clean option to clean up all external library sources
83+
echo.before pulling in the current versions.
84+
echo.
85+
echo.Use the --clean-only option to do the same cleaning, without pulling in
86+
echo.anything new.
87+
echo.
88+
echo.Only the first argument is checked, all others are ignored.
89+
echo.
90+
echo.**WARNING**: the cleaning options unconditionally remove any directory
91+
echo.that is a child of
92+
echo. %CD%
93+
echo.and matches wildcard patterns beginning with bzip2-, db-, nasm-, openssl-,
94+
echo.tcl-, tcltk, tk-, tix-, sqlite-, or xz-, and as such has the potential
95+
echo.to be very destructive if you are not aware of what it is doing. Use with
96+
echo.caution!
97+
popd
98+
exit /b -1
99+
100+
101+
:end
102+
echo Finished.
103+
popd

PCbuild/rt.bat

+9-7
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ rem -q runs the tests just once, and without deleting .py[co] files.
99
rem -x64 Run the 64-bit build of python (or python_d if -d was specified)
1010
rem from the 'amd64' dir instead of the 32-bit build in this dir.
1111
rem All leading instances of these switches are shifted off, and
12-
rem whatever remains is passed to regrtest.py. For example,
12+
rem whatever remains (up to 9 arguments) is passed to regrtest.py.
13+
rem For example,
1314
rem rt -O -d -x test_thread
1415
rem runs
1516
rem python_d -O ../lib/test/regrtest.py -x test_thread
@@ -26,7 +27,8 @@ rem rt -u "network,largefile"
2627

2728
setlocal
2829

29-
set prefix=.\
30+
set pcbuild=%~dp0
31+
set prefix=%pcbuild%
3032
set suffix=
3133
set qmode=
3234
set dashO=
@@ -36,15 +38,15 @@ set tcltk=tcltk
3638
if "%1"=="-O" (set dashO=-O) & shift & goto CheckOpts
3739
if "%1"=="-q" (set qmode=yes) & shift & goto CheckOpts
3840
if "%1"=="-d" (set suffix=_d) & shift & goto CheckOpts
39-
if "%1"=="-x64" (set prefix=amd64) & (set tcltk=tcltk64) & shift & goto CheckOpts
41+
if "%1"=="-x64" (set prefix=%prefix%amd64) & (set tcltk=tcltk64) & shift & goto CheckOpts
4042

41-
PATH %PATH%;%~dp0..\externals\%tcltk%\bin
42-
set exe=%prefix%\python%suffix%
43-
set cmd=%exe% %dashO% -Wd -E -bb ../lib/test/regrtest.py %1 %2 %3 %4 %5 %6 %7 %8 %9
43+
PATH %PATH%;%pcbuild%..\externals\%tcltk%\bin
44+
set exe="%prefix%\python%suffix%"
45+
set cmd=%exe% %dashO% -Wd -E -bb "%pcbuild%..\lib\test\regrtest.py" %1 %2 %3 %4 %5 %6 %7 %8 %9
4446
if defined qmode goto Qmode
4547

4648
echo Deleting .pyc/.pyo files ...
47-
%exe% rmpyc.py
49+
%exe% "%pcbuild%\rmpyc.py"
4850

4951
echo on
5052
%cmd%

Tools/buildbot/README.tcltk-AMD64

-36
This file was deleted.

Tools/buildbot/build-amd64.bat

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,2 @@
11
@rem Used by the buildbot "compile" step.
2-
cmd /c Tools\buildbot\external-amd64.bat
3-
call "%VS100COMNTOOLS%\..\..\VC\vcvarsall.bat" x86_amd64
4-
cmd /c Tools\buildbot\clean-amd64.bat
5-
6-
msbuild PCbuild\pcbuild.sln /p:Configuration=Debug /p:Platform=x64
2+
call "%~dp0build.bat" -p x64 %*

Tools/buildbot/build.bat

+14-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,17 @@
11
@rem Used by the buildbot "compile" step.
2-
cmd /c Tools\buildbot\external.bat
3-
call "%VS100COMNTOOLS%vsvars32.bat"
4-
cmd /c Tools\buildbot\clean.bat
52

6-
msbuild PCbuild\pcbuild.sln /p:Configuration=Debug /p:Platform=Win32
3+
@rem Clean up
4+
call "%~dp0clean.bat" %*
75

6+
@rem If you need the buildbots to start fresh (such as when upgrading to
7+
@rem a new version of an external library, especially Tcl/Tk):
8+
@rem 1) uncomment the following line:
9+
10+
@rem call "%~dp0..\..\PCbuild\get_externals.bat" --clean-only
11+
12+
@rem 2) commit and push
13+
@rem 3) wait for all Windows bots to start a build with that changeset
14+
@rem 4) re-comment, commit and push again
15+
16+
@rem Do the build
17+
call "%~dp0..\..\PCbuild\build.bat" -e -d -k -v %*

Tools/buildbot/clean-amd64.bat

+1-9
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,2 @@
11
@rem Used by the buildbot "clean" step.
2-
call "%VS100COMNTOOLS%\..\..\VC\vcvarsall.bat" x86_amd64
3-
@echo Deleting .pyc/.pyo files ...
4-
del /s Lib\*.pyc Lib\*.pyo
5-
@echo Deleting test leftovers ...
6-
rmdir /s /q build
7-
cd PCbuild
8-
msbuild /target:clean pcbuild.sln /p:Configuration=Release /p:PlatformTarget=x64
9-
msbuild /target:clean pcbuild.sln /p:Configuration=Debug /p:PlatformTarget=x64
10-
cd ..
2+
call "%~dp0clean.bat" -p x64 %*

Tools/buildbot/clean.bat

+16-8
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
1-
@rem Used by the buildbot "clean" step.
2-
call "%VS100COMNTOOLS%vsvars32.bat"
3-
@echo Deleting test leftovers ...
4-
rmdir /s /q build
5-
cd PCbuild
6-
msbuild /target:clean pcbuild.sln /p:Configuration=Release /p:PlatformTarget=x86
7-
msbuild /target:clean pcbuild.sln /p:Configuration=Debug /p:PlatformTarget=x86
8-
cd ..
1+
@echo off
2+
rem Used by the buildbot "clean" step.
3+
4+
setlocal
5+
set root=%~dp0..\..
6+
set pcbuild=%root%\PCbuild
7+
8+
echo Deleting build
9+
call "%pcbuild%\build.bat" -t Clean -k %*
10+
call "%pcbuild%\build.bat" -t Clean -k -d %*
11+
12+
echo Deleting .pyc/.pyo files ...
13+
del /s "%root%\Lib\*.pyc" "%root%\Lib\*.pyo"
14+
15+
echo Deleting test leftovers ...
16+
rmdir /s /q "%root%\build"

0 commit comments

Comments
 (0)