Skip to content

Commit 371cf40

Browse files
authored
chore: Add scripts to automate plugin extensions setup (getsentry#1104)
* Add console extension setup script * Fix count * Add top level script to init multiple consoles at once * Clean up logs * Add fresh build flag * Fix path
1 parent 3171804 commit 371cf40

File tree

2 files changed

+335
-0
lines changed

2 files changed

+335
-0
lines changed

scripts/init-console-ext.ps1

Lines changed: 201 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,201 @@
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

scripts/init-consoles.ps1

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
param(
2+
[switch]$All,
3+
[switch]$Switch,
4+
[switch]$PS5,
5+
[switch]$XSX,
6+
[switch]$XB1
7+
)
8+
9+
Set-StrictMode -Version Latest
10+
$ErrorActionPreference = "Stop"
11+
12+
Write-Host "Setting up console plugin extensions" -ForegroundColor Cyan
13+
14+
# If -All is specified, enable all platforms
15+
if ($All) {
16+
$Switch = $true
17+
$PS5 = $true
18+
$XSX = $true
19+
$XB1 = $true
20+
}
21+
22+
# Check if at least one platform is selected
23+
if (-not ($Switch -or $PS5 -or $XSX -or $XB1)) {
24+
Write-Host "Error: No platform specified. Use -All or specify individual platforms (-Switch, -PS5, -XSX, -XB1)" -ForegroundColor Red
25+
Write-Host ""
26+
Write-Host "Examples:"
27+
Write-Host " ./scripts/init-consoles.ps1 -All"
28+
Write-Host " ./scripts/init-consoles.ps1 -Switch -PS5"
29+
Write-Host " ./scripts/init-consoles.ps1 -XSX -XB1"
30+
Write-Host ""
31+
Write-Host "Environment variables required:"
32+
Write-Host " SENTRY_SWITCH_PATH - Path to sentry-switch repo"
33+
Write-Host " SENTRY_PLAYSTATION_PATH - Path to sentry-playstation repo"
34+
Write-Host " SENTRY_XBOX_PATH - Path to sentry-xbox repo"
35+
exit 1
36+
}
37+
38+
# Platform configuration with env var mapping
39+
$platformConfigs = @{
40+
'Switch' = @{
41+
EnvVar = 'SENTRY_SWITCH_PATH'
42+
Enabled = $Switch
43+
}
44+
'PS5' = @{
45+
EnvVar = 'SENTRY_PLAYSTATION_PATH'
46+
Enabled = $PS5
47+
}
48+
'XSX' = @{
49+
EnvVar = 'SENTRY_XBOX_PATH'
50+
Enabled = $XSX
51+
}
52+
'XB1' = @{
53+
EnvVar = 'SENTRY_XBOX_PATH'
54+
Enabled = $XB1
55+
}
56+
}
57+
58+
# Track results
59+
$results = @()
60+
61+
# Process each enabled platform
62+
foreach ($platform in $platformConfigs.Keys | Sort-Object) {
63+
$config = $platformConfigs[$platform]
64+
65+
if (-not $config.Enabled) {
66+
continue
67+
}
68+
69+
Write-Host ""
70+
71+
# Get extension path from environment variable
72+
$envVarName = $config.EnvVar
73+
$extensionPath = [Environment]::GetEnvironmentVariable($envVarName)
74+
75+
if (-not $extensionPath) {
76+
Write-Host "ERROR: Environment variable '$envVarName' is not set" -ForegroundColor Red
77+
$results += @{
78+
Platform = $platform
79+
Status = "Failed"
80+
Message = "Environment variable not set: $envVarName"
81+
}
82+
continue
83+
}
84+
85+
# Call init-console-ext.ps1 for this platform
86+
try {
87+
$scriptPath = Join-Path $PSScriptRoot "init-console-ext.ps1"
88+
& $scriptPath -Platform $platform -ExtensionPath $extensionPath
89+
90+
if ($LASTEXITCODE -ne 0) {
91+
throw "Script failed with exit code $LASTEXITCODE"
92+
}
93+
94+
$results += @{
95+
Platform = $platform
96+
Status = "Success"
97+
Message = "Setup completed"
98+
}
99+
}
100+
catch {
101+
Write-Host "ERROR: Failed to setup $platform - $_" -ForegroundColor Red
102+
$results += @{
103+
Platform = $platform
104+
Status = "Failed"
105+
Message = $_.Exception.Message
106+
}
107+
}
108+
}
109+
110+
# Summary report
111+
Write-Host "`nSummary:`n" -ForegroundColor Cyan
112+
113+
$successCount = 0
114+
$failCount = 0
115+
116+
foreach ($result in $results) {
117+
$statusColor = if ($result.Status -eq "Success") { "Green" } else { "Red" }
118+
$statusSymbol = if ($result.Status -eq "Success") { "" } else { "" }
119+
120+
Write-Host "$statusSymbol $($result.Platform): " -NoNewline -ForegroundColor $statusColor
121+
Write-Host $result.Message
122+
123+
if ($result.Status -eq "Success") {
124+
$successCount++
125+
} else {
126+
$failCount++
127+
}
128+
}
129+
130+
Write-Host "`nTotal: $($results.Count) | Success: $successCount | Failed: $failCount" -ForegroundColor $(if ($failCount -eq 0) { "Green" } else { "Yellow" })
131+
132+
if ($failCount -gt 0) {
133+
exit 1
134+
}

0 commit comments

Comments
 (0)