From 2f38ed7876ff45a75dd40a017f156b2f02416cdb Mon Sep 17 00:00:00 2001 From: Slan Date: Fri, 8 Jul 2022 05:06:16 +0530 Subject: refactor: refactored MSVS validation (#439) - Added todo for ARM machines - Only run 'npm config set' if there is none Co-authored-by: Ricardo Cino --- scripts/build-windows.ps1 | 40 +++++++++++++++++++++++++++------------- 1 file changed, 27 insertions(+), 13 deletions(-) (limited to 'scripts/build-windows.ps1') diff --git a/scripts/build-windows.ps1 b/scripts/build-windows.ps1 index f0aeaee32..a8c1787a1 100644 --- a/scripts/build-windows.ps1 +++ b/scripts/build-windows.ps1 @@ -94,27 +94,41 @@ if ($env:CLEAN -eq "true") # ----------------------------------------------------------------------------- # Ensure that the system dependencies are at the correct version - fail if not # Check MSVS Tools through MSVS_VERSION + + $EXPECTED_MSVST_VERSION = @("2019","2022") -$MSVS_REG_PATH = "Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\Setup" +$NPM_CONFIG_MSVS_VERSION = npm config get msvs_version +if((-not $NPM_CONFIG_MSVS_VERSION) -or -not ($EXPECTED_MSVST_VERSION -contains $NPM_CONFIG_MSVS_VERSION)){ + Write-Host "Your Microsoft Visual Studio Tools isn't set properly or it's not the right version! + Checking your version..." -if(-not (Test-Path -Path $MSVS_REG_PATH)){ - fail_with_docs "You don't have MSVS Tools Installed!" -} + # TODO: Implement path for ARM machines + $MSVS_REG_PATH = "Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\14.0\VC\Runtimes\X64" -$MSVS_PATH = (Get-ItemProperty -Path $MSVS_REG_PATH).SharedInstallationPath | Split-Path + if(-not (Test-Path -Path $MSVS_REG_PATH)){ + fail_with_docs "You don't have the Microsoft Visual Studio Tools installed!" + } -Get-ChildItem($MSVS_PATH) | ForEach-Object{ - if($EXPECTED_MSVST_VERSION -contains $_){ - $ACTUAL_MSVST_VERSION = $_ - break + $MSVS_VERSION = [int]((Get-ItemProperty -Path $MSVS_REG_PATH).Version.substring(4, 2)) + switch($MSVS_VERSION) { + { $MSVS_VERSION -ge 30 } {$ACTUAL_MSVST_VERSION = "2022"} + { ($MSVS_VERSION -ge 20) -and ($MSVS_VERSION -le 29) } {$ACTUAL_MSVST_VERSION = "2019"} + { $MSVS_VERSION -lt 20 } {$ACTUAL_MSVST_VERSION = "2017 or lower"} } -} -if(-not $ACTUAL_MSVST_VERSION){ - fail_with_docs "You are not running the expected version of MSVS Tools! - expected: [$EXPECTED_MSVST_VERSION]" + if (-not ($EXPECTED_MSVST_VERSION -contains $ACTUAL_MSVST_VERSION)) { + fail_with_docs "You are not running the expected version of MSVS Tools! + expected: [$EXPECTED_MSVST_VERSION] + actual : [$ACTUAL_MSVST_VERSION]" + } + + Write-Host "Changing your msvs_version on npm to [$ACTUAL_MSVST_VERSION]" + npm config set msvs_version $ACTUAL_MSVST_VERSION } + + + # ----------------------------------------------------------------------------- # Ensure that the system dependencies are at the correct version - recover if not # Check npm version -- cgit v1.2.3-70-g09d2