build.ps1 2.0 KB

123456789101112131415161718192021222324252627282930
  1. param([switch]$SkipSubmoduleUpdate, [switch]$NoGitProxy)
  2. $ErrorActionPreference = 'Stop'
  3. $root = $PSScriptRoot
  4. $sub = Join-Path $root 'mavlink'
  5. $python = Join-Path $root 'venv/Scripts/python.exe'
  6. function Run-Checked([string]$exe, [string[]]$arguments) {
  7. & $exe @arguments
  8. if ($LASTEXITCODE -ne 0) { throw "Command failed ($LASTEXITCODE): $exe $($arguments -join ' ')" }
  9. }
  10. if (-not (Test-Path $python)) { throw "Python virtual environment not found: $python" }
  11. if (-not $SkipSubmoduleUpdate) {
  12. $gitOptions = @()
  13. if ($NoGitProxy) { $gitOptions = @('-c','http.proxy=','-c','https.proxy=') }
  14. if (-not (Test-Path (Join-Path $sub '.git'))) {
  15. Run-Checked 'git' ($gitOptions + @('-C',$root,'submodule','update','--init','--','mavlink'))
  16. }
  17. $dirty = & git -C $sub status --porcelain --untracked-files=normal
  18. if ($LASTEXITCODE -ne 0) { throw 'Cannot inspect MAVLink submodule' }
  19. if ($dirty) { throw 'MAVLink submodule has local changes; refusing to overwrite them.' }
  20. Run-Checked 'git' ($gitOptions + @('-C',$sub,'fetch','origin','main'))
  21. & git -C $sub merge-base --is-ancestor HEAD origin/main
  22. if ($LASTEXITCODE -ne 0) { throw 'MAVLink submodule has local or divergent commits; refusing to move it.' }
  23. Run-Checked 'git' @('-C',$sub,'switch','--detach','origin/main')
  24. Write-Host 'MAVLink submodule updated; parent repository may now show a modified submodule pointer.'
  25. }
  26. Run-Checked $python @('-m','pip','install','-r',(Join-Path $PSScriptRoot 'requirements.txt'))
  27. Run-Checked $python @((Join-Path $PSScriptRoot 'generate_dialect.py'))
  28. Run-Checked $python @('-m','unittest','discover','-s',(Join-Path $PSScriptRoot 'tests'),'-v')
  29. 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'))
  30. Write-Host "EXE: $PSScriptRoot\dist\VKGroundStation\VKGroundStation.exe"