# Compiles the forked client from the existing sources. Fast iteration loop: # fix, run this, look at the numbers. Use prepare-game.ps1 when the sources # themselves need regenerating. # # ASCII only: PowerShell 5.1 reads a .ps1 without a byte order mark using the # system ANSI code page. $ErrorActionPreference = 'Stop' $Fork = Split-Path -Parent $PSScriptRoot if (-not $Fork) { $Fork = $PSCommandPath | Split-Path -Parent | Split-Path -Parent } $Root = Split-Path -Parent $Fork $Client = Join-Path $Root 'rsx-client' $Astral = Join-Path $env:APPDATA 'AstralRinthApp\meta' $Src = Join-Path $Fork 'src' $Out = Join-Path $Fork 'build\classes' $Temp = Join-Path $env:TEMP 'opencode' Add-Type -AssemblyName System.IO.Compression.FileSystem $good = New-Object System.Collections.Generic.List[string] foreach ($j in (Get-ChildItem (Join-Path $Astral 'libraries') -Recurse -Filter '*.jar' -File)) { if ($j.Length -le 100) { continue } $ok = $false try { $z = [System.IO.Compression.ZipFile]::OpenRead($j.FullName); $z.Dispose(); $ok = $true } catch { $ok = $false } if ($ok) { $good.Add(($j.FullName -replace '\\', '/')) } } # The fork calls into the mod loader, so the loader has to be visible to javac # exactly as it is at runtime. Building the loader first is what keeps the two # from drifting apart. $Loader = Join-Path $Client 'dist\rsx-loader.jar' $cp = @($good + $(if (Test-Path $Loader) { $Loader -replace '\\', '/' } else { $null })) -join ';' $argf = Join-Path $Temp 'fork-build.txt' $errf = Join-Path $Temp 'fork-build-errors.txt' $sb = New-Object System.Text.StringBuilder foreach ($a in @('-nowarn', '-proc:none', '-encoding', 'UTF-8', '--release', '17', '-d', ($Out -replace '\\', '/'))) { [void]$sb.AppendLine($a) } [void]$sb.AppendLine('-cp'); [void]$sb.AppendLine('"' + $cp + '"') Get-ChildItem $Src -Recurse -Filter '*.java' | ForEach-Object { [void]$sb.AppendLine(($_.FullName -replace '\\', '/')) } Set-Content -LiteralPath $argf -Value $sb.ToString() -Encoding ASCII Remove-Item $Out -Recurse -Force -ErrorAction SilentlyContinue New-Item -ItemType Directory -Force -Path $Out | Out-Null $javac = (Get-Command javac).Source & cmd /c "`"$javac`" @`"$argf`" -Xmaxerrs 10000 > `"$errf`" 2>&1" $errors = Get-Content -LiteralPath $errf | Select-String -Pattern ': error:' $classes = (Get-ChildItem $Out -Recurse -Filter '*.class' -File -ErrorAction SilentlyContinue).Count if ($errors.Count -eq 0) { Write-Host '' Write-Host " FORK COMPILES CLEAN - $classes classes" -ForegroundColor Green exit 0 } $files = $errors | ForEach-Object { if ($_.Line -match '^([A-Z]:.*?\.java):\d+:') { $matches[1] } } | Sort-Object -Unique Write-Host '' Write-Host " $classes classes, $($errors.Count) errors in $($files.Count) files" -ForegroundColor Yellow $errors | ForEach-Object { if ($_.Line -match '^([A-Z]:.*?\.java):\d+:') { $matches[1] } } | Group-Object | Sort-Object Count -Descending | Select-Object -First 25 | ForEach-Object { Write-Host (" {0,4} {1}" -f $_.Count, ($_.Name.Replace(($Src + '\'), ''))) -ForegroundColor Gray }