Steve Dower | 40a23e8 | 2017-06-19 10:34:25 -0700 | [diff] [blame] | 1 | @rem |
| 2 | @rem Searches for MSBuild.exe. This is the only tool we need to initiate |
| 3 | @rem a build, so we no longer search for the full VC toolset. |
| 4 | @rem |
| 5 | @rem This file is supposed to modify the state of the caller (specifically |
| 6 | @rem the MSBUILD variable), so we do not use setlocal or echo, and avoid |
| 7 | @rem changing any other persistent state. |
| 8 | @rem |
| 9 | |
| 10 | @rem No arguments provided means do full search |
| 11 | @if '%1' EQU '' goto :begin_search |
| 12 | |
| 13 | @rem One argument may be the full path. Use a goto so we don't try to |
| 14 | @rem parse the next if statement - incorrect quoting in the multi-arg |
| 15 | @rem case can cause us to break immediately. |
| 16 | @if '%2' EQU '' goto :one_arg |
| 17 | |
| 18 | @rem Entire command line may represent the full path if quoting failed. |
| 19 | @if exist "%*" (set MSBUILD="%*") & (set _Py_MSBuild_Source=environment) & goto :found |
| 20 | @goto :begin_search |
| 21 | |
| 22 | :one_arg |
| 23 | @if exist "%~1" (set MSBUILD="%~1") & (set _Py_MSBuild_Source=environment) & goto :found |
| 24 | |
| 25 | :begin_search |
| 26 | @set MSBUILD= |
| 27 | |
| 28 | @rem If msbuild.exe is on the PATH, assume that the user wants that one. |
| 29 | @where msbuild > "%TEMP%\msbuild.loc" 2> nul && set /P MSBUILD= < "%TEMP%\msbuild.loc" & del "%TEMP%\msbuild.loc" |
| 30 | @if exist "%MSBUILD%" set MSBUILD="%MSBUILD%" & (set _Py_MSBuild_Source=PATH) & goto :found |
| 31 | |
| 32 | @rem VS 2017 sets exactly one install as the "main" install, so we may find MSBuild in there. |
| 33 | @reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\SxS\VS7" /v 15.0 /reg:32 >nul 2>nul |
| 34 | @if NOT ERRORLEVEL 1 @for /F "tokens=1,2*" %%i in ('reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\SxS\VS7" /v 15.0 /reg:32') DO @( |
| 35 | @if "%%i"=="15.0" @if exist "%%k\MSBuild\15.0\Bin\msbuild.exe" @(set MSBUILD="%%k\MSBuild\15.0\Bin\msbuild.exe") |
| 36 | ) |
| 37 | @if exist %MSBUILD% (set _Py_MSBuild_Source=Visual Studio 2017 registry) & goto :found |
| 38 | |
| 39 | @rem VS 2015 and earlier register MSBuild separately, so we can find it. |
| 40 | @reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSBuild\ToolsVersions\14.0" /v MSBuildToolsPath /reg:32 >nul 2>nul |
| 41 | @if NOT ERRORLEVEL 1 @for /F "tokens=1,2*" %%i in ('reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSBuild\ToolsVersions\14.0" /v MSBuildToolsPath /reg:32') DO @( |
| 42 | @if "%%i"=="MSBuildToolsPath" @if exist "%%k\msbuild.exe" @(set MSBUILD="%%k\msbuild.exe") |
| 43 | ) |
| 44 | @if exist %MSBUILD% (set _Py_MSBuild_Source=registry) & goto :found |
| 45 | |
| 46 | |
| 47 | @exit /b 1 |
| 48 | |
| 49 | :found |
| 50 | @echo Using %MSBUILD% (found in the %_Py_MSBuild_Source%) |
| 51 | @set _Py_MSBuild_Source= |