Package-Windows.ps1 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. Log-Group "Archiving ${ProductName}..."
  53. $CompressArgs = @{
  54. Path = (Get-ChildItem -Path "${ProjectRoot}/release/${Configuration}" -Exclude "${OutputName}*.*")
  55. CompressionLevel = 'Optimal'
  56. DestinationPath = "${ProjectRoot}/release/${OutputName}.zip"
  57. Verbose = ($Env:CI -ne $null)
  58. }
  59. Compress-Archive -Force @CompressArgs
  60. Log-Group
  61. if ( ( $BuildInstaller ) ) {
  62. Log-Group "Packaging ${ProductName}..."
  63. $IsccFile = "${ProjectRoot}/build_${Target}/installer-Windows.generated.iss"
  64. if ( ! ( Test-Path -Path $IsccFile ) ) {
  65. throw 'InnoSetup install script not found. Run the build script or the CMake build and install procedures first.'
  66. }
  67. Log-Information 'Creating InnoSetup installer...'
  68. Push-Location -Stack BuildTemp
  69. Ensure-Location -Path "${ProjectRoot}/release"
  70. Copy-Item -Path ${Configuration} -Destination Package -Recurse
  71. Invoke-External iscc ${IsccFile} /O"${ProjectRoot}/release" /F"${OutputName}-Installer"
  72. Remove-Item -Path Package -Recurse
  73. Pop-Location -Stack BuildTemp
  74. Log-Group
  75. }
  76. }
  77. Package