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 | |
Steve Dower | 0cd6391 | 2018-12-10 18:52:57 -0800 | [diff] [blame] | 32 | @rem VS 2017 and later provide vswhere.exe, which can be used |
| 33 | @if not exist "%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" goto :skip_vswhere |
| 34 | @set _Py_MSBuild_Root= |
| 35 | @for /F "tokens=*" %%i in ('"%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" -property installationPath -latest') DO @(set _Py_MSBuild_Root=%%i\MSBuild) |
| 36 | @if not defined _Py_MSBuild_Root goto :skip_vswhere |
| 37 | @for %%j in (Current 15.0) DO @if exist "%_Py_MSBuild_Root%\%%j\Bin\msbuild.exe" (set MSBUILD="%_Py_MSBuild_Root%\%%j\Bin\msbuild.exe") |
| 38 | @set _Py_MSBuild_Root= |
| 39 | @if defined MSBUILD @if exist %MSBUILD% (set _Py_MSBuild_Source=Visual Studio installation) & goto :found |
| 40 | :skip_vswhere |
| 41 | |
Steve Dower | 40a23e8 | 2017-06-19 10:34:25 -0700 | [diff] [blame] | 42 | @rem VS 2017 sets exactly one install as the "main" install, so we may find MSBuild in there. |
| 43 | @reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\SxS\VS7" /v 15.0 /reg:32 >nul 2>nul |
| 44 | @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 @( |
| 45 | @if "%%i"=="15.0" @if exist "%%k\MSBuild\15.0\Bin\msbuild.exe" @(set MSBUILD="%%k\MSBuild\15.0\Bin\msbuild.exe") |
| 46 | ) |
| 47 | @if exist %MSBUILD% (set _Py_MSBuild_Source=Visual Studio 2017 registry) & goto :found |
| 48 | |
Steve Dower | 881323d | 2018-02-27 22:09:27 -0800 | [diff] [blame] | 49 | @rem VS 2015 and earlier register MSBuild separately, so we can find it. |
| 50 | @reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSBuild\ToolsVersions\14.0" /v MSBuildToolsPath /reg:32 >nul 2>nul |
| 51 | @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 @( |
| 52 | @if "%%i"=="MSBuildToolsPath" @if exist "%%k\msbuild.exe" @(set MSBUILD="%%k\msbuild.exe") |
| 53 | ) |
| 54 | @if exist %MSBUILD% (set _Py_MSBuild_Source=registry) & goto :found |
| 55 | |
Steve Dower | 40a23e8 | 2017-06-19 10:34:25 -0700 | [diff] [blame] | 56 | |
| 57 | @exit /b 1 |
| 58 | |
| 59 | :found |
Steve Dower | e97ba4c | 2018-05-28 12:32:05 -0700 | [diff] [blame] | 60 | @pushd %MSBUILD% >nul 2>nul |
| 61 | @if not ERRORLEVEL 1 @( |
| 62 | @if exist msbuild.exe @(set MSBUILD="%CD%\msbuild.exe") else @(set MSBUILD=) |
| 63 | @popd |
| 64 | ) |
| 65 | |
| 66 | @if defined MSBUILD @echo Using %MSBUILD% (found in the %_Py_MSBuild_Source%) |
| 67 | @if not defined MSBUILD @echo Failed to find MSBuild |
Steve Dower | 40a23e8 | 2017-06-19 10:34:25 -0700 | [diff] [blame] | 68 | @set _Py_MSBuild_Source= |
Steve Dower | e97ba4c | 2018-05-28 12:32:05 -0700 | [diff] [blame] | 69 | @if not defined MSBUILD @exit /b 1 |
Steve Dower | f9b364f | 2018-05-28 14:05:05 -0700 | [diff] [blame] | 70 | @exit /b 0 |