diff --git a/build.cmd b/build.cmd index fd4aba34c4c92..fc540200df859 100644 --- a/build.cmd +++ b/build.cmd @@ -1,6 +1,12 @@ @echo off setlocal +:: Call setup_vs_tools with the '1' flag to tell it to only check for the +:: VS installation, and not launch the Dev Prompt. More details are in that +:: script source file. + +call "%~dp0src\coreclr\setup_vs_tools.cmd" 1 + set _args=%* if "%~1"=="-?" set _args=-help if "%~1"=="/?" set _args=-help diff --git a/eng/build.ps1 b/eng/build.ps1 index 6f030f298f767..18fe4bf6f7bf1 100644 --- a/eng/build.ps1 +++ b/eng/build.ps1 @@ -106,6 +106,18 @@ function Get-Help() { Write-Host "For more information, check out https://github.com/dotnet/runtime/blob/master/docs/workflow/README.md" } +function Assert-InstalledDependency($dependencyName) +{ + try { + Get-Command -Name $dependencyName -ErrorAction Stop >$null 2>&1 + } + catch { + Write-Host "$dependencyName is required to build this repo. Make sure to install it and try again." + Write-Host "For a full list of requirements, see https://github.com/dotnet/runtime/blob/master/docs/workflow/requirements/windows-requirements.md" + exit 1 + } +} + if ($help) { Get-Help exit 0 @@ -116,6 +128,8 @@ if ($subset -eq 'help') { exit 0 } +Assert-InstalledDependency("Git") + if ($vs) { . $PSScriptRoot\common\tools.ps1 diff --git a/eng/build.sh b/eng/build.sh index f271bb0ca7627..047c766e87625 100755 --- a/eng/build.sh +++ b/eng/build.sh @@ -144,6 +144,21 @@ showSubsetHelp() "$scriptroot/common/build.sh" "-restore" "-build" "/p:Subset=help" "/clp:nosummary" } +assertInstalledDependency() +{ + dependency="$(echo "$1" | awk '{print tolower($0)}')" + location="$(command -v $dependency)" + + if [ -z "$location" ]; then + echo "$dependency is required to build this repo. Make sure to install it and try again." + echo "For a full list of requirements, see https://github.com/dotnet/runtime/blob/master/docs/workflow/requirements/linux-requirements.md" + exit 1 + fi +} + +assertInstalledDependency 'CMake' +assertInstalledDependency 'Git' + arguments='' cmakeargs='' extraargs='' diff --git a/src/coreclr/setup_vs_tools.cmd b/src/coreclr/setup_vs_tools.cmd index 802038b0d8ca5..b35ea3b521ca7 100644 --- a/src/coreclr/setup_vs_tools.cmd +++ b/src/coreclr/setup_vs_tools.cmd @@ -16,6 +16,19 @@ REM vs2017 or vs2019 :: Visual Studio available on the machine. Finally, we will fail the script if not supported :: instance can be found. +:: This script is also called by the main build.cmd, located at the root of the +:: runtime repo. For this specific scenario, we want to check if there is a +:: valid VS installation, but not call the Developer Command Prompt. For this +:: purpose, we pass a flag labelled as the number '1' from said script and store +:: it in this variable "__VSOnlyCheck". This is then checked at the end to define +:: whether or not to call the VS Dev Prompt. +:: +:: The original CoreCLR callers within this directory remain untouched. In this +:: case, they don't pass any flags and so since "__VSOnlyCheck" will be undefined +:: in those cases, execution will proceed as normally. + +set __VSOnlyCheck=%1 + if defined VisualStudioVersion ( if not defined __VSVersion echo %__MsgPrefix%Detected Visual Studio %VisualStudioVersion% developer command ^prompt environment goto skip_setup @@ -34,6 +47,12 @@ if not exist "%_VSCOMNTOOLS%" ( echo Please see https://github.com/dotnet/runtime/blob/master/docs/workflow/requirements/windows-requirements.md for build instructions. exit /b 1 ) + +:: If called from runtime's build.cmd, we are done here and thus we proceed +:: to the exit. + +if "%__VSOnlyCheck%" == "1" goto :skip_setup + echo %__MsgPrefix%"%_VSCOMNTOOLS%\VsDevCmd.bat" call "%_VSCOMNTOOLS%\VsDevCmd.bat"