build.ps1 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. function Get-LatestDirectory {
  2. param (
  3. $Path
  4. )
  5. Get-ChildItem -Path $Path | Where-Object {$_.PSIsContainer} | Sort-Object LastWriteTime -Descending | Select-Object -First 1
  6. }
  7. $build_commands = @(
  8. [PSCustomObject]@{
  9. Name = "Official Dev \ Unleashed";
  10. FbtSwitch = "od";
  11. FirmwarePath = "flipperzero-firmware_official_dev";
  12. ArtifactName = "totp_official-dev_unleashed_fw{FEATURES_SUFFIX}.fap"
  13. }
  14. [PSCustomObject]@{
  15. Name = "Official Stable";
  16. FbtSwitch = "os";
  17. FirmwarePath = "flipperzero-firmware_official_stable";
  18. ArtifactName = "totp_official-stable_fw{FEATURES_SUFFIX}.fap"
  19. }
  20. )
  21. Push-Location $PSScriptRoot
  22. if (!(Test-Path -PathType Container "build")) {
  23. New-Item -ItemType Directory -Path "build"
  24. } else {
  25. Remove-Item "build\*" -Recurse -Force
  26. }
  27. function Features-Configure {
  28. param (
  29. [string[]]$enable,
  30. [string[]]$disable
  31. )
  32. $featuresConfigContent = Get-Content "totp/features_config.h" -Raw
  33. $appManifestContent = Get-Content "totp/application.fam" -Raw
  34. foreach ($feature in $enable) {
  35. $featuresConfigContent = $featuresConfigContent -replace "(#undef)(\s+$feature(\s|$)+)", '#define$2'
  36. [regex]$appManifestFeaturePattern="(#ifdef $feature\r?\n)((.+\r?\n)+)(#\s*endif)"
  37. $appManifestContent = $appManifestFeaturePattern.Replace($appManifestContent, { param($match)
  38. return $match.Groups[1].Value +
  39. ($match.Groups[2].Value -replace '^(\s*)#(.+)$', '$1$2') +
  40. $match.Groups[4].Value
  41. })
  42. }
  43. foreach ($feature in $disable) {
  44. $featuresConfigContent = $featuresConfigContent -replace "(#define)(\s+$feature(\s|$)+)", '#undef$2'
  45. [regex]$appManifestFeaturePattern="(#ifdef $feature\r?\n)((.+\r?\n)+)(#\s*endif)"
  46. $appManifestContent = $appManifestFeaturePattern.Replace($appManifestContent, { param($match)
  47. return $match.Groups[1].Value +
  48. ($match.Groups[2].Value -replace '^(\s*)(.+)$', '#$1$2') +
  49. $match.Groups[4].Value
  50. })
  51. }
  52. Set-Content -Path "totp/features_config.h" -NoNewline -Value $featuresConfigContent
  53. Set-Content -Path "totp/application.fam" -NoNewline -Value $appManifestContent
  54. }
  55. function Build-Run {
  56. param (
  57. [string]$FeaturesSuffix
  58. )
  59. foreach ($build_command in $build_commands) {
  60. Write-Host "Building $($build_command.Name)"
  61. $build_path = Join-Path -Path $build_command.FirmwarePath -ChildPath "build"
  62. if (Test-Path -PathType Container $build_path) {
  63. Remove-Item "$build_path\*" -Recurse -Force
  64. }
  65. ./fbt $build_command.FbtSwitch COMPACT=1 DEBUG=0 VERBOSE=0 fap_totp
  66. $latest_dir = Get-LatestDirectory -Path $build_path
  67. $build_output_artifact = "build\$($build_command.ArtifactName -replace '{FEATURES_SUFFIX}',$FeaturesSuffix)"
  68. Copy-Item "$build_path\$latest_dir\.extapps\totp.fap" -Destination $build_output_artifact
  69. Write-Host "Artifacts for $($build_command.Name) stored at $build_output_artifact"
  70. }
  71. }
  72. Write-Information 'Building with all the features enables'
  73. Features-Configure -enable TOTP_BADBT_TYPE_ENABLED,TOTP_BADBT_TYPE_ICON_ENABLED
  74. Build-Run -FeaturesSuffix ''
  75. Write-Information 'Building with BadBT but without BadBT icon'
  76. Features-Configure -disable TOTP_BADBT_TYPE_ICON_ENABLED
  77. Build-Run -FeaturesSuffix '_badbt-wo-icon'
  78. Write-Information 'Building without BadBT'
  79. Features-Configure -disable TOTP_BADBT_TYPE_ENABLED,TOTP_BADBT_TYPE_ICON_ENABLED
  80. Build-Run -FeaturesSuffix '_no-badbt'
  81. Features-Configure -enable TOTP_BADBT_TYPE_ENABLED,TOTP_BADBT_TYPE_ICON_ENABLED
  82. Pop-Location