Package-Windows.ps1 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. [CmdletBinding()]
  2. param(
  3. [ValidateSet('x64', 'arm64')]
  4. [string] $Target = 'x64',
  5. [ValidateSet('Debug', 'RelWithDebInfo', 'Release', 'MinSizeRel')]
  6. [string] $Configuration = 'RelWithDebInfo'
  7. )
  8. $ErrorActionPreference = 'Stop'
  9. if ( $DebugPreference -eq 'Continue' ) {
  10. $VerbosePreference = 'Continue'
  11. $InformationPreference = 'Continue'
  12. }
  13. if ( $env:CI -eq $null ) {
  14. throw "Package-Windows.ps1 requires CI environment"
  15. }
  16. if ( ! ( [System.Environment]::Is64BitOperatingSystem ) ) {
  17. throw "obs-studio requires a 64-bit system to build and run."
  18. }
  19. if ( $PSVersionTable.PSVersion -lt '7.2.0' ) {
  20. Write-Warning 'The obs-studio packaging script requires PowerShell Core 7. Install or upgrade your PowerShell version: https://aka.ms/pscore6'
  21. exit 2
  22. }
  23. function Package {
  24. trap {
  25. Write-Error $_
  26. exit 2
  27. }
  28. $ScriptHome = $PSScriptRoot
  29. $ProjectRoot = Resolve-Path -Path "$PSScriptRoot/../.."
  30. $UtilityFunctions = Get-ChildItem -Path $PSScriptRoot/utils.pwsh/*.ps1 -Recurse
  31. foreach( $Utility in $UtilityFunctions ) {
  32. Write-Debug "Loading $($Utility.FullName)"
  33. . $Utility.FullName
  34. }
  35. Install-BuildDependencies -WingetFile "${ScriptHome}/.Wingetfile"
  36. $GitDescription = Invoke-External git describe --tags --long
  37. $Tokens = ($GitDescription -split '-')
  38. $CommitVersion = $Tokens[0..$($Tokens.Count - 3)] -join '-'
  39. $CommitHash = $($Tokens[-1]).SubString(1)
  40. $CommitDistance = $Tokens[-2]
  41. if ( $CommitDistance -gt 0 ) {
  42. $OutputName = "obs-studio-${CommitVersion}-${CommitHash}"
  43. } else {
  44. $OutputName = "obs-studio-${CommitVersion}"
  45. }
  46. $CpackArgs = @(
  47. '-C', "${Configuration}"
  48. )
  49. if ( $DebugPreference -eq 'Continue' ) {
  50. $CpackArgs += ('--verbose')
  51. }
  52. Log-Group "Packaging obs-studio..."
  53. Push-Location -Stack PackageTemp "build_${Target}"
  54. cpack @CpackArgs
  55. $Package = Get-ChildItem -filter "obs-studio-*-windows-${Target}.zip" -File
  56. Move-Item -Path $Package -Destination "${OutputName}-windows-${Target}.zip"
  57. Pop-Location -Stack PackageTemp
  58. }
  59. Package