fix: Enhance build environment verification scripts with automatic issue fixes and improved CMake version checks

This commit is contained in:
scawful
2025-10-02 19:55:07 -04:00
parent cadda0d446
commit ef631d263a
3 changed files with 173 additions and 34 deletions

View File

@@ -26,22 +26,27 @@ Comprehensive build environment verification script that checks:
-**Git Installation** - With submodule support
-**C++ Compiler** - GCC 13+, Clang 16+, or MSVC 2019+
-**Platform Tools** - Xcode (macOS), Visual Studio (Windows), build-essential (Linux)
-**Git Submodules** - All dependencies synchronized
-**Git Submodules** - All dependencies synchronized (auto-fixes if missing/empty)
-**CMake Cache** - Freshness check (warns if >7 days old)
-**Dependency Compatibility** - gRPC isolation, httplib, nlohmann/json
-**CMake Configuration** - Test configuration (verbose mode only)
**Automatic Fixes:**
The script now automatically fixes common issues without requiring `-FixIssues`:
- 🔧 **Missing/Empty Submodules** - Automatically runs `git submodule update --init --recursive`
- 🔧 **Old CMake Cache** - Prompts for confirmation when using `-FixIssues` (auto-skips otherwise)
#### Usage
**Windows:**
```powershell
# Basic verification
# Basic verification (auto-fixes submodules)
.\scripts\verify-build-environment.ps1
# With automatic fixes (sync submodules, clean cache)
# With interactive fixes (prompts for cache cleaning)
.\scripts\verify-build-environment.ps1 -FixIssues
# Clean old CMake cache files
# Force clean old CMake cache (no prompts)
.\scripts\verify-build-environment.ps1 -CleanCache
# Verbose output (includes CMake configuration test)
@@ -53,13 +58,13 @@ Comprehensive build environment verification script that checks:
**macOS/Linux:**
```bash
# Basic verification
# Basic verification (auto-fixes submodules)
./scripts/verify-build-environment.sh
# With automatic fixes
# With interactive fixes (prompts for cache cleaning)
./scripts/verify-build-environment.sh --fix
# Clean old CMake cache files
# Force clean old CMake cache (no prompts)
./scripts/verify-build-environment.sh --clean
# Verbose output
@@ -135,6 +140,45 @@ cmake --build build
# Should report: "Build Environment Ready for Development!"
```
## Automatic Fixes
The script automatically fixes common issues when detected:
### Always Auto-Fixed (No Confirmation Required)
1. **Missing/Empty Git Submodules**
```bash
git submodule sync --recursive
git submodule update --init --recursive
```
- Runs automatically when submodules are missing or empty
- No user confirmation required
- Re-verifies after sync to ensure success
### Fixed with `-FixIssues` / `--fix` Flag
2. **Clean Old CMake Cache** (with confirmation prompt)
- Prompts user before removing build directories
- Only when cache is older than 7 days
- User can choose to skip
### Fixed with `-CleanCache` / `--clean` Flag
3. **Force Clean CMake Cache** (no confirmation)
- Removes `build/`, `build_test/`, `build-grpc-test/`
- Removes Visual Studio cache (`out/`)
- No prompts, immediate cleanup
### Optional Verbose Tests
When run with `--verbose` or `-Verbose`:
4. **Test CMake Configuration**
- Creates temporary build directory
- Tests minimal configuration
- Reports success/failure
- Cleans up test directory
## Integration with Visual Studio
The verification script integrates with Visual Studio CMake workflow:

View File

@@ -39,8 +39,13 @@ function Test-Command {
function Get-CMakeVersion {
try {
$output = & cmake --version 2>&1
if ($output -match "cmake version (\d+\.\d+\.\d+)") {
$output = & cmake --version 2>&1 | Select-Object -First 1
# Handle various CMake version output formats
if ($output -match "cmake version ([0-9]+\.[0-9]+\.[0-9]+)") {
return $matches[1]
}
# Try alternative format (some versions print differently)
if ($output -match "([0-9]+\.[0-9]+\.[0-9]+)") {
return $matches[1]
}
} catch {
@@ -160,13 +165,21 @@ function Sync-GitSubmodules {
Push-Location (Join-Path $PSScriptRoot "..")
try {
Write-Status "Running: git submodule sync --recursive" "Info"
git submodule sync --recursive
$syncOutput = git submodule sync --recursive 2>&1
Write-Status "Running: git submodule update --init --recursive" "Info"
git submodule update --init --recursive
$updateOutput = git submodule update --init --recursive 2>&1
Write-Status "Submodules synced successfully" "Success"
return $true
if ($LASTEXITCODE -eq 0) {
Write-Status "Submodules synced successfully" "Success"
return $true
} else {
Write-Status "Git submodule commands completed with warnings" "Warning"
if ($Verbose) {
Write-Host $updateOutput -ForegroundColor Gray
}
return $true # Still return true as submodules may be partially synced
}
} catch {
Write-Status "Failed to sync submodules: $_" "Error"
return $false
@@ -228,12 +241,26 @@ $startTime = Get-Date
Write-Status "Checking CMake installation..." "Step"
if (Test-Command "cmake") {
$cmakeVersion = Get-CMakeVersion
Write-Status "CMake found: version $cmakeVersion" "Success"
$major, $minor = $cmakeVersion.Split('.')[0..1]
if ([int]$major -lt 3 -or ([int]$major -eq 3 -and [int]$minor -lt 16)) {
Write-Status "CMake version too old (need 3.16+)" "Error"
$script:issuesFound += "CMake version $cmakeVersion is below minimum 3.16"
if ($cmakeVersion) {
Write-Status "CMake found: version $cmakeVersion" "Success"
# Parse version components
try {
$versionParts = $cmakeVersion.Split('.')
$major = [int]$versionParts[0]
$minor = [int]$versionParts[1]
if ($major -lt 3 -or ($major -eq 3 -and $minor -lt 16)) {
Write-Status "CMake version too old (need 3.16+)" "Error"
$script:issuesFound += "CMake version $cmakeVersion is below minimum 3.16"
}
} catch {
Write-Status "Could not parse CMake version: $cmakeVersion" "Warning"
$script:warnings += "Unable to verify CMake version requirement (need 3.16+)"
}
} else {
Write-Status "CMake found but version could not be determined" "Warning"
$script:warnings += "CMake version could not be parsed - ensure version 3.16+ is installed"
}
} else {
Write-Status "CMake not found in PATH" "Error"
@@ -275,11 +302,25 @@ $submodulesOk = Test-GitSubmodules
if ($submodulesOk) {
Write-Status "All required submodules present" "Success"
} else {
Write-Status "Some submodules are missing" "Error"
Write-Status "Some submodules are missing or empty" "Error"
if ($FixIssues) {
Sync-GitSubmodules
# Re-check after sync
$submodulesOk = Test-GitSubmodules
if (-not $submodulesOk) {
Write-Status "Submodule sync completed but some issues remain" "Warning"
}
} else {
Write-Status "Run with -FixIssues to automatically sync submodules" "Info"
# Auto-fix without confirmation
Write-Status "Automatically syncing submodules..." "Info"
if (Sync-GitSubmodules) {
Write-Status "Submodules synced successfully" "Success"
# Re-check after sync
$submodulesOk = Test-GitSubmodules
} else {
Write-Status "Failed to sync submodules automatically" "Error"
Write-Status "Run with -FixIssues to try again, or manually run: git submodule update --init --recursive" "Info"
}
}
}
@@ -289,9 +330,20 @@ $cacheOk = Test-CMakeCache
if ($cacheOk) {
Write-Status "CMake cache is up to date" "Success"
} else {
if ($CleanCache -or $FixIssues) {
if ($CleanCache) {
Clean-CMakeCache
} elseif ($FixIssues) {
# Ask for confirmation before cleaning cache
Write-Host "`nCMake cache is older than 7 days. Clean it?" -ForegroundColor Yellow
Write-Host "This will remove build/, build_test/, build-grpc-test/, and out/ directories." -ForegroundColor Gray
$response = Read-Host "Continue? (Y/n)"
if ($response -eq "" -or $response -match "^[Yy]") {
Clean-CMakeCache
} else {
Write-Status "Skipping cache clean" "Info"
}
} else {
Write-Status "CMake cache is older than 7 days (consider cleaning)" "Warning"
Write-Status "Run with -CleanCache to remove old cache files" "Info"
}
}

