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

Skip to content

Commit e12fa65

Browse files
committed
Issue #21907: Improved the batch scripts provided for building Python.
The user-facing scripts in PCbuild have been updated to be easier to use and the buildbot scripts in Tools\buildbot have been updated to use the user-facing scripts in PCbuild wherever possible.
1 parent b132069 commit e12fa65

17 files changed

Lines changed: 230 additions & 133 deletions

Misc/NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -746,6 +746,8 @@ Tools/Demos
746746
Windows
747747
-------
748748

749+
- Issue #21907: Improved the batch scripts provided for building Python.
750+
749751
- Issue #21671, CVE-2014-0224: The bundled version of OpenSSL has been
750752
updated to 1.0.1h.
751753

PCbuild/build.bat

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,34 @@
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 -d Set the configuration to Debug
10+
rem -e Pull in external libraries using get_externals.bat
11+
512
setlocal
613
set platf=Win32
714
set conf=Release
8-
set target=build
15+
set target=Build
916
set dir=%~dp0
1017

1118
:CheckOpts
1219
if "%1"=="-c" (set conf=%2) & shift & shift & goto CheckOpts
1320
if "%1"=="-p" (set platf=%2) & shift & shift & goto CheckOpts
14-
if "%1"=="-r" (set target=rebuild) & shift & goto CheckOpts
21+
if "%1"=="-r" (set target=Rebuild) & shift & goto CheckOpts
1522
if "%1"=="-d" (set conf=Debug) & shift & goto CheckOpts
23+
if "%1"=="-e" call "%dir%get_externals.bat" & shift & goto CheckOpts
24+
25+
if "%platf%"=="x64" (set vs_platf=x86_amd64)
26+
27+
rem Setup the environment
28+
call "%VS100COMNTOOLS%..\..\VC\vcvarsall.bat" %vs_platf%
1629

17-
set cmd=msbuild /p:useenv=true %dir%pcbuild.sln /t:%target% /p:Configuration=%conf% /p:Platform=%platf%
18-
echo %cmd%
19-
%cmd%
30+
rem Call on MSBuild to do the work, echo the command.
31+
rem Passing %1-9 is not the preferred option, but argument parsing in
32+
rem batch is, shall we say, "lackluster"
33+
echo on
34+
msbuild "%dir%pcbuild.sln" /t:%target% /p:Configuration=%conf% /p:Platform=%platf% %1 %2 %3 %4 %5 %6 %7 %8 %9

PCbuild/build_pgo.bat

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ setlocal
99
set platf=Win32
1010

1111
rem use the performance testsuite. This is quick and simple
12-
set job1=..\tools\pybench\pybench.py -n 1 -C 1 --with-gc
13-
set path1=..\tools\pybench
12+
set job1=%~dp0..\tools\pybench\pybench.py -n 1 -C 1 --with-gc
13+
set path1=%~dp0..\tools\pybench
1414

1515
rem or the whole testsuite for more thorough testing
16-
set job2=..\lib\test\regrtest.py
17-
set path2=..\lib
16+
set job2=%~dp0..\lib\test\regrtest.py
17+
set path2=%~dp0..\lib
1818

1919
set job=%job1%
2020
set clrpath=%path1%
@@ -31,9 +31,9 @@ rem build the instrumented version
3131
call build -p %platf% -c PGInstrument
3232

3333
rem remove .pyc files, .pgc files and execute the job
34-
%PGI%\python.exe rmpyc.py %clrpath%
34+
%PGI%\python.exe rmpyc.py "%clrpath%"
3535
del %PGI%\*.pgc
36-
%PGI%\python.exe %job%
36+
%PGI%\python.exe "%job%"
3737

3838
rem finally build the optimized version
3939
if exist %PGO% del /s /q %PGO%

PCbuild/env.bat

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
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
62

73
echo Build environments: x86, ia64, amd64, x86_amd64, x86_ia64
84
echo.
9-
call "%VS10%\VC\vcvarsall.bat" %1
5+
call "%VS100COMNTOOLS%..\..\VC\vcvarsall.bat" %1

PCbuild/get_externals.bat

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

PCbuild/readme.txt

Lines changed: 40 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
Quick Start Guide
2+
-----------------
3+
4+
1. Install Microsoft Visual C++ 2010 SP1, any edition.
5+
2. Install Subversion, and make sure 'svn.exe' is on your PATH.
6+
3. Install NASM, and make sure 'nasm.exe' is on your PATH.
7+
4. Run "build.bat -e" to build Python in 32-bit Release configuration.
8+
5. (Optional, but recommended) Run the test suite with "rt.bat -q".
9+
10+
111
Building Python using Microsoft Visual C++
212
------------------------------------------
313

