param([switch]$SkipSubmoduleUpdate, [switch]$NoGitProxy) $ErrorActionPreference = 'Stop' $root = $PSScriptRoot $sub = Join-Path $root 'mavlink' $python = Join-Path $root 'venv/Scripts/python.exe' function Run-Checked([string]$exe, [string[]]$arguments) { & $exe @arguments if ($LASTEXITCODE -ne 0) { throw "Command failed ($LASTEXITCODE): $exe $($arguments -join ' ')" } } if (-not (Test-Path $python)) { throw "Python virtual environment not found: $python" } if (-not $SkipSubmoduleUpdate) { $gitOptions = @() if ($NoGitProxy) { $gitOptions = @('-c','http.proxy=','-c','https.proxy=') } if (-not (Test-Path (Join-Path $sub '.git'))) { Run-Checked 'git' ($gitOptions + @('-C',$root,'submodule','update','--init','--','mavlink')) } $dirty = & git -C $sub status --porcelain --untracked-files=normal if ($LASTEXITCODE -ne 0) { throw 'Cannot inspect MAVLink submodule' } if ($dirty) { throw 'MAVLink submodule has local changes; refusing to overwrite them.' } Run-Checked 'git' ($gitOptions + @('-C',$sub,'fetch','origin','main')) & git -C $sub merge-base --is-ancestor HEAD origin/main if ($LASTEXITCODE -ne 0) { throw 'MAVLink submodule has local or divergent commits; refusing to move it.' } Run-Checked 'git' @('-C',$sub,'switch','--detach','origin/main') Write-Host 'MAVLink submodule updated; parent repository may now show a modified submodule pointer.' } Run-Checked $python @('-m','pip','install','-r',(Join-Path $PSScriptRoot 'requirements.txt')) Run-Checked $python @((Join-Path $PSScriptRoot 'generate_dialect.py')) Run-Checked $python @('-m','unittest','discover','-s',(Join-Path $PSScriptRoot 'tests'),'-v') Run-Checked $python @('-m','PyInstaller','--noconfirm','--clean','--windowed','--onedir','--name','VKGroundStation','--distpath',(Join-Path $PSScriptRoot 'dist'),'--workpath',(Join-Path $PSScriptRoot 'build'),'--specpath',(Join-Path $PSScriptRoot 'build'),(Join-Path $PSScriptRoot 'app.py')) Write-Host "EXE: $PSScriptRoot\dist\VKGroundStation\VKGroundStation.exe"