Files
sovereign_ai/SovereignAI-Starter/scripts/run_appcontainer_probe.ps1
T

52 lines
2.3 KiB
PowerShell

$ErrorActionPreference = 'Stop'
$repoRoot = (Resolve-Path (Join-Path $PSScriptRoot '..')).Path
$source = Join-Path $PSScriptRoot 'appcontainer_probe.cpp'
$vcvars = Join-Path ${env:ProgramFiles(x86)} 'Microsoft Visual Studio\2022\BuildTools\VC\Auxiliary\Build\vcvars64.bat'
if (-not (Test-Path -LiteralPath $vcvars)) {
throw "Visual Studio C++ Build Tools not found: $vcvars"
}
$outputDir = Join-Path $env:TEMP ("SovereignAI-AppContainer-" + [guid]::NewGuid().ToString('N'))
New-Item -ItemType Directory -Path $outputDir | Out-Null
$exe = Join-Path $outputDir 'appcontainer_probe.exe'
$obj = Join-Path $outputDir 'appcontainer_probe.obj'
$previousPythonHome = $env:SOVEREIGNAI_PYTHON_HOME
try {
Push-Location $repoRoot
try {
$compile = 'call "{0}" && cl.exe /nologo /EHsc /W4 /MT /Fo:"{1}" "{2}" /Fe:"{3}" /link Userenv.lib Ole32.lib Advapi32.lib' -f $vcvars, $obj, $source, $exe
& cmd.exe /d /s /c $compile
if ($LASTEXITCODE -ne 0) {
throw "C++ probe compilation failed with exit code $LASTEXITCODE"
}
$pythonHome = (& python -c 'import sys; print(sys.base_prefix)').Trim()
if ($LASTEXITCODE -ne 0 -or -not (Test-Path -LiteralPath $pythonHome -PathType Container)) {
throw 'Could not locate the active Python runtime to test isolated Python execution.'
}
$env:SOVEREIGNAI_PYTHON_HOME = $pythonHome
$driver = Join-Path $PSScriptRoot 'run_appcontainer_probe.py'
& python $driver $exe
$probeExit = $LASTEXITCODE
if ($probeExit -ne 0) {
throw "AppContainer probe failed with exit code $probeExit"
}
} finally {
Pop-Location
}
} finally {
if ($null -eq $previousPythonHome) {
Remove-Item Env:SOVEREIGNAI_PYTHON_HOME -ErrorAction SilentlyContinue
} else {
$env:SOVEREIGNAI_PYTHON_HOME = $previousPythonHome
}
$resolvedOutput = (Resolve-Path -LiteralPath $outputDir -ErrorAction SilentlyContinue).Path
$tempRoot = [IO.Path]::GetFullPath($env:TEMP).TrimEnd('\') + '\'
if ($resolvedOutput -and $resolvedOutput.StartsWith($tempRoot, [StringComparison]::OrdinalIgnoreCase) -and
(Split-Path -Leaf $resolvedOutput).StartsWith('SovereignAI-AppContainer-', [StringComparison]::Ordinal)) {
Remove-Item -LiteralPath $resolvedOutput -Recurse -Force
}
}