@@ -24,8 +34,8 @@ All you need to do to build is open the solution "pcbuild.sln" in Visual
2434
Studio, select the desired combination of configuration and platform,
2535
then build with "Build Solution" or the F7 keyboard shortcut. You can
2636
also build from the command line using the "build.bat" script in this
27-
directory. The solution is configured to build the projects in the
28-
correct order.
37+
directory; see below for details. The solution is configured to build
38+
the projects in the correct order.
2939

3040
The solution currently supports two platforms. The Win32 platform is
3141
used to build standard x86-compatible 32-bit binaries, output into this
@@ -56,6 +66,26 @@ Release
5666
settings, though without PGO.
5767

5868

69+
Building Python using the build.bat script
70+
----------------------------------------------
71+
72+
In this directory you can find build.bat, a script designed to make
73+
building Python on Windows simpler. The only absolute requirement for
74+
using this script is for the VS100COMNTOOLS environment variable to be
75+
properly set, which should be done by Microsoft Visual C++ 2010
76+
installation.
77+
78+
By default, build.bat will build Python in Release configuration for
79+
the 32-bit Win32 platform. It accepts several arguments to change
80+
this behavior:
81+
82+
-c <configuration> Set the configuration (see above)
83+
-d Shortcut for "-c Debug"
84+
-p <platform> Set the platform to build for ("Win32" or "x64")
85+
-r Rebuild instead of just building
86+
-e Use get_externals.bat to fetch external sources
87+
88+
5989
Legacy support
6090
--------------
6191

@@ -227,25 +257,18 @@ Getting External Sources
227257
The last category of sub-projects listed above wrap external projects
228258
Python doesn't control, and as such a little more work is required in
229259
order to download the relevant source files for each project before they
230-
can be built. The buildbots must ensure that all libraries are present
231-
before building, so the easiest approach is to run either external.bat
232-
or external-amd64.bat (depending on platform) in the ..\Tools\buildbot
233-
directory from ..\, i.e.:
234-
235-
C:\python\cpython\PCbuild>cd ..
236-
C:\python\cpython>Tools\buildbot\external.bat
237-
238-
This extracts all the external sub-projects from
260+
can be built. However, a simple script is provided to make this as
261+
painless as possible, called "get_externals.bat" and located in this
262+
directory. This script extracts all the external sub-projects from
239263
http://svn.python.org/projects/external
240-
via Subversion (so you'll need an svn.exe on your PATH) and places them
264+
via Subversion (so you'll need svn.exe on your PATH) and places them
241265
in ..\.. (relative to this directory).
242266

243267
It is also possible to download sources from each project's homepage,
244-
though you may have to change the names of some folders in order to make
245-
things work. For instance, if you were to download a version 5.0.7 of
246-
XZ Utils, you would need to extract the archive into ..\..\xz-5.0.5
247-
anyway, since that is where the solution is set to look for xz. The
248-
same is true for all other external projects.
268+
though you may have to change folder names or pass the names to MSBuild
269+
as the values of certain properties in order for the build solution to
270+
find them. This is an advanced topic and not necessarily fully
271+
supported.
249272

250273

251274
Building for AMD64

Tools/buildbot/build-amd64.bat

Lines changed: 1 addition & 5 deletions
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

Lines changed: 14 additions & 4 deletions
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 %*

Tools/buildbot/buildmsi.bat

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
11
@rem Used by the buildbot "buildmsi" step.
2+
setlocal
23

3-
cmd /c Tools\buildbot\external.bat
4+
set cwd=%CD%
45
@rem build release versions of things
5-
call "%VS100COMNTOOLS%vsvars32.bat"
6-
7-
@rem build Python
8-
msbuild /p:useenv=true PCbuild\pcbuild.sln /p:Configuration=Release /p:Platform=Win32
6+
call "%~dp0build.bat" -c Release
97

108
@rem build the documentation
11-
bash.exe -c 'cd Doc;make PYTHON=python2.5 update htmlhelp'
12-
"%ProgramFiles%\HTML Help Workshop\hhc.exe" Doc\build\htmlhelp\python26a3.hhp
9+
call "%~dp0..\..\Doc\make.bat" htmlhelp
1310

1411
@rem build the MSI file
15-
cd PC
12+
call "%VS100COMNTOOLS%..\..\VC\vcvarsall.bat" x86
13+
cd "%~dp0..\..\PC"
1614
nmake /f icons.mak
1715
cd ..\Tools\msi
1816
del *.msi
1917
nmake /f msisupport.mak
2018
%HOST_PYTHON% msi.py
2119

20+
cd "%cwd%"

Tools/buildbot/clean-amd64.bat

Lines changed: 1 addition & 9 deletions
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"

0 commit comments

Comments
 (0)