From 9a51c1d5a77a8578a96a8f146eb836ef8f22fb37 Mon Sep 17 00:00:00 2001 From: scawful Date: Sun, 28 Sep 2025 00:42:28 -0400 Subject: [PATCH] Refactor Windows development setup script for improved error handling and dependency checks - Enhanced Git and Python checks to ensure proper installation before proceeding with setup. - Updated vcpkg cloning logic to verify Git availability and provide clearer error messages. - Improved project file generation and build testing sections with additional user feedback and error handling. - Removed obsolete PowerShell syntax test script to streamline the repository. --- scripts/setup-windows-dev.ps1 | 91 +++++++++++++++++------------- scripts/test-powershell-syntax.ps1 | 31 ---------- 2 files changed, 53 insertions(+), 69 deletions(-) delete mode 100644 scripts/test-powershell-syntax.ps1 diff --git a/scripts/setup-windows-dev.ps1 b/scripts/setup-windows-dev.ps1 index 74b85110..8af73200 100644 --- a/scripts/setup-windows-dev.ps1 +++ b/scripts/setup-windows-dev.ps1 @@ -52,13 +52,12 @@ if (-not $SkipVS) { # Check for Git Write-Host "Checking for Git..." -ForegroundColor Yellow +$gitFound = $false try { - $gitVersion = & git --version 2>$null - if ($LASTEXITCODE -eq 0) { - Write-Host "✓ Git found: $gitVersion" -ForegroundColor Green - } else { - throw "Git not found" - } + $null = Get-Command git -ErrorAction Stop + $gitVersion = & git --version + Write-Host "✓ Git found: $gitVersion" -ForegroundColor Green + $gitFound = $true } catch { Write-Warning "Git not found. Please install Git for Windows." Write-Host "Download from: https://git-scm.com/download/win" -ForegroundColor Yellow @@ -66,13 +65,12 @@ try { # Check for Python Write-Host "Checking for Python..." -ForegroundColor Yellow +$pythonFound = $false try { - $pythonVersion = & python --version 2>$null - if ($LASTEXITCODE -eq 0) { - Write-Host "✓ Python found: $pythonVersion" -ForegroundColor Green - } else { - throw "Python not found" - } + $null = Get-Command python -ErrorAction Stop + $pythonVersion = & python --version + Write-Host "✓ Python found: $pythonVersion" -ForegroundColor Green + $pythonFound = $true } catch { Write-Warning "Python not found. Please install Python 3.8 or later." Write-Host "Download from: https://www.python.org/downloads/" -ForegroundColor Yellow @@ -84,15 +82,21 @@ if (-not $SkipVcpkg) { if (-not (Test-Path "vcpkg")) { Write-Host "Cloning vcpkg..." -ForegroundColor Yellow - try { - & git clone https://github.com/Microsoft/vcpkg.git vcpkg - if ($LASTEXITCODE -eq 0) { - Write-Host "✓ vcpkg cloned successfully" -ForegroundColor Green - } else { - throw "Failed to clone vcpkg" + if ($gitFound) { + try { + & git clone https://github.com/Microsoft/vcpkg.git vcpkg + if ($LASTEXITCODE -eq 0) { + Write-Host "✓ vcpkg cloned successfully" -ForegroundColor Green + } else { + Write-Error "Failed to clone vcpkg" + exit 1 + } + } catch { + Write-Error "Failed to clone vcpkg: $_" + exit 1 } - } catch { - Write-Error "Failed to clone vcpkg: $_" + } else { + Write-Error "Git is required to clone vcpkg. Please install Git first." exit 1 } } else { @@ -109,7 +113,9 @@ if (-not $SkipVcpkg) { if ($LASTEXITCODE -eq 0) { Write-Host "✓ vcpkg bootstrapped successfully" -ForegroundColor Green } else { - throw "Failed to bootstrap vcpkg" + Write-Error "Failed to bootstrap vcpkg" + Pop-Location + exit 1 } Pop-Location } catch { @@ -139,30 +145,39 @@ if (-not $SkipVcpkg) { # Generate Visual Studio project files Write-Host "Generating Visual Studio project files..." -ForegroundColor Yellow -try { - & python scripts/generate-vs-projects.py - if ($LASTEXITCODE -eq 0) { - Write-Host "✓ Visual Studio project files generated" -ForegroundColor Green - } else { - throw "Failed to generate project files" +if ($pythonFound) { + try { + & python scripts/generate-vs-projects.py + if ($LASTEXITCODE -eq 0) { + Write-Host "✓ Visual Studio project files generated" -ForegroundColor Green + } else { + Write-Warning "Failed to generate project files" + } + } catch { + Write-Warning "Failed to generate project files: $_" + Write-Host "You can manually run: python scripts/generate-vs-projects.py" -ForegroundColor Yellow } -} catch { - Write-Warning "Failed to generate project files: $_" +} else { + Write-Warning "Python is required to generate project files. Please install Python first." Write-Host "You can manually run: python scripts/generate-vs-projects.py" -ForegroundColor Yellow } # Test build Write-Host "Testing build..." -ForegroundColor Yellow -try { - & .\scripts\build-windows.ps1 -Configuration Release -Platform x64 - if ($LASTEXITCODE -eq 0) { - Write-Host "✓ Test build successful" -ForegroundColor Green - } else { - Write-Warning "Test build failed, but setup is complete" +if (Test-Path "scripts\build-windows.ps1") { + try { + & .\scripts\build-windows.ps1 -Configuration Release -Platform x64 + if ($LASTEXITCODE -eq 0) { + Write-Host "✓ Test build successful" -ForegroundColor Green + } else { + Write-Warning "Test build failed, but setup is complete" + } + } catch { + Write-Warning "Test build failed: $_" + Write-Host "You can manually run: .\scripts\build-windows.ps1" -ForegroundColor Yellow } -} catch { - Write-Warning "Test build failed: $_" - Write-Host "You can manually run: .\scripts\build-windows.ps1" -ForegroundColor Yellow +} else { + Write-Warning "Build script not found. You can manually build using Visual Studio." } Write-Host "========================================" -ForegroundColor Cyan diff --git a/scripts/test-powershell-syntax.ps1 b/scripts/test-powershell-syntax.ps1 deleted file mode 100644 index 1b3fb007..00000000 --- a/scripts/test-powershell-syntax.ps1 +++ /dev/null @@ -1,31 +0,0 @@ -# Simple test script to verify PowerShell syntax -# This script tests basic PowerShell constructs used in our build scripts - -Write-Host "Testing PowerShell syntax..." -ForegroundColor Green - -# Test try-catch blocks -try { - Write-Host "✓ Try-catch syntax works" -ForegroundColor Green -} catch { - Write-Host "✗ Try-catch syntax failed" -ForegroundColor Red -} - -# Test if-else blocks -if ($true) { - Write-Host "✓ If-else syntax works" -ForegroundColor Green -} else { - Write-Host "✗ If-else syntax failed" -ForegroundColor Red -} - -# Test parameter blocks -param( - [switch]$TestParam = $false -) - -Write-Host "✓ Parameter syntax works" -ForegroundColor Green - -# Test string interpolation -$testVar = "PowerShell" -Write-Host "✓ String interpolation works: $testVar" -ForegroundColor Green - -Write-Host "All syntax tests passed!" -ForegroundColor Green