Package-Windows.ps1 3.0 KB

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