04_package_plugin.ps1 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. Param(
  2. [Switch]$Help = $(if (Test-Path variable:Help) { $Help }),
  3. [Switch]$Quiet = $(if (Test-Path variable:Quiet) { $Quiet }),
  4. [Switch]$Verbose = $(if (Test-Path variable:Verbose) { $Verbose }),
  5. [Switch]$BuildInstaller = $(if ($BuildInstaller.isPresent) { $true }),
  6. [String]$ProductName = $(if (Test-Path variable:ProductName) { "${ProductName}" } else { "obs-plugin" }),
  7. [Switch]$CombinedArchs = $(if ($CombinedArchs.isPresent) { $true }),
  8. [String]$BuildDirectory = $(if (Test-Path variable:BuildDirectory) { "${BuildDirectory}" } else { "build" }),
  9. [String]$BuildArch = $(if (Test-Path variable:BuildArch) { "${BuildArch}" } else { (Get-WmiObject Win32_OperatingSystem).OSArchitecture}),
  10. [String]$BuildConfiguration = $(if (Test-Path variable:BuildConfiguration) { "${BuildConfiguration}" } else { "RelWithDebInfo" })
  11. )
  12. ##############################################################################
  13. # Windows libobs plugin package function
  14. ##############################################################################
  15. #
  16. # This script file can be included in build scripts for Windows or run
  17. # directly with the -Standalone switch
  18. #
  19. ##############################################################################
  20. $ErrorActionPreference = "Stop"
  21. function Package-OBS-Plugin {
  22. Param(
  23. [String]$BuildDirectory = $(if (Test-Path variable:BuildDirectory) { "${BuildDirectory}" }),
  24. [String]$BuildArch = $(if (Test-Path variable:BuildArch) { "${BuildArch}" }),
  25. [String]$BuildConfiguration = $(if (Test-Path variable:BuildConfiguration) { "${BuildConfiguration}" })
  26. )
  27. Write-Status "Package plugin ${ProductName}"
  28. Ensure-Directory ${CheckoutDir}
  29. if ($CombinedArchs.isPresent) {
  30. if (!(Test-Path ${CheckoutDir}/release/obs-plugins/64bit)) {
  31. cmake --build ${BuildDirectory}64 --config ${BuildConfiguration} -t install
  32. }
  33. if (!(Test-Path ${CheckoutDir}/release/obs-plugins/32bit)) {
  34. cmake --build ${BuildDirectory}32 --config ${BuildConfiguration} -t install
  35. }
  36. $CompressVars = @{
  37. Path = "${CheckoutDir}/release/*"
  38. CompressionLevel = "Optimal"
  39. DestinationPath = "${FileName}-Windows.zip"
  40. }
  41. Write-Step "Creating zip archive..."
  42. Compress-Archive -Force @CompressVars
  43. if(($BuildInstaller.isPresent) -And (Test-CommandExists "iscc")) {
  44. Write-Step "Creating installer..."
  45. & iscc ${CheckoutDir}/installer/installer-Windows.generated.iss /O. /F"${FileName}-Windows-Installer"
  46. }
  47. } elseif ($BuildArch -eq "64-bit") {
  48. cmake --build ${BuildDirectory}64 --config ${BuildConfiguration} -t install
  49. $CompressVars = @{
  50. Path = "${CheckoutDir}/release/*"
  51. CompressionLevel = "Optimal"
  52. DestinationPath = "${FileName}-Win64.zip"
  53. }
  54. Write-Step "Creating zip archive..."
  55. Compress-Archive -Force @CompressVars
  56. if(($BuildInstaller.isPresent) -And (Test-CommandExists "iscc")) {
  57. Write-Step "Creating installer..."
  58. & iscc ${CheckoutDir}/installer/installer-Windows.generated.iss /O. /F"${FileName}-Win64-Installer"
  59. }
  60. } elseif ($BuildArch -eq "32-bit") {
  61. cmake --build ${BuildDirectory}32 --config ${BuildConfiguration} -t install
  62. $CompressVars = @{
  63. Path = "${CheckoutDir}/release/*"
  64. CompressionLevel = "Optimal"
  65. DestinationPath = "${FileName}-Win32.zip"
  66. }
  67. Write-Step "Creating zip archive..."
  68. Compress-Archive -Force @CompressVars
  69. if(($BuildInstaller.isPresent) -And (Test-CommandExists "iscc")) {
  70. Write-Step "Creating installer..."
  71. & iscc ${CheckoutDir}/installer/installer-Windows.generated.iss /O. /F"${FileName}-Win32-Installer"
  72. }
  73. }
  74. }
  75. function Package-Plugin-Standalone {
  76. $CheckoutDir = git rev-parse --show-toplevel
  77. if (Test-Path ${CheckoutDir}/CI/include/build_environment.ps1) {
  78. . ${CheckoutDir}/CI/include/build_environment.ps1
  79. }
  80. . ${CheckoutDir}/CI/include/build_support_windows.ps1
  81. Ensure-Directory ${CheckoutDir}
  82. $GitBranch = git rev-parse --abbrev-ref HEAD
  83. $GitHash = git rev-parse --short HEAD
  84. $ErrorActionPreference = "SilentlyContiue"
  85. $GitTag = git describe --tags --abbrev=0
  86. $ErrorActionPreference = "Stop"
  87. if ($GitTag -eq $null) {
  88. $GitTag=$ProductVersion
  89. }
  90. $FileName = "${ProductName}-${GitTag}-${GitHash}"
  91. Package-OBS-Plugin
  92. }
  93. function Print-Usage {
  94. $Lines = @(
  95. "Usage: ${MyInvocation.MyCommand.Name}",
  96. "-Help : Print this help",
  97. "-Quiet : Suppress most build process output",
  98. "-Verbose : Enable more verbose build process output",
  99. "-CombinedArchs : Create combined architecture package",
  100. "-BuildDirectory : Directory to use for builds - Default: build64 on 64-bit systems, build32 on 32-bit systems",
  101. "-BuildArch : Build architecture to use (32bit or 64bit) - Default: local architecture",
  102. "-BuildConfiguration : Build configuration to use - Default: RelWithDebInfo"
  103. )
  104. $Lines | Write-Host
  105. }
  106. if(!(Test-Path variable:_RunObsBuildScript)) {
  107. if($Help.isPresent) {
  108. Print-Usage
  109. exit 0
  110. }
  111. Package-Plugin-Standalone
  112. }