Refactor Windows development setup script to a sequential approach for improved clarity and user experience

- Transitioned from a function-based structure to a sequential approach, simplifying the script flow.
- Enhanced user feedback with clear status messages for each setup step, including checks for project directory, Visual Studio, Git, Python, and vcpkg.
- Improved error handling and instructions for missing dependencies, ensuring a smoother setup process.
- Streamlined the process for generating Visual Studio project files and testing builds, making it more user-friendly.
This commit is contained in:
scawful
2025-09-28 00:59:43 -04:00
parent e008bc2766
commit 8205de84f9

View File

@@ -1,5 +1,5 @@
# YAZE Windows Development Setup Script # YAZE Windows Development Setup Script
# Function-based approach with minimal if-else statements # Sequential approach with no functions and minimal conditionals
param( param(
[switch]$SkipVcpkg, [switch]$SkipVcpkg,
@@ -9,212 +9,202 @@ param(
$ErrorActionPreference = "Continue" $ErrorActionPreference = "Continue"
function Write-Status { Write-Host "========================================" -ForegroundColor Cyan
param([string]$Message, [string]$Color = "White") Write-Host "YAZE Windows Development Setup" -ForegroundColor Cyan
Write-Host $Message -ForegroundColor $Color Write-Host "========================================" -ForegroundColor Cyan
}
function Test-Command { # Step 1: Check project directory
param([string]$Command) Write-Host "Step 1: Checking project directory..." -ForegroundColor Yellow
try {
$null = Get-Command $Command -ErrorAction Stop
return $true
} catch {
return $false
}
}
function Check-ProjectDirectory {
Write-Status "Checking project directory..." "Yellow"
$projectValid = Test-Path "YAZE.sln" $projectValid = Test-Path "YAZE.sln"
if ($projectValid) { switch ($projectValid) {
Write-Status "✓ YAZE.sln found" "Green" $true { Write-Host "✓ YAZE.sln found" -ForegroundColor Green }
return $true $false {
} else { Write-Host "✗ YAZE.sln not found" -ForegroundColor Red
Write-Status "✗ YAZE.sln not found" "Red" Write-Host "Please run this script from the YAZE project root directory" -ForegroundColor Yellow
Write-Status "Please run this script from the YAZE project root directory" "Yellow" exit 1
return $false
} }
} }
function Check-VisualStudio { # Step 2: Check Visual Studio
Write-Status "Checking Visual Studio..." "Yellow" Write-Host "Step 2: Checking Visual Studio..." -ForegroundColor Yellow
switch ($SkipVS) {
$true { Write-Host "Skipping Visual Studio check" -ForegroundColor Yellow }
$false {
$vsWhere = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe" $vsWhere = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe"
$vsFound = $false $vsFound = $false
if (Test-Path $vsWhere) { $vsExists = Test-Path $vsWhere
switch ($vsExists) {
$true {
$vsInstall = & $vsWhere -latest -products * -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath $vsInstall = & $vsWhere -latest -products * -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath
if ($vsInstall) { switch ($null -ne $vsInstall) {
$true {
$msbuildPath = Join-Path $vsInstall "MSBuild\Current\Bin\MSBuild.exe" $msbuildPath = Join-Path $vsInstall "MSBuild\Current\Bin\MSBuild.exe"
$vsFound = Test-Path $msbuildPath $vsFound = Test-Path $msbuildPath
} }
} }
if ($vsFound) {
Write-Status "✓ Visual Studio 2022 with C++ workload found" "Green"
} else {
Write-Status "⚠ Visual Studio 2022 with C++ workload not found" "Yellow"
Write-Status "Please install Visual Studio 2022 with 'Desktop development with C++' workload" "White"
} }
return $vsFound
} }
function Check-Git { switch ($vsFound) {
Write-Status "Checking Git..." "Yellow" $true { Write-Host "✓ Visual Studio 2022 with C++ workload found" -ForegroundColor Green }
$gitFound = Test-Command "git" $false {
if ($gitFound) { Write-Host "⚠ Visual Studio 2022 with C++ workload not found" -ForegroundColor Yellow
Write-Host "Please install Visual Studio 2022 with 'Desktop development with C++' workload" -ForegroundColor White
}
}
}
}
# Step 3: Check Git
Write-Host "Step 3: Checking Git..." -ForegroundColor Yellow
$gitFound = $false
try {
$null = Get-Command git -ErrorAction Stop
$gitFound = $true
} catch {
$gitFound = $false
}
switch ($gitFound) {
$true {
$gitVersion = & git --version $gitVersion = & git --version
Write-Status "✓ Git found: $gitVersion" "Green" Write-Host "✓ Git found: $gitVersion" -ForegroundColor Green
} else { }
Write-Status "⚠ Git not found" "Yellow" $false {
Write-Status "Please install Git for Windows from: https://git-scm.com/download/win" "White" Write-Host "⚠ Git not found" -ForegroundColor Yellow
Write-Host "Please install Git for Windows from: https://git-scm.com/download/win" -ForegroundColor White
} }
return $gitFound
} }
function Check-Python { # Step 4: Check Python
Write-Status "Checking Python..." "Yellow" Write-Host "Step 4: Checking Python..." -ForegroundColor Yellow
$pythonFound = Test-Command "python" $pythonFound = $false
if ($pythonFound) { try {
$null = Get-Command python -ErrorAction Stop
$pythonFound = $true
} catch {
$pythonFound = $false
}
switch ($pythonFound) {
$true {
$pythonVersion = & python --version $pythonVersion = & python --version
Write-Status "✓ Python found: $pythonVersion" "Green" Write-Host "✓ Python found: $pythonVersion" -ForegroundColor Green
} else { }
Write-Status "⚠ Python not found" "Yellow" $false {
Write-Status "Please install Python 3.8+ from: https://www.python.org/downloads/" "White" Write-Host "⚠ Python not found" -ForegroundColor Yellow
Write-Host "Please install Python 3.8+ from: https://www.python.org/downloads/" -ForegroundColor White
} }
return $pythonFound
} }
function Setup-Vcpkg { # Step 5: Setup vcpkg
Write-Status "Setting up vcpkg..." "Yellow" Write-Host "Step 5: Setting up vcpkg..." -ForegroundColor Yellow
switch ($SkipVcpkg) {
$true { Write-Host "Skipping vcpkg setup" -ForegroundColor Yellow }
$false {
# Clone vcpkg # Clone vcpkg
$vcpkgExists = Test-Path "vcpkg" $vcpkgExists = Test-Path "vcpkg"
if (-not $vcpkgExists) { switch ($vcpkgExists) {
Write-Status "Cloning vcpkg..." "Yellow" $false {
$gitFound = Test-Command "git" Write-Host "Cloning vcpkg..." -ForegroundColor Yellow
if ($gitFound) { switch ($gitFound) {
$true {
& git clone https://github.com/Microsoft/vcpkg.git vcpkg & git clone https://github.com/Microsoft/vcpkg.git vcpkg
$cloneSuccess = ($LASTEXITCODE -eq 0) $cloneSuccess = ($LASTEXITCODE -eq 0)
if ($cloneSuccess) { switch ($cloneSuccess) {
Write-Status "✓ vcpkg cloned successfully" "Green" $true { Write-Host "✓ vcpkg cloned successfully" -ForegroundColor Green }
} else { $false {
Write-Status "✗ Failed to clone vcpkg" "Red" Write-Host "✗ Failed to clone vcpkg" -ForegroundColor Red
exit 1 exit 1
} }
} else { }
Write-Status "✗ Git is required to clone vcpkg" "Red" }
$false {
Write-Host "✗ Git is required to clone vcpkg" -ForegroundColor Red
exit 1 exit 1
} }
} else { }
Write-Status "✓ vcpkg directory already exists" "Green" }
$true { Write-Host "✓ vcpkg directory already exists" -ForegroundColor Green }
} }
# Bootstrap vcpkg # Bootstrap vcpkg
$vcpkgExe = "vcpkg\vcpkg.exe" $vcpkgExe = "vcpkg\vcpkg.exe"
$vcpkgBootstrapped = Test-Path $vcpkgExe $vcpkgBootstrapped = Test-Path $vcpkgExe
if (-not $vcpkgBootstrapped) { switch ($vcpkgBootstrapped) {
Write-Status "Bootstrapping vcpkg..." "Yellow" $false {
Write-Host "Bootstrapping vcpkg..." -ForegroundColor Yellow
Push-Location vcpkg Push-Location vcpkg
& .\bootstrap-vcpkg.bat & .\bootstrap-vcpkg.bat
$bootstrapSuccess = ($LASTEXITCODE -eq 0) $bootstrapSuccess = ($LASTEXITCODE -eq 0)
Pop-Location Pop-Location
if ($bootstrapSuccess) { switch ($bootstrapSuccess) {
Write-Status "✓ vcpkg bootstrapped successfully" "Green" $true { Write-Host "✓ vcpkg bootstrapped successfully" -ForegroundColor Green }
} else { $false {
Write-Status "✗ Failed to bootstrap vcpkg" "Red" Write-Host "✗ Failed to bootstrap vcpkg" -ForegroundColor Red
exit 1 exit 1
} }
} else { }
Write-Status "✓ vcpkg already bootstrapped" "Green" }
$true { Write-Host "✓ vcpkg already bootstrapped" -ForegroundColor Green }
} }
# Install dependencies # Install dependencies
Write-Status "Installing dependencies..." "Yellow" Write-Host "Installing dependencies..." -ForegroundColor Yellow
& $vcpkgExe install --triplet x64-windows & $vcpkgExe install --triplet x64-windows
$installSuccess = ($LASTEXITCODE -eq 0) $installSuccess = ($LASTEXITCODE -eq 0)
if ($installSuccess) { switch ($installSuccess) {
Write-Status "✓ Dependencies installed successfully" "Green" $true { Write-Host "✓ Dependencies installed successfully" -ForegroundColor Green }
} else { $false { Write-Host "⚠ Some dependencies may not have installed correctly" -ForegroundColor Yellow }
Write-Status "⚠ Some dependencies may not have installed correctly" "Yellow" }
} }
} }
function Generate-ProjectFiles { # Step 6: Generate project files
Write-Status "Generating Visual Studio project files..." "Yellow" Write-Host "Step 6: Generating Visual Studio project files..." -ForegroundColor Yellow
$pythonFound = Test-Command "python" switch ($pythonFound) {
if ($pythonFound) { $true {
& python scripts/generate-vs-projects.py & python scripts/generate-vs-projects.py
$generateSuccess = ($LASTEXITCODE -eq 0) $generateSuccess = ($LASTEXITCODE -eq 0)
if ($generateSuccess) { switch ($generateSuccess) {
Write-Status "✓ Project files generated successfully" "Green" $true { Write-Host "✓ Project files generated successfully" -ForegroundColor Green }
} else { $false { Write-Host "⚠ Failed to generate project files" -ForegroundColor Yellow }
Write-Status "⚠ Failed to generate project files" "Yellow"
} }
} else {
Write-Status "⚠ Python required to generate project files" "Yellow"
} }
$false { Write-Host "⚠ Python required to generate project files" -ForegroundColor Yellow }
} }
function Test-Build { # Step 7: Test build
Write-Status "Testing build..." "Yellow" Write-Host "Step 7: Testing build..." -ForegroundColor Yellow
switch ($SkipBuild) {
$true { Write-Host "Skipping test build" -ForegroundColor Yellow }
$false {
$buildScriptExists = Test-Path "scripts\build-windows.ps1" $buildScriptExists = Test-Path "scripts\build-windows.ps1"
if ($buildScriptExists) { switch ($buildScriptExists) {
$true {
& .\scripts\build-windows.ps1 -Configuration Release -Platform x64 & .\scripts\build-windows.ps1 -Configuration Release -Platform x64
$buildSuccess = ($LASTEXITCODE -eq 0) $buildSuccess = ($LASTEXITCODE -eq 0)
if ($buildSuccess) { switch ($buildSuccess) {
Write-Status "✓ Test build successful" "Green" $true { Write-Host "✓ Test build successful" -ForegroundColor Green }
} else { $false { Write-Host "⚠ Test build failed, but setup is complete" -ForegroundColor Yellow }
Write-Status "⚠ Test build failed, but setup is complete" "Yellow" }
}
$false { Write-Host "⚠ Build script not found" -ForegroundColor Yellow }
} }
} else {
Write-Status "⚠ Build script not found" "Yellow"
} }
} }
function Show-FinalInstructions { # Final instructions
Write-Status "========================================" "Cyan" Write-Host "========================================" -ForegroundColor Cyan
Write-Status "✓ YAZE Windows development setup complete!" "Green" Write-Host "✓ YAZE Windows development setup complete!" -ForegroundColor Green
Write-Status "========================================" "Cyan" Write-Host "========================================" -ForegroundColor Cyan
Write-Status "" Write-Host ""
Write-Status "Next steps:" "Yellow" Write-Host "Next steps:" -ForegroundColor Yellow
Write-Status "1. Open YAZE.sln in Visual Studio 2022" "White" Write-Host "1. Open YAZE.sln in Visual Studio 2022" -ForegroundColor White
Write-Status "2. Select configuration (Debug/Release) and platform (x64/x86/ARM64)" "White" Write-Host "2. Select configuration (Debug/Release) and platform (x64/x86/ARM64)" -ForegroundColor White
Write-Status "3. Build the solution (Ctrl+Shift+B)" "White" Write-Host "3. Build the solution (Ctrl+Shift+B)" -ForegroundColor White
Write-Status "" Write-Host ""
Write-Status "Or use command line:" "Yellow" Write-Host "Or use command line:" -ForegroundColor Yellow
Write-Status " .\scripts\build-windows.ps1 -Configuration Release -Platform x64" "White" Write-Host " .\scripts\build-windows.ps1 -Configuration Release -Platform x64" -ForegroundColor White
Write-Status "" Write-Host ""
Write-Status "For more information, see docs/windows-development-guide.md" "Cyan" Write-Host "For more information, see docs/windows-development-guide.md" -ForegroundColor Cyan
}
# Main execution
Write-Status "========================================" "Cyan"
Write-Status "YAZE Windows Development Setup" "Cyan"
Write-Status "========================================" "Cyan"
# Execute setup steps
$projectValid = Check-ProjectDirectory
if (-not $projectValid) { exit 1 }
if (-not $SkipVS) {
Check-VisualStudio
}
Check-Git
Check-Python
if (-not $SkipVcpkg) {
Setup-Vcpkg
} else {
Write-Status "Skipping vcpkg setup" "Yellow"
}
Generate-ProjectFiles
if (-not $SkipBuild) {
Test-Build
} else {
Write-Status "Skipping test build" "Yellow"
}
Show-FinalInstructions