build.ps1 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. FW_CDEF = "TOTP_FIRMWARE_OFFICIAL_DEV"
  14. }
  15. [PSCustomObject]@{
  16. Name = "Official Stable";
  17. FbtSwitch = "os";
  18. FirmwarePath = "flipperzero-firmware_official_stable";
  19. ArtifactName = "totp_official-stable_fw{FEATURES_SUFFIX}.fap";
  20. FW_CDEF = "TOTP_FIRMWARE_OFFICIAL_STABLE"
  21. }
  22. [PSCustomObject]@{
  23. Name = "Xtreme";
  24. FbtSwitch = "x";
  25. FirmwarePath = "flipperzero-firmware_xtreme";
  26. ArtifactName = "totp_xtreme_fw{FEATURES_SUFFIX}.fap";
  27. FW_CDEF = "TOTP_FIRMWARE_XTREME"
  28. }
  29. )
  30. Push-Location $PSScriptRoot
  31. if (!(Test-Path -PathType Container "build")) {
  32. New-Item -ItemType Directory -Path "build"
  33. } else {
  34. Remove-Item "build\*" -Recurse -Force
  35. }
  36. function Features-Configure {
  37. param (
  38. [string[]]$enable,
  39. [string[]]$disable,
  40. [string]$set
  41. )
  42. $featuresConfigContent = Get-Content "totp/features_config.h" -Raw
  43. $appManifestContent = Get-Content "totp/application.fam" -Raw
  44. foreach ($feature in $enable) {
  45. $featuresConfigContent = $featuresConfigContent -replace "(#undef)(\s+$feature(\s|$)+)", '#define$2'
  46. [regex]$appManifestFeaturePattern="(#ifdef $feature\r?\n)((.+\r?\n)+)(#\s*endif)"
  47. $appManifestContent = $appManifestFeaturePattern.Replace($appManifestContent, { param($match)
  48. return $match.Groups[1].Value +
  49. ($match.Groups[2].Value -replace '^(\s*)#(.+)$', '$1$2') +
  50. $match.Groups[4].Value
  51. })
  52. }
  53. foreach ($feature in $disable) {
  54. $featuresConfigContent = $featuresConfigContent -replace "(#define)(\s+$feature(\s|$)+)", '#undef$2'
  55. [regex]$appManifestFeaturePattern="(#ifdef $feature\r?\n)((.+\r?\n)+)(#\s*endif)"
  56. $appManifestContent = $appManifestFeaturePattern.Replace($appManifestContent, { param($match)
  57. return $match.Groups[1].Value +
  58. ($match.Groups[2].Value -replace '^(\s*)(.+)$', '#$1$2') +
  59. $match.Groups[4].Value
  60. })
  61. }
  62. if ($set) {
  63. $keyValue = $set -split '='
  64. $key = $keyValue[0]
  65. $value = $keyValue[1]
  66. $featuresConfigContent = $featuresConfigContent -replace "(#define +)($key)( +.+)(( |$)+)", "`$1`$2 $value`$4"
  67. }
  68. Set-Content -Path "totp/features_config.h" -NoNewline -Value $featuresConfigContent
  69. Set-Content -Path "totp/application.fam" -NoNewline -Value $appManifestContent
  70. }
  71. function Build-Run {
  72. param (
  73. [string]$FeaturesSuffix
  74. )
  75. foreach ($build_command in $build_commands) {
  76. Write-Host "Building $($build_command.Name)"
  77. $build_path = Join-Path -Path $build_command.FirmwarePath -ChildPath "build"
  78. if (Test-Path -PathType Container $build_path) {
  79. Remove-Item "$build_path\*" -Recurse -Force
  80. }
  81. Features-Configure -set "TOTP_TARGET_FIRMWARE=$($build_command.FW_CDEF)"
  82. ./fbt $build_command.FbtSwitch COMPACT=1 DEBUG=0 VERBOSE=0 fap_totp
  83. $latest_dir = Get-LatestDirectory -Path $build_path
  84. $build_output_artifact = "build\$($build_command.ArtifactName -replace '{FEATURES_SUFFIX}',$FeaturesSuffix)"
  85. Copy-Item "$build_path\$latest_dir\.extapps\totp.fap" -Destination $build_output_artifact
  86. Write-Host "Artifacts for $($build_command.Name) stored at $build_output_artifact"
  87. }
  88. }
  89. Write-Information 'Building with all the features enables'
  90. Features-Configure -enable TOTP_BADBT_TYPE_ENABLED,TOTP_AUTOMATION_ICONS_ENABLED
  91. Build-Run -FeaturesSuffix ''
  92. Write-Information 'Building with BadBT but without BadBT icon'
  93. Features-Configure -disable TOTP_AUTOMATION_ICONS_ENABLED
  94. Build-Run -FeaturesSuffix '_badbt-wo-icon'
  95. Write-Information 'Building without BadBT'
  96. Features-Configure -disable TOTP_BADBT_TYPE_ENABLED,TOTP_AUTOMATION_ICONS_ENABLED
  97. Build-Run -FeaturesSuffix '_no-badbt'
  98. Features-Configure -enable TOTP_BADBT_TYPE_ENABLED,TOTP_AUTOMATION_ICONS_ENABLED -set TOTP_TARGET_FIRMWARE=TOTP_FIRMWARE_XTREME
  99. Pop-Location