|
| 1 | +@echo off |
| 2 | +goto Run |
| 3 | +:Usage |
| 4 | +echo.%~nx0 [flags and arguments] [quoted MSBuild options] |
| 5 | +echo. |
| 6 | +echo.Build CPython from the command line. Requires the appropriate |
| 7 | +echo.version(s) of Microsoft Visual Studio to be installed (see readme.txt). |
| 8 | +echo.Also requires Subversion (svn.exe) to be on PATH if the '-e' flag is |
| 9 | +echo.given. |
| 10 | +echo. |
| 11 | +echo.After the flags recognized by this script, up to 9 arguments to be passed |
| 12 | +echo.directly to MSBuild may be passed. If the argument contains an '=', the |
| 13 | +echo.entire argument must be quoted (e.g. `%~nx0 "/p:PlatformToolset=v100"`) |
| 14 | +echo. |
| 15 | +echo.Available flags: |
| 16 | +echo. -h Display this help message |
| 17 | +echo. -V Display version information for the current build |
| 18 | +echo. -r Target Rebuild instead of Build |
| 19 | +echo. -d Set the configuration to Debug |
| 20 | +echo. -e Build external libraries fetched by get_externals.bat |
| 21 | +echo. Extension modules that depend on external libraries will not attempt |
| 22 | +echo. to build if this flag is not present |
| 23 | +echo. -m Enable parallel build (enabled by default) |
| 24 | +echo. -M Disable parallel build |
| 25 | +echo. -v Increased output messages |
| 26 | +echo. -k Attempt to kill any running Pythons before building (usually done |
| 27 | +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. |
| 31 | +echo. |
| 32 | +echo.Available flags to avoid building certain modules. |
| 33 | +echo.These flags have no effect if '-e' is not given: |
| 34 | +echo. --no-ssl Do not attempt to build _ssl |
| 35 | +echo. --no-tkinter Do not attempt to build Tkinter |
| 36 | +echo. |
| 37 | +echo.Available arguments: |
| 38 | +echo. -c Release ^| Debug ^| PGInstrument ^| PGUpdate |
| 39 | +echo. Set the configuration (default: Release) |
| 40 | +echo. -p x64 ^| Win32 |
| 41 | +echo. Set the platform (default: Win32) |
| 42 | +echo. -t Build ^| Rebuild ^| Clean ^| CleanAll |
| 43 | +echo. Set the target manually |
| 44 | +echo. --pgo-job The job to use for PGO training; implies --pgo |
| 45 | +echo. (default: "-m test --pgo") |
| 46 | +exit /b 127 |
| 47 | + |
| 48 | +:Run |
| 49 | +setlocal |
| 50 | +set platf=Win32 |
| 51 | +set vs_platf=x86 |
| 52 | +set conf=Release |
| 53 | +set target=Build |
| 54 | +set dir=%~dp0 |
| 55 | +set parallel=/m |
| 56 | +set verbose=/nologo /v:m |
| 57 | +set kill= |
| 58 | +set do_pgo= |
| 59 | +set pgo_job=-m test --pgo |
| 60 | + |
| 61 | +:CheckOpts |
| 62 | +if "%~1"=="-h" goto Usage |
| 63 | +if "%~1"=="-c" (set conf=%2) & shift & shift & goto CheckOpts |
| 64 | +if "%~1"=="-p" (set platf=%2) & shift & shift & goto CheckOpts |
| 65 | +if "%~1"=="-r" (set target=Rebuild) & shift & goto CheckOpts |
| 66 | +if "%~1"=="-t" (set target=%2) & shift & shift & goto CheckOpts |
| 67 | +if "%~1"=="-d" (set conf=Debug) & shift & goto CheckOpts |
| 68 | +if "%~1"=="-m" (set parallel=/m) & shift & goto CheckOpts |
| 69 | +if "%~1"=="-M" (set parallel=) & shift & goto CheckOpts |
| 70 | +if "%~1"=="-v" (set verbose=/v:n) & shift & goto CheckOpts |
| 71 | +if "%~1"=="-k" (set kill=true) & shift & goto CheckOpts |
| 72 | +if "%~1"=="--pgo" (set do_pgo=true) & shift & goto CheckOpts |
| 73 | +if "%~1"=="--pgo-job" (set do_pgo=true) & (set pgo_job=%~2) & shift & shift & goto CheckOpts |
| 74 | +if "%~1"=="--test-marker" (set UseTestMarker=true) & shift & goto CheckOpts |
| 75 | +if "%~1"=="-V" shift & goto Version |
| 76 | +rem These use the actual property names used by MSBuild. We could just let |
| 77 | +rem them in through the environment, but we specify them on the command line |
| 78 | +rem anyway for visibility so set defaults after this |
| 79 | +if "%~1"=="-e" (set IncludeExternals=true) & shift & goto CheckOpts |
| 80 | +if "%~1"=="--no-ssl" (set IncludeSSL=false) & shift & goto CheckOpts |
| 81 | +if "%~1"=="--no-tkinter" (set IncludeTkinter=false) & shift & goto CheckOpts |
| 82 | + |
| 83 | +if "%IncludeExternals%"=="" set IncludeExternals=false |
| 84 | +if "%IncludeSSL%"=="" set IncludeSSL=true |
| 85 | +if "%IncludeTkinter%"=="" set IncludeTkinter=true |
| 86 | + |
| 87 | +rem UBS has called get_externals_activestate.bat before running the build |
| 88 | +rem if "%IncludeExternals%"=="true" call "%dir%get_externals_activestate.bat" |
| 89 | + |
| 90 | +if "%do_pgo%" EQU "true" if "%platf%" EQU "x64" ( |
| 91 | + if "%PROCESSOR_ARCHITEW6432%" NEQ "AMD64" if "%PROCESSOR_ARCHITECTURE%" NEQ "AMD64" ( |
| 92 | + echo.ERROR: Cannot cross-compile with PGO |
| 93 | + echo. 32bit operating system detected. Ensure your PROCESSOR_ARCHITECTURE |
| 94 | + echo. and PROCESSOR_ARCHITEW6432 environment variables are correct. |
| 95 | + exit /b 1 |
| 96 | + ) |
| 97 | +) |
| 98 | + |
| 99 | +if "%platf%"=="x64" (set vs_platf=x86_amd64) |
| 100 | + |
| 101 | +rem Setup the environment |
| 102 | +call "%dir%env.bat" %vs_platf% >nul |
| 103 | + |
| 104 | +if "%kill%"=="true" call :Kill |
| 105 | + |
| 106 | +if "%do_pgo%"=="true" ( |
| 107 | + set conf=PGInstrument |
| 108 | + call :Build |
| 109 | + del /s "%dir%\*.pgc" |
| 110 | + del /s "%dir%\..\Lib\*.pyc" |
| 111 | + echo on |
| 112 | + call "%dir%\..\python.bat" %pgo_job% |
| 113 | + @echo off |
| 114 | + call :Kill |
| 115 | + set conf=PGUpdate |
| 116 | +) |
| 117 | +goto Build |
| 118 | + |
| 119 | +:Kill |
| 120 | +echo on |
| 121 | +msbuild "%dir%\pythoncore.vcxproj" /t:KillPython %verbose%^ |
| 122 | + /p:Configuration=%conf% /p:Platform=%platf%^ |
| 123 | + /p:KillPython=true |
| 124 | + |
| 125 | +@echo off |
| 126 | +goto :eof |
| 127 | + |
| 128 | +:Build |
| 129 | +rem Call on MSBuild to do the work, echo the command. |
| 130 | +rem Passing %1-9 is not the preferred option, but argument parsing in |
| 131 | +rem batch is, shall we say, "lackluster" |
| 132 | +echo on |
| 133 | +if "%IncludeSSL%"=="true" ( |
| 134 | + if "%PERL%" == "" where perl > "%TEMP%\perl.loc" 2> nul && set /P PERL= <"%TEMP%\perl.loc" & del "%TEMP%\perl.loc" |
| 135 | + if "%PERL%" == "" (echo Cannot locate perl.exe on PATH or as PERL variable & exit /b 4) |
| 136 | + msbuild "%dir%openssl.vcxproj"^ |
| 137 | + /p:Configuration=%conf% /p:Platform=%platf% |
| 138 | +) |
| 139 | +msbuild "%dir%pcbuild.proj" /t:%target% %parallel% %verbose%^ |
| 140 | + /p:Configuration=%conf% /p:Platform=%platf%^ |
| 141 | + /p:IncludeExternals=%IncludeExternals%^ |
| 142 | + /p:IncludeSSL=%IncludeSSL% /p:IncludeTkinter=%IncludeTkinter%^ |
| 143 | + /p:UseTestMarker=%UseTestMarker%^ |
| 144 | + %1 %2 %3 %4 %5 %6 %7 %8 %9 |
| 145 | + |
| 146 | +@echo off |
| 147 | +goto :eof |
| 148 | + |
| 149 | +:Version |
| 150 | +rem Display the current build version information |
| 151 | +msbuild "%dir%python.props" /t:ShowVersionInfo /v:m /nologo %1 %2 %3 %4 %5 %6 %7 %8 %9 |
0 commit comments