Package-Windows.ps1 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. [CmdletBinding()]
  2. param(
  3. [ValidateSet('Debug', 'RelWithDebInfo', 'Release', 'MinSizeRel')]
  4. [string] $Configuration = 'RelWithDebInfo',
  5. [ValidateSet('x86', 'x64', 'x86+x64')]
  6. [string] $Target,
  7. [switch] $BuildInstaller = $false
  8. )
  9. $ErrorActionPreference = 'Stop'
  10. if ( $DebugPreference -eq 'Continue' ) {
  11. $VerbosePreference = 'Continue'
  12. $InformationPreference = 'Continue'
  13. }
  14. if ( $PSVersionTable.PSVersion -lt '7.0.0' ) {
  15. Write-Warning 'The obs-deps PowerShell build script requires PowerShell Core 7. Install or upgrade your PowerShell version: https://aka.ms/pscore6'
  16. exit 2
  17. }
  18. function Package {
  19. trap {
  20. Write-Error $_
  21. exit 2
  22. }
  23. $ScriptHome = $PSScriptRoot
  24. $ProjectRoot = Resolve-Path -Path "$PSScriptRoot/../.."
  25. $BuildSpecFile = "${ProjectRoot}/buildspec.json"
  26. $UtilityFunctions = Get-ChildItem -Path $PSScriptRoot/utils.pwsh/*.ps1 -Recurse
  27. foreach( $Utility in $UtilityFunctions ) {
  28. Write-Debug "Loading $($Utility.FullName)"
  29. . $Utility.FullName
  30. }
  31. $BuildSpec = Get-Content -Path ${BuildSpecFile} -Raw | ConvertFrom-Json
  32. $ProductName = $BuildSpec.name
  33. $ProductVersion = $BuildSpec.version
  34. $OutputName = "${ProductName}-${ProductVersion}-windows-${Target}"
  35. Install-BuildDependencies -WingetFile "${ScriptHome}/.Wingetfile"
  36. Log-Information "Packaging ${ProductName}..."
  37. $RemoveArgs = @{
  38. ErrorAction = 'SilentlyContinue'
  39. Path = @(
  40. "${ProjectRoot}/release/${ProductName}-*-windows-*.zip"
  41. "${ProjectRoot}/release/${ProductName}-*-windows-*.exe"
  42. )
  43. }
  44. Remove-Item @RemoveArgs
  45. if ( ( $BuildInstaller ) ) {
  46. if ( $Target -eq 'x86+x64' ) {
  47. $IsccCandidates = Get-ChildItem -Recurse -Path '*.iss'
  48. if ( $IsccCandidates.length -gt 0 ) {
  49. $IsccFile = $IsccCandidates[0].FullName
  50. } else {
  51. $IsccFile = ''
  52. }
  53. } else {
  54. $IsccFile = "${ProjectRoot}/build_${Target}/installer-Windows.generated.iss"
  55. }
  56. if ( ! ( Test-Path -Path $IsccFile ) ) {
  57. throw 'InnoSetup install script not found. Run the build script or the CMake build and install procedures first.'
  58. }
  59. Log-Information 'Creating InnoSetup installer...'
  60. Push-Location -Stack BuildTemp
  61. Ensure-Location -Path "${ProjectRoot}/release"
  62. Invoke-External iscc ${IsccFile} /O. /F"${OutputName}-Installer"
  63. Pop-Location -Stack BuildTemp
  64. }
  65. $CompressArgs = @{
  66. Path = (Get-ChildItem -Path "${ProjectRoot}/release" -Exclude "${OutputName}*.*")
  67. CompressionLevel = 'Optimal'
  68. DestinationPath = "${ProjectRoot}/release/${OutputName}.zip"
  69. }
  70. Compress-Archive -Force @CompressArgs
  71. }
  72. Package