From 5235fed2c7e3ff175163e3dc4dc4725cd83212d8 Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Wed, 10 Aug 2016 12:49:16 -0700 Subject: [PATCH] Refactor Start-PSPackage Moved Unix package code into New-UnixPackage, switching on $Types to call the appropriate function given the list of types. Also fixed bug with chmod on a symlink; it was unnecessary. --- .gitignore | 4 + assets/{powershellorig => powershell.1.ronn} | 0 build.psm1 | 169 ++++++++++++------- 3 files changed, 108 insertions(+), 65 deletions(-) rename assets/{powershellorig => powershell.1.ronn} (100%) diff --git a/.gitignore b/.gitignore index 92a2b0dbe..5b084185d 100644 --- a/.gitignore +++ b/.gitignore @@ -43,6 +43,10 @@ powershell.version # default location for produced nuget packages /nuget-artifacts +# generated man files +/assets/powershell.1 +/assets/powershell.1.gz + # resgen output gen diff --git a/assets/powershellorig b/assets/powershell.1.ronn similarity index 100% rename from assets/powershellorig rename to assets/powershell.1.ronn diff --git a/build.psm1 b/build.psm1 index 3a8a2b05d..57ecf12b6 100644 --- a/build.psm1 +++ b/build.psm1 @@ -690,7 +690,7 @@ function Start-PSBootstrap { brew install $Deps } - # Install [fpm](https://github.com/jordansissel/fpm) + # Install [fpm](https://github.com/jordansissel/fpm) and [ronn](https://github.com/rtomayko/ronn) if ($Package) { gem install fpm ronn } @@ -814,24 +814,15 @@ function Start-PSPackage { [CmdletBinding()]param( # PowerShell packages use Semantic Versioning http://semver.org/ [string]$Version, - # Package iteration version (rarely changed) - [int]$Iteration = 1, - # Ubuntu, CentOS, and OS X packages are supported - [ValidateSet("deb", "osxpkg", "rpm")] - [string]$Type + + # Package name + [string]$Name = "powershell", + + # Ubuntu, CentOS, and OS X, and Windows packages are supported + [ValidateSet("deb", "osxpkg", "rpm", "msi", "appx")] + [string[]]$Types ) - $Description = @" -PowerShell is an automation and configuration management platform. -It consists of a cross-platform command-line shell and associated scripting language. -"@ - - #runn ronn to convert man page to roff - $manorigfile = $PSScriptRoot + "/assets/powershellorig" - $mantxtfile = $PSScriptRoot + "/assets/powershell" - $manronnfile = $PSScriptRoot + "/assets/powershell.1" - $gzipmanfile = $PSScriptRoot + "/assets/powershell.1.gz" - # Use Git tag if not given a version if (-not $Version) { $Version = (git --git-dir="$PSScriptRoot/.git" describe) -Replace '^v' @@ -840,37 +831,87 @@ It consists of a cross-platform command-line shell and associated scripting lang $Source = Split-Path -Parent (Get-PSOutput -Options (New-PSOptions -Publish)) Write-Verbose "Packaging $Source" - if ($IsWindows) { - # Product Guid needs to be unique for every PowerShell version to allow SxS install - $productGuid = [guid]::NewGuid() - $msiPackagePath = New-MSIPackage -ProductSourcePath $Source -ProductVersion $Version -AssetsPath "$PSScriptRoot\assets" -LicenseFilePath "$PSScriptRoot\assets\license.rtf" -ProductGuid $productGuid - $appxPackagePath = New-AppxPackage -PackageVersion $Version -SourcePath $Source -AssetsPath "$PSScriptRoot\Assets" - - $packages = @($msiPackagePath, $appxPackagePath) - - return $packages - } - - if (-not (Get-Command "fpm" -ErrorAction SilentlyContinue)) { - throw "Build dependency 'fpm' not found in PATH! See: https://github.com/jordansissel/fpm" - } - # Decide package output type - if (-not $Type) { - $Type = if ($IsLinux) { - if ($LinuxInfo.ID -match 'ubuntu') { + if (-not $Types) { + $Types = if ($IsLinux) { + if ($LinuxInfo.ID -match "ubuntu") { "deb" - } elseif ($LinuxInfo.ID -match 'centos') { + } elseif ($LinuxInfo.ID -match "centos") { "rpm" } else { throw "Building packages for $($LinuxInfo.PRETTY_NAME) is unsupported!" } } elseif ($IsOSX) { - 'osxpkg' + "osxpkg" + } elseif ($IsWindows) { + "msi", "appx" } - Write-Warning "-Type was not specified, continuing with $Type" + Write-Warning "-Types was not specified, continuing with $Types" } + switch ($Types) { + "msi" { + $Arguments = @{ + ProductSourcePath = $Source; + ProductVersion = $Version; + AssetsPath = "$PSScriptRoot\assets"; + LicenseFilePath = "$PSScriptRoot\assets\license.rtf"; + # Product Guid needs to be unique for every PowerShell version to allow SxS install + ProductGuid = [Guid]::NewGuid() + } + New-MSIPackage @Arguments + } + "appx" { + $Arguments = @{ + PackageVersion = $Version; + SourcePath = $Source; + AssetsPath = "$PSScriptRoot\assets" + } + New-AppxPackage @Arguments + } + default { + $Arguments = @{ + Type = $_; + Source = $Source; + Name = $Name; + Version = $Version + } + New-UnixPackage @Arguments + } + } +} + + +function New-UnixPackage { + [CmdletBinding()]param( + [Parameter(Mandatory)] + [ValidateSet("deb", "osxpkg", "rpm")] + [string]$Type, + + [Parameter(Mandatory)] + [string]$Source, + + [Parameter(Mandatory)] + [string]$Name, + + [Parameter(Mandatory)] + [string]$Version, + + # Package iteration version (rarely changed) + [int]$Iteration = 1 + ) + + foreach ($Dependency in "fpm", "ronn") { + if (!(precheck $Dependency "Package dependency '$Dependency' not found. Run Start-PSBootstrap -Publish")) { + throw "Dependency precheck failed!" + } + } + + $Description = @" +PowerShell is an automation and configuration management platform. +It consists of a cross-platform command-line shell and associated scripting language. +"@ + # Follow the Filesystem Hierarchy Standard for Linux and OS X $Destination = if ($IsLinux) { "/opt/microsoft/powershell" @@ -887,35 +928,33 @@ It consists of a cross-platform command-line shell and associated scripting lang New-Item -Force -ItemType SymbolicLink -Path /tmp/powershell -Target $Destination/powershell >$null - # there is a weired bug in fpm + # there is a weird bug in fpm # if the target of the powershell symlink exists, `fpm` aborts # with a `utime` error on OS X. # so we move it to make symlink broken $symlink_dest = "$Destination/powershell" $hack_dest = "./_fpm_symlink_hack_powershell" - if ($IsOSX) - { - if (Test-Path $symlink_dest) - { + if ($IsOSX) { + if (Test-Path $symlink_dest) { Write-Warning "Move $symlink_dest to $hack_dest (fpm utime bug)" Move-Item $symlink_dest $hack_dest } } - #copy backup to new file - cp $manorigfile $mantxtfile - - #run ronn on assets file - ronn $mantxtfile + # run ronn to convert man page to roff + $RoffFile = Join-Path $PSScriptRoot "/assets/powershell.1" + $RonnFile = "$RoffFile.ronn" + $GzipFile = "$RoffFile.gz" + $ManFile = Join-Path "/usr/local/share/man/man1" (Split-Path -Leaf $GzipFile) - #rename ronn file - mv $mantxtfile $manronnfile + # Run ronn on assets file + Start-NativeExecution { ronn --roff $RonnFile } - #gzip in assets directory - gzip -f $manronnfile + # gzip in assets directory + Start-NativeExecution { gzip -f $RoffFile } # Change permissions for packaging - chmod -R go=u $Source /tmp/powershell + Start-NativeExecution { chmod -R go=u $Source $GzipFile } $libunwind = switch ($Type) { "deb" { "libunwind8" } @@ -927,10 +966,9 @@ It consists of a cross-platform command-line shell and associated scripting lang "rpm" { "libicu" } } - $Arguments = @( "--force", "--verbose", - "--name", "powershell", + "--name", $Name, "--version", $Version, "--iteration", $Iteration, "--maintainer", "PowerShell Team ", @@ -948,24 +986,25 @@ It consists of a cross-platform command-line shell and associated scripting lang "-t", $Type, "-s", "dir", "$Source/=$Destination/", - "assets/powershell.1.gz=/usr/local/share/man/man1/powershell.1.gz", + "$GzipFile=$ManFile", "/tmp/powershell=$Link" ) # Build package - fpm $Arguments - - if ($IsOSX) - { - # this is continuation of a fpm hack for a weired bug - if (Test-Path $hack_dest) - { - Write-Warning "Move $hack_dest to $symlink_dest (fpm utime bug)" - Move-Item $hack_dest $symlink_dest + try { + Start-NativeExecution { fpm $Arguments } + } finally { + if ($IsOSX) { + # this is continuation of a fpm hack for a weird bug + if (Test-Path $hack_dest) { + Write-Warning "Move $hack_dest to $symlink_dest (fpm utime bug)" + Move-Item $hack_dest $symlink_dest + } } } } + function Publish-NuGetFeed { param(