From 724cb29db3a76b7e4b95be18567b1de52661483c Mon Sep 17 00:00:00 2001 From: Ivan Diaz Sanchez Date: Thu, 9 Jul 2020 18:37:26 -0700 Subject: [PATCH 1/5] Added checks for main dependencies on build scripts. --- eng/build.ps1 | 38 ++++++++++++++++++++++++++++++++++++++ eng/build.sh | 18 ++++++++++++++++++ 2 files changed, 56 insertions(+) diff --git a/eng/build.ps1 b/eng/build.ps1 index bfce8766eced9..60488dd946b26 100644 --- a/eng/build.ps1 +++ b/eng/build.ps1 @@ -100,6 +100,34 @@ 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) +{ + Write-Host "Checking for $dependencyName..." + if (((Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*).DisplayName -Match + $dependencyName).Length -le 0) + { + 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 + } +} + +function Assert-GitLongPathsEnabled() +{ + Write-Host "Ensuring Git Long Paths are enabled..." + # This needs to be in a variable. Otherwise, Invoke-Command complains about + # an incompatible cast. + $gitscript = [scriptblock]::Create("git config --get core.longpaths") + $longpaths = Invoke-Command -scriptblock $gitscript + + if (-Not $longpaths) { + Write-Host "Git Long Paths must be enabled to build this repo." + Write-Host "For a full list of requirements, see https://github.com/dotnet/runtime/blob/master/docs/workflow/requirements/windows-requirements.md" + exit 1 + } + Write-Host "Done!" +} + if ($help -or (($null -ne $properties) -and ($properties.Contains('/help') -or $properties.Contains('/?')))) { Get-Help exit 0 @@ -110,6 +138,16 @@ if ($subset -eq 'help') { exit 0 } +Write-Host "" +Assert-InstalledDependency("Python 3") +Assert-InstalledDependency("CMake") +Assert-InstalledDependency("Git") +Assert-InstalledDependency("Visual Studio") +Assert-GitLongPathsEnabled +Write-Host "All dependencies fulfilled! Initiating Build..." +Write-Host "" +exit 0 + if ($vs) { . $PSScriptRoot\common\tools.ps1 diff --git a/eng/build.sh b/eng/build.sh index 97df9cd8a1cef..2779bf67a2703 100755 --- a/eng/build.sh +++ b/eng/build.sh @@ -136,6 +136,24 @@ showSubsetHelp() "$scriptroot/common/build.sh" "-restore" "-build" "/p:Subset=help" "/clp:nosummary" } +assertInstalledDependency() +{ + dependency="$(echo "$1" | awk '{print tolower($0)}')" + echo "Checking for $dependency..." + + if ! which $dependency > /dev/null; 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 'python3' +assertInstalledDependency 'git' +assertInstalledDependency 'cmake' +echo "All dependencies fulfilled! Initiating build..." +exit 1 + arguments='' cmakeargs='' extraargs='' From 2cc29b2794ad2ec5e1a30958b937f47b5c52c608 Mon Sep 17 00:00:00 2001 From: Ivan Diaz Sanchez Date: Mon, 3 Aug 2020 19:16:00 -0700 Subject: [PATCH 2/5] Changed Windows to check the Path and removed unnecessary messages. --- eng/build.ps1 | 12 ++---------- eng/build.sh | 4 ---- 2 files changed, 2 insertions(+), 14 deletions(-) diff --git a/eng/build.ps1 b/eng/build.ps1 index 60488dd946b26..8128d84b325ff 100644 --- a/eng/build.ps1 +++ b/eng/build.ps1 @@ -102,9 +102,8 @@ function Get-Help() { function Assert-InstalledDependency($dependencyName) { - Write-Host "Checking for $dependencyName..." - if (((Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*).DisplayName -Match - $dependencyName).Length -le 0) + $envPath = $Env:Path + if (-Not $envPath -Match $dependencyName) { 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" @@ -114,7 +113,6 @@ function Assert-InstalledDependency($dependencyName) function Assert-GitLongPathsEnabled() { - Write-Host "Ensuring Git Long Paths are enabled..." # This needs to be in a variable. Otherwise, Invoke-Command complains about # an incompatible cast. $gitscript = [scriptblock]::Create("git config --get core.longpaths") @@ -125,7 +123,6 @@ function Assert-GitLongPathsEnabled() Write-Host "For a full list of requirements, see https://github.com/dotnet/runtime/blob/master/docs/workflow/requirements/windows-requirements.md" exit 1 } - Write-Host "Done!" } if ($help -or (($null -ne $properties) -and ($properties.Contains('/help') -or $properties.Contains('/?')))) { @@ -138,14 +135,9 @@ if ($subset -eq 'help') { exit 0 } -Write-Host "" -Assert-InstalledDependency("Python 3") Assert-InstalledDependency("CMake") Assert-InstalledDependency("Git") -Assert-InstalledDependency("Visual Studio") Assert-GitLongPathsEnabled -Write-Host "All dependencies fulfilled! Initiating Build..." -Write-Host "" exit 0 if ($vs) { diff --git a/eng/build.sh b/eng/build.sh index 2779bf67a2703..5db87785ae5fc 100755 --- a/eng/build.sh +++ b/eng/build.sh @@ -139,7 +139,6 @@ showSubsetHelp() assertInstalledDependency() { dependency="$(echo "$1" | awk '{print tolower($0)}')" - echo "Checking for $dependency..." if ! which $dependency > /dev/null; then echo "$dependency is required to build this repo. Make sure to install it and try again." @@ -148,11 +147,8 @@ assertInstalledDependency() fi } -assertInstalledDependency 'python3' assertInstalledDependency 'git' assertInstalledDependency 'cmake' -echo "All dependencies fulfilled! Initiating build..." -exit 1 arguments='' cmakeargs='' From a2fc0bc4ae3bb283d68a488d5c08b5e1f1b36769 Mon Sep 17 00:00:00 2001 From: Ivan Diaz Sanchez Date: Wed, 12 Aug 2020 12:36:33 -0700 Subject: [PATCH 3/5] Changed dependency checks to using "command" on both, sh and ps1, and added a check script for VS. --- build.cmd | 2 ++ eng/build.ps1 | 8 ++++---- eng/build.sh | 7 ++++--- eng/vs_tools_check.cmd | 40 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 50 insertions(+), 7 deletions(-) create mode 100644 eng/vs_tools_check.cmd diff --git a/build.cmd b/build.cmd index 76f4d8418947e..b10b49f12f69f 100644 --- a/build.cmd +++ b/build.cmd @@ -1,6 +1,8 @@ @echo off setlocal +call "%~dp0eng\vs_tools_check.cmd" + set _args=%* if "%~1"=="-?" set _args=-help diff --git a/eng/build.ps1 b/eng/build.ps1 index 8128d84b325ff..d4b6249edbf4b 100644 --- a/eng/build.ps1 +++ b/eng/build.ps1 @@ -102,9 +102,10 @@ function Get-Help() { function Assert-InstalledDependency($dependencyName) { - $envPath = $Env:Path - if (-Not $envPath -Match $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 @@ -138,7 +139,6 @@ if ($subset -eq 'help') { Assert-InstalledDependency("CMake") Assert-InstalledDependency("Git") Assert-GitLongPathsEnabled -exit 0 if ($vs) { . $PSScriptRoot\common\tools.ps1 diff --git a/eng/build.sh b/eng/build.sh index 5db87785ae5fc..95b970c5353cc 100755 --- a/eng/build.sh +++ b/eng/build.sh @@ -139,16 +139,17 @@ showSubsetHelp() assertInstalledDependency() { dependency="$(echo "$1" | awk '{print tolower($0)}')" + location="$(command -v $dependency)" - if ! which $dependency > /dev/null; then + 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 'git' -assertInstalledDependency 'cmake' +assertInstalledDependency 'CMake' +assertInstalledDependency 'Git' arguments='' cmakeargs='' diff --git a/eng/vs_tools_check.cmd b/eng/vs_tools_check.cmd new file mode 100644 index 0000000000000..d4846f47c56a5 --- /dev/null +++ b/eng/vs_tools_check.cmd @@ -0,0 +1,40 @@ +@if not defined _echo @echo off + +REM This script checks and ensures there is a working Visual Studio installation +REM alongside its dev tools. This is a requirement to build the runtime repo. +REM All passed arguments are ignored +REM Script will return 0 if a VS installation is found, and 1 if any problems +REM cause it to fail. + +:: Default to highest Visual Studio version available + +:: For VS2017 and later, multiple instances can be installed on the same box. +:: SxS and VS1*0COMNTOOLS are no longer set as global environment variables and +:: are instead only set if the user has launched the Visual Studio Developer +:: Command Prompt. + +:: Following this logic, we will default to the Visual Studio toolset associated +:: with the active Developer Command Prompt. Otherwise, we will query VSWhere to +:: locate the later version of Visual Studio available on the machine. Finally, +:: we will fail the script if not supported instance can be found. + +if defined VisualStudioVersion ( + goto skip_setup +) + +set _VSWHERE="%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" +if exist %_VSWHERE% ( + for /f "usebackq tokens=*" %%i in (`%_VSWHERE% -latest -prerelease -property installationPath`) do set _VSCOMNTOOLS=%%i\Common7\Tools + goto call_vs +) + +:call_vs +if not exist "%_VSCOMNTOOLS%" ( + echo %__MsgPrefix%Error: Visual Studio 2019 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/windows-requirements.md + exit /b 1 +) + +:skip_setup + +exit /b 0 From 4f9a919e565126b6f0b2b933b3402a5841d4ebab Mon Sep 17 00:00:00 2001 From: Ivan Diaz Sanchez Date: Mon, 24 Aug 2020 17:12:22 -0700 Subject: [PATCH 4/5] Added flag to only check for VS installation, and not call the Dev prompt. Also removed CMake checks as that has been fixed. --- build.cmd | 6 ++++- eng/build.ps1 | 1 - eng/vs_tools_check.cmd | 40 ---------------------------------- src/coreclr/setup_vs_tools.cmd | 19 ++++++++++++++++ 4 files changed, 24 insertions(+), 42 deletions(-) delete mode 100644 eng/vs_tools_check.cmd diff --git a/build.cmd b/build.cmd index b10b49f12f69f..351c227056e41 100644 --- a/build.cmd +++ b/build.cmd @@ -1,7 +1,11 @@ @echo off setlocal -call "%~dp0eng\vs_tools_check.cmd" +:: 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 diff --git a/eng/build.ps1 b/eng/build.ps1 index d4b6249edbf4b..3f4fc66facd5f 100644 --- a/eng/build.ps1 +++ b/eng/build.ps1 @@ -136,7 +136,6 @@ if ($subset -eq 'help') { exit 0 } -Assert-InstalledDependency("CMake") Assert-InstalledDependency("Git") Assert-GitLongPathsEnabled diff --git a/eng/vs_tools_check.cmd b/eng/vs_tools_check.cmd deleted file mode 100644 index d4846f47c56a5..0000000000000 --- a/eng/vs_tools_check.cmd +++ /dev/null @@ -1,40 +0,0 @@ -@if not defined _echo @echo off - -REM This script checks and ensures there is a working Visual Studio installation -REM alongside its dev tools. This is a requirement to build the runtime repo. -REM All passed arguments are ignored -REM Script will return 0 if a VS installation is found, and 1 if any problems -REM cause it to fail. - -:: Default to highest Visual Studio version available - -:: For VS2017 and later, multiple instances can be installed on the same box. -:: SxS and VS1*0COMNTOOLS are no longer set as global environment variables and -:: are instead only set if the user has launched the Visual Studio Developer -:: Command Prompt. - -:: Following this logic, we will default to the Visual Studio toolset associated -:: with the active Developer Command Prompt. Otherwise, we will query VSWhere to -:: locate the later version of Visual Studio available on the machine. Finally, -:: we will fail the script if not supported instance can be found. - -if defined VisualStudioVersion ( - goto skip_setup -) - -set _VSWHERE="%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" -if exist %_VSWHERE% ( - for /f "usebackq tokens=*" %%i in (`%_VSWHERE% -latest -prerelease -property installationPath`) do set _VSCOMNTOOLS=%%i\Common7\Tools - goto call_vs -) - -:call_vs -if not exist "%_VSCOMNTOOLS%" ( - echo %__MsgPrefix%Error: Visual Studio 2019 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/windows-requirements.md - exit /b 1 -) - -:skip_setup - -exit /b 0 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" From 2ae488eccef948541be93fa7f852615429af5f63 Mon Sep 17 00:00:00 2001 From: Ivan Diaz Sanchez Date: Fri, 28 Aug 2020 11:57:50 -0700 Subject: [PATCH 5/5] Removed Git long paths check because there are scenarios where they are not used, like CI pipelines. --- eng/build.ps1 | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/eng/build.ps1 b/eng/build.ps1 index 3f4fc66facd5f..89245b5f354ae 100644 --- a/eng/build.ps1 +++ b/eng/build.ps1 @@ -112,20 +112,6 @@ function Assert-InstalledDependency($dependencyName) } } -function Assert-GitLongPathsEnabled() -{ - # This needs to be in a variable. Otherwise, Invoke-Command complains about - # an incompatible cast. - $gitscript = [scriptblock]::Create("git config --get core.longpaths") - $longpaths = Invoke-Command -scriptblock $gitscript - - if (-Not $longpaths) { - Write-Host "Git Long Paths must be enabled to build this repo." - 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 -or (($null -ne $properties) -and ($properties.Contains('/help') -or $properties.Contains('/?')))) { Get-Help exit 0 @@ -137,7 +123,6 @@ if ($subset -eq 'help') { } Assert-InstalledDependency("Git") -Assert-GitLongPathsEnabled if ($vs) { . $PSScriptRoot\common\tools.ps1