Files
NESLite/tools/check.ps1
T
2026-09-12 11:24:43 +08:00

76 lines
2.9 KiB
PowerShell

[CmdletBinding()]
param(
[ValidateSet('Build', 'Local', 'Module', 'Stage')]
[string]$Scope = 'Build'
)
$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 }
if (-not (Test-Path (Join-Path $env:JAVA_HOME 'bin\java.exe'))) {
throw 'JDK 17 not found. Set JAVA_HOME to the pinned JDK; see docs/build.md.'
}
$javaExecutable = Join-Path $env:JAVA_HOME 'bin\java.exe'
$javaVersionProcess = New-Object System.Diagnostics.Process
$javaVersionProcess.StartInfo = New-Object System.Diagnostics.ProcessStartInfo
$javaVersionProcess.StartInfo.FileName = $javaExecutable
$javaVersionProcess.StartInfo.Arguments = '-version'
$javaVersionProcess.StartInfo.UseShellExecute = $false
$javaVersionProcess.StartInfo.RedirectStandardError = $true
$javaVersionProcess.StartInfo.CreateNoWindow = $true
$null = $javaVersionProcess.Start()
$javaVersion = $javaVersionProcess.StandardError.ReadToEnd()
$javaVersionProcess.WaitForExit()
if ($javaVersionProcess.ExitCode -ne 0) {
throw "Could not query JDK version at ${javaExecutable}."
}
if ($javaVersion -notmatch 'version "17\.') {
throw "JDK 17 is required, but JAVA_HOME resolves to: $javaVersion"
}
if (-not (Test-Path (Join-Path $sdkRoot 'platforms\android-36.1'))) {
throw "Android SDK Platform 36.1 not found at $sdkRoot. See docs/build.md."
}
$env:ANDROID_HOME = $sdkRoot
$env:ANDROID_SDK_ROOT = $sdkRoot
$env:Path = "$env:JAVA_HOME\bin;$env:Path"
$gradle = Join-Path $root 'gradlew.bat'
$cmake = Join-Path $sdkRoot 'cmake\3.22.1\bin\cmake.exe'
function Invoke-AppBuild {
& $gradle ':app:assembleDebug'
if ($LASTEXITCODE -ne 0) { throw 'Debug APK build failed.' }
}
function Invoke-LocalTest {
& $gradle ':app:testDebugUnitTest'
if ($LASTEXITCODE -ne 0) { throw 'Local unit test failed.' }
}
function Invoke-NativeTest {
if (-not (Test-Path $cmake)) { throw "Pinned Android CMake was not found: $cmake" }
$buildDir = Join-Path $root '.build\native-tests'
$ctest = Join-Path (Split-Path -Parent $cmake) 'ctest.exe'
& $cmake -S (Join-Path $root 'app\src\main\cpp') -B $buildDir
if ($LASTEXITCODE -ne 0) { throw 'Native test configuration failed.' }
& $cmake --build $buildDir --config Debug
if ($LASTEXITCODE -ne 0) { throw 'Native test build failed.' }
& $ctest --test-dir $buildDir -C Debug --output-on-failure
if ($LASTEXITCODE -ne 0) { throw 'Native smoke test failed.' }
}
Push-Location $root
try {
switch ($Scope) {
'Build' { Invoke-AppBuild }
'Local' { Invoke-LocalTest }
'Module' { Invoke-NativeTest; Invoke-LocalTest }
'Stage' { Invoke-AppBuild; Invoke-NativeTest; Invoke-LocalTest }
}
} finally {
Pop-Location
}