build.ps1 3.3 KB

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