Skip to content

Commit

Permalink
refactor: refactored MSVS validation (#439)
Browse files Browse the repository at this point in the history
Co-authored-by: Ricardo Cino <[email protected]>
  • Loading branch information
2 people authored and vraravam committed Jul 7, 2022
1 parent 4870969 commit 11ab0cd
Showing 1 changed file with 27 additions and 13 deletions.
40 changes: 27 additions & 13 deletions scripts/build-windows.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 11ab0cd

Please sign in to comment.