View File

@@ -86,7 +86,12 @@ check_command() {
}
get_cmake_version() {
cmake --version 2>/dev/null | head -n1 | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' || echo "unknown"
local version=$(cmake --version 2>/dev/null | head -n1 | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' | head -n1)
if [ -n "$version" ]; then
echo "$version"
else
echo "unknown"
fi
}
check_git_submodules() {
@@ -248,15 +253,27 @@ start_time=$(date +%s)
print_status step "Checking CMake installation..."
if check_command cmake; then
cmake_version=$(get_cmake_version)
print_status success "CMake found: version $cmake_version"
# Check version
major=$(echo "$cmake_version" | cut -d. -f1)
minor=$(echo "$cmake_version" | cut -d. -f2)
if [ "$major" -lt 3 ] || ([ "$major" -eq 3 ] && [ "$minor" -lt 16 ]); then
print_status error "CMake version too old (need 3.16+)"
issues_found+=("CMake version $cmake_version is below minimum 3.16")
if [ "$cmake_version" != "unknown" ]; then
print_status success "CMake found: version $cmake_version"
# Check version
major=$(echo "$cmake_version" | cut -d. -f1)
minor=$(echo "$cmake_version" | cut -d. -f2)
# Validate that we got numeric values
if [[ "$major" =~ ^[0-9]+$ ]] && [[ "$minor" =~ ^[0-9]+$ ]]; then
if [ "$major" -lt 3 ] || ([ "$major" -eq 3 ] && [ "$minor" -lt 16 ]); then
print_status error "CMake version too old (need 3.16+)"
issues_found+=("CMake version $cmake_version is below minimum 3.16")
fi
else
print_status warning "Could not parse CMake version: $cmake_version"
warnings+=("Unable to verify CMake version requirement (need 3.16+)")
fi
else
print_status warning "CMake found but version could not be determined"
warnings+=("CMake version could not be parsed - ensure version 3.16+ is installed")
fi
else
print_status error "CMake not found in PATH"
@@ -305,11 +322,24 @@ print_status step "Checking git submodules..."
if check_git_submodules; then
print_status success "All required submodules present"
else
print_status error "Some submodules are missing"
print_status error "Some submodules are missing or empty"
if [ $FIX_ISSUES -eq 1 ]; then
sync_git_submodules
# Re-check after sync
if ! check_git_submodules; then
print_status warning "Submodule sync completed but some issues remain"
fi
else
print_status info "Run with --fix to automatically sync submodules"
# Auto-fix without confirmation
print_status info "Automatically syncing submodules..."
if sync_git_submodules; then
print_status success "Submodules synced successfully"
# Re-check after sync
check_git_submodules
else
print_status error "Failed to sync submodules automatically"
print_status info "Run with --fix to try again, or manually run: git submodule update --init --recursive"
fi
fi
fi
@@ -318,9 +348,22 @@ print_status step "Checking CMake cache..."
if check_cmake_cache; then
print_status success "CMake cache is up to date"
else
if [ $CLEAN_CACHE -eq 1 ] || [ $FIX_ISSUES -eq 1 ]; then
if [ $CLEAN_CACHE -eq 1 ]; then
clean_cmake_cache
elif [ $FIX_ISSUES -eq 1 ]; then
# Ask for confirmation before cleaning cache
echo ""
echo -e "${YELLOW}CMake cache is older than 7 days. Clean it?${NC}"
echo -e "${CYAN}This will remove build/, build_test/, and build-grpc-test/ directories.${NC}"
read -p "Continue? (Y/n) " -n 1 -r
echo ""
if [[ $REPLY =~ ^[Yy]$ ]] || [[ -z $REPLY ]]; then
clean_cmake_cache
else
print_status info "Skipping cache clean"
fi
else
print_status warning "CMake cache is older than 7 days (consider cleaning)"
print_status info "Run with --clean to remove old cache files"
fi
fi