Files

36 lines
2.0 KiB
PowerShell

param(
[Parameter(Mandatory = $true)]
[string]$CompilerPath
)
$ErrorActionPreference = 'Stop'
$compiler = (Resolve-Path -LiteralPath $CompilerPath).Path
$repo = Split-Path -Parent $PSScriptRoot
$files = @(Get-ChildItem -LiteralPath $repo -Filter 'tws_*.gsc' | Sort-Object Name)
$expected = @('tws_t6_common.gsc', 'tws_t6_hud.gsc', 'tws_t6_afk.gsc', 'tws_t6_lock.gsc', 'tws_t6_telemetry.gsc', 'tws_t6_join.gsc', 'tws_t6_leaderboard.gsc', 'tws_t6_bank.gsc', 'tws_t6_moderation.gsc')
if (@(Compare-Object $expected @($files.Name)).Count -ne 0) { throw 'Expected the nine TWS modules: common, HUD, AFK, lock, telemetry, join, leaderboard, bank, moderation.' }
$common = Get-Content -LiteralPath (Join-Path $repo 'tws_t6_common.gsc') -Raw
$functions = @([regex]::Matches($common, '(?m)^([a-zA-Z_][a-zA-Z_0-9]*)\([^\r\n]*\)\s*\r?\n\{') | ForEach-Object { $_.Groups[1].Value })
foreach ($file in $files) {
$source = Get-Content -LiteralPath $file.FullName -Raw
foreach ($entry in @('main', 'init')) {
if ($source -notmatch "(?m)^$entry\(\)\s*\r?\n\{") {
throw "Missing $entry entry point in $($file.Name)"
}
}
if ($source -match 'scripts\\sp\\|maps\\_utility|#"zombiemode"') {
throw "T5-only reference in $($file.Name)"
}
foreach ($reference in [regex]::Matches($source, 'scripts\\zm\\tws_t6_common::([a-zA-Z_][a-zA-Z_0-9]*)')) {
if ($reference.Groups[1].Value -notin $functions) {
throw "Missing common function: $($reference.Groups[1].Value)"
}
}
$output = (& $compiler -m comp -g t6 -s pc -y $file.FullName 2>&1 | Out-String)
# gsc-tool can return zero even when compilation emits an error.
if ($LASTEXITCODE -ne 0 -or $output -match '(?i)error|failed' -or $output -notmatch 'compiled t6/') {
throw "Compile failed for $($file.Name):`n$output"
}
Write-Output "PASS $($file.Name)"
}
Write-Output 'All nine T6 compile checks and common references passed. Runtime linking/gameplay require Plutonium.'