Files
NESLite/tools/package-rc.ps1
T

153 lines
8.6 KiB
PowerShell

[CmdletBinding()]
param(
[string]$OutputDirectory = ''
)
$ErrorActionPreference = 'Stop'
$root = Split-Path -Parent $PSScriptRoot
$sdkRoot = if ($env:ANDROID_HOME) { $env:ANDROID_HOME } else { 'C:\Users\shenw_o246oq4\AppData\Local\Android\Sdk' }
$bundledJdk = Join-Path $root '.toolchains\jdk-17.0.17+10'
$env:JAVA_HOME = if ($env:JAVA_HOME -and (Test-Path (Join-Path $env:JAVA_HOME 'bin\java.exe'))) {
$env:JAVA_HOME
} else {
$bundledJdk
}
$env:ANDROID_HOME = $sdkRoot
$env:ANDROID_SDK_ROOT = $sdkRoot
$versionName = '0.9.14'
$versionCode = 9014
$gitStatus = @(& git -C $root status --porcelain)
if ($LASTEXITCODE -ne 0) { throw 'Cannot inspect the Git worktree.' }
if ($gitStatus.Count -ne 0) { throw 'RC packaging requires a clean committed worktree.' }
$sourceCommit = (& git -C $root rev-parse HEAD).Trim()
if ($LASTEXITCODE -ne 0) { throw 'Cannot resolve the source commit.' }
if (-not $OutputDirectory) { $OutputDirectory = Join-Path $root ".build\rc-$versionName" }
$resolvedOutput = [IO.Path]::GetFullPath($OutputDirectory)
$resolvedBuildRoot = [IO.Path]::GetFullPath((Join-Path $root '.build'))
if (-not $resolvedOutput.StartsWith($resolvedBuildRoot, [StringComparison]::OrdinalIgnoreCase)) {
throw 'RC output must remain inside the repository .build directory.'
}
if (Test-Path $resolvedOutput) { Remove-Item -LiteralPath $resolvedOutput -Recurse -Force }
$null = New-Item -ItemType Directory -Path $resolvedOutput
& pwsh -NoProfile -ExecutionPolicy Bypass -File (Join-Path $root 'tools\check.ps1') -Scope Stage
if ($LASTEXITCODE -ne 0) { throw 'Stage checks failed.' }
& (Join-Path $root 'gradlew.bat') ':app:assembleRelease' ':app:lintRelease' ':app:assembleDebugAndroidTest'
if ($LASTEXITCODE -ne 0) { throw 'Release build or lint failed.' }
$builtApk = Join-Path $root 'app\build\outputs\apk\release\app-release-unsigned.apk'
$builtSymbols = Join-Path $root 'app\build\outputs\native-debug-symbols\release\native-debug-symbols.zip'
if (-not (Test-Path $builtApk)) { throw "Unsigned release APK not found: $builtApk" }
if (-not (Test-Path $builtSymbols)) { throw "Native symbols not found: $builtSymbols" }
$candidateApk = Join-Path $resolvedOutput "NESLite-$versionName-rc-arm64-v8a-unsigned.apk"
$candidateSymbols = Join-Path $resolvedOutput "NESLite-$versionName-native-debug-symbols.zip"
Copy-Item -LiteralPath $builtApk -Destination $candidateApk
Copy-Item -LiteralPath $builtSymbols -Destination $candidateSymbols
$testTools = Join-Path $resolvedOutput 'test-tools'
$null = New-Item -ItemType Directory -Path $testTools
Copy-Item -LiteralPath (Join-Path $root 'app\build\outputs\apk\debug\app-debug.apk') -Destination $testTools
Copy-Item -LiteralPath (Join-Path $root 'app\build\outputs\apk\androidTest\debug\app-debug-androidTest.apk') -Destination $testTools
$nativeAudit = Join-Path $resolvedOutput 'native-audit.json'
& pwsh -NoProfile -ExecutionPolicy Bypass -File (Join-Path $root 'tools\check-rc-native.ps1') -ApkPath $candidateApk -OutputPath $nativeAudit
if ($LASTEXITCODE -ne 0) { throw 'Native static audit failed.' }
$aapt = Join-Path $sdkRoot 'build-tools\36.1.0\aapt.exe'
$badging = @(& $aapt dump badging $candidateApk 2>&1)
if ($LASTEXITCODE -ne 0) { throw 'Could not inspect candidate APK identity.' }
$packageLine = $badging | Select-Object -First 1
if ($packageLine -notmatch "name='org\.neslite\.app'.*versionCode='$versionCode'.*versionName='$versionName'") {
throw "Unexpected release identity: $packageLine"
}
$appSourceArchive = Join-Path $resolvedOutput "NESLite-$versionName-source.zip"
& git -C $root archive --format=zip "--prefix=NESLite-$versionName/" "--output=$appSourceArchive" HEAD
if ($LASTEXITCODE -ne 0) { throw 'Application source archive failed.' }
$thirdPartyManifest = Get-Content (Join-Path $root 'third_party\manifest.json') -Raw | ConvertFrom-Json
$thirdPartyArchives = @()
foreach ($source in $thirdPartyManifest.sources) {
$sourceDirectory = Join-Path $root "third_party\sources\$($source.directory)"
if (-not (Test-Path $sourceDirectory)) { throw "Third-party source is missing: $($source.directory)" }
$actualCommit = (& git -C $sourceDirectory rev-parse HEAD).Trim()
if ($LASTEXITCODE -ne 0 -or $actualCommit -ne $source.commit) {
throw "Third-party source is not at its locked commit: $($source.directory)"
}
$archive = Join-Path $resolvedOutput "$($source.directory)-$($source.commit.Substring(0, 12))-source.zip"
& git -C $sourceDirectory archive --format=zip "--prefix=$($source.directory)/" "--output=$archive" $source.commit
if ($LASTEXITCODE -ne 0) { throw "Source archive failed: $($source.directory)" }
$thirdPartyArchives += Split-Path -Leaf $archive
}
$materials = Join-Path $resolvedOutput 'release-materials'
$null = New-Item -ItemType Directory -Path $materials
Copy-Item -LiteralPath (Join-Path $root 'LICENSE') -Destination $materials
Copy-Item -LiteralPath (Join-Path $root 'THIRD_PARTY_NOTICES.md') -Destination $materials
Copy-Item -LiteralPath (Join-Path $root 'third_party\manifest.json') -Destination $materials
Copy-Item -LiteralPath (Join-Path $root 'third_party\sources\oboe\LICENSE') -Destination (Join-Path $materials 'APACHE-2.0.txt')
Copy-Item -LiteralPath (Join-Path $root 'third_party\sources\libretro-fceumm\Copying') -Destination (Join-Path $materials 'GPL-2.0.txt')
Copy-Item -LiteralPath (Join-Path $root 'docs\build.md') -Destination $materials
Copy-Item -LiteralPath (Join-Path $root 'docs\usage.md') -Destination $materials
Copy-Item -LiteralPath (Join-Path $root 'docs\architecture.md') -Destination $materials
Copy-Item -LiteralPath (Join-Path $root 'docs\save-format.md') -Destination $materials
Copy-Item -LiteralPath (Join-Path $root 'docs\known-issues.md') -Destination $materials
Copy-Item -LiteralPath (Join-Path $root 'docs\reports\m8-release-candidate.md') -Destination $materials
& pwsh -NoProfile -ExecutionPolicy Bypass -File (Join-Path $root 'tools\generate-rc-roms.ps1')
if ($LASTEXITCODE -ne 0) { throw 'Frozen RC ROM generation or hash verification failed.' }
$fixtureMetadata = Join-Path $resolvedOutput 'rom-fixture-metadata'
$null = New-Item -ItemType Directory -Path $fixtureMetadata
Copy-Item -LiteralPath (Join-Path $root '.build\rc-roms\manifest.json') -Destination $fixtureMetadata
Copy-Item -LiteralPath (Join-Path $root '.build\rc-roms\LICENSE.txt') -Destination $fixtureMetadata
$manifest = [ordered]@{
formatVersion = 1
generatedAt = (Get-Date).ToUniversalTime().ToString('o')
sourceCommit = $sourceCommit
versionName = $versionName
versionCode = $versionCode
applicationId = 'org.neslite.app'
abi = @('arm64-v8a')
signing = [ordered]@{
signed = $false
status = 'BLOCKED_PENDING_RELEASE_KEY'
note = 'This static-audit candidate must be signed with the protected release key before installation or upgrade testing.'
}
native = [ordered]@{
fceummCommit = '236ccdfc911e84c60fea6b9d0699c2d440a8de14'
libretroHeaderCommit = '0c9622896333ee62dc4326bbe8784a210ddeb03c'
oboeCommit = 'a81bb9f87d4105b84b682685d3bfbb5beca371d1'
symbols = Split-Path -Leaf $candidateSymbols
mapping = 'not generated; minification is disabled'
}
artifacts = [ordered]@{
apk = Split-Path -Leaf $candidateApk
applicationSource = Split-Path -Leaf $appSourceArchive
thirdPartySources = $thirdPartyArchives
nativeAudit = Split-Path -Leaf $nativeAudit
materials = 'release-materials/'
romFixtureMetadata = 'rom-fixture-metadata/'
androidMigrationTest = 'test-tools/app-debug-androidTest.apk'
}
runtimeEvidence = [ordered]@{
romCompatibility = 'BLOCKED_NO_EXECUTED_RC_COMPATIBILITY_OR_GAMEPLAY_SAMPLES'
hLong = 'BLOCKED_NO_DEVICE'
hInput = 'BLOCKED_NO_DEVICE'
fourKiB = 'BLOCKED_NO_DEVICE'
sixteenKiB = 'BLOCKED_NO_DEVICE'
api28 = 'BLOCKED_NO_DEVICE'
upgrade = 'BLOCKED_NO_SIGNED_OLD_DATASET_OR_DEVICE'
}
}
$manifestPath = Join-Path $resolvedOutput 'candidate-manifest.json'
$manifest | ConvertTo-Json -Depth 8 | Set-Content -LiteralPath $manifestPath -Encoding utf8NoBOM
$checksumFiles = Get-ChildItem $resolvedOutput -File -Recurse | Where-Object Name -ne 'SHA256SUMS.txt' | Sort-Object FullName
$checksumLines = foreach ($file in $checksumFiles) {
$relative = [IO.Path]::GetRelativePath($resolvedOutput, $file.FullName).Replace('\', '/')
"{0} {1}" -f (Get-FileHash $file.FullName -Algorithm SHA256).Hash, $relative
}
$checksumLines | Set-Content -LiteralPath (Join-Path $resolvedOutput 'SHA256SUMS.txt') -Encoding ascii
Write-Output "RC materials created: $resolvedOutput"
Write-Output 'The APK is intentionally unsigned; device and upgrade gates remain blocked until release signing is available.'