|
| 1 | +param( |
| 2 | + [Parameter(Mandatory=$true)] |
| 3 | + [ValidateSet('Switch', 'PS5', 'XSX', 'XB1')] |
| 4 | + [string]$Platform, |
| 5 | + |
| 6 | + [Parameter(Mandatory=$true)] |
| 7 | + [string]$ExtensionPath |
| 8 | +) |
| 9 | + |
| 10 | +Set-StrictMode -Version Latest |
| 11 | +$ErrorActionPreference = "Stop" |
| 12 | + |
| 13 | +# Platform-specific configuration |
| 14 | +$platformConfig = @{ |
| 15 | + 'Switch' = @{ |
| 16 | + Preset = 'nx64-unreal' |
| 17 | + BuildDir = 'nx64-unreal' |
| 18 | + PlatformFolder = 'Switch' |
| 19 | + SourceDir = 'Sentry' |
| 20 | + } |
| 21 | + 'PS5' = @{ |
| 22 | + Preset = 'ps5-unreal' |
| 23 | + BuildDir = 'ps5-unreal' |
| 24 | + PlatformFolder = 'PS5' |
| 25 | + SourceDir = 'Sentry' |
| 26 | + } |
| 27 | + 'XSX' = @{ |
| 28 | + Preset = 'scarlett-unreal' |
| 29 | + BuildDir = 'scarlett-unreal' |
| 30 | + PlatformFolder = 'XSX' |
| 31 | + SourceDir = 'Sentry_XSX' |
| 32 | + } |
| 33 | + 'XB1' = @{ |
| 34 | + Preset = 'xboxone-unreal' |
| 35 | + BuildDir = 'xboxone-unreal' |
| 36 | + PlatformFolder = 'XB1' |
| 37 | + SourceDir = 'Sentry_XB1' |
| 38 | + } |
| 39 | +} |
| 40 | + |
| 41 | +$config = $platformConfig[$Platform] |
| 42 | +$repoRoot = Resolve-Path "$PSScriptRoot/.." |
| 43 | + |
| 44 | +Write-Host "Setting up $Platform console extension..." -ForegroundColor Cyan |
| 45 | +Write-Host "Extension path: $ExtensionPath" |
| 46 | + |
| 47 | +# Step 1: Validate extension path |
| 48 | +Write-Host "`n[1/5] Validating extension path..." -ForegroundColor Yellow |
| 49 | + |
| 50 | +if (-not (Test-Path $ExtensionPath)) { |
| 51 | + throw "Extension path does not exist: $ExtensionPath" |
| 52 | +} |
| 53 | +$ExtensionPath = Resolve-Path $ExtensionPath |
| 54 | + |
| 55 | +$cmakeFile = Join-Path $ExtensionPath "CMakeLists.txt" |
| 56 | +if (-not (Test-Path $cmakeFile)) { |
| 57 | + throw "CMakeLists.txt not found in extension path: $ExtensionPath" |
| 58 | +} |
| 59 | + |
| 60 | +$unrealDir = Join-Path $ExtensionPath "unreal" |
| 61 | +if (-not (Test-Path $unrealDir)) { |
| 62 | + throw "unreal directory not found in extension path: $ExtensionPath" |
| 63 | +} |
| 64 | + |
| 65 | +$sourceDir = Join-Path $unrealDir $config.SourceDir |
| 66 | +if (-not (Test-Path $sourceDir)) { |
| 67 | + throw "Source directory not found: $sourceDir" |
| 68 | +} |
| 69 | + |
| 70 | +Write-Host " ✓ Extension path validated" -ForegroundColor Green |
| 71 | + |
| 72 | +# Step 2: Build extension |
| 73 | +Write-Host "`n[2/5] Building extension..." -ForegroundColor Yellow |
| 74 | +Write-Host " Running: cmake --workflow --preset $($config.Preset) --fresh" |
| 75 | + |
| 76 | +Push-Location $ExtensionPath |
| 77 | +try { |
| 78 | + $buildOutput = & cmake --workflow --preset $config.Preset --fresh 2>&1 |
| 79 | + if ($LASTEXITCODE -ne 0) { |
| 80 | + Write-Host $buildOutput -ForegroundColor Red |
| 81 | + throw "Build failed with exit code $LASTEXITCODE" |
| 82 | + } |
| 83 | + Write-Host " ✓ Extension built successfully" -ForegroundColor Green |
| 84 | +} finally { |
| 85 | + Pop-Location |
| 86 | +} |
| 87 | + |
| 88 | +# Verify build output exists |
| 89 | +$buildOutputDir = Join-Path $ExtensionPath "build" $config.BuildDir "unreal" "Sentry" |
| 90 | +if (-not (Test-Path $buildOutputDir)) { |
| 91 | + throw "Build output directory not found: $buildOutputDir" |
| 92 | +} |
| 93 | + |
| 94 | +# Step 3: Create directory structure in sample project |
| 95 | +Write-Host "`n[3/5] Creating directory structure..." -ForegroundColor Yellow |
| 96 | + |
| 97 | +$targetPluginRoot = Join-Path $repoRoot "sample" "Platforms" $config.PlatformFolder "Plugins" "Sentry" |
| 98 | +$targetSourceRoot = Join-Path $targetPluginRoot "Source" |
| 99 | +$targetThirdPartyDir = Join-Path $targetSourceRoot "ThirdParty" $config.PlatformFolder |
| 100 | + |
| 101 | +# Create all necessary directories |
| 102 | +$dirsToCreate = @( |
| 103 | + $targetPluginRoot, |
| 104 | + $targetSourceRoot, |
| 105 | + (Join-Path $targetSourceRoot "Sentry" "Private"), |
| 106 | + $targetThirdPartyDir |
| 107 | +) |
| 108 | + |
| 109 | +foreach ($dir in $dirsToCreate) { |
| 110 | + if (-not (Test-Path $dir)) { |
| 111 | + New-Item -ItemType Directory -Path $dir -Force | Out-Null |
| 112 | + Write-Host " Created: $dir" |
| 113 | + } |
| 114 | +} |
| 115 | + |
| 116 | +Write-Host " ✓ Directory structure created" -ForegroundColor Green |
| 117 | + |
| 118 | +# Step 4: Copy build artifacts (ThirdParty libs/headers) |
| 119 | +Write-Host "`n[4/5] Copying build artifacts..." -ForegroundColor Yellow |
| 120 | + |
| 121 | +$buildThirdPartyDir = Join-Path $buildOutputDir "Source" "ThirdParty" $config.PlatformFolder |
| 122 | +if (-not (Test-Path $buildThirdPartyDir)) { |
| 123 | + throw "Build ThirdParty directory not found: $buildThirdPartyDir" |
| 124 | +} |
| 125 | + |
| 126 | +# Remove existing ThirdParty directory if it exists to ensure clean copy |
| 127 | +if (Test-Path $targetThirdPartyDir) { |
| 128 | + Remove-Item -Path $targetThirdPartyDir -Recurse -Force |
| 129 | +} |
| 130 | + |
| 131 | +# Copy entire ThirdParty directory |
| 132 | +Copy-Item -Path $buildThirdPartyDir -Destination (Join-Path $targetSourceRoot "ThirdParty") -Recurse -Force |
| 133 | +Write-Host " Copied: ThirdParty/$($config.PlatformFolder)/" |
| 134 | + |
| 135 | +Write-Host " ✓ Build artifacts copied" -ForegroundColor Green |
| 136 | + |
| 137 | +# Step 5: Symlink source files for live editing |
| 138 | +Write-Host "`n[5/5] Creating symlinks to source files..." -ForegroundColor Yellow |
| 139 | + |
| 140 | +# Helper function to create symlink/junction |
| 141 | +function New-SymbolicLink { |
| 142 | + param( |
| 143 | + [string]$LinkPath, |
| 144 | + [string]$TargetPath |
| 145 | + ) |
| 146 | + |
| 147 | + # Remove existing link if it exists |
| 148 | + if (Test-Path $LinkPath) { |
| 149 | + $item = Get-Item $LinkPath |
| 150 | + if ($item.LinkType -eq "Junction" -or $item.LinkType -eq "SymbolicLink") { |
| 151 | + $item.Delete() |
| 152 | + } else { |
| 153 | + Remove-Item -Path $LinkPath -Recurse -Force |
| 154 | + } |
| 155 | + } |
| 156 | + |
| 157 | + # Create parent directory if needed |
| 158 | + $parentDir = Split-Path -Parent $LinkPath |
| 159 | + if (-not (Test-Path $parentDir)) { |
| 160 | + New-Item -ItemType Directory -Path $parentDir -Force | Out-Null |
| 161 | + } |
| 162 | + |
| 163 | + # Create junction (works cross-platform with PowerShell) |
| 164 | + if (Test-Path $TargetPath -PathType Container) { |
| 165 | + New-Item -ItemType Junction -Path $LinkPath -Target $TargetPath | Out-Null |
| 166 | + } else { |
| 167 | + New-Item -ItemType SymbolicLink -Path $LinkPath -Target $TargetPath | Out-Null |
| 168 | + } |
| 169 | +} |
| 170 | + |
| 171 | +# Symlink .uplugin file |
| 172 | +$upluginFiles = @(Get-ChildItem -Path $sourceDir -Filter "*.uplugin" -ErrorAction SilentlyContinue) |
| 173 | +if ($upluginFiles.Count -eq 0) { |
| 174 | + throw "No .uplugin file found in $sourceDir" |
| 175 | +} |
| 176 | +$upluginTarget = $upluginFiles[0].FullName |
| 177 | +$upluginLink = Join-Path $targetPluginRoot $upluginFiles[0].Name |
| 178 | +New-SymbolicLink -LinkPath $upluginLink -TargetPath $upluginTarget |
| 179 | +Write-Host " Linked: $($upluginFiles[0].Name)" |
| 180 | + |
| 181 | +# Symlink .Build.cs file |
| 182 | +$buildcsFiles = @(Get-ChildItem -Path (Join-Path $sourceDir "Source") -Filter "*.Build.cs" -ErrorAction SilentlyContinue) |
| 183 | +if ($buildcsFiles.Count -gt 0) { |
| 184 | + $buildcsTarget = $buildcsFiles[0].FullName |
| 185 | + $buildcsLink = Join-Path $targetSourceRoot $buildcsFiles[0].Name |
| 186 | + New-SymbolicLink -LinkPath $buildcsLink -TargetPath $buildcsTarget |
| 187 | + Write-Host " Linked: Source/$($buildcsFiles[0].Name)" |
| 188 | +} |
| 189 | + |
| 190 | +# Symlink Sentry/Private directory (contains .cpp/.h files) |
| 191 | +$privateSourceDir = Join-Path $sourceDir "Source" "Sentry" "Private" |
| 192 | +if (Test-Path $privateSourceDir) { |
| 193 | + $privateTargetDir = Join-Path $targetSourceRoot "Sentry" "Private" |
| 194 | + New-SymbolicLink -LinkPath $privateTargetDir -TargetPath $privateSourceDir |
| 195 | + Write-Host " Linked: Source/Sentry/Private/" |
| 196 | +} |
| 197 | + |
| 198 | +Write-Host " ✓ Source files symlinked" -ForegroundColor Green |
| 199 | + |
| 200 | +Write-Host "`n✓ Console extension setup complete!" -ForegroundColor Green |
| 201 | +Write-Host "`nTarget location: $targetPluginRoot" -ForegroundColor Cyan |
0 commit comments