build.ps1 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. param (
  2. [switch]$doNotClearBuildFolder = $false
  3. )
  4. function Get-LatestDirectory {
  5. param (
  6. $Path
  7. )
  8. Get-ChildItem -Path $Path | Where-Object {$_.PSIsContainer} | Sort-Object LastWriteTime -Descending | Select-Object -First 1
  9. }
  10. $build_commands = @(
  11. [PSCustomObject]@{
  12. Name = "Official Dev";
  13. FbtSwitch = "od";
  14. FirmwarePath = "flipperzero-firmware_official_dev";
  15. ArtifactName = "totp_official-dev_fw{FEATURES_SUFFIX}.fap";
  16. }
  17. [PSCustomObject]@{
  18. Name = "Official Stable";
  19. FbtSwitch = "os";
  20. FirmwarePath = "flipperzero-firmware_official_stable";
  21. ArtifactName = "totp_official-stable_fw{FEATURES_SUFFIX}.fap";
  22. }
  23. [PSCustomObject]@{
  24. Name = "Xtreme \ Unleashed";
  25. FbtSwitch = "x";
  26. FirmwarePath = "flipperzero-firmware_xtreme";
  27. ArtifactName = "totp_xtreme_unleashed_fw{FEATURES_SUFFIX}.fap";
  28. }
  29. )
  30. Push-Location $PSScriptRoot
  31. if (!(Test-Path -PathType Container "build")) {
  32. New-Item -ItemType Directory -Path "build"
  33. } elseif (!$doNotClearBuildFolder) {
  34. Remove-Item "build/*" -Recurse -Force
  35. }
  36. function Build-Run {
  37. param (
  38. [string]$FeaturesSuffix,
  39. [string[]]$CppDefine,
  40. [string]$Subfolder
  41. )
  42. foreach ($build_command in $build_commands) {
  43. Write-Host "Building $($build_command.Name)"
  44. $build_path = Join-Path -Path $build_command.FirmwarePath -ChildPath "build"
  45. $fbt_args = @($build_command.FbtSwitch, "COMPACT=1", "DEBUG=0", "VERBOSE=0", "fap_totp", "--clean")
  46. if ($CppDefine.Length -gt 0) {
  47. $CppDefine | ForEach-Object {
  48. $fbt_args += '-D'
  49. $fbt_args += $_
  50. }
  51. }
  52. Invoke-Expression -Command "./fbt.ps1 $fbt_args"
  53. $latest_dir = (Get-LatestDirectory -Path $build_path).Name
  54. $build_output_folder = "build"
  55. if ($Subfolder -ne $null -and $Subfolder -ne '') {
  56. $build_output_folder = Join-Path $build_output_folder $Subfolder
  57. if (!(Test-Path -PathType Container $build_output_folder)) {
  58. New-Item -ItemType Directory -Path $build_output_folder
  59. }
  60. }
  61. $build_output_artifact = Join-Path $build_output_folder "$($build_command.ArtifactName -replace '{FEATURES_SUFFIX}',$FeaturesSuffix)"
  62. Copy-Item "$build_path/$latest_dir/.extapps/totp.fap" -Destination $build_output_artifact
  63. Write-Host "Artifacts for $($build_command.Name) stored at $build_output_artifact"
  64. }
  65. }
  66. Write-Information 'Building with all the features enables'
  67. Build-Run -FeaturesSuffix ''
  68. Write-Information 'Building without BadBT'
  69. Build-Run -FeaturesSuffix '_no-badbt' -CppDefine TOTP_NO_BADBT_AUTOMATION
  70. $checksum_file = 'build/checksums.sha256'
  71. New-Item $checksum_file -ItemType File -Force
  72. Get-ChildItem -Path 'build/*.fap' | ForEach-Object {
  73. $checksum = (Get-FileHash $_ -Algorithm SHA256).Hash.ToLower()
  74. $filename = $_.Name
  75. "$checksum $filename" >> $checksum_file
  76. }
  77. Pop-Location