Zachary Ware | 6b6e687 | 2017-06-10 14:58:42 -0500 | [diff] [blame] | 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.Alternatively you can put extra flags for MSBuild in a file named |
| 15 | echo.`msbuild.rsp` in the `PCbuild` directory, one flag per line. This file |
| 16 | echo.will be picked automatically by MSBuild. Flags put in this file does not |
| 17 | echo.need to be quoted. You can still use environment variables inside the |
| 18 | echo.response file. |
| 19 | echo. |
| 20 | echo.Available flags: |
| 21 | echo. -h Display this help message |
| 22 | echo. -V Display version information for the current build |
| 23 | echo. -r Target Rebuild instead of Build |
| 24 | echo. -d Set the configuration to Debug |
| 25 | echo. -e Build external libraries fetched by get_externals.bat |
| 26 | echo. Extension modules that depend on external libraries will not attempt |
| 27 | echo. to build if this flag is not present |
| 28 | echo. -m Enable parallel build (enabled by default) |
| 29 | echo. -M Disable parallel build |
| 30 | echo. -v Increased output messages |
| 31 | echo. -k Attempt to kill any running Pythons before building (usually done |
| 32 | echo. automatically by the pythoncore project) |
| 33 | echo. --pgo Build with Profile-Guided Optimization. This flag |
| 34 | echo. overrides -c and -d |
| 35 | echo. --test-marker Enable the test marker within the build. |
| 36 | echo. |
| 37 | echo.Available flags to avoid building certain modules. |
| 38 | echo.These flags have no effect if '-e' is not given: |
| 39 | echo. --no-ssl Do not attempt to build _ssl |
| 40 | echo. --no-tkinter Do not attempt to build Tkinter |
| 41 | echo. |
| 42 | echo.Available arguments: |
| 43 | echo. -c Release ^| Debug ^| PGInstrument ^| PGUpdate |
| 44 | echo. Set the configuration (default: Release) |
| 45 | echo. -p x64 ^| Win32 |
| 46 | echo. Set the platform (default: Win32) |
| 47 | echo. -t Build ^| Rebuild ^| Clean ^| CleanAll |
| 48 | echo. Set the target manually |
| 49 | echo. --pgo-job The job to use for PGO training; implies --pgo |
| 50 | echo. (default: "-m test --pgo") |
| 51 | exit /b 127 |
| 52 | |
| 53 | :Run |
| 54 | setlocal |
| 55 | set platf=Win32 |
| 56 | set vs_platf=x86 |
| 57 | set conf=Release |
| 58 | set target=Build |
| 59 | set dir=%~dp0 |
| 60 | set parallel=/m |
| 61 | set verbose=/nologo /v:m |
| 62 | set kill= |
| 63 | set do_pgo= |
| 64 | set pgo_job=-m test --pgo |
| 65 | set on_64_bit=true |
| 66 | |
| 67 | rem This may not be 100% accurate, but close enough. |
| 68 | if "%ProgramFiles(x86)%"=="" (set on_64_bit=false) |
| 69 | |
| 70 | :CheckOpts |
| 71 | if "%~1"=="-h" goto Usage |
| 72 | if "%~1"=="-c" (set conf=%2) & shift & shift & goto CheckOpts |
| 73 | if "%~1"=="-p" (set platf=%2) & shift & shift & goto CheckOpts |
| 74 | if "%~1"=="-r" (set target=Rebuild) & shift & goto CheckOpts |
| 75 | if "%~1"=="-t" (set target=%2) & shift & shift & goto CheckOpts |
| 76 | if "%~1"=="-d" (set conf=Debug) & shift & goto CheckOpts |
| 77 | if "%~1"=="-m" (set parallel=/m) & shift & goto CheckOpts |
| 78 | if "%~1"=="-M" (set parallel=) & shift & goto CheckOpts |
| 79 | if "%~1"=="-v" (set verbose=/v:n) & shift & goto CheckOpts |
| 80 | if "%~1"=="-k" (set kill=true) & shift & goto CheckOpts |
| 81 | if "%~1"=="--pgo" (set do_pgo=true) & shift & goto CheckOpts |
| 82 | if "%~1"=="--pgo-job" (set do_pgo=true) & (set pgo_job=%~2) & shift & shift & goto CheckOpts |
| 83 | if "%~1"=="--test-marker" (set UseTestMarker=true) & shift & goto CheckOpts |
| 84 | if "%~1"=="-V" shift & goto Version |
| 85 | rem These use the actual property names used by MSBuild. We could just let |
| 86 | rem them in through the environment, but we specify them on the command line |
| 87 | rem anyway for visibility so set defaults after this |
| 88 | if "%~1"=="-e" (set IncludeExternals=true) & shift & goto CheckOpts |
| 89 | if "%~1"=="--no-ssl" (set IncludeSSL=false) & shift & goto CheckOpts |
| 90 | if "%~1"=="--no-tkinter" (set IncludeTkinter=false) & shift & goto CheckOpts |
| 91 | |
| 92 | if "%IncludeExternals%"=="" set IncludeExternals=false |
| 93 | if "%IncludeSSL%"=="" set IncludeSSL=true |
| 94 | if "%IncludeTkinter%"=="" set IncludeTkinter=true |
| 95 | |
| 96 | if "%IncludeExternals%"=="true" call "%dir%get_externals.bat" |
| 97 | |
| 98 | if "%platf%"=="x64" ( |
| 99 | if "%on_64_bit%"=="true" ( |
| 100 | rem This ought to always be correct these days... |
| 101 | set vs_platf=amd64 |
| 102 | ) else ( |
| 103 | if "%do_pgo%"=="true" ( |
| 104 | echo.ERROR: Cannot cross-compile with PGO |
| 105 | echo. 32bit operating system detected, if this is incorrect, |
| 106 | echo. make sure the ProgramFiles(x86^) environment variable is set |
| 107 | exit /b 1 |
| 108 | ) |
| 109 | set vs_platf=x86_amd64 |
| 110 | ) |
| 111 | ) |
| 112 | |
| 113 | if not exist "%GIT%" where git > "%TEMP%\git.loc" 2> nul && set /P GIT= < "%TEMP%\git.loc" & del "%TEMP%\git.loc" |
| 114 | if exist "%GIT%" set GITProperty=/p:GIT="%GIT%" |
| 115 | if not exist "%GIT%" echo Cannot find Git on PATH & set GITProperty= |
| 116 | |
| 117 | rem Setup the environment |
| 118 | call "%dir%env.bat" %vs_platf% >nul |
| 119 | |
| 120 | if "%kill%"=="true" call :Kill |
| 121 | |
| 122 | if "%do_pgo%"=="true" ( |
| 123 | set conf=PGInstrument |
| 124 | call :Build %1 %2 %3 %4 %5 %6 %7 %8 %9 |
| 125 | del /s "%dir%\*.pgc" |
| 126 | del /s "%dir%\..\Lib\*.pyc" |
| 127 | echo on |
| 128 | call "%dir%\..\python.bat" %pgo_job% |
| 129 | @echo off |
| 130 | call :Kill |
| 131 | set conf=PGUpdate |
| 132 | set target=Build |
| 133 | ) |
| 134 | goto Build |
| 135 | :Kill |
| 136 | echo on |
| 137 | msbuild "%dir%\pythoncore.vcxproj" /t:KillPython %verbose%^ |
| 138 | /p:Configuration=%conf% /p:Platform=%platf%^ |
| 139 | /p:KillPython=true |
| 140 | |
| 141 | @echo off |
| 142 | goto :eof |
| 143 | |
| 144 | :Build |
| 145 | rem Call on MSBuild to do the work, echo the command. |
| 146 | rem Passing %1-9 is not the preferred option, but argument parsing in |
| 147 | rem batch is, shall we say, "lackluster" |
| 148 | echo on |
| 149 | msbuild "%dir%pcbuild.proj" /t:%target% %parallel% %verbose%^ |
| 150 | /p:Configuration=%conf% /p:Platform=%platf%^ |
| 151 | /p:IncludeExternals=%IncludeExternals%^ |
| 152 | /p:IncludeSSL=%IncludeSSL% /p:IncludeTkinter=%IncludeTkinter%^ |
| 153 | /p:UseTestMarker=%UseTestMarker% %GITProperty%^ |
| 154 | %1 %2 %3 %4 %5 %6 %7 %8 %9 |
| 155 | |
| 156 | @echo off |
| 157 | goto :eof |
| 158 | |
| 159 | :Version |
| 160 | rem Display the current build version information |
| 161 | msbuild "%dir%python.props" /t:ShowVersionInfo /v:m /nologo %1 %2 %3 %4 %5 %6 %7 %8 %9 |