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). |
Zachary Ware | 6b6e687 | 2017-06-10 14:58:42 -0500 | [diff] [blame] | 8 | echo. |
| 9 | echo.After the flags recognized by this script, up to 9 arguments to be passed |
| 10 | echo.directly to MSBuild may be passed. If the argument contains an '=', the |
| 11 | echo.entire argument must be quoted (e.g. `%~nx0 "/p:PlatformToolset=v100"`). |
| 12 | echo.Alternatively you can put extra flags for MSBuild in a file named |
| 13 | echo.`msbuild.rsp` in the `PCbuild` directory, one flag per line. This file |
| 14 | echo.will be picked automatically by MSBuild. Flags put in this file does not |
| 15 | echo.need to be quoted. You can still use environment variables inside the |
| 16 | echo.response file. |
| 17 | echo. |
| 18 | echo.Available flags: |
| 19 | echo. -h Display this help message |
| 20 | echo. -V Display version information for the current build |
| 21 | echo. -r Target Rebuild instead of Build |
| 22 | echo. -d Set the configuration to Debug |
Zachary Ware | d01db1c | 2017-09-06 17:29:37 -0700 | [diff] [blame] | 23 | echo. -E Don't fetch or build external libraries. Extension modules that |
| 24 | echo. depend on external libraries will not attempt to build if this flag |
| 25 | echo. is present; -e is also accepted to explicitly enable fetching and |
| 26 | echo. building externals. |
Zachary Ware | 6b6e687 | 2017-06-10 14:58:42 -0500 | [diff] [blame] | 27 | echo. -m Enable parallel build (enabled by default) |
| 28 | echo. -M Disable parallel build |
| 29 | echo. -v Increased output messages |
| 30 | echo. -k Attempt to kill any running Pythons before building (usually done |
| 31 | echo. automatically by the pythoncore project) |
| 32 | echo. --pgo Build with Profile-Guided Optimization. This flag |
| 33 | echo. overrides -c and -d |
| 34 | echo. --test-marker Enable the test marker within the build. |
| 35 | echo. |
| 36 | echo.Available flags to avoid building certain modules. |
| 37 | echo.These flags have no effect if '-e' is not given: |
Paul Monson | f96e7fd | 2019-05-17 10:07:24 -0700 | [diff] [blame] | 38 | echo. --no-ctypes Do not attempt to build _ctypes |
Zachary Ware | 6b6e687 | 2017-06-10 14:58:42 -0500 | [diff] [blame] | 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) |
Paul Monson | f96e7fd | 2019-05-17 10:07:24 -0700 | [diff] [blame] | 45 | echo. -p x64 ^| Win32 ^| ARM ^| ARM64 |
Zachary Ware | 6b6e687 | 2017-06-10 14:58:42 -0500 | [diff] [blame] | 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 |
Zachary Ware | 6b6e687 | 2017-06-10 14:58:42 -0500 | [diff] [blame] | 56 | set conf=Release |
| 57 | set target=Build |
| 58 | set dir=%~dp0 |
| 59 | set parallel=/m |
| 60 | set verbose=/nologo /v:m |
| 61 | set kill= |
| 62 | set do_pgo= |
| 63 | set pgo_job=-m test --pgo |
Zachary Ware | 6b6e687 | 2017-06-10 14:58:42 -0500 | [diff] [blame] | 64 | |
| 65 | :CheckOpts |
| 66 | if "%~1"=="-h" goto Usage |
| 67 | if "%~1"=="-c" (set conf=%2) & shift & shift & goto CheckOpts |
| 68 | if "%~1"=="-p" (set platf=%2) & shift & shift & goto CheckOpts |
| 69 | if "%~1"=="-r" (set target=Rebuild) & shift & goto CheckOpts |
| 70 | if "%~1"=="-t" (set target=%2) & shift & shift & goto CheckOpts |
| 71 | if "%~1"=="-d" (set conf=Debug) & shift & goto CheckOpts |
| 72 | if "%~1"=="-m" (set parallel=/m) & shift & goto CheckOpts |
| 73 | if "%~1"=="-M" (set parallel=) & shift & goto CheckOpts |
| 74 | if "%~1"=="-v" (set verbose=/v:n) & shift & goto CheckOpts |
| 75 | 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 |
| 78 | if "%~1"=="--test-marker" (set UseTestMarker=true) & shift & goto CheckOpts |
Steve Dower | 21a92f8 | 2019-06-14 08:29:20 -0700 | [diff] [blame] | 79 | if "%~1"=="-V" shift & goto :Version |
Zachary Ware | 6b6e687 | 2017-06-10 14:58:42 -0500 | [diff] [blame] | 80 | rem These use the actual property names used by MSBuild. We could just let |
| 81 | rem them in through the environment, but we specify them on the command line |
| 82 | rem anyway for visibility so set defaults after this |
| 83 | if "%~1"=="-e" (set IncludeExternals=true) & shift & goto CheckOpts |
Zachary Ware | d01db1c | 2017-09-06 17:29:37 -0700 | [diff] [blame] | 84 | if "%~1"=="-E" (set IncludeExternals=false) & shift & goto CheckOpts |
Paul Monson | f96e7fd | 2019-05-17 10:07:24 -0700 | [diff] [blame] | 85 | if "%~1"=="--no-ctypes" (set IncludeCTypes=false) & shift & goto CheckOpts |
Zachary Ware | 6b6e687 | 2017-06-10 14:58:42 -0500 | [diff] [blame] | 86 | if "%~1"=="--no-ssl" (set IncludeSSL=false) & shift & goto CheckOpts |
| 87 | if "%~1"=="--no-tkinter" (set IncludeTkinter=false) & shift & goto CheckOpts |
| 88 | |
Steve Dower | 05f01d8 | 2017-09-07 11:49:23 -0700 | [diff] [blame] | 89 | if "%IncludeExternals%"=="" set IncludeExternals=true |
Paul Monson | f96e7fd | 2019-05-17 10:07:24 -0700 | [diff] [blame] | 90 | if "%IncludeCTypes%"=="" set IncludeCTypes=true |
Zachary Ware | 6b6e687 | 2017-06-10 14:58:42 -0500 | [diff] [blame] | 91 | if "%IncludeSSL%"=="" set IncludeSSL=true |
| 92 | if "%IncludeTkinter%"=="" set IncludeTkinter=true |
| 93 | |
| 94 | if "%IncludeExternals%"=="true" call "%dir%get_externals.bat" |
| 95 | |
Steve Dower | 40a23e8 | 2017-06-19 10:34:25 -0700 | [diff] [blame] | 96 | if "%do_pgo%" EQU "true" if "%platf%" EQU "x64" ( |
| 97 | if "%PROCESSOR_ARCHITEW6432%" NEQ "AMD64" if "%PROCESSOR_ARCHITECTURE%" NEQ "AMD64" ( |
| 98 | echo.ERROR: Cannot cross-compile with PGO |
| 99 | echo. 32bit operating system detected. Ensure your PROCESSOR_ARCHITECTURE |
| 100 | echo. and PROCESSOR_ARCHITEW6432 environment variables are correct. |
| 101 | exit /b 1 |
Zachary Ware | 6b6e687 | 2017-06-10 14:58:42 -0500 | [diff] [blame] | 102 | ) |
| 103 | ) |
| 104 | |
| 105 | if not exist "%GIT%" where git > "%TEMP%\git.loc" 2> nul && set /P GIT= < "%TEMP%\git.loc" & del "%TEMP%\git.loc" |
| 106 | if exist "%GIT%" set GITProperty=/p:GIT="%GIT%" |
| 107 | if not exist "%GIT%" echo Cannot find Git on PATH & set GITProperty= |
| 108 | |
| 109 | rem Setup the environment |
Steve Dower | 40a23e8 | 2017-06-19 10:34:25 -0700 | [diff] [blame] | 110 | call "%dir%find_msbuild.bat" %MSBUILD% |
| 111 | if ERRORLEVEL 1 (echo Cannot locate MSBuild.exe on PATH or as MSBUILD variable & exit /b 2) |
Zachary Ware | 6b6e687 | 2017-06-10 14:58:42 -0500 | [diff] [blame] | 112 | |
| 113 | if "%kill%"=="true" call :Kill |
Steve Dower | 21a92f8 | 2019-06-14 08:29:20 -0700 | [diff] [blame] | 114 | if ERRORLEVEL 1 exit /B 3 |
Zachary Ware | 6b6e687 | 2017-06-10 14:58:42 -0500 | [diff] [blame] | 115 | |
| 116 | if "%do_pgo%"=="true" ( |
| 117 | set conf=PGInstrument |
| 118 | call :Build %1 %2 %3 %4 %5 %6 %7 %8 %9 |
Steve Dower | 21a92f8 | 2019-06-14 08:29:20 -0700 | [diff] [blame] | 119 | ) |
| 120 | rem %VARS% are evaluated eagerly, which would lose the ERRORLEVEL |
| 121 | rem value if we didn't split it out here. |
| 122 | if "%do_pgo%"=="true" if ERRORLEVEL 1 exit /B %ERRORLEVEL% |
| 123 | if "%do_pgo%"=="true" ( |
Zachary Ware | 6b6e687 | 2017-06-10 14:58:42 -0500 | [diff] [blame] | 124 | del /s "%dir%\*.pgc" |
| 125 | del /s "%dir%\..\Lib\*.pyc" |
| 126 | echo on |
| 127 | call "%dir%\..\python.bat" %pgo_job% |
| 128 | @echo off |
| 129 | call :Kill |
| 130 | set conf=PGUpdate |
| 131 | set target=Build |
| 132 | ) |
Steve Dower | 21a92f8 | 2019-06-14 08:29:20 -0700 | [diff] [blame] | 133 | goto :Build |
| 134 | |
Zachary Ware | 6b6e687 | 2017-06-10 14:58:42 -0500 | [diff] [blame] | 135 | :Kill |
| 136 | echo on |
Steve Dower | 40a23e8 | 2017-06-19 10:34:25 -0700 | [diff] [blame] | 137 | %MSBUILD% "%dir%\pythoncore.vcxproj" /t:KillPython %verbose%^ |
Zachary Ware | 6b6e687 | 2017-06-10 14:58:42 -0500 | [diff] [blame] | 138 | /p:Configuration=%conf% /p:Platform=%platf%^ |
| 139 | /p:KillPython=true |
| 140 | |
| 141 | @echo off |
Steve Dower | 21a92f8 | 2019-06-14 08:29:20 -0700 | [diff] [blame] | 142 | exit /B %ERRORLEVEL% |
Zachary Ware | 6b6e687 | 2017-06-10 14:58:42 -0500 | [diff] [blame] | 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 |
Steve Dower | 40a23e8 | 2017-06-19 10:34:25 -0700 | [diff] [blame] | 149 | %MSBUILD% "%dir%pcbuild.proj" /t:%target% %parallel% %verbose%^ |
Zachary Ware | 6b6e687 | 2017-06-10 14:58:42 -0500 | [diff] [blame] | 150 | /p:Configuration=%conf% /p:Platform=%platf%^ |
| 151 | /p:IncludeExternals=%IncludeExternals%^ |
Paul Monson | f96e7fd | 2019-05-17 10:07:24 -0700 | [diff] [blame] | 152 | /p:IncludeCTypes=%IncludeCTypes%^ |
Zachary Ware | 6b6e687 | 2017-06-10 14:58:42 -0500 | [diff] [blame] | 153 | /p:IncludeSSL=%IncludeSSL% /p:IncludeTkinter=%IncludeTkinter%^ |
| 154 | /p:UseTestMarker=%UseTestMarker% %GITProperty%^ |
| 155 | %1 %2 %3 %4 %5 %6 %7 %8 %9 |
| 156 | |
| 157 | @echo off |
Steve Dower | 21a92f8 | 2019-06-14 08:29:20 -0700 | [diff] [blame] | 158 | exit /b %ERRORLEVEL% |
Zachary Ware | 6b6e687 | 2017-06-10 14:58:42 -0500 | [diff] [blame] | 159 | |
| 160 | :Version |
| 161 | rem Display the current build version information |
Jeremy Kloth | f46eccd | 2018-12-09 20:59:32 -0700 | [diff] [blame] | 162 | call "%dir%find_msbuild.bat" %MSBUILD% |
Steve Dower | 21a92f8 | 2019-06-14 08:29:20 -0700 | [diff] [blame] | 163 | if ERRORLEVEL 1 (echo Cannot locate MSBuild.exe on PATH or as MSBUILD variable & exit /b 2) |
| 164 | %MSBUILD% "%dir%pythoncore.vcxproj" /t:ShowVersionInfo /v:m /nologo %1 %2 %3 %4 %5 %6 %7 %8 %9 |
| 165 | if ERRORLEVEL 1 exit /b 3 |