Package-Windows.ps1 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. [CmdletBinding()]
  2. param(
  3. [ValidateSet('x64')]
  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. $BuildSpecFile = "${ProjectRoot}/buildspec.json"
  31. $UtilityFunctions = Get-ChildItem -Path $PSScriptRoot/utils.pwsh/*.ps1 -Recurse
  32. foreach( $Utility in $UtilityFunctions ) {
  33. Write-Debug "Loading $($Utility.FullName)"
  34. . $Utility.FullName
  35. }
  36. Install-BuildDependencies -WingetFile "${ScriptHome}/.Wingetfile"
  37. $GitDescription = Invoke-External git describe --tags --long
  38. $Tokens = ($GitDescription -split '-')
  39. $CommitVersion = $Tokens[0..$($Tokens.Count - 3)] -join '-'
  40. $CommitHash = $($Tokens[-1]).SubString(1)
  41. $CommitDistance = $Tokens[-2]
  42. if ( $CommitDistance -gt 0 ) {
  43. $OutputName = "obs-studio-${CommitVersion}-${CommitHash}"
  44. } else {
  45. $OutputName = "obs-studio-${CommitVersion}"
  46. }
  47. $CpackArgs = @(
  48. '-C', "${Configuration}"
  49. )
  50. if ( $DebugPreference -eq 'Continue' ) {
  51. $CpackArgs += ('--verbose')
  52. }
  53. Log-Group "Packaging obs-studio..."
  54. Push-Location -Stack PackageTemp "build_${Target}"
  55. cpack @CpackArgs
  56. $Package = Get-ChildItem -filter "obs-studio-*-windows-x64.zip" -File
  57. Move-Item -Path $Package -Destination "${OutputName}-windows-x64.zip"
  58. Pop-Location -Stack PackageTemp
  59. }
  60. Package