12e5b6d6dSopenharmony_ci# Copyright (C) 2016 and later: Unicode, Inc. and others.
22e5b6d6dSopenharmony_ci# License & terms of use: http://www.unicode.org/copyright.html
32e5b6d6dSopenharmony_ci#-------------------------
42e5b6d6dSopenharmony_ci# Script: icu\packaging\distrelease.ps1
52e5b6d6dSopenharmony_ci# Author: Steven R. Loomis
62e5b6d6dSopenharmony_ci# Date: 2017-04-14
72e5b6d6dSopenharmony_ci#-------------------------
82e5b6d6dSopenharmony_ci#
92e5b6d6dSopenharmony_ci# This builds a zipfile containing the 64-bit (x64) and/or 32-bit (x86) Windows binaries.
102e5b6d6dSopenharmony_ci# (Note: The zipfile does not include the UWP binaries.)
112e5b6d6dSopenharmony_ci#
122e5b6d6dSopenharmony_ci# Usage: (after building ICU using MSVC) 
132e5b6d6dSopenharmony_ci#  (bring up Powershell ISE)
142e5b6d6dSopenharmony_ci#    cd C:\icu\icu4c\
152e5b6d6dSopenharmony_ci#    Set-ExecutionPolicy -Scope Process Unrestricted
162e5b6d6dSopenharmony_ci#    .\packaging\distrelease.ps1 -arch "x64 or x86 or ARM64"
172e5b6d6dSopenharmony_ci#
182e5b6d6dSopenharmony_ci# Will emit: c:\icu4c\icu\source\dist\icu-windows.zip
192e5b6d6dSopenharmony_ci#
202e5b6d6dSopenharmony_ci#
212e5b6d6dSopenharmony_ci# You will get warnings from the execution policy and the script itself.
222e5b6d6dSopenharmony_ci#  see https://docs.microsoft.com/powershell/module/microsoft.powershell.core/about/about_execution_policies?view=powershell-5.1&viewFallbackFrom=powershell-Microsoft.PowerShell.Core 
232e5b6d6dSopenharmony_ci#    for more about execution policies.
242e5b6d6dSopenharmony_ci
252e5b6d6dSopenharmony_ciParam(
262e5b6d6dSopenharmony_ci  [string]$arch = "x64" # use x64 as default
272e5b6d6dSopenharmony_ci)
282e5b6d6dSopenharmony_ci
292e5b6d6dSopenharmony_ci$icuDir = Split-Path -Path $MyInvocation.MyCommand.Definition -Parent
302e5b6d6dSopenharmony_ci$icuDir = Resolve-Path -Path '$icuDir\..'
312e5b6d6dSopenharmony_ci
322e5b6d6dSopenharmony_ciecho  $icuDir
332e5b6d6dSopenharmony_ci
342e5b6d6dSopenharmony_ci# ok, create some work areas
352e5b6d6dSopenharmony_ciNew-Item -Path "$icuDir\source\dist" -ErrorAction SilentlyContinue -ItemType "directory"
362e5b6d6dSopenharmony_ci$source = "$icuDir\source\dist\icu"
372e5b6d6dSopenharmony_ciGet-ChildItem -Path $source -ErrorAction SilentlyContinue | Remove-Item -Recurse
382e5b6d6dSopenharmony_ciNew-Item -Path $source -ItemType "directory" -ErrorAction SilentlyContinue
392e5b6d6dSopenharmony_ci
402e5b6d6dSopenharmony_ci# copy required stuff
412e5b6d6dSopenharmony_ciif ($arch -eq "x64")
422e5b6d6dSopenharmony_ci{
432e5b6d6dSopenharmony_ci    Copy-Item -Path "$icuDir\lib64" -Destination $source -Recurse
442e5b6d6dSopenharmony_ci    Copy-Item -Path "$icuDir\bin64" -Destination $source -Recurse
452e5b6d6dSopenharmony_ci}
462e5b6d6dSopenharmony_cielseif ($arch -eq "x86")
472e5b6d6dSopenharmony_ci{
482e5b6d6dSopenharmony_ci    Copy-Item -Path "$icuDir\lib" -Destination $source -Recurse
492e5b6d6dSopenharmony_ci    Copy-Item -Path "$icuDir\bin" -Destination $source -Recurse
502e5b6d6dSopenharmony_ci}
512e5b6d6dSopenharmony_cielseif ($arch -eq "ARM64")
522e5b6d6dSopenharmony_ci{
532e5b6d6dSopenharmony_ci    Copy-Item -Path "$icuDir\libARM64" -Destination $source -Recurse
542e5b6d6dSopenharmony_ci    Copy-Item -Path "$icuDir\binARM64" -Destination $source -Recurse
552e5b6d6dSopenharmony_ci}
562e5b6d6dSopenharmony_cielse
572e5b6d6dSopenharmony_ci{
582e5b6d6dSopenharmony_ci    $filename = $MyInvocation.MyCommand.Name;
592e5b6d6dSopenharmony_ci    echo "Invalid architecture."
602e5b6d6dSopenharmony_ci    echo "Usage: $filename -arch `"x64 or x86`""
612e5b6d6dSopenharmony_ci    exit
622e5b6d6dSopenharmony_ci}
632e5b6d6dSopenharmony_ci
642e5b6d6dSopenharmony_ciCopy-Item -Path "$icuDir\include" -Destination $source -Recurse
652e5b6d6dSopenharmony_ciCopy-Item -Path "$icuDir\APIChangeReport.html" -Destination $source -Recurse
662e5b6d6dSopenharmony_ciCopy-Item -Path "$icuDir\icu4c.css" -Destination $source -Recurse
672e5b6d6dSopenharmony_ciCopy-Item -Path "$icuDir\LICENSE" -Destination $source -Recurse
682e5b6d6dSopenharmony_ciCopy-Item -Path "$icuDir\readme.html" -Destination $source -Recurse
692e5b6d6dSopenharmony_ci
702e5b6d6dSopenharmony_ci
712e5b6d6dSopenharmony_ci$destination = "$icuDir\source\dist\icu-windows.zip"
722e5b6d6dSopenharmony_ciRemove-Item -Path $destination -ErrorAction Continue
732e5b6d6dSopenharmony_ciEcho $source
742e5b6d6dSopenharmony_ciEcho $destination
752e5b6d6dSopenharmony_ci
762e5b6d6dSopenharmony_ci# Use 7Zip to build zip file to avoid backslash path separator errors when unzipping on CygWin
772e5b6d6dSopenharmony_ciif (-not (Get-Module -ListAvailable -Name 7Zip4PowerShell)) 
782e5b6d6dSopenharmony_ci{
792e5b6d6dSopenharmony_ci    Install-Module 7Zip4PowerShell -Force -Verbose
802e5b6d6dSopenharmony_ci} 
812e5b6d6dSopenharmony_ciCompress-7Zip $source -ArchiveFileName $destination -Format Zip
822e5b6d6dSopenharmony_ci
832e5b6d6dSopenharmony_ciecho $